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
"
27
#include "
core/communication.hpp
"
28
#include "
core/system/System.hpp
"
29
30
#include <
walberla_bridge/LatticeWalberla.hpp
>
31
32
#include <
script_interface/ScriptInterface.hpp
>
33
#include <
script_interface/auto_parameters/AutoParameters.hpp
>
34
35
#include <cmath>
36
#include <memory>
37
#include <stdexcept>
38
#include <string>
39
40
namespace
ScriptInterface::walberla
{
41
42
class
LatticeWalberla
:
public
AutoParameters
<LatticeWalberla> {
43
std::shared_ptr<::LatticeWalberla> m_lattice;
44
double
m_agrid;
45
Utils::Vector3d
m_box_l;
46
47
public
:
48
LatticeWalberla
() {
49
add_parameters
({
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()); }},
53
{
"shape"
,
AutoParameter::read_only
,
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
65
context
()->
parallel_try_catch
([&]() {
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 =
73
::LatticeWalberla::calc_grid_dimensions
(m_box_l, m_agrid);
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
AutoParameters.hpp
BoxGeometry.hpp
ScriptInterface.hpp
LatticeWalberla::calc_grid_dimensions
static Utils::Vector3i calc_grid_dimensions(Utils::Vector3d const &box_size, double agrid)
Definition
LatticeWalberla.cpp:102
ScriptInterface::AutoParameters
Bind parameters in the script interface.
Definition
AutoParameters.hpp:93
ScriptInterface::AutoParameters< LatticeWalberla >::add_parameters
void add_parameters(std::vector< AutoParameter > &¶ms)
Definition
AutoParameters.hpp:115
ScriptInterface::Context::parallel_try_catch
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:58
ScriptInterface::walberla::LatticeWalberla
Definition
script_interface/walberla/LatticeWalberla.hpp:42
ScriptInterface::walberla::LatticeWalberla::lattice
std::shared_ptr<::LatticeWalberla > lattice()
Definition
script_interface/walberla/LatticeWalberla.hpp:80
ScriptInterface::walberla::LatticeWalberla::do_construct
void do_construct(VariantMap const &args) override
Definition
script_interface/walberla/LatticeWalberla.hpp:59
ScriptInterface::walberla::LatticeWalberla::LatticeWalberla
LatticeWalberla()
Definition
script_interface/walberla/LatticeWalberla.hpp:48
ScriptInterface::walberla::LatticeWalberla::lattice
std::shared_ptr< const ::LatticeWalberla > lattice() const
Definition
script_interface/walberla/LatticeWalberla.hpp:81
System::System::box_geo
std::shared_ptr< BoxGeometry > box_geo
Definition
core/system/System.hpp:278
Utils::Vector
Definition
Vector.hpp:48
communicator
Communicator communicator
Definition
communication.cpp:48
config.hpp
This file contains the defaults for ESPResSo.
communication.hpp
This file contains the asynchronous MPI communication.
System.hpp
ScriptInterface::walberla
Definition
script_interface/walberla/EKContainer.hpp:47
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:69
System::get_system
System & get_system()
Definition
core/system/System.cpp:122
ScriptInterface::AutoParameter::read_only
static constexpr const ReadOnly read_only
Definition
AutoParameter.hpp:42
LatticeWalberla.hpp
src
script_interface
walberla
LatticeWalberla.hpp
Generated on Thu Dec 19 2024 02:13:16 for ESPResSo by
1.9.8