WaSH Docs
wash.hpp
Go to the documentation of this file.
1 
25 #pragma once
26 
27 // Ensure that the compilation stage has defined an implementation specific flag
28 // this is used to enable some optional parameters and features in e.g. the Particle class
29 // Usually the user should not see this message as the wash tool will define the appropriate flag for them.
30 #if !defined WASH_WSER && !defined WASH_WISB && !defined WASH_WEST && !defined WASH_CSTONE && !defined WASH_WONE
31 #error "Please specify an implementation when compiling WASH"
32 #endif
33 
34 // DIM is the compile-time flag for the dimensionality of the simulation, dictating
35 // the dimensionality of the vector to use. This should be specified in the implementation library.
36 #ifndef DIM
37 #error "Please define -DDIM=d when compiling WASH"
38 #endif
39 
40 #include <chrono>
41 #include <cassert>
42 #include <chrono>
43 #include <functional>
44 #include <optional>
45 #include <stdexcept>
46 #include <string>
47 #include <unordered_map>
48 #include <vector>
49 
50 #include "io.hpp"
51 #include "particle.hpp"
52 #include "particle_data.hpp"
53 #include "util.hpp"
54 #include "vector.hpp"
55 #include "kernels.hpp"
56 
64 #define defineWashForceKernel(kernel_name, particle_name) \
65  void kernel_name (wash::Particle& particle_name, \
66  const std::vector<wash::Particle>::const_iterator& begin, \
67  const std::vector<wash::Particle>::const_iterator& end)
68 
74 #define defineWashVoidKernel(kernel_name) \
75  void kernel_name (void)
76 
84 #define defineWashUpdateKernel(kernel_name, particle_name) \
85  void kernel_name (wash::Particle& particle_name)
86 
94 #define defineWashReductionKernel(kernel_name, particle_name) \
95  double kernel_name (const wash::Particle& particle_name)
96 
104 #define washForEachNeighbour(var_name, body) \
105  _Pragma("omp simd")\
106  for (auto it = begin; it != end; it++) {\
107  const auto& var_name = *it;\
108  { body }\
109  }
110 
111 namespace wash {
112 
118  uint64_t get_max_iterations();
119 
125  void set_max_iterations(const uint64_t iterations);
126 
130  void set_bounding_box(const double min, const double max, const bool periodic);
131 
135  void set_bounding_box(const double xmin, const double xmax, const double ymin, const double ymax, const double zmin,
136  const double zmax, const bool x_periodic, const bool y_periodic, const bool z_periodic);
137 
143  void add_force_scalar(const std::string force);
144 
150  void add_force_vector(const std::string force);
151 
158  void add_variable(const std::string variable, double init_value = 0.0);
159 
165  void add_init_update_kernel(const UpdateFuncT func);
166 
172  void add_init_void_kernel(const VoidFuncT func);
173 
180  void add_force_kernel(const ForceFuncT func);
181 
187  void add_update_kernel(const UpdateFuncT func);
188 
199  void add_reduction_kernel(const MapFuncT map_func, const ReduceOp reduce_op, double* variable);
200 
206  void add_void_kernel(const VoidFuncT func);
207 
215  void set_default_neighbor_search(const unsigned max_count);
216 
223  void set_neighbor_search_kernel(const NeighborsFuncT func, const unsigned max_count);
224 
231  double get_variable(const std::string& variable);
232 
239  double* use_variable(const std::string& variable);
240 
247  void set_variable(const std::string& variable, const double value);
248 
249  // /**
250  // * @brief Get the vector of all particles in the simulation
251  // *
252  // * @return std::vector<Particle>&
253  // */
254  // std::vector<Particle>& get_particles();
255 
259  void start();
260 
266  void set_simulation_name(const std::string name);
267 
273  void set_output_file_name(const std::string name);
274 
276 
283  double eucdist(const Particle& p, const Particle& q);
284 
290  void set_particle_count(const size_t count);
291 
297  size_t get_particle_count();
298 
304  void set_dimension(int dim);
305 
309  void set_io(const std::string format, size_t output_nth, bool timings = true);
310 };
uint64_t get_max_iterations()
Get the max iterations of the simulation.
Definition: wash.cpp:42
void add_reduction_kernel(const MapFuncT map_func, const ReduceOp reduce_op, double *variable)
Add a reduction kernel to the simulation which will loop over the particles.
Definition: wash.cpp:116
void add_void_kernel(const VoidFuncT func)
Add a void kernel to the simulation.
Definition: wash.cpp:121
void start()
Get the vector of all particles in the simulation.
Definition: wash.cpp:255
void set_particle_count(const size_t count)
Set the number of particles to be used in the simulation.
Definition: wash.cpp:51
void add_force_vector(const std::string force)
Add a n-dim vector force to the simulation.
Definition: wash.cpp:83
ReduceOp
Type of reduction operation to perform in a reduce kernel.
Definition: kernels.hpp:18
void add_variable(const std::string variable, double init_value=0.0)
Add a scalar variable to the simulation.
Definition: wash.cpp:90
void set_default_neighbor_search(const unsigned max_count)
Set the neighborhood search to use the provided default which uses the smoothing length of the partic...
Definition: wash.cpp:126
double get_variable(const std::string &variable)
Get the value of a variable.
Definition: wash.cpp:184
void set_max_iterations(const uint64_t iterations)
Set the max number of iterations.
Definition: wash.cpp:44
double * use_variable(const std::string &variable)
Returns a reference to a variable useful for e.g. reduction kernels.
Definition: wash.cpp:186
void set_output_file_name(const std::string name)
Set the output file name of the simulation.
Definition: wash.cpp:147
void set_simulation_name(const std::string name)
Set the name of the simulation, used in IO.
Definition: wash.cpp:140
void add_update_kernel(const UpdateFuncT func)
Add an update kernel to the simulation which will loop over the particles.
Definition: wash.cpp:111
void add_force_kernel(const ForceFuncT func)
Add a force kernel to the simulation which will loop over the particles and their neighbourhood...
Definition: wash.cpp:106
size_t get_particle_count()
Get the number of particles used in the simulation.
Definition: wash.cpp:49
TODO: Consider having this as a private header in WISB/WS2ST/etc implementations. ...
Definition: ascii.hpp:5
void set_neighbor_search_kernel(const NeighborsFuncT func, const unsigned max_count)
Sets the neighbourhood search to use a custom function.
Definition: wash.cpp:132
void set_variable(const std::string &variable, const double value)
Set the value of a variable.
Definition: wash.cpp:188
double eucdist(const Particle &p, const Particle &q)
TODO: Move eucdist calculation to the paticle header?
Definition: wash.cpp:394
void add_init_update_kernel(const UpdateFuncT func)
Add an initialisation update kernel (will be executed for each particle)
Definition: wash.cpp:96
void add_force_scalar(const std::string force)
Add a scalar force to the simulation.
Definition: wash.cpp:75
void add_init_void_kernel(const VoidFuncT func)
Add an initialization void kernel to the simulation - run once.
Definition: wash.cpp:101
void set_dimension(int dim)
Set the dimensionality of the simulation.
Definition: wash.cpp:423
void set_io(const std::string format, size_t output_nth, bool timings=true)
Set the IO parameters used for the simulation.
Definition: wash.cpp:429
void set_bounding_box(const double min, const double max, const bool periodic)
Set the bounding box dimensions and periodicity type.
Definition: wash.cpp:56