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
Utils::Vector3i
m_blocks_per_mpi_rank;
47
48
public
:
49
LatticeWalberla
() {
50
add_parameters
({
51
{
"agrid"
,
AutoParameter::read_only
, [
this
]() {
return
m_agrid; }},
52
{
"n_ghost_layers"
,
AutoParameter::read_only
,
53
[
this
]() {
return
static_cast<
int
>
(m_lattice->get_ghost_layers()); }},
54
{
"shape"
,
AutoParameter::read_only
,
55
[
this
]() {
return
m_lattice->get_grid_dimensions(); }},
56
{
"_box_l"
,
AutoParameter::read_only
, [
this
]() {
return
m_box_l; }},
57
{
"blocks_per_mpi_rank"
,
AutoParameter::read_only
,
58
[
this
]() {
return
m_blocks_per_mpi_rank; }},
59
});
60
}
61
62
void
do_construct
(
VariantMap
const
&args)
override
{
63
auto
const
&box_geo = *
::System::get_system
().
box_geo
;
64
m_agrid = get_value<double>(args,
"agrid"
);
65
m_box_l = get_value_or<Utils::Vector3d>(args,
"_box_l"
, box_geo.length());
66
m_blocks_per_mpi_rank =
67
get_value<Utils::Vector3i>(args,
"blocks_per_mpi_rank"
);
68
auto
const
n_ghost_layers = get_value<int>(args,
"n_ghost_layers"
);
69
auto
const
block_grid =
Utils::hadamard_product
(
::communicator
.node_grid,
70
m_blocks_per_mpi_rank);
71
72
context
()->
parallel_try_catch
([&]() {
73
if
(m_agrid <= 0.) {
74
throw
std::domain_error(
"Parameter 'agrid' must be > 0"
);
75
}
76
if
(n_ghost_layers < 0) {
77
throw
std::domain_error(
"Parameter 'n_ghost_layers' must be >= 0"
);
78
}
79
if
(not(m_blocks_per_mpi_rank >=
Utils::Vector3i::broadcast
(1))) {
80
throw
std::domain_error(
"Parameter 'blocks_per_mpi_rank' must be >= 1"
);
81
}
82
auto
const
grid_dim =
83
::LatticeWalberla::calc_grid_dimensions
(m_box_l, m_agrid);
84
m_lattice = std::make_shared<::LatticeWalberla>(
85
grid_dim,
::communicator
.node_grid, block_grid,
86
static_cast<
unsigned
int
>
(n_ghost_layers));
87
});
88
}
89
90
std::shared_ptr<::LatticeWalberla>
lattice
() {
return
m_lattice; }
91
std::shared_ptr<const ::LatticeWalberla>
lattice
()
const
{
return
m_lattice; }
92
};
93
94
}
// namespace ScriptInterface::walberla
95
96
#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:134
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:117
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:90
ScriptInterface::walberla::LatticeWalberla::do_construct
void do_construct(VariantMap const &args) override
Definition
script_interface/walberla/LatticeWalberla.hpp:62
ScriptInterface::walberla::LatticeWalberla::LatticeWalberla
LatticeWalberla()
Definition
script_interface/walberla/LatticeWalberla.hpp:49
ScriptInterface::walberla::LatticeWalberla::lattice
std::shared_ptr< const ::LatticeWalberla > lattice() const
Definition
script_interface/walberla/LatticeWalberla.hpp:91
System::System::box_geo
std::shared_ptr< BoxGeometry > box_geo
Definition
core/system/System.hpp:278
Utils::Vector
Definition
Vector.hpp:48
Utils::Vector::broadcast
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value) noexcept
Create a vector that has all entries set to the same value.
Definition
Vector.hpp:110
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
Utils::hadamard_product
auto hadamard_product(Vector< T, N > const &a, Vector< U, N > const &b)
Definition
Vector.hpp:379
ScriptInterface::AutoParameter::read_only
static constexpr const ReadOnly read_only
Definition
AutoParameter.hpp:42
LatticeWalberla.hpp
src
script_interface
walberla
LatticeWalberla.hpp
Generated on Wed Feb 5 2025 02:14:25 for ESPResSo by
1.9.8