ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/walberla/LatticeWalberla.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-2023 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "config/config.hpp"
23
24#ifdef WALBERLA
25
26#include "core/BoxGeometry.hpp"
29
31
34
35#include <cmath>
36#include <memory>
37#include <stdexcept>
38#include <string>
39
41
42class LatticeWalberla : public AutoParameters<LatticeWalberla> {
43 std::shared_ptr<::LatticeWalberla> m_lattice;
44 double m_agrid;
45 Utils::Vector3d m_box_l;
46
47public:
50 {"agrid", AutoParameter::read_only, [this]() { return m_agrid; }},
51 {"n_ghost_layers", AutoParameter::read_only,
52 [this]() { return static_cast<int>(m_lattice->get_ghost_layers()); }},
54 [this]() { return m_lattice->get_grid_dimensions(); }},
55 {"_box_l", AutoParameter::read_only, [this]() { return m_box_l; }},
56 });
57 }
58
59 void do_construct(VariantMap const &args) override {
60 auto const &box_geo = *::System::get_system().box_geo;
61 m_agrid = get_value<double>(args, "agrid");
62 m_box_l = get_value_or<Utils::Vector3d>(args, "_box_l", box_geo.length());
63 auto const n_ghost_layers = get_value<int>(args, "n_ghost_layers");
64
66 if (m_agrid <= 0.) {
67 throw std::domain_error("Parameter 'agrid' must be > 0");
68 }
69 if (n_ghost_layers < 0) {
70 throw std::domain_error("Parameter 'n_ghost_layers' must be >= 0");
71 }
72 auto const grid_dim =
74 m_lattice = std::make_shared<::LatticeWalberla>(
75 grid_dim, ::communicator.node_grid,
76 static_cast<unsigned int>(n_ghost_layers));
77 });
78 }
79
80 std::shared_ptr<::LatticeWalberla> lattice() { return m_lattice; }
81 std::shared_ptr<const ::LatticeWalberla> lattice() const { return m_lattice; }
82};
83
84} // namespace ScriptInterface::walberla
85
86#endif // WALBERLA
static Utils::Vector3i calc_grid_dimensions(Utils::Vector3d const &box_size, double agrid)
Bind parameters in the script interface.
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Context * context() const
Responsible context.
std::shared_ptr< const ::LatticeWalberla > lattice() const
std::shared_ptr< BoxGeometry > box_geo
Communicator communicator
This file contains the defaults for ESPResSo.
This file contains the asynchronous MPI communication.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
System & get_system()
static constexpr const ReadOnly read_only