Skip to content

PATCH — Common Modules ​

The common/ directory contains the modules shared by all PATCH backends. They define the problem physics, boundary and initial conditions, I/O, convergence parameters, and the base type that every backend extends.

Source Layout ​

FileModuleRole
adam_patch_common_object.F90adam_patch_common_objectpatch_common_object base type and initialize_common
adam_patch_bc_object.F90adam_patch_bc_objectBoundary conditions handler
adam_patch_ic_object.F90adam_patch_ic_objectInitial conditions handler
adam_patch_io_object.F90adam_patch_io_objectI/O options and residuals log
adam_patch_time_object.F90adam_patch_time_objectConvergence and output frequency parameters
adam_patch_common_library.F90adam_patch_common_libraryBarrel re-export of all common modules

patch_common_object ​

patch_common_object is the base type for all PATCH backends. It aggregates the ADAM framework objects, the FLAIL linear algebra handler, and the PATCH-specific sub-objects.

Data Members ​

MemberTypeDescription
mpihmpih_objectMPI handler
adamadam_objectCore ADAM object (tree, grid, field, I/O)
fieldfield_object*Pointer alias to adam%field
gridgrid_object*Pointer alias to adam%grid
amramr_objectAMR marker handler
ibib_objectImmersed boundary handler
flailflail_objectFLAIL linear algebra / smoothing handler
iopatch_io_objectI/O configuration
icpatch_ic_objectInitial conditions
bcpatch_bc_objectBoundary conditions
timepatch_time_objectConvergence and output frequency
qreal(R8P)(:,:,:,:,:)Scalar potential φ — shape (nv, ni, nj, nk, nb)
rreal(R8P)(:,:,:,:,:)Source distribution f — shape (nv, ni, nj, nk, nb)
q_namecharacter(3)(1)Output label for q (fixed to 'phi')
ngc, ni, nj, nk, nbinteger(I4P)*Pointer aliases to grid/field dimension scalars
blocks_numberinteger(I4P)*Pointer alias to field%blocks_number
nvinteger(I4P)*Pointer alias to field%nv (always 1 for PATCH)

Methods ​

ProcedureDescription
allocate_commonAllocates r with ghost-cell bounds (nv, 1-ngc:ni+ngc, …, nb)
initialize_commonFull initialisation sequence (see below)

initialize_common Sequence ​

initialize_common sets up the entire simulation state:

  1. mpih%initialize — start MPI, query rank and memory
  2. io%initialize(filename) — parse INI file
  3. bc%initialize — load BC configuration
  4. adam%grid%initialize — set domain bounds, resolution, BC types
  5. adam%compute_blocks_number — estimate block count from available memory (nv = 1, fields_number = 170)
  6. adam%initialize — build AMR tree (11 nodes), field (nv=1), maps; allocates q
  7. adam%refine_uniform — apply initial uniform refinement levels from INI
  8. adam%prune — prune tree according to ijkl_prune settings
  9. amr%initialize — load AMR marker configuration
  10. time%initialize — load convergence parameters
  11. ic%initialize — load IC configuration
  12. ib%initialize — load IB body geometry
  13. flail%initialize — load linear algebra (smoothing method and iteration counts)
  14. allocate_common — allocate r
  15. adam%io%initialize — register r as 'rho' field for output

patch_bc_object ​

Manages Dirichlet boundary conditions on the six domain faces.

Supported BC Types ​

IdentifierINI valueDescription
BC_DIRICHLETdirichletFix φ to a constant value on the face

Data Members ​

MemberDescription
bc_type(6)BC type index for each face (1 = Dirichlet)
q(:,:)Prescribed φ value for each face and variable

INI Configuration ​

ini
[bc_x_min]
type = dirichlet
phi  = 0.0

[bc_x_max]
type = dirichlet
phi  = 0.0

[bc_y_min]
type = dirichlet
phi  = 0.0

[bc_y_max]
type = dirichlet
phi  = 0.0

[bc_z_min]
type = dirichlet
phi  = 0.0

[bc_z_max]
type = dirichlet
phi  = 0.0

Methods ​

ProcedureDescription
initializeInitialises MPI and calls load_from_file
load_from_fileReads type and φ value for all six faces
descriptionReturns a human-readable summary

patch_ic_object ​

Sets the initial distribution of the source term r (forcing function f).

Supported IC Types ​

