HyPar
1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
|
Class describing sparse grids simulations. More...
#include <sparse_grids_simulation.h>
Public Member Functions | |
SparseGridsSimulation () | |
~SparseGridsSimulation () | |
int | define (int, int) |
int | ReadInputs () |
int | Initialize () |
int | InitialSolution () |
int | InitializeBoundaries () |
int | InitializeImmersedBoundaries () |
int | InitializePhysics () |
int | InitializePhysicsData () |
int | InitializeSolvers () |
int | InitializationWrapup () |
int | Solve () |
void | WriteErrors (double, double) |
bool | isDefined () const |
int | mpiCommDup () |
void | usePetscTS (PetscBool a_flag) |
int | SolvePETSc () |
Public Member Functions inherited from Simulation | |
Simulation () | |
virtual | ~Simulation () |
Protected Member Functions | |
int | SanityChecks () |
int | ComputeSGDimsAndCoeffs () |
int | ComputeProcessorDistribution (ProcDistribution &, const GridDimensions &) |
void | GetCTGridSizes (const int, std::vector< GridDimensions > &) |
int | InitializeBarebones (SimulationObject *) |
int | InitializeSolversBarebones (SimulationObject *) |
int | CleanupBarebones (SimulationObject *) |
int | SetSolverParameters (SimulationObject &, const GridDimensions &, const ProcDistribution &, const SimulationObject &, const int, const int) |
void | OutputSolution (double) |
void | CombinationTechnique (SimulationObject *const) |
void | interpolate (SimulationObject *const, const SimulationObject *const) |
void | interpolate (const GridDimensions &, double **const, const SimulationObject *const) |
void | interpolateGrid (SimulationObject *const, const SimulationObject *const) |
void | coarsenGrid1D (const GridDimensions &, const GridDimensions &, const double *const, double *const, int) |
void | refineGrid1D (const GridDimensions &, const GridDimensions &, const double *const, double *const, int) |
void | fillGhostCells (const GridDimensions &, const int, double *const, const int) |
void | CalculateError () |
void | computeError (SimulationObject &, double *const) |
bool | isPowerOfTwo (int x) |
double | cfunc (int a, int b) |
int | factorial (int a) |
void | allocateGridArrays (const GridDimensions &a_dim, double **const a_x, const int a_ngpt=0) |
void | allocateDataArrays (const GridDimensions &a_dim, const int a_nvars, double **const a_u, const int a_ngpt=0) |
Protected Attributes | |
bool | m_is_defined |
int | m_nsims_sg |
int | m_ndims |
int | m_rank |
int | m_nproc |
int | m_interp_order |
std::vector< bool > | m_is_periodic |
int | m_write_sg_solutions |
int | m_print_sg_errors |
SimulationObject * | m_sim_fg |
std::vector< SimulationObject > | m_sims_sg |
int | m_n_fg |
int | m_imin |
std::vector< SGCTElem > | m_combination |
std::vector< ProcDistribution > | m_iprocs |
Class describing sparse grids simulations.
Class describing sparse grids simulations This class contains all data and functions needed to run a sparse grids simulation.
This class contains all data and functions needed to run sparse grids simulations.
Definition at line 38 of file sparse_grids_simulation.h.
|
inline |
Constructor
Definition at line 43 of file sparse_grids_simulation.h.
|
inline |
Destructor
Definition at line 65 of file sparse_grids_simulation.h.
|
virtual |
Define this object
Define the sparse grids simulation object - here, only the full grid simulation object SparseGridsSimulation::m_sim_fg is created.
This function also reads sparse grids inputs from the file sparse_grids.inp. Rank 0 reads in the inputs and broadcasts them to all the processors.
The format of sparse_grids.inp is as follows:
begin <keyword> <value> <keyword> <value> ... <keyword> <value> end
where the list of keywords and their type are:
Keyword name | Type | Variable | Default value |
---|---|---|---|
log2_imin | int | SparseGridsSimulation::m_imin | 2 |
interp_order | int | SparseGridsSimulation::m_interp_order | 6 |
write_sg_solution | char[] | SparseGridsSimulation::m_write_sg_solutions | "no" (0) |
write_sg_errors | char[] | SparseGridsSimulation::m_print_sg_errors | "no" (0) |
a_rank | MPI rank of this process |
a_nproc | Total number of MPI ranks |
Implements Simulation.
Definition at line 33 of file SparseGridsDefine.cpp.
|
inlinevirtual |
Read solver inputs for the full grid simulation object
Implements Simulation.
Definition at line 86 of file sparse_grids_simulation.h.
|
virtual |
Initialize the simulation
Initialize all the stuff required for a sparse grids simulation. Before this function is called, the solver inputs for the full grid object has already been read, and therefore, the global dimensions and processor decompositions are available. This function does the following:
Implements Simulation.
Definition at line 15 of file SparseGridsInitialize.cpp.
|
virtual |
Read initial solution
Reads in the initial solution for the full grid, saves it in the full grid object. Then interpolates (coarsens) the grid coordinates to all the sparge grids. The solution is not yet interpolated because boundary information is not yet available. It is done in SparseGridsSimulation::InitializationWrapup().
Implements Simulation.
Definition at line 17 of file SparseGridsInitialSolution.cpp.
|
inlinevirtual |
Initialize the boundary conditions of the simulation
Implements Simulation.
Definition at line 101 of file sparse_grids_simulation.h.
|
inlinevirtual |
Initialize the immersed boundary conditions of the simulation
Implements Simulation.
Definition at line 116 of file sparse_grids_simulation.h.
|
inlinevirtual |
Initialize the physics of the simulations
Implements Simulation.
Definition at line 124 of file sparse_grids_simulation.h.
|
inlinevirtual |
Initialize the physics of the simulations
Implements Simulation.
Definition at line 132 of file sparse_grids_simulation.h.
|
inlinevirtual |
Initialize the numerical solvers of the simulations
Implements Simulation.
Definition at line 150 of file sparse_grids_simulation.h.
|
virtual |
Wrap up initializations
Finish all the initializations: Interpolate the initial solution on the full grid to all the sparse grids, now that the boundary conditions are available.
Reimplemented from Simulation.
Definition at line 15 of file SparseGridsInitializationWrapup.cpp.
|
virtual |
Run the simulation using native time integrators
This function integrates the semi-discrete ODE (obtained from discretizing the PDE in space) using natively implemented time integration methods. It initializes the time integration object, iterates the simulation for the required number of time steps, and calculates the errors. After the specified number of iterations, it writes out some information to the screen and the solution to a file.
Implements Simulation.
Definition at line 17 of file SparseGridsSolve.cpp.
|
virtual |
Write simulation errors and wall times to file
Writes out the errors and other data for the sparse grids simulation.
solver_runtime | Measured runtime of solver |
main_runtime | Measured total runtime |
Implements Simulation.
Definition at line 14 of file SparseGridsWriteErrors.cpp.
|
inlinevirtual |
Return whether object is defined or not
Implements Simulation.
Definition at line 176 of file sparse_grids_simulation.h.
|
inlinevirtual |
Create duplicate MPI communicators
Implements Simulation.
Definition at line 180 of file sparse_grids_simulation.h.
|
inlinevirtual |
Set flag whether to use PETSc time integration
Implements Simulation.
Definition at line 194 of file sparse_grids_simulation.h.
|
inlinevirtual |
Run the simulation using PETSc time integrators
Implements Simulation.
Definition at line 200 of file sparse_grids_simulation.h.
|
protected |
Some basic sanity checks
Do some basic sanity checks to make sure that a sparse grids simulation can be carried out for this setup.
For the full grid:
Definition at line 18 of file SparseGridsSanityChecks.cpp.
|
protected |
Compute the number, coefficients, and dimensions of all the sparse grids that go into the combination technique.
Definition at line 24 of file SparseGridsMiscFuncs.cpp.
|
protected |
Compute the load-balanced MPI ranks distributions
Compute the load-balanced processor distribution for a given grid size and the total number of MPI ranks available
a_iprocs | Processor distribution to compute |
a_dim | Grid dimensions |
Definition at line 85 of file SparseGridsMiscFuncs.cpp.
|
protected |
Compute all grids such that the base2 logs of the size in each dimension adds up to the input argument
a_N | Desired sum of the base2 logs of grid sizes |
a_dims | Vector of grid sizes |
Definition at line 56 of file SparseGridsMiscFuncs.cpp.
|
protected |
Initialize a "barebones" simulation object
A barebones initialization function for a simulation object. It will allocate data holders for only the stuff needed for storing a solution; this object cannot be used for an actual simulation. This function does the following:
simobj | simulation objects of type SimulationObject |
Definition at line 194 of file SparseGridsMiscFuncs.cpp.
|
protected |
Initialize some function pointers for a "barebones" simulation object
This function initializes all some function pointers needed by a barebones simulation object.
sim | simulation objects of type SimulationObject |
Definition at line 324 of file SparseGridsMiscFuncs.cpp.
|
protected |
Cleanup (deallocate) a "barebones" simulation object
Cleanup (deallocation) function for a barebones simulation object that has been allocated using SparseGridsSimulation::InitializeBarebones().
sim | simulation objects of type SimulationObject |
Definition at line 146 of file SparseGridsMiscFuncs.cpp.
|
protected |
Set solver parameters for a simulation object
Set the solver parameters (stuff that is usually read in from solver.inp) for a simulation object, where the global grid sizes and processor distribution are specified, and all other parameters are same as a source simulation object
a_dst_sim | Simulation object |
a_dim_global | Specified global grid sizes |
a_iproc | Specified processor distibution |
a_src_sim | Source simulation object |
a_idx | Index or serial number |
a_nsims | Total number of simulations |
Definition at line 11 of file SparseGridsSetSolverParameters.cpp.
|
protected |
Output solutions to file
Write solutions to file
a_time | simulation time |
Definition at line 11 of file SparseGridsOutputSolution.cpp.
|
protected |
Combination technique
Implements the combination technique where the solutions from all the sparse grids are combined to give a higher-resolution solution.
The sparse grids domains may have different processor layouts, so this combination is carried out on rank 0, and the solution is distributed.
a_sim | target simulation object on which to combine |
Definition at line 23 of file SparseGridsCombinationTechnique.cpp.
|
protected |
Interpolate data from one simulation object to another
Interpolate data from one grid to another. Note that along each dimension, the ratio of the number of grid points in the source grid and that in the destination grid must be an integer power of 2 (negative or positive).
a_dst | Destination object |
a_src | Source object |
Definition at line 15 of file SparseGridsInterpolate.cpp.
|
protected |
Interpolate data from a simulation to a global C-array
Interpolate data from one grid to another of a desired resolution. Note that along each dimension, the ratio of the number of grid points in the source grid and that in the destination grid must be an integer power of 2 (negative or positive).
The incoming pointer must be NULL. After this function is executed, it will point to a chunk of memory with the interpolated solution. This is the global solution.
Since the source and destination grids may have different processor layouts, the interpolation is carried out on rank 0 by allocating global arrays on it. Therefore, this function is not scalable.
a_dim_dst | grid dimensions to interpolate to |
a_u_dst | pointer to array containing interpolated data |
a_src | Source object |
Definition at line 63 of file SparseGridsInterpolate.cpp.
|
protected |
Interpolate data from one simulation object to another
Interpolate grid coordinates from one grid to another. Note that along each dimension, the ratio of the number of grid points in the source grid and that in the destination grid must be an integer power of 2 (negative or positive).
Since the source and destination grids may have different processor layouts, the interpolation is carried out on rank 0 by allocating global arrays on it. Therefore, this function is not scalable.
a_dst | Destination object |
a_src | Source object |
Definition at line 20 of file SparseGridsInterpolateGrid.cpp.
|
protected |
Coarsen along a given dimension
Coarsen along a given dimension - the source and destination must have the same sizes along all other dimensions.
Note that the grid must not have any ghost points!
a_dim_src | Grid size of source data |
a_dim_dst | Grid size of destination data |
a_x_src | Source grid |
a_x_dst | Destination grid |
a_dir | Dimension along which to coarsen |
Definition at line 168 of file SparseGridsInterpolateGrid.cpp.
|
protected |
Refine along a given dimension
Refine along a given dimension - the source and destination must have the same sizes along all other dimensions.
Note that the grid must not have any ghost points!
a_dim_src | Grid size of source data |
a_dim_dst | Grid size of destination data |
a_x_src | Source grid |
a_x_dst | Destination grid |
a_dir | Dimension along which to refine |
Definition at line 238 of file SparseGridsInterpolateGrid.cpp.
|
protected |
Fill ghost cells for interpolation
Fill the ghost cells of a solution. Note that the solution array must be a global one (not one that is partitioned among MPI ranks). This is not a parallel operation (it will execute independently on multiple MPI ranks, if called by multiple processes).
For periodicity along any dimension, the ghost cells are filled appropriately from the other side of the domain. Otherwise, the interior data is extrapolated by a 4th order polynomial (assuming uniform grid spacing).
a_dim | grid dimensions of solution |
a_ngpt | number of ghost cells |
a_u | solution array |
a_nvars | number of vector components of the solution |
Definition at line 18 of file SparseGridsFillGhostCells.cpp.
|
protected |
Calculate errors
Calculates the error in the solution if the exact solution is available. The exact solution should be provided in the file "exact.inp" in the same format as the initial solution.
Definition at line 17 of file SparseGridsCalculateError.cpp.
|
protected |
Compute error for a simulation object
compute errors for a particular simulation object
a_sim | Simulation object |
a_uex | Exact solution |
Definition at line 155 of file SparseGridsCalculateError.cpp.
|
inlineprotected |
Checks if an integer is a power of 2
Definition at line 317 of file sparse_grids_simulation.h.
|
inlineprotected |
The combination/choose function from probability stuff
Definition at line 329 of file sparse_grids_simulation.h.
|
inlineprotected |
Factorial function
Definition at line 335 of file sparse_grids_simulation.h.
|
inlineprotected |
|
inlineprotected |
|
protected |
Boolean to show if this object is defined
Definition at line 212 of file sparse_grids_simulation.h.
|
protected |
Number of sparse grids simulations
Definition at line 214 of file sparse_grids_simulation.h.
|
protected |
Number of spatial dimensions
Definition at line 215 of file sparse_grids_simulation.h.
|
protected |
MPI rank of this process
Definition at line 216 of file sparse_grids_simulation.h.
|
protected |
Total number of MPI ranks
Definition at line 216 of file sparse_grids_simulation.h.
|
protected |
Order of interpolation between grids (input - sparse_grids.inp )
Definition at line 220 of file sparse_grids_simulation.h.
|
protected |
Periodicity along each dimension
Definition at line 222 of file sparse_grids_simulation.h.
|
protected |
Write out the sparse grid solutions to file? (input - sparse_grids.inp )
Definition at line 225 of file sparse_grids_simulation.h.
|
protected |
Print and write out the sparse grid errors? (input - sparse_grids.inp )
Definition at line 228 of file sparse_grids_simulation.h.
|
protected |
full grid simulation object
Definition at line 230 of file sparse_grids_simulation.h.
|
protected |
vector of sparse grids simulation objects
Definition at line 231 of file sparse_grids_simulation.h.
|
protected |
Base2 log of the number of grid points along a dimension of the full grid
Definition at line 233 of file sparse_grids_simulation.h.
|
protected |
Base2 log of the minimum number of grid points along any dimension (input - sparse_grids.inp )
Definition at line 234 of file sparse_grids_simulation.h.
|
protected |
Coefficients and grid dimensions for the combination technique
Definition at line 236 of file sparse_grids_simulation.h.
|
protected |
MPI ranks along each dimension for the grids in the combination technique
Definition at line 237 of file sparse_grids_simulation.h.