ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/walberla/LatticeModel.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2022-2026 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 "
LatticeWalberla.hpp
"
23
24
#include <
walberla_bridge/LatticeModel.hpp
>
25
26
#include <
script_interface/ScriptInterface.hpp
>
27
#include <
script_interface/auto_parameters/AutoParameters.hpp
>
28
#include <
script_interface/system/Leaf.hpp
>
29
30
#include <algorithm>
31
#include <memory>
32
#include <stdexcept>
33
#include <string>
34
#include <vector>
35
36
namespace
ScriptInterface::walberla
{
37
38
template
<
class
Method,
class
VTKHandle>
39
class
LatticeModel
40
:
public
AutoParameters
<LatticeModel<Method, VTKHandle>, System::Leaf> {
41
protected
:
42
std::shared_ptr<LatticeWalberla>
m_lattice
;
43
std::shared_ptr<Method>
m_instance
;
44
std::vector<std::shared_ptr<VTKHandle>>
m_vtk_writers
;
45
46
virtual ::LatticeModel::units_map
47
get_lattice_to_md_units_conversion
()
const
= 0;
48
virtual
void
make_instance
(
VariantMap
const
¶ms) = 0;
49
50
auto
find_vtk
(std::shared_ptr<VTKHandle>
const
&vtk)
const
{
51
return
std::ranges::find(
m_vtk_writers
, vtk);
52
}
53
54
auto
has_vtk
(std::shared_ptr<VTKHandle>
const
&vtk)
const
{
55
return
find_vtk
(vtk) !=
m_vtk_writers
.end();
56
}
57
58
auto
serialize_vtk_writers
()
const
{
59
return
make_vector_of_variants
(
m_vtk_writers
);
60
}
61
62
public
:
63
Variant
do_call_method
(std::string
const
&
method_name
,
64
VariantMap
const
¶ms)
override
{
65
if
(
method_name
==
"add_vtk_writer"
) {
66
auto
vtk =
get_value<std::shared_ptr<VTKHandle>
>(params,
"vtk"
);
67
auto
const
contained
=
has_vtk
(vtk);
68
ObjectHandle::context
()->
parallel_try_catch
([&]() {
69
if
(
contained
) {
70
throw
std::runtime_error(
71
"VTK object is already attached to this lattice"
);
72
}
73
vtk->attach_to_lattice(
m_instance
,
74
get_lattice_to_md_units_conversion
());
75
m_vtk_writers
.emplace_back(vtk);
76
});
77
return
{};
78
}
79
if
(
method_name
==
"remove_vtk_writer"
) {
80
auto
const
vtk =
get_value<std::shared_ptr<VTKHandle>
>(params,
"vtk"
);
81
auto
const
contained
=
has_vtk
(vtk);
82
ObjectHandle::context
()->
parallel_try_catch
([&]() {
83
if
(
not
contained
) {
84
throw
std::runtime_error(
85
"VTK object is not attached to this lattice"
);
86
}
87
vtk->detach_from_lattice();
88
});
89
m_vtk_writers
.erase(
find_vtk
(vtk));
90
return
{};
91
}
92
if
(
method_name
==
"clear_vtk_writers"
) {
93
for
(
auto
const
&vtk :
m_vtk_writers
) {
94
vtk->detach_from_lattice();
95
}
96
m_vtk_writers
.clear();
97
}
98
return
{};
99
}
100
};
101
102
}
// namespace ScriptInterface::walberla
AutoParameters.hpp
ScriptInterface.hpp
ScriptInterface::AutoParameters
Bind parameters in the script interface.
Definition
AutoParameters.hpp:94
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:57
ScriptInterface::walberla::LatticeModel
Definition
script_interface/walberla/LatticeModel.hpp:40
ScriptInterface::walberla::LatticeModel::has_vtk
auto has_vtk(std::shared_ptr< VTKHandle > const &vtk) const
Definition
script_interface/walberla/LatticeModel.hpp:54
ScriptInterface::walberla::LatticeModel::m_instance
std::shared_ptr< Method > m_instance
Definition
script_interface/walberla/LatticeModel.hpp:43
ScriptInterface::walberla::LatticeModel::serialize_vtk_writers
auto serialize_vtk_writers() const
Definition
script_interface/walberla/LatticeModel.hpp:58
ScriptInterface::walberla::LatticeModel::do_call_method
Variant do_call_method(std::string const &method_name, VariantMap const ¶ms) override
Definition
script_interface/walberla/LatticeModel.hpp:63
ScriptInterface::walberla::LatticeModel::m_vtk_writers
std::vector< std::shared_ptr< VTKHandle > > m_vtk_writers
Definition
script_interface/walberla/LatticeModel.hpp:44
ScriptInterface::walberla::LatticeModel::m_lattice
std::shared_ptr< LatticeWalberla > m_lattice
Definition
script_interface/walberla/LatticeModel.hpp:42
ScriptInterface::walberla::LatticeModel::find_vtk
auto find_vtk(std::shared_ptr< VTKHandle > const &vtk) const
Definition
script_interface/walberla/LatticeModel.hpp:50
ScriptInterface::walberla::LatticeModel::make_instance
virtual void make_instance(VariantMap const ¶ms)=0
ScriptInterface::walberla::LatticeModel::get_lattice_to_md_units_conversion
virtual ::LatticeModel::units_map get_lattice_to_md_units_conversion() const =0
stream
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Definition
common_cuda.cu:34
ScriptInterface::walberla
Definition
script_interface/walberla/EKContainer.hpp:49
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:133
ScriptInterface::make_vector_of_variants
auto make_vector_of_variants(std::vector< T > const &v)
Definition
Variant.hpp:148
Leaf.hpp
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
LatticeModel.hpp
LatticeWalberla.hpp
src
script_interface
walberla
LatticeModel.hpp
Generated on Thu Mar 5 2026 02:40:46 for ESPResSo by
1.9.8