Identifiertype keyDescription
IC_TYPE_GAUSSgaussGaussian centred at (0.5,0.5,0.5) with variance σ2=0.01

The Gaussian IC is defined pointwise as:

ri,j,k=exp(−(xi−0.5)2+(yj−0.5)2+(zk−0.5)20.01)

Data Members ​

MemberDescription
ic_typeSelected IC type string
amr_iterationsNumber of AMR refinement cycles to apply after imposing IC
regions_numberNumber of IC regions
r(1, regions_number)Source amplitude per region
emin(3, regions_number)Bounding box minimum corner per region
emax(3, regions_number)Bounding box maximum corner per region

INI Configuration ​

ini
[initial_conditions]
type           = gauss
amr_iterations = 2
regions_number = 1

[initial_conditions_region_1]
r      = 1.0
emin_x = 0.0
emin_y = 0.0
emin_z = 0.0
emax_x = 1.0
emax_y = 1.0
emax_z = 1.0

Methods ​

ProcedureDescription
initializeInitialises MPI and calls load_from_file
load_from_fileReads type, region count, and per-region parameters
set_initial_conditionsFills r array according to the selected IC type
descriptionReturns a human-readable summary

patch_io_object ​

Manages all I/O options: output frequency, restart, and the residuals log file.

Data Members and INI Keys ​

INI section: [IO]

INI keyMemberDefaultDescription
output_basenameoutput_basename—Basename for output files
it_saveit_save100Main output iteration frequency
restartrestart.false.Enable restart from existing files
restart_basenamerestart_basename—Basename for restart files
restart_saverestart_save100Restart checkpoint frequency
residuals_saveresiduals_save10Residuals log write frequency
save_memory_statussave_memory_status.false.Log memory allocation status
ini
[IO]
output_basename   = results/patch
it_save           = 50
restart           = .false.
restart_basename  = restart/patch
restart_save      = 100
residuals_save    = 10
save_memory_status = .false.

Residuals Log ​

The residuals file is written to {output_basename}-residuals.dat with columns:

VARIABLES="it" "time" "blocks_number" "rq1"

One line is written per residuals_save iterations. The rq value is the MPI-reduced L2 norm of dq normalised by the number of cells.

Methods ​

ProcedureDescription
initializeOpens and parses the INI file
load_from_fileReads all IO options
open_file_residualsOpens the residuals log file and writes the header
close_file_residualsCloses the residuals log file
save_residualsAppends one record to the residuals log
descriptionReturns a human-readable summary

patch_time_object ​

Holds iteration counters, convergence parameters, and output frequency for the solver loop. PATCH is an iterative (not time-marching) solver; the time and CFL fields are present for framework compatibility.

Data Members and INI Keys ​

INI section: [time]

INI keyMemberDefaultDescription
it_maxit_max-1Maximum iterations (-1 = no limit)
time_maxtime_max1.0Maximum pseudo-time (used when it_max ≤ 0)
CFLCFL0.3CFL number (framework compatibility)
ini
[time]
it_max   = 500
time_max = 1.0
CFL      = 0.3

Termination Criteria ​

The solver exits if either condition is met:

ConditionDescription
dq_max < toleranceResidual falls below FLAIL tolerance (primary criterion)
it >= it_max and it_max > 0Iteration budget exhausted
time >= time_max and it_max ≤ 0Pseudo-time budget exhausted

Methods ​

ProcedureDescription
initializeInitialises MPI and calls load_from_file
load_from_fileReads it_max, time_max, CFL
is_to_saveReturns .true. when data should be written at current iteration
print_progressPrints iteration count, step, pseudo-time, and percentage to stdout
descriptionReturns a human-readable summary

adam_patch_common_library ​

Barrel re-export of all common modules. Backends use a single use adam_patch_common_library to access all common types and constants.

Re-exported moduleKey public symbols
adam_patch_bc_objectpatch_bc_object, BC_DIRICHLET
adam_patch_common_objectpatch_common_object
adam_patch_ic_objectpatch_ic_object, IC_TYPE_GAUSS
adam_patch_io_objectpatch_io_object
adam_patch_time_objectpatch_time_object

License ​

PATCH is part of the ADAM framework, released under the GNU Lesser General Public License v3.0 (LGPLv3).

Copyright (C) Andrea Di Mascio, Federico Negro, Giacomo Rossi, Francesco Salvadore, Stefano Zaghi.