### Fortran AMR Initialization Example Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst Provides a basic structure for an AMReX program using Fortran. It shows the necessary calls to initialize and finalize AMReX and its AMR core infrastructure, along with placeholders for user-defined initialization and finalization routines. ```Fortran program main use amrex_amr_module implicit none call amrex_init() call amrex_amrcore_init() call my_amr_init() ! user's own code, not part of AMReX ! ... call my_amr_finalize() ! user's own code, not part of AMReX call amrex_amrcore_finalize() call amrex_finalize() end program main ``` -------------------------------- ### Configure AMReX Library Installation Path Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/BuildingAMReX.rst Example of using the `./configure` script to specify a custom installation prefix for the AMReX library. ```bash ./configure --prefix=[AMReX library path] ``` -------------------------------- ### Initialize and Print Hello World in Fortran Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst This Fortran code demonstrates the basic initialization and finalization of AMReX, along with a simple parallel print statement. It utilizes the `amrex_base_module` for core functionalities. ```Fortran program main use amrex_base_module implicit none call amrex_init() if (amrex_parallel_ioprocessor()) then print *, "Hello world!" end if call amrex_finalize() end program main ``` -------------------------------- ### AMReX Boundary Condition Setup Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Basics.rst Provides an example of setting up boundary conditions for AMReX using BCRec objects. It iterates through components and dimensions to define boundary types, handling periodic and non-periodic cases. ```c++ // Set up BC; see ``amrex/Src/Base/AMReX_BC_TYPES.H`` for supported types Vector bc(phi.nComp()); for (int n = 0; n < phi.nComp(); ++n) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (geom.isPeriodic(idim)) { bc[n].setLo(idim, BCType::int_dir); // interior bc[n].setHi(idim, BCType::int_dir); } else { bc[n].setLo(idim, BCType::foextrap); // first-order extrapolation bc[n].setHi(idim, BCType::foextrap); } } } ``` -------------------------------- ### Build and Run AMReX with MPI and OpenMP Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/GettingStarted.rst Demonstrates how to build an AMReX application with both MPI and OpenMP support and provides an example command to run it. It also shows the expected output upon initialization. ```console USE_MPI=TRUE USE_OMP=TRUE OMP_NUM_THREADS=4 mpiexec -n 2 ./main3d.gnu.DEBUG.MPI.OMP.ex ``` -------------------------------- ### Build AMReX Geometry in Fortran Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst This Fortran example demonstrates how to construct an `amrex_geometry` object, which wraps AMReX's `Geometry` class. It involves defining an `amrex_box` for the domain and then building the geometry object. ```Fortran integer :: n_cell type(amrex_box) :: domain type(amrex_geometry) : geom ! n_cell = ... ! Define a single box covering the domain domain = amrex_box((/0,0,0/), (/n_cell-1, n_cell-1, n_cell-1/)) ! This defines a amrex_geometry object. call amrex_geometry_build(geom, domain) ! ! ... ! call amrex_geometry_destroy(geom) ``` -------------------------------- ### Build and Run 2D Heat Equation Solver Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/GettingStarted.rst Instructions for building a 2D executable for the Heat Equation solver example and how to run it with an input file. It also mentions the output files generated. ```console cd amrex-tutorials/ExampleCodes/Basic/HeatEquation_EX1_C/Exec make DIM=2 ./main2d.gnu.ex inputs_2d ``` -------------------------------- ### AMReX Hello World C++ Example Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/GettingStarted.rst A basic 'Hello World' program demonstrating the core AMReX initialization, version display, and finalization. It requires including AMReX header files and using the 'amrex' namespace. ```c++ #include #include int main(int argc, char* argv[]) { amrex::Initialize(argc,argv); amrex::Print() << "Hello world from AMReX version " << amrex::Version() << "\n"; amrex::Finalize(); } ``` -------------------------------- ### Fill Boundary and Parallel Copy for amrex_multifab Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst This example demonstrates parallel communication operations for amrex_multifab: fill_boundary and parallel_copy. It shows how to fill ghost cells and copy data from another multifab, highlighting the component indexing and similarity to C++ counterparts. ```Fortran type(amrex_geometry) :: geom type(amrex_multifab) :: mf, mfsrc ! ... call mf%fill_boundary(geom) ! Fill all components call mf%fill_boundary(geom, 1, 3) ! Fill 3 components starting with component 1 call mf%parallel_copy(mfsrc, geom) ! Parallel copy from another multifab ``` -------------------------------- ### Building AMReX with CMake (Basic) Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/BuildingAMReX.rst This console snippet demonstrates the fundamental steps to build and install AMReX using CMake. It involves creating a build directory, navigating into it, invoking CMake with build type and installation prefix, and then running 'make install'. ```bash mkdir /path/to/builddir cd /path/to/builddir cmake [options] -DCMAKE_BUILD_TYPE=[Debug|Release|RelWithDebInfo|MinSizeRel] -DCMAKE_INSTALL_PREFIX=/path/to/installdir /path/to/amrex make install make test_install # optional step to test if the installation is working ``` -------------------------------- ### Fortran AMR Virtual Function Interface Setup Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst Defines the subroutine signature for setting up virtual functions in AMReX's Fortran AMR core. It specifies the procedures required for level creation, clearing, and error estimation, along with their expected argument types. ```Fortran subroutine amrex_init_virtual_functions (mk_lev_scrtch, mk_lev_crse, & mk_lev_re, clr_lev, err_est) ! Make a new level from scratch using provided boxarray and distromap ! Only used during initialization. procedure(amrex_make_level_proc) :: mk_lev_scrtch ! Make a new level using provided boxarray and distromap, and fill ! with interpolated coarse level data. procedure(amrex_make_level_proc) :: mk_lev_crse ! Remake an existing level using provided boxarray and distromap, ! and fill with existing fine and coarse data. procedure(amrex_make_level_proc) :: mk_lev_re ! Delete level data procedure(amrex_clear_level_proc) :: clr_lev ! Tag cells for refinement procedure(amrex_error_est_proc) :: err_est end subroutine amrex_init_virtual_functions ``` -------------------------------- ### Fortran amrex_multifab Assignment Example Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst Demonstrates the assignment operator for amrex_multifab objects in Fortran. It shows how assignment creates a shallow copy and affects data ownership, leading to potential issues if not handled carefully. ```Fortran type(amrex_multifab) :: mf1, mf2 call amrex_multifab_build(mf1, ...) call amrex_multifab_build(mf2, ...) ! At this point, both mf1 and mf2 are data owners mf2 = mf1 ! This will destroy the original data in mf2. ! Then mf2 becomes a shallow copy of mf1. ! mf1 is still the owner of the data. call amrex_multifab_destroy(mf1) ! mf2 no longer contains a valid pointer because mf1 has been destroyed. call amrex_multifab_destroy(mf2) ! But we still need to destroy it. ``` -------------------------------- ### Build amrex_boxarray and amrex_distromap Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst This snippet demonstrates the initialization of amrex_boxarray and amrex_distromap, which are fundamental for defining and distributing data across parallel processes. It involves building a boxarray from a domain and then creating a distribution map for it. ```Fortran type(amrex_boxarray) : ba type(amrex_distromap) :: dm ! n_cell = ... ! Define a single box covering the domain domain = amrex_box((/0,0,0/), (/n_cell-1, n_cell-1, n_cell-1/)) ! Initialize the boxarray "ba" from the single box "bx" call amrex_boxarray_build(ba, domain) ! Break up boxarray "ba" into chunks no larger than "max_grid_size" call ba%maxSize(max_grid_size) ! Build a DistributionMapping for the boxarray call amrex_distromap_build(dm, ba) ! ! ... ! call amrex_distromap_distromap(dm) call amrex_boxarray_destroy(ba) ``` -------------------------------- ### Build amrex_multifab Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst This code illustrates how to construct an amrex_multifab, a Fortran wrapper for the C++ MultiFab class. It shows the creation of both standard and nodal multifabs, specifying the number of components and ghost cells. ```Fortran integer :: ncomp, nghost type(amrex_boxarray) : ba type(amrex_distromap) :: dm type(amrex_multifab) :: mf, ndmf ! Build amrex_boxarray and amrex_distromap ! ncomp = ... ! nghost = ... ! ... ! Build amrex_multifab with ncomp component and nghost ghost cells call amrex_multifab_build(mf, ba, dm, ncomp, nghost) ! Build a nodal multifab call amrex_multifab_build(ndmf,ba,dm,ncomp,nghost,(/.true.,.true.,.true./)) ! ! ... ! call amrex_multifab_destroy(mf) call amrex_multifab_destroy(ndmf) ``` -------------------------------- ### Build AMReX BoxArray and DistributionMapping in Fortran Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst This Fortran code illustrates the creation of an `amrex_boxarray` and an `amrex_distromap`, which are wrappers for AMReX's `BoxArray` and `DistributionMapping` classes respectively. It shows the initial steps for defining grid structures. ```Fortran integer :: n_cell type(amrex_box) :: domain ``` -------------------------------- ### Build AMReX Code with SENSEI (CMake) Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Visualization.rst Configures the build process for AMReX codes using CMake, enabling SENSEI support and specifying the directory where SENSEI's CMake configuration is installed. Replace '' with the actual installation path. ```bash cmake -DAMReX_SENSEI=ON -DSENSEI_DIR=//cmake .. make -j4 -f GNUmakefile ``` -------------------------------- ### Initialize and Finalize AMReX Octree Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst Demonstrates the correct sequence for initializing and finalizing AMReX core functionalities along with the octree module. This includes calling `amrex_init`, `amrex_octree_int`, `amrex_amrcore_init`, and their corresponding finalize procedures. ```Fortran program main use amrex_amrcore_module use amrex_octree_module implicit none call amrex_init() call amrex_octree_int() ! This should be called before amrex_amrcore_init. call amrex_amrcore_init() call my_amr_init() ! user's own code, not part of AMReX ! ... call my_amr_finalize() ! user's own code, not part of AMReX call amrex_amrcore_finalize() call amrex_octree_finalize() call amrex_finalize() end program main ``` -------------------------------- ### C++: AMReX Doxygen API Documentation Example Source: https://github.com/amrex-codes/amrex/blob/development/CONTRIBUTING.md Provides an example of Doxygen comment blocks used for API documentation in AMReX, including brief and detailed descriptions, and parameter documentation. ```cpp /** * \brief A one line description. * * \param[in] variable A short description of the variable. * \param[inout] data The value of data is read and changed. * * A longer description can be included here. */ void MyFunction (int variable, MultiFab& data){ ... ``` -------------------------------- ### Configure GCC on macOS with Make.local Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/BuildingAMReX.rst An example `Make.local` configuration for building AMReX on macOS using GCC version 8, including specifying include paths for Homebrew installations. ```makefile CXX = g++-8 CC = gcc-8 FC = gfortran-8 F90 = gfortran-8 INCLUDE_LOCATIONS += /usr/local/include ``` -------------------------------- ### Build AMReX as a Library with GNU Make Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/BuildingAMReX_Chapter.rst In this approach, AMReX is built and installed as a separate library. Your application code then uses its own build system to link against the installed AMReX library. This requires the same prerequisites as the direct adoption method. ```Make make install ``` -------------------------------- ### Configure AMReX Tests with CMake Source: https://github.com/amrex-codes/amrex/blob/development/Tests/Amr/Advection_AmrCore/CMakeLists.txt This CMake script configures tests for the AMReX project. It iterates through spatial dimensions, defines source and input files, and calls a setup function for each dimension. The script dynamically adds source files and input files, including dimension-specific kernels. ```CMake foreach(D IN LISTS AMReX_SPACEDIM) if (D EQUAL 1) continue() endif () # List of source files set(_sources AdvancePhiAllLevels.cpp AdvancePhiAtLevel.cpp AmrCoreAdv.cpp AmrCoreAdv.H bc_fill.H) list(APPEND _sources DefineVelocity.cpp face_velocity.H Kernels.H main.cpp Tagging.H) list(APPEND _sources Src_K/Adv_K.H Src_K/compute_flux_${D}D_K.H Src_K/slope_K.H) list(TRANSFORM _sources PREPEND Source/) list(APPEND _sources Exec/Prob.H) # List of input files set(_input_files inputs-ci) list(TRANSFORM _input_files PREPEND "Exec/") setup_test(${D} _sources _input_files) unset( _sources ) unset( _input_files ) endforeach() ``` -------------------------------- ### NERSC: Setup Anaconda Python Environment for yt Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Visualization.rst This console command sequence shows how to set up a custom Anaconda Python environment on NERSC's Cori system for using the yt library. It involves loading a specific Python module, creating a new conda environment with numpy, and activating it, followed by installing yt using pip. ```console module load python/3.5-anaconda conda create -p $HOME/yt-conda numpy source activate $HOME/yt-conda pip install yt ``` -------------------------------- ### Install macOS Dependencies for Amrvis Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Visualization.rst Installs necessary dependencies for building Amrvis on macOS using Homebrew. This includes x11 (via xquartz) and openmotif. ```bash brew cask install xquartz brew install openmotif ``` -------------------------------- ### Example AMReX CUDA Application Output Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/GPU.rst This is an example of the output generated when running a basic AMReX CUDA application. It shows initialization messages, GPU memory information, and AMReX version details. ```console $ ./main3d.gnu.DEBUG.CUDA.ex Initializing CUDA... CUDA initialized with 1 GPU AMReX (19.06-404-g0455b168b69c-dirty) initialized Hello world from AMReX version 19.06-404-g0455b168b69c-dirty Total GPU global memory (MB): 6069 Free GPU global memory (MB): 5896 [The Arena] space (MB): 4552 [The Managed Arena] space (MB): 8 [The Pinned Arena] space (MB): 8 AMReX (19.06-404-g0455b168b69c-dirty) finalized ``` -------------------------------- ### AMReX ParmParse Input File Format Example Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Basics.rst Provides an example of an AMReX inputs file, demonstrating how to define parameters of various types including integers, floating-point numbers, lists, strings, and multi-dimensional tables. It shows syntax for comments, continuation lines, and nested structures. ```python nsteps = 100 # integer nsteps = 1000 # nsteps appears a second time dt = 0.03 # floating point number ncells = 128 64 32 # a list of 3 ints xrange = -0.5 0.5 # a list of 2 reals title = "Three Kingdoms" # a string hydro.cfl = 0.8 # with prefix, hydro my_2d_table = \ # col 1 2 3 {{ 11.0, 12.0, 13.0 } # row 1 { 21.0, 22.0, 23.0 } # row 2 { 31.0, 32.0, 33.0 } # row 3 { 41.0, 42.0, 43.0 } } # row 4 # or my_2d_table = # col 1 2 3 {{ 11, 12, 13 } # row 1 { 21, 22, 23 } # row 2 { 31, 32, 33 } # row 3 { 41, 42, 43 } } # row 4 # or my_2d_table = # col 1 2 3 {{ 11, 12, 13 }, # row 1 { 21, 22, 23 }, # row 2 { 31, 32, 33 }, # row 3 { 41, 42, 43 } } # row 4 ``` -------------------------------- ### Generate AMReX Install Targets Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/BuildingAMReX.rst Generates install targets for AMReX, facilitating the installation of the library and its components into a specified directory. This is a compile-time option. ```C++ #define AMReX_INSTALL ``` -------------------------------- ### AMReX Type Check Output Example Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Basics.rst Example output from the AMReX type checking tool, illustrating a detected error in function argument matching between C++ and Fortran. ```console Function my_f in main_F.H vs. Fortran procedure in f.f90 number of arguments 1 does NOT match 2. arg #1: C type ['double', 'pointer'] does NOT match Fortran type ('INTEGER 4', 'pointer', 'x'). 22 functions checked, 1 error(s) found. More details can be found in tmp_build_dir/t/3d.gnu.DEBUG.EXE/amrex_typecheck.ou. ``` -------------------------------- ### AMReX Profiling Output Example (Console) Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/AMReX_Profiling_Tools.rst An example of the console output from AMReX profiling, showing function call counts, exclusive minimum, average, and maximum times, and their percentage of total time. This helps identify performance bottlenecks. ```console -------------------------------------------------------------------------------------------- Name NCalls Excl. Min Excl. Avg Excl. Max Max % -------------------------------------------------------------------------------------------- FillBoundary_finish() 607 0.01568 0.3367 0.6574 41.97% MLPoisson::Fsmooth() 560 0.2133 0.4047 0.5973 38.13% FabArray::ParallelCopy_finish() 231 0.002977 0.09748 0.1895 12.10% ``` -------------------------------- ### Install AMReX using Spack Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/BuildingAMReX.rst This bash command installs the latest release of AMReX and its dependencies using the Spack package manager. Spack simplifies the management of scientific software, supporting multiple versions and configurations. ```bash spack install amrex ``` -------------------------------- ### Setup AMReX Test Executable and Execution Source: https://github.com/amrex-codes/amrex/blob/development/Tests/CMakeLists.txt This CMake function sets up an executable for an AMReX test, including specifying sources, linking libraries, and defining the execution command. It supports OpenMP and MPI execution, and can copy input files to the execution directory. ```cmake function (setup_test _dim _srcs _inputs) cmake_parse_arguments( "" "HAS_FORTRAN_MODULES" "BASE_NAME;RUNTIME_SUBDIR;EXTRA_DEFINITIONS;CMDLINE_PARAMS;NTASKS;NTHREADS" "" ${ARGN} ) if (_BASE_NAME) set(_base_name ${_BASE_NAME}_${_dim}d) else () string(REGEX REPLACE ".*Tests/" "" _base_name ${CMAKE_CURRENT_LIST_DIR}) string(REPLACE "/" "_" _base_name ${_base_name}) set(_base_name ${_base_name}_${_dim}d) endif () if (_RUNTIME_SUBDIR) set(_exe_dir ${CMAKE_CURRENT_BINARY_DIR}/${_RUNTIME_SUBDIR}_${_dim}d) else () set(_exe_dir ${CMAKE_CURRENT_BINARY_DIR}/${_dim}d) endif () set( _exe_name Test_${_base_name} ) set( _test_name ${_base_name} ) add_executable( ${_exe_name} ) target_sources( ${_exe_name} PRIVATE ${${_srcs}} ) set_target_properties( ${_exe_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${_exe_dir} ) if (_EXTRA_DEFINITIONS) target_compile_definitions(${_exe_name} PRIVATE ${_EXTRA_DEFINITIONS}) endif () # Find out which include directory is needed set(_includes ${${_srcs}}) list(FILTER _includes INCLUDE REGEX "\\.H") foreach(_item IN LISTS _includes) get_filename_component( _include_dir ${_item} DIRECTORY ) target_include_directories( ${_exe_name} PRIVATE ${_include_dir} ) endforeach() if (_HAS_FORTRAN_MODULES) target_include_directories(${_exe_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${_exe_name}_mod_files_${_dim}d) set_target_properties(${_exe_name} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_exe_name}_mod_files_${_dim}d) endif () target_link_libraries( ${_exe_name} AMReX::amrex_${_dim}d ) if (AMReX_CUDA) setup_target_for_cuda_compilation( ${_exe_name} ) endif () # # Assemble the commands sequence to launch the test # set(_cmd ${_exe_dir}/${_exe_name}) if (_CMDLINE_PARAMS) list(APPEND _cmd ${_CMDLINE_PARAMS}) endif () if (${_inputs}) file( COPY ${${_inputs}} DESTINATION ${_exe_dir} ) list(GET ${_inputs} 0 _first_inputs) get_filename_component( _inputs_filename ${_first_inputs} NAME ) list(APPEND _cmd ${_inputs_filename}) endif () # # Add the test # if (AMReX_OMP) add_test( NAME ${_test_name} COMMAND ${_cmd} WORKING_DIRECTORY ${_exe_dir} ) set_tests_properties(${_test_name} PROPERTIES ENVIRONMENT OMP_NUM_THREADS=2) elseif (AMReX_MPI) add_test( NAME ${_test_name} COMMAND mpiexec -n 2 ${_cmd} WORKING_DIRECTORY ${_exe_dir} ) else () add_test( NAME ${_test_name} COMMAND ${_cmd} WORKING_DIRECTORY ${_exe_dir} ) endif () endfunction () ``` -------------------------------- ### Python ParmParse Example Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Basics.rst Demonstrates basic assignment and modification of variables using Python syntax, likely within an AMReX context. ```python foo.a = 1 foo.b = foo.a foo.a = 2 ``` ```python foo.a = 2 foo.b = 2 ``` ```python color1 = red color2 = BLue ``` ```python amrex.envfoo = 0 amrex.envbar = 1 amrex.envabc = 1 2 3 amrex.envstr = "a b c" ``` -------------------------------- ### Running AMReX Hello World with MPI Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/GettingStarted.rst Runs the AMReX 'Hello World' program using MPI with a specified number of processes. The output indicates MPI initialization and the AMReX version. ```console mpiexec -n 4 ./main3d.gnu.DEBUG.MPI.ex amrex.v=1 ``` -------------------------------- ### Iterate Over Octree Grid Leaves Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst Provides an example of iterating through the leaves of an octree grid using the `amrex_octree_iter` type. It shows how to build the iterator, loop through each grid, retrieve level, grid index, and box information, and access data pointers. ```Fortran type(amrex_octree_iter) :: oti type(multifab) :: phi_new(*) integer :: ilev, igrd type(amrex_box) :: bx real(amrex_real), contiguous, pointer, dimension(:,:,:,:) :: pout call amrex_octree_iter_build(oti) do while(oti%next()) ilev = oti%level() igrd = oti%grid_index() bx = oti%box() pout => phi_new(ilev)%dataptr(igrd) ! ... end do call amrex_octree_iter_destroy(oti) ``` -------------------------------- ### Running AMReX Hello World with OpenMP Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/GettingStarted.rst Executes the AMReX 'Hello World' program using OpenMP with a specified number of threads. The output shows OpenMP initialization and the AMReX version. ```console OMP_NUM_THREADS=4 ./main3d.gnu.DEBUG.OMP.ex ``` -------------------------------- ### Setup AMReX Tutorial with SENSEI on Cori Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Visualization.rst Steps to set up and run the AmrLevel tutorial with ParaView Catalyst on the NERSC Cori cluster. This involves cloning repositories, loading modules, configuring the environment, and modifying simulation inputs. ```bash ssh cori.nersc.gov cd $SCRATCH git clone https://github.com/AMReX-Codes/amrex.git git clone https://github.com/AMReX-Codes/amrex-tutorials.git cd amrex-tutorials/ExampleCodes/Amr/Advection_AmrLevel/Exec/SingleVortex module use /usr/common/software/sensei/modulefiles module load sensei/2.1.0-catalyst-shared source sensei_config vim GNUmakefile # USE_SENSEI_INSITU=TRUE make -j4 -f GNUmakefile vim inputs # sensei.enabled=1 ``` -------------------------------- ### Setup and Run Advection_AmrLevel Tutorial with Libsim Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Visualization.rst This snippet details the bash commands required to set up the environment for the Advection_AmrLevel tutorial. It includes cloning the necessary repositories, loading modules, configuring Sensei, compiling the code, and running the simulation with Libsim enabled. ```bash ssh cori.nersc.gov cd $SCRATCH git clone https://github.com/AMReX-Codes/amrex.git git clone https://github.com/AMReX-Codes/amrex-tutorials.git cd amrex-tutorials/ExampleCodes/Amr/Advection_AmrLevel/Exec/SingleVortex module use /usr/common/software/sensei/modulefiles module load sensei/2.1.0-libsim-shared source sensei_config salloc -C haswell -N 1 -t 00:30:00 -q debug cd $SCRATCH/amrex-tutorials/ExampleCodes/Amr/Advection_AmrLevel/Exec/SingleVortex ./main2d.gnu.haswell.MPI.ex inputs ``` -------------------------------- ### Running AMReX Hello World (Debug) Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/GettingStarted.rst Executes the compiled AMReX 'Hello World' program in debug mode. The output includes initialization and finalization messages along with the AMReX version. ```console ./main3d.gnu.DEBUG.ex ``` -------------------------------- ### SUNDIALS Installation with CMake Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/TimeIntegration_Chapter.rst Provides a command-line example using CMake to build and install the SUNDIALS library. It specifies the source and build directories, installation prefix, and enables MPI and CUDA support, which are common configurations for scientific applications. ```bash cmake -S /path_to_sundials_source_code -B /path_to_sundials_build_dir -D CMAKE_INSTALL_PREFIX=/path_to_sundials_install_dir -D ENABLE_MPI=ON -D ENABLE_CUDA=ON cd /path_to_sundials_build_dir make make install ``` -------------------------------- ### AMReX Parameter Parsing in Fortran Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst This Fortran snippet shows how to use the `amrex_parmparse_module` to read parameters from an input file. It includes building the `ParmParse` object, getting integer values, and optionally querying for values with a default. ```Fortran type(amrex_parmparse) :: pp integer :: n_cell, max_grid_size call amrex_parmparse_build(pp) call pp%get("n_cell", n_cell) max_grid_size = 32 ! default size call pp%query("max_grid_size", max_grid_size) call amrex_parmpase_destroy(pp) ! optional if compiler supports finalization ``` -------------------------------- ### Setup Single Vortex Tutorial (AMReX) Source: https://github.com/amrex-codes/amrex/blob/development/Tests/Amr/Advection_AmrLevel/CMakeLists.txt Configures the Single Vortex advection tutorial for AMReX. It defines source files, input files, and test parameters for 2D and 3D builds, excluding Windows. ```cmake set(_sv_exe_dir Exec/SingleVortex/) set(_sv_sources face_velocity_${D}d_K.H Prob_Parm.H Adv_prob.cpp Prob.cpp Prob.H) list(TRANSFORM _sv_sources PREPEND ${_sv_exe_dir}) list(APPEND _sv_sources ${_sources}) set(_input_files inputs-ci) list(TRANSFORM _input_files PREPEND ${_sv_exe_dir}) setup_test(${D} _sv_sources _input_files BASE_NAME Advection_AmrLevel_SV RUNTIME_SUBDIR SingleVortex) unset(_sv_sources) unset(_sv_exe_dir) ``` -------------------------------- ### C++ BaseFab Member Functions: Box, Components, Data Pointer Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Basics.rst Provides examples of common BaseFab member functions in C++: `box()` to get the defining Box, `nComp()` to get the number of components, and `dataPtr()` to obtain a pointer to the array data. ```c++ const Box& box() const; ``` ```c++ int nComp() const; ``` ```c++ T* dataPtr(int n=0); // Data pointer to the nth component // T is template parameter (e.g., Real) const T* dataPtr(int n=0) const; // const version ``` -------------------------------- ### Manual Visualization in ParaView Source: https://github.com/amrex-codes/amrex/blob/development/Tests/Amr/Advection_AmrCore/README.md Step-by-step guide for manually visualizing AMReX data in ParaView 5.8, including loading data, applying slices, and setting display properties. ```plaintext 1. Start Paraview 5.8 2. File --> Open ... and select the collection of directories named "plt.." --> [OK] 3. From the "Open Data With..." dialog that pops up, select "AMReX/BoxLib Grid Reader" --> [OK] 4. Check the "phi" box in the "Cell Array Status" menu that appears 5. Click green Apply button 6. Click on the "slice" icon -- three to the right of the calculator This will create "Slice 1" in the Pipeline Browser which will be highlighted. 7. Click on "Z Normal" 8. Unclick the "Show Plane" button 9. Click green Apply button 10. Change the drop-down menu option (above the calculator row) from "vtkBlockColors" to "phi" ``` -------------------------------- ### Setting AMREX_HOME in Tcsh Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/BuildingAMReX.rst This snippet shows how to set the AMREX_HOME environment variable in a Tcsh shell. Similar to the Bash example, this variable is essential for the build process, indicating the AMReX installation path. ```bash setenv AMREX_HOME /path/to/amrex ``` -------------------------------- ### AMReX ParallelDescriptor Functions Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Basics.rst Provides examples of using the ParallelDescriptor namespace for MPI communication, including getting process information, checking the IO processor, and performing broadcasts and reductions. ```c++ int myproc = ParallelDescriptor::MyProc(); int nprocs = ParallelDescriptor::NProcs(); ``` ```c++ if (ParallelDescriptor::IOProcessor()) { // Code for IO process } ``` ```c++ Vector data(100); ParallelDescriptor::Bcast(data.data(), data.size(), ParallelDescriptor::IOProcessorNumber()); ``` ```c++ double x = 10.0; ParallelDescriptor::ReduceRealSum(x); ``` -------------------------------- ### Setup Combustor Tutorial Test Case (CMake) Source: https://github.com/amrex-codes/amrex/blob/development/Tests/EB_CNS/CMakeLists.txt This CMake snippet configures the 'Combustor' tutorial for the AMReX project. It defines the specific source files and input files required for the tutorial and uses the `setup_test` macro to register it as a buildable test case, specifying its base name and runtime subdirectory. ```cmake set(_combustor_sources Exec/Combustor/cns_prob.H Exec/Combustor/cns_prob.cpp Exec/Combustor/cns_prob_parm.H Exec/Combustor/cns_prob_parm.cpp Exec/Combustor/CNS_bcfill.cpp ${_sources}) set(_input_files Exec/Combustor/inputs Exec/Combustor/inputs-ci) setup_test(${D} _combustor_sources _input_files BASE_NAME CNS_Combustor RUNTIME_SUBDIR Combustor) ``` -------------------------------- ### Fortran amrex_multifab Ownership Transfer Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst Illustrates how to transfer ownership of an amrex_multifab object in Fortran using the 'move' procedure. This ensures that only one object owns the data, preventing double destruction. ```Fortran type(amrex_multifab) :: mf1, mf2 call amrex_multifab_build(mf1, ...) call mf2%move(mf1) ! mf2 is now the data owner and mf1 is not. call amrex_multifab_destroy(mf1) call amrex_multifab_destroy(mf2) ``` -------------------------------- ### Setup Sod Tutorial Test (CMake) Source: https://github.com/amrex-codes/amrex/blob/development/Tests/GPU/CNS/CMakeLists.txt This snippet configures the Sod tutorial test for AMReX. It defines the source files and input files for the test, sets a base name for the executable, and specifies a runtime subdirectory. ```cmake set(_sod_sources Exec/Sod/cns_prob.cpp Exec/Sod/cns_prob.H Exec/Sod/cns_prob_parm.H ${_sources}) set(_input_files Exec/Sod/inputs-ci) setup_test(3 _sod_sources _input_files BASE_NAME GPU_CNS_Sod RUNTIME_SUBDIR Sod) unset(_sod_sources) # # Clean-up # unset(_sources) unset(_input_files) ``` -------------------------------- ### Setup Uniform Velocity Tutorial (AMReX) Source: https://github.com/amrex-codes/amrex/blob/development/Tests/Amr/Advection_AmrLevel/CMakeLists.txt Configures the Uniform Velocity advection tutorial for AMReX. It specifies source files, input files, and test parameters for 2D and 3D builds, excluding Windows. ```cmake set(_uv_exe_dir Exec/UniformVelocity/) set(_uv_sources face_velocity_${D}d_K.H Prob_Parm.H Adv_prob.cpp Prob.cpp Prob.H) list(TRANSFORM _uv_sources PREPEND ${_uv_exe_dir}) list(APPEND _uv_sources ${_sources}) set(_input_files inputs-ci) list(TRANSFORM _input_files PREPEND ${_uv_exe_dir}) setup_test(${D} _uv_sources _input_files BASE_NAME Advection_AmrLevel_UV RUNTIME_SUBDIR UniformVelocity) unset(_uv_sources) unset(_uv_exe_dir) ``` -------------------------------- ### SENSEI VisIt Libsim Backend Configuration (XML) Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Visualization.rst An example XML configuration for SENSEI to use the VisIt Libsim backend for in situ visualization. It specifies parameters like the analysis type, frequency, mode, VisIt directory, session file, image output format, and dimensions. ```xml ``` -------------------------------- ### View AMReX Spack Configuration Options Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/BuildingAMReX.rst This bash command displays the available configuration options for installing AMReX via Spack. Users can view different versions, dimensions, and feature support like CUDA. ```bash spack info amrex ``` -------------------------------- ### Iterate over amrex_multifab using amrex_mfiter Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst This snippet shows how to use the amrex_mfiter to iterate over the data within an amrex_multifab, including tiling. It demonstrates accessing data pointers and using them within a Fortran subroutine for computation. ```Fortran integer :: plo(4), phi(4) type(amrex_box) :: bx real(amrex_real), contiguous, dimension(:,:,:,:), pointer :: po, pn type(amrex_multifab) :: old_phi, new_phi type(amrex_mfiter) :: mfi ! Define old_phi and new_phi ... ! In this example they are built with the same boxarray and distromap. ! And they have the same number of ghost cells and 1 component. call amrex_mfiter_build(mfi, old_phi, tiling=.true.) do while (mfi%next()) bx = mfi%tilebox() po => old_phi%dataptr(mfi) pn => new_phi%dataptr(mfi) plo = lbound(po) phi = ubound(po) call update_phi(bx%lo, bx&hi, po, pn, plo, phi) end do call amrex_mfiter_destroy(mfi) ``` -------------------------------- ### CMake: Setup Sod Tutorial Test Source: https://github.com/amrex-codes/amrex/blob/development/Tests/EB/CNS/CMakeLists.txt Configures a test for the Sod tutorial within the AMReX project. It specifies the source files, input files, and indicates that the test has Fortran modules and a specific runtime subdirectory. ```cmake # # Sod tutorial # set(_sod_sources Exec/Sod/cns_prob.F90 ${_sources}) set(_input_files Exec/Sod/inputs-ci) setup_test(3 _sod_sources _input_files HAS_FORTRAN_MODULES BASE_NAME CNS_Sod RUNTIME_SUBDIR Sod) unset(_sod_sources) ``` -------------------------------- ### AMReX C++: MFIter with Tiling Enabled Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Basics.rst Shows how to enable tiling in AMReX's MFIter by passing `true` during initialization. This simplifies the implementation of cache blocking compared to manual tiling. ```c++ // * true * turns on tiling ``` -------------------------------- ### Build Hypre for CPU Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/LinearSolvers.rst This console command sequence outlines the steps to clone the Hypre repository, check out a specific version (v2.32.0), configure it for CPU build, and install it. It also mentions setting the HYPRE_DIR environment variable. ```console 1.- git clone https://github.com/hypre-space/hypre.git 2.- cd hypre/src 3.- git checkout v2.32.0 4.- ./configure (if you want to build hypre with long long int, do ./configure --enable-bigint ) 5.- make install 6.- Create an environment variable with the HYPRE directory -- HYPRE_DIR=/hypre_path/hypre/src/hypre ``` -------------------------------- ### Fortran AMR Callback Procedure Signatures Source: https://github.com/amrex-codes/amrex/blob/development/Docs/sphinx_documentation/source/Fortran.rst Specifies the Fortran signatures for the callback procedures used in AMReX's AMR core: amrex_make_level_proc, amrex_clear_level_proc, and amrex_error_est_proc. These are designed to be called from C++ using the 'bind(c)' attribute. ```Fortran subroutine amrex_make_level_proc (lev, time, ba, dm) bind(c) import implicit none integer, intent(in), value :: lev real(amrex_real), intent(in), value :: time type(c_ptr), intent(in), value :: ba, dm end subroutine amrex_make_level_proc subroutine amrex_clear_level_proc (lev) bind(c) import implicit none integer, intent(in) , value :: lev end subroutine amrex_clear_level_proc subroutine amrex_error_est_proc (lev, tags, time, tagval, clearval) bind(c) import implicit none integer, intent(in), value :: lev type(c_ptr), intent(in), value :: tags real(amrex_real), intent(in), value :: time character(c_char), intent(in), value :: tagval, clearval end subroutine amrex_error_est_proc ```