PICurv
0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
simulation.h
Go to the documentation of this file.
1
#ifndef SIMULATION_H
2
#define SIMULATION_H
3
4
#include <petscpf.h>
5
#include <petscdmswarm.h>
6
#include <stdlib.h>
7
#include <time.h>
8
#include <math.h>
9
#include <petsctime.h>
10
#include <petscsys.h>
11
#include <petscdmcomposite.h>
12
#include <petscsystypes.h>
13
14
// Include additional headers
15
#include "
variables.h
"
// Shared type definitions
16
#include "
ParticleSwarm.h
"
// Particle swarm functions
17
#include "
walkingsearch.h
"
// Particle location functions
18
#include "
grid.h
"
// Grid functions
19
#include "
logging.h
"
// Logging macros
20
#include "
io.h
"
// Data Input and Output functions
21
#include "
interpolation.h
"
// Interpolation routines
22
#include "
initialcondition.h
"
// Analytical Solution for testing
23
#include "
ParticleMotion.h
"
// Functions related to motion of particles
24
#include "
Boundaries.h
"
// Functions related to Boundary conditions
25
#include "
setup.h
"
// Functions related to setup
26
#include "
solvers.h
"
27
28
29
/**
30
* @brief Copies the current time step's solution fields into history vectors
31
* (e.g., U(t_n) -> U_o, U_o -> U_rm1) for the next time step's calculations.
32
*
33
* This function is critical for multi-step time integration schemes (like BDF2)
34
* used by the legacy solver. It must be called at the end of every time step,
35
* after the new solution has been fully computed.
36
*
37
* The order of operations is important to avoid overwriting data prematurely.
38
*
39
* @param user The UserCtx for a single block. The function modifies the history
40
* vectors (Ucont_o, Ucont_rm1, etc.) within this context.
41
* @return PetscErrorCode 0 on success.
42
*/
43
PetscErrorCode
UpdateSolverHistoryVectors
(
UserCtx
*user);
44
45
/**
46
* @brief Executes the main time-marching loop for the particle simulation.
47
*
48
* This version uses the new, integrated `LocateAllParticlesInGrid` orchestrator
49
* and the `ResetAllParticleStatuses` helper for a clean, robust, and understandable workflow.
50
*
51
* For each timestep, it performs:
52
* 1. Sets the background fluid velocity field (Ucat) for the current step.
53
* 2. Updates particle positions using velocity from the *previous* step's interpolation.
54
* 3. Removes any particles that have left the global domain.
55
* 4. A single call to `LocateAllParticlesInGrid', which handles all
56
* particle location and migration until the swarm is fully settled.
57
* 5. Interpolates the current fluid velocity to the newly settled particle locations.
58
* 6. Scatters particle data back to Eulerian fields.
59
* 7. Outputs data at specified intervals.
60
*
61
* @param user Pointer to the UserCtx structure..
62
* @return PetscErrorCode 0 on success, non-zero on failure.
63
*/
64
PetscErrorCode
AdvanceSimulation
(
SimCtx
*simCtx);
65
66
/**
67
* @brief Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
68
*
69
* This function is called from main() after the initial Eulerian and Lagrangian states have been
70
* created but before the main time loop begins. Its responsibilities are:
71
*
72
* 1. Settling the particle swarm: Migrates particles to their correct owner ranks and finds their
73
* initial host cells. This includes handling special surface initializations.
74
* 2. Coupling the fields: Interpolates the initial Eulerian fields to the settled particle locations.
75
* 3. Preparing for the first step: Scatters particle data back to the grid.
76
* 4. Writing the initial output for step 0.
77
*
78
* @param simCtx Pointer to the main simulation context structure.
79
* @return PetscErrorCode 0 on success, non-zero on failure.
80
*/
81
PetscErrorCode
PerformInitializedParticleSetup
(
SimCtx
*simCtx);
82
83
/**
84
* @brief Finalizes the simulation state after particle and fluid data have been loaded from a restart.
85
*
86
* This helper function performs the critical sequence of operations required to ensure
87
* the loaded Lagrangian and Eulerian states are fully consistent and the solver is
88
* ready to proceed. This includes:
89
* 1. Verifying particle locations in the grid and building runtime links.
90
* 2. Synchronizing particle velocity with the authoritative grid velocity via interpolation.
91
* 3. Scattering particle source terms (e.g., volume fraction) back to the grid.
92
* 4. Updating the solver's history vectors with the final, fully-coupled state.
93
* 5. Writing the complete, consistent state to output files for the restart step.
94
*
95
* @param simCtx The main simulation context.
96
* @return PetscErrorCode 0 on success.
97
*/
98
PetscErrorCode
PerformLoadedParticleSetup
(
SimCtx
*simCtx);
99
100
/**
101
* @brief Performs post-load/post-init consistency checks for a restarted simulation.
102
*
103
* This function is called from main() ONLY when a restart is being performed
104
* (i.e., StartStep > 0). It inspects the particle restart mode to determine the
105
* correct finalization procedure for the Lagrangian swarm.
106
*
107
* - If particles were loaded from a file (`mode == "load"`), it verifies their
108
* locations within the grid to establish necessary runtime links.
109
* - If new particles were initialized into the restarted flow (`mode == "init"`),
110
* it runs the full `PerformInitialSetup` sequence to migrate, locate, and
111
* couple the new particles with the existing fluid state.
112
*
113
* @param simCtx The main simulation context.
114
* @return PetscErrorCode 0 on success.
115
*/
116
PetscErrorCode
FinalizeRestartState
(
SimCtx
*simCtx);
117
118
#endif
// SIMULATION_H
Boundaries.h
ParticleMotion.h
Header file for Particle Motion and migration related functions.
ParticleSwarm.h
Header file for Particle Swarm management functions.
grid.h
Public interface for grid, solver, and metric setup routines.
initialcondition.h
interpolation.h
io.h
Public interface for data input/output routines.
logging.h
Logging utilities and macros for PETSc-based applications.
setup.h
AdvanceSimulation
PetscErrorCode AdvanceSimulation(SimCtx *simCtx)
Executes the main time-marching loop for the particle simulation.
Definition
simulation.c:307
UpdateSolverHistoryVectors
PetscErrorCode UpdateSolverHistoryVectors(UserCtx *user)
Copies the current time step's solution fields into history vectors (e.g., U(t_n) -> U_o,...
Definition
simulation.c:23
FinalizeRestartState
PetscErrorCode FinalizeRestartState(SimCtx *simCtx)
Performs post-load/post-init consistency checks for a restarted simulation.
Definition
simulation.c:242
PerformInitializedParticleSetup
PetscErrorCode PerformInitializedParticleSetup(SimCtx *simCtx)
Finalizes the simulation setup at t=0, ensuring a consistent state before time marching.
Definition
simulation.c:95
PerformLoadedParticleSetup
PetscErrorCode PerformLoadedParticleSetup(SimCtx *simCtx)
Finalizes the simulation state after particle and fluid data have been loaded from a restart.
Definition
simulation.c:176
solvers.h
variables.h
Main header file for a complex fluid dynamics solver.
SimCtx
The master context for the entire simulation.
Definition
variables.h:538
UserCtx
User-defined context containing data specific to a single computational grid level.
Definition
variables.h:661
walkingsearch.h
Header file for particle location functions using the walking search algorithm.
include
simulation.h
Generated by
1.9.8