21#ifdef ESPRESSO_WALBERLA
34#include <boost/mpi.hpp>
35#include <boost/mpi/collectives/all_reduce.hpp>
36#include <boost/mpi/collectives/broadcast.hpp>
51std::unordered_map<std::string, int>
const EKVTKHandle::obs_map = {
58 if (
method ==
"update_flux_boundary_from_shape") {
67 if (
method ==
"update_density_boundary_from_shape") {
70 m_instance->update_density_boundary_from_shape(
74 if (
method ==
"clear_flux_boundaries") {
78 if (
method ==
"clear_density_boundaries") {
82 if (
method ==
"save_checkpoint") {
85 save_checkpoint(path,
mode);
88 if (
method ==
"load_checkpoint") {
91 load_checkpoint(path,
mode);
138 not params.contains(
"seed")) {
139 throw std::invalid_argument(
140 "Parameter 'seed' is required for thermalized EKSpecies");
143 throw std::domain_error(
"Parameter 'seed' must be >= 0");
146 throw std::domain_error(
"Parameter 'tau' must be > 0");
149 throw std::domain_error(
"Parameter 'kT' must be >= 0");
152 throw std::domain_error(
"Parameter 'density' must be >= 0");
168void EKSpecies::load_checkpoint(std::filesystem::path
const &path,
int mode) {
176 std::stringstream message;
177 message <<
"grid dimensions mismatch, read [" <<
read_grid_size <<
"], "
179 throw std::runtime_error(message.str());
189 for (
int i = 0; i <
i_max; i++) {
191 for (
int k = 0; k <
k_max; k++) {
195 if (
cpnode.is_boundary_density) {
199 if (
cpnode.is_boundary_flux) {
203 if (
cpnode.is_boundary_density) {
204 ek_obj.set_node_density_boundary(ind,
cpnode.density_boundary);
206 if (
cpnode.is_boundary_flux) {
207 ek_obj.set_node_flux_boundary(ind,
cpnode.flux_boundary);
220void EKSpecies::save_checkpoint(std::filesystem::path
const &path,
int mode) {
233 auto const on_failure = [](std::shared_ptr<CheckpointFile>
const &,
245 [&](
Utils::Vector3i const &ind) -> std::optional<EKWalberlaNodeState> {
247 auto const is_b_d =
ek_obj.get_node_is_density_boundary(ind);
248 auto const dens_b =
ek_obj.get_node_density_at_boundary(ind);
249 auto const is_b_f =
ek_obj.get_node_is_flux_boundary(ind);
250 auto const flux_b =
ek_obj.get_node_flux_at_boundary(ind);
269 auto failure =
false;
279 for (
int i = 0; i <
i_max; i++) {
281 for (
int k = 0; k <
k_max; k++) {
285 assert(1 == boost::mpi::all_reduce(comm,
static_cast<int>(!!result),
287 "Incorrect number of return values");
293 comm.recv(boost::mpi::any_source, 42,
cpnode);
298 if (
cpnode.is_boundary_density) {
302 if (
cpnode.is_boundary_flux) {
305 boost::mpi::broadcast(comm, failure, 0);
308 comm.send(0, 42, *result);
310 boost::mpi::broadcast(comm, failure, 0);
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
Context * context() const
Responsible context.
Handle for a checkpoint file.
void flux_boundary_ghost_layer_size_sanity_check() const
::LatticeModel::units_map get_lattice_to_md_units_conversion() const override
std::optional< ResourceObserver > m_mpi_cart_comm_observer
void make_instance(VariantMap const ¶ms) override
Variant do_call_method(std::string const &method, VariantMap const ¶meters) override
void do_construct(VariantMap const ¶ms) override
std::shared_ptr< ::EKinWalberlaBase > m_instance
Variant do_call_method(std::string const &method_name, VariantMap const ¶ms) override
std::vector< std::shared_ptr< EKVTKHandle > > m_vtk_writers
std::shared_ptr< LatticeWalberla > m_lattice
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
void check_features(std::vector< std::string > const &features)
void save_checkpoint_common(Context const &context, std::string const classname, std::filesystem::path const &path, 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::filesystem::path const &path, 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 get_value_or(VariantMap const &vals, std::string const &name, T const &default_)
Get a value from a VariantMap by name, or return a default value if it does not exist.
std::shared_ptr< EKinWalberlaBase > new_ek_walberla_cpu(std::shared_ptr< LatticeWalberla > const &lattice, double diffusion, double kT, double valency, Utils::Vector3d ext_efield, double density, bool advection, bool friction_coupling, bool single_precision, bool thermalized, unsigned int seed)
std::shared_ptr< EKinWalberlaBase > new_ek_walberla_gpu(std::shared_ptr< LatticeWalberla > const &lattice, double diffusion, double kT, double valency, Utils::Vector3d ext_efield, double density, bool advection, bool friction_coupling, bool single_precision, bool thermalized, unsigned int seed)
ResourceObserver get_mpi_cart_comm_observer()
Get an observer on waLBerla's MPI Cartesian communicator status.
Checkpoint data for a EK node.
Recursive variant implementation.