Molecular Dynamics Simulation  1.0
Classes | Public Member Functions | Public Attributes | List of all members
SimulationParams Class Reference

Contains all parameters needed to run a simulation. More...

#include <SimulationParams.h>

Collaboration diagram for SimulationParams:
Collaboration graph

Classes

struct  DirectSumType
 Struct to specify the type of the particle container as DirectSumType. More...
 
struct  LinkedCellsType
 Struct to specify the type of the particle container as LinkedCellsType (needs domain_size and cutoff_radius) More...
 

Public Member Functions

 SimulationParams (const std::filesystem::path &input_file_path, double delta_t, double end_time, const std::variant< DirectSumType, LinkedCellsType > &container_type, const std::vector< std::shared_ptr< SimulationInterceptor >> &interceptors, const std::vector< std::shared_ptr< SimpleForceSource >> &simple_forces, const std::vector< std::shared_ptr< PairwiseForceSource >> &pairwise_forces, const std::vector< std::shared_ptr< TargettedForceSource >> &targetted_forces, bool fresh=false, const std::filesystem::path &base_path="./output", size_t start_iteration=0)
 Construct a new SimulationParams object. More...
 
void logSummary (int depth=0) const
 Prints a summary of the simulation parameters to the console. More...
 

Public Attributes

std::filesystem::path input_file_path
 Path to the input file of the simulation. More...
 
std::size_t input_file_hash
 Hash of the input file of the simulation. More...
 
std::filesystem::path output_dir_path
 Path to the directory in which to save the simulation output. More...
 
double delta_t
 Time step of a single simulation iteration. More...
 
double end_time
 End time of the simulation. More...
 
std::vector< std::shared_ptr< SimulationInterceptor > > interceptors
 List of interceptors to be used in the simulation. More...
 
std::variant< DirectSumType, LinkedCellsTypecontainer_type
 Type of the particle container. More...
 
std::vector< std::shared_ptr< SimpleForceSource > > simple_forces
 Simple Forces to be applied to the particles. More...
 
std::vector< std::shared_ptr< PairwiseForceSource > > pairwise_forces
 Pairwise Forces to be applied to the particles. More...
 
std::vector< std::shared_ptr< TargettedForceSource > > targetted_forces
 Targetted Forces to be applied to the particles. More...
 
size_t num_particles
 Number of particles in the simulation. More...
 
bool fresh
 Flag to indicate whether the simulation should be run from scratch, or whether cached data should be used. More...
 
size_t start_iteration
 Start iteration of the simulation. More...
 

Detailed Description

Contains all parameters needed to run a simulation.

This class is used to pass the parameters from the input file / CLI to the Simulation class.

Definition at line 22 of file SimulationParams.h.

Constructor & Destructor Documentation

◆ SimulationParams()

SimulationParams::SimulationParams ( const std::filesystem::path &  input_file_path,
double  delta_t,
double  end_time,
const std::variant< DirectSumType, LinkedCellsType > &  container_type,
const std::vector< std::shared_ptr< SimulationInterceptor >> &  interceptors,
const std::vector< std::shared_ptr< SimpleForceSource >> &  simple_forces,
const std::vector< std::shared_ptr< PairwiseForceSource >> &  pairwise_forces,
const std::vector< std::shared_ptr< TargettedForceSource >> &  targetted_forces,
bool  fresh = false,
const std::filesystem::path &  base_path = "./output",
size_t  start_iteration = 0 
)

Construct a new SimulationParams object.

Parameters
input_file_pathPath to the input file of the simulation
delta_tTime step of a single simulation iteration
end_timeEnd time of the simulation
container_typeType of the particle container
interceptorsList of interceptors to be used in the simulation
simple_forcesSimple Forces to be applied to the particles
pairwise_forcesForces to be applied to the particles
targetted_forcesTargetted Forces to be applied to the particles
freshFlag to indicate whether the simulation should be run from scratch, or whether cached data should be used
base_pathBase path to the output directory. This is used to construct the output directory path if none is given explicitly. Defaults to "./output/"
start_iterationStart iteration of the simulation

Definition at line 27 of file SimulationParams.cpp.

