21#ifdef ESPRESSO_WALBERLA
30#include <boost/mpi.hpp>
31#include <boost/mpi/collectives/all_reduce.hpp>
32#include <boost/mpi/collectives/broadcast.hpp>
47std::unordered_map<std::string, int>
const EKVTKHandle::obs_map = {
54 if (
method ==
"update_flux_boundary_from_shape") {
56 if (
get_lattice()->lattice()->get_ghost_layers() < 2) {
57 if (
context()->get_comm().size() > 1) {
58 throw std::runtime_error(
"The number of ghostlayers should be > 1 "
59 "when using flux boundaries and mpi.");
62 "using flux boundaries and mpi.";
72 if (
method ==
"update_density_boundary_from_shape") {
75 m_instance->update_density_boundary_from_shape(
79 if (
method ==
"clear_flux_boundaries") {
83 if (
method ==
"clear_density_boundaries") {
87 if (
method ==
"save_checkpoint") {
90 save_checkpoint(path,
mode);
93 if (
method ==
"load_checkpoint") {
96 load_checkpoint(path,
mode);
156 throw std::invalid_argument(
157 "Parameter 'seed' is required for thermalized EKSpecies");
160 throw std::domain_error(
"Parameter 'seed' must be >= 0");
163 throw std::domain_error(
"Parameter 'tau' must be > 0");
166 throw std::domain_error(
"Parameter 'kT' must be >= 0");
169 throw std::domain_error(
"Parameter 'density' must be >= 0");
184void EKSpecies::load_checkpoint(std::filesystem::path
const &path,
int mode) {
192 std::stringstream message;
193 message <<
"grid dimensions mismatch, read [" <<
read_grid_size <<
"], "
195 throw std::runtime_error(message.str());
200 auto const grid_size =
ek_obj.get_lattice().get_grid_dimensions();
201 auto const i_max = grid_size[0];
202 auto const j_max = grid_size[1];
203 auto const k_max = grid_size[2];
205 for (
int i = 0; i <
i_max; i++) {
207 for (
int k = 0; k <
k_max; k++) {
211 if (
cpnode.is_boundary_density) {
215 if (
cpnode.is_boundary_flux) {
219 if (
cpnode.is_boundary_density) {
220 ek_obj.set_node_density_boundary(ind,
cpnode.density_boundary);
222 if (
cpnode.is_boundary_flux) {
223 ek_obj.set_node_flux_boundary(ind,
cpnode.flux_boundary);
236void EKSpecies::save_checkpoint(std::filesystem::path
const &path,
int mode) {
249 auto const on_failure = [](std::shared_ptr<CheckpointFile>
const &,
261 [&](
Utils::Vector3i const &ind) -> std::optional<EKWalberlaNodeState> {
263 auto const is_b_d =
ek_obj.get_node_is_density_boundary(ind);
264 auto const dens_b =
ek_obj.get_node_density_at_boundary(ind);
265 auto const is_b_f =
ek_obj.get_node_is_flux_boundary(ind);
266 auto const flux_b =
ek_obj.get_node_flux_at_boundary(ind);
285 auto failure =
false;
295 for (
int i = 0; i <
i_max; i++) {
297 for (
int k = 0; k <
k_max; k++) {
301 assert(1 == boost::mpi::all_reduce(comm,
static_cast<int>(!!result),
303 "Incorrect number of return values");
309 comm.recv(boost::mpi::any_source, 42,
cpnode);
314 if (
cpnode.is_boundary_density) {
318 if (
cpnode.is_boundary_flux) {
321 boost::mpi::broadcast(comm, failure, 0);
324 comm.send(0, 42, *result);
326 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 make_instance(VariantMap const ¶ms) override
void make_instance(VariantMap const ¶ms) override
::LatticeModel::units_map get_lattice_to_md_units_conversion() const 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
virtual void make_instance(VariantMap const ¶ms)=0
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 ...
#define runtimeWarningMsg()
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
static FUNC_PREFIX double *RESTRICT const 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 int64_t const int64_t const int64_t const int64_t const double grid_size
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)
static SteepestDescentParameters params
Currently active steepest descent instance.
Checkpoint data for a EK node.
Recursive variant implementation.