43#include <boost/mpi.hpp>
44#include <boost/mpi/collectives/all_reduce.hpp>
45#include <boost/mpi/collectives/broadcast.hpp>
60std::unordered_map<std::string, int>
const LBVTKHandle::obs_map = {
68 if (
name ==
"activate") {
75 if (
name ==
"deactivate") {
82 if (
name ==
"add_force_at_pos") {
86 auto const folded_pos = box_geo.folded_position(pos);
90 if (
name ==
"get_interpolated_velocity") {
92 return get_interpolated_velocity(pos);
94 if (
name ==
"get_pressure_tensor") {
95 return get_average_pressure_tensor();
97 if (
name ==
"load_checkpoint") {
100 load_checkpoint(path,
mode);
103 if (
name ==
"save_checkpoint") {
106 save_checkpoint(path,
mode);
109 if (
name ==
"clear_boundaries") {
114 if (
name ==
"add_boundary_from_shape") {
120 if (
name ==
"get_lattice_speed") {
164 throw std::domain_error(
"Parameter 'tau' must be > 0");
179 throw std::domain_error(
"Parameter 'seed' must be >= 0");
182 throw std::domain_error(
"Parameter 'kT' must be >= 0");
185 throw std::domain_error(
"Parameter 'density' must be > 0");
188 throw std::domain_error(
"Parameter 'kinematic_viscosity' must be >= 0");
192 static_cast<unsigned int>(seed));
201std::vector<Variant> LBFluid::get_average_pressure_tensor()
const {
206 return std::vector<Variant>{
tensor.row<0>().as_vector(),
207 tensor.row<1>().as_vector(),
208 tensor.row<2>().as_vector()};
219void LBFluid::load_checkpoint(std::string
const &
filename,
int mode) {
230 std::stringstream message;
231 message <<
"grid dimensions mismatch, read [" <<
read_grid_size <<
"], "
233 throw std::runtime_error(message.str());
236 throw std::runtime_error(
"population size mismatch, read " +
249 for (
int i = 0; i <
i_max; i++) {
251 for (
int k = 0; k <
k_max; k++) {
260 lb_obj.set_node_last_applied_force(ind,
cpnode.last_applied_force);
262 lb_obj.set_node_velocity_at_boundary(ind,
cpnode.slip_velocity);
270 lb_obj.ghost_communication();
271 lb_obj.reallocate_ubb_field();
278void LBFluid::save_checkpoint(std::string
const &
filename,
int mode) {
293 auto const on_failure = [](std::shared_ptr<CheckpointFile>
const &,
305 [&](
Utils::Vector3i const &ind) -> std::optional<LBWalberlaNodeState> {
306 auto const pop =
lb_obj.get_node_population(ind);
307 auto const laf =
lb_obj.get_node_last_applied_force(ind);
308 auto const lbb =
lb_obj.get_node_is_boundary(ind);
309 auto const vbb =
lb_obj.get_node_velocity_at_boundary(ind);
323 auto failure =
false;
333 for (
int i = 0; i <
i_max; i++) {
335 for (
int k = 0; k <
k_max; k++) {
339 assert(1 == boost::mpi::all_reduce(comm,
static_cast<int>(!!result),
341 "Incorrect number of return values");
347 comm.recv(boost::mpi::any_source, 42,
cpnode);
356 boost::mpi::broadcast(comm, failure, 0);
359 comm.send(0, 42, *result);
361 boost::mpi::broadcast(comm, failure, 0);
Vector implementation and trait types for boost qvm interoperability.
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual bool is_head_node() const =0
virtual boost::mpi::communicator const & get_comm() const =0
boost::string_ref name() const
Context * context() const
Responsible context.
void make_instance(VariantMap const ¶ms) override
void make_instance(VariantMap const ¶ms) override
void do_construct(VariantMap const ¶ms) override
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
std::shared_ptr<::LB::LBWalberlaParams > m_lb_params
::LatticeModel::units_map get_latice_to_md_units_conversion() const override
std::shared_ptr< ::LBWalberlaBase > m_instance
Variant do_call_method(std::string const &method_name, VariantMap const ¶ms) override
std::vector< std::shared_ptr< LBVTKHandle > > m_vtk_writers
std::shared_ptr< LatticeWalberla > m_lattice
virtual void make_instance(VariantMap const ¶ms)=0
void on_lb_boundary_conditions_change()
Called when the LB boundary conditions change (geometry, slip velocity, or both).
std::shared_ptr< BoxGeometry > box_geo
This file contains the defaults for ESPResSo.
std::shared_ptr< LBWalberlaBase > new_lb_walberla_cpu(std::shared_ptr< LatticeWalberla > const &lattice, double viscosity, double density, bool single_precision)
std::shared_ptr< LBWalberlaBase > new_lb_walberla_gpu(std::shared_ptr< LatticeWalberla > const &lattice, double viscosity, double density, bool single_precision)
Matrix implementation and trait types for boost qvm interoperability.
void save_checkpoint_common(Context const &context, std::string const classname, std::string const &filename, int mode, F1 const write_metadata, F2 const write_data, F3 const on_failure)
void unit_test_handle(int mode)
Inject code for unit tests.
void load_checkpoint_common(Context const &context, std::string const classname, std::string const &filename, int mode, F1 const read_metadata, F2 const read_data, F3 const on_success)
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
T mpi_reduce_sum(boost::mpi::communicator const &comm, T const &result)
Reduce object by sum on the head node.
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
T reduce_optional(boost::mpi::communicator const &comm, std::optional< T > const &result)
Reduce an optional on the head node.
static FUNC_PREFIX double *RESTRICT int64_t const int64_t const int64_t const int64_t const int64_t const int64_t const int64_t const int64_t const int64_t const int64_t const int64_t const double grid_size
static SteepestDescentParameters params
Currently active steepest descent instance.
Checkpoint data for a LB node.
std::vector< double > populations
void update_collision_model()
void reset()
Remove the LB solver.
void set(Args... args)
Set the LB solver.
Matrix representation with static size.