Pressure Calculation Methods
How It's Switched
Let's take a look at how the pressure calculation method is being modified.
Input
First, we specify which method to use in settings.yml
:
# pressure calculation method
pressureCalculationMethod: Implicit # Implicit or Explicit
# for Implicit
compressibility: 0.45e-09
relaxationCoefficientForPressure: 0.2
# for Explicit
soundSpeed: 17.1
Loading
When executing the program, the location of settings.yml
is passed through the --setting
argument. Then main() function initiates Simulation class:
int main(
int argc,
char** argv) {
auto settingPath = fs::path(program.get<std::string>("--setting"));
auto outputDirectory = fs::path(program.get<std::string>("--output"));
Simulation simulation(settingPath, outputDirectory);
simulation.run();
return 0;
}
int main(int argc, char **argv)
entry point of the program
Simulation::Simulation() receives settingPath
, and make Loader load settings.yml
. User-defined pressure calculation method is now set in input.settings.pressureCalculationMethod
.
}
Input load(const fs::path &settingPath, const fs::path &outputDirectory)
Load the setting file and the particle file.
Simulation(std::filesystem::path &settingPath, std::filesystem::path &outputDirectory)
Assigning the Class
Then it moves on to switching the pressure method. This part consists of three steps.
- Create PressureCalculator::Interface class variable named
pressureCalculator
.
- User-specified Pressure Calculator class (
Implicit
, Explicit
, ...) will be assigned to the pressureCalculator
variable, using if
statements.
pressureCalculator
will be handed over to MPS::MPS(), the constructor of MPS class. Inside MPS::MPS(), pressureCalculator
will be copied to it's own public attributes.
std::unique_ptr<PressureCalculator::Interface> pressureCalculator;
pressureCalculator.reset(
));
pressureCalculator.reset(
));
}
mps =
MPS(input, std::move(pressureCalculator));
}
Class for explicit pressure calculation.
Class for implicit pressure calculation.
std::string pressureCalculationMethod
Method for pressure calculation.
- Note
- Here we use "Interface Class" and "Smart Pointer". See Coding Techniques for more information.
Pressure Calculation
Finally, at each time step, MPS::stepForward() calls pressureCalculator
that MPS class maintains, and execute pressure calculation.
particle.pressure = pressures[particle.id];
}
}
std::unique_ptr< PressureCalculator::Interface > pressureCalculator
Interface for pressure calculation.
Particles particles
Particles in the simulation.