34  : input_file_path(std::filesystem::absolute(input_file_path)),
42  fresh(fresh),
44  if (end_time < 0) {
45  Logger::logger->error("End time must be positive");
46  throw std::runtime_error("End time must be positive");
47  }
48  if (delta_t < 0) {
49  Logger::logger->error("Delta t must be positive");
50  throw std::runtime_error("Delta t must be positive");
51  }
52 
53  this->output_dir_path = constructOutputPath(base_path, input_file_path.stem().string());
54 
56 
57  this->num_particles = 0;
58 }
std::filesystem::path constructOutputPath(const std::filesystem::path &base_path, const std::string &name)
static size_t calculateHash(const std::filesystem::path &filepath)
Calculates the hash for the given input file.
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Definition: Logger.h:35
std::vector< std::shared_ptr< PairwiseForceSource > > pairwise_forces
Pairwise Forces to be applied to the particles.
size_t num_particles
Number of particles in the simulation.
double delta_t
Time step of a single simulation iteration.
std::vector< std::shared_ptr< SimulationInterceptor > > interceptors
List of interceptors to be used in the simulation.
bool fresh
Flag to indicate whether the simulation should be run from scratch, or whether cached data should be ...
std::filesystem::path output_dir_path
Path to the directory in which to save the simulation output.
std::filesystem::path input_file_path
Path to the input file of the simulation.
std::size_t input_file_hash
Hash of the input file of the simulation.
size_t start_iteration
Start iteration of the simulation.
std::vector< std::shared_ptr< SimpleForceSource > > simple_forces
Simple Forces to be applied to the particles.
std::vector< std::shared_ptr< TargettedForceSource > > targetted_forces
Targetted Forces to be applied to the particles.
std::variant< DirectSumType, LinkedCellsType > container_type
Type of the particle container.
double end_time
End time of the simulation.

Member Function Documentation

◆ logSummary()

void SimulationParams::logSummary ( int  depth = 0) const

Prints a summary of the simulation parameters to the console.

Parameters
depthdetermines the indentation of the log message

Definition at line 60 of file SimulationParams.cpp.

60  {
61  std::string indent = std::string(depth * 2, ' ');
62 
63  std::string force_names =
64  std::accumulate(
65  simple_forces.begin(), simple_forces.end(), std::string{},
66  [](const std::string& acc, const std::shared_ptr<SimpleForceSource>& force) { return acc + std::string(*force) + ", "; }) +
67  std::accumulate(
68  pairwise_forces.begin(), pairwise_forces.end(), std::string{},
69  [](const std::string& acc, const std::shared_ptr<PairwiseForceSource>& force) { return acc + std::string(*force) + ", "; });
70 
71  Logger::logger->info("{}╔════════════════════════════════════════", indent);
72  Logger::logger->info("{}╟┤{}Simulation arguments: {}", indent, ansi_yellow_bold, ansi_end);
73  Logger::logger->info("{}║ Input file path: {}", indent, input_file_path.string());
74  Logger::logger->info("{}║ Output directory path: {}", indent, output_dir_path.string());
75  Logger::logger->info("{}║ Start iteration: {}", indent, start_iteration);
76  Logger::logger->info("{}║ Delta_t: {}", indent, delta_t);
77  Logger::logger->info("{}║ End_time: {}", indent, end_time);
78  Logger::logger->info("{}║ Reuse cached data: {}", indent, !fresh);
79 
80  // Print Physical setup
81  Logger::logger->info("{}╟┤{}Physical setup: {}", indent, ansi_yellow_bold, ansi_end);
82  Logger::logger->info("{}║ Number of particles: {}", indent, num_particles);
83  Logger::logger->info("{}║ Number of forces: {}", indent, pairwise_forces.size() + simple_forces.size());
84  Logger::logger->info("{}║ Forces: {}", indent, force_names);
85 
86  Logger::logger->info("{}╟┤{}Container: {}", indent, ansi_yellow_bold, ansi_end);
87 
88  if (std::holds_alternative<SimulationParams::LinkedCellsType>(container_type)) {
89  auto lc_container = std::get<SimulationParams::LinkedCellsType>(container_type);
90 
91  using LC = LinkedCellsContainer;
92 
93  auto domain_size = lc_container.domain_size;
94  Logger::logger->info("{}║ Linked Cells", indent);
95  Logger::logger->info("{}║ Domain size: {} x {} x {}", indent, domain_size[0], domain_size[1], domain_size[2]);
96  Logger::logger->info("{}║ Cutoff radius: {}", indent, lc_container.cutoff_radius);
97  Logger::logger->info("{}║ ┌Left: {}", indent, LC::boundaryConditionToString(lc_container.boundary_conditions[0]));
98  Logger::logger->info("{}║ ├Right: {}", indent, LC::boundaryConditionToString(lc_container.boundary_conditions[1]));
99  Logger::logger->info("{}║ ├Bottom: {}", indent, LC::boundaryConditionToString(lc_container.boundary_conditions[2]));
100  Logger::logger->info("{}║ ├Top: {}", indent, LC::boundaryConditionToString(lc_container.boundary_conditions[3]));
101  Logger::logger->info("{}║ ├Back: {}", indent, LC::boundaryConditionToString(lc_container.boundary_conditions[4]));
102  Logger::logger->info("{}║ └Front: {}", indent, LC::boundaryConditionToString(lc_container.boundary_conditions[5]));
103  } else if (std::holds_alternative<SimulationParams::DirectSumType>(container_type)) {
104  Logger::logger->info("{}║ Direct Sum", indent);
105  } else {
106  Logger::logger->error("Invalid container type");
107  throw std::runtime_error("Invalid container type");
108  }
109 
110  Logger::logger->info("{}╟┤{}Interceptors: {}", indent, ansi_yellow_bold, ansi_end);
111  if (interceptors.empty()) {
112  Logger::logger->info("{}║ None", indent);
113  } else {
114  for (auto& interceptor : interceptors) {
115  interceptor->logSummary(depth);
116  }
117  }
118 
119 #ifdef _OPENMP
120  Logger::logger->info("{}╟┤{}Maximum Number of Threads:{} {}", indent, ansi_yellow_bold, ansi_end, omp_get_max_threads());
121 #endif
122 
123  Logger::logger->info("{}╚════════════════════════════════════════", indent);
124 }
const std::string ansi_yellow_bold
Definition: Logger.h:11
const std::string ansi_end
Definition: Logger.h:13
Extension of the ParticleContainer class using a linked cells data structure for improved performance...
std::array< double, 3 > domain_size
Domain size in each dimension.

Member Data Documentation

◆ container_type

std::variant<DirectSumType, LinkedCellsType> SimulationParams::container_type

Type of the particle container.

Definition at line 89 of file SimulationParams.h.

◆ delta_t

double SimulationParams::delta_t

Time step of a single simulation iteration.

Definition at line 74 of file SimulationParams.h.

◆ end_time

double SimulationParams::end_time

End time of the simulation.

Definition at line 79 of file SimulationParams.h.

◆ fresh

bool SimulationParams::fresh

Flag to indicate whether the simulation should be run from scratch, or whether cached data should be used.

Definition at line 114 of file SimulationParams.h.

◆ input_file_hash

std::size_t SimulationParams::input_file_hash

Hash of the input file of the simulation.

Definition at line 64 of file SimulationParams.h.

◆ input_file_path

std::filesystem::path SimulationParams::input_file_path

Path to the input file of the simulation.

Definition at line 59 of file SimulationParams.h.

◆ interceptors

std::vector<std::shared_ptr<SimulationInterceptor> > SimulationParams::interceptors

List of interceptors to be used in the simulation.

Definition at line 84 of file SimulationParams.h.

◆ num_particles

size_t SimulationParams::num_particles

Number of particles in the simulation.

Definition at line 109 of file SimulationParams.h.

◆ output_dir_path

std::filesystem::path SimulationParams::output_dir_path

Path to the directory in which to save the simulation output.

Definition at line 69 of file SimulationParams.h.

◆ pairwise_forces

std::vector<std::shared_ptr<PairwiseForceSource> > SimulationParams::pairwise_forces

Pairwise Forces to be applied to the particles.

Definition at line 99 of file SimulationParams.h.

◆ simple_forces

std::vector<std::shared_ptr<SimpleForceSource> > SimulationParams::simple_forces

Simple Forces to be applied to the particles.

Definition at line 94 of file SimulationParams.h.

◆ start_iteration

size_t SimulationParams::start_iteration

Start iteration of the simulation.

Definition at line 119 of file SimulationParams.h.

◆ targetted_forces

std::vector<std::shared_ptr<TargettedForceSource> > SimulationParams::targetted_forces

Targetted Forces to be applied to the particles.

Definition at line 104 of file SimulationParams.h.


The documentation for this class was generated from the following files: