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-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 "
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
serialize_vtk_writers
()
const
{
55
return
make_vector_of_variants
(
m_vtk_writers
);
56
}
57
58
public
:
59
Variant
do_call_method
(std::string
const
&
method_name
,
60
VariantMap
const
¶ms)
override
{
61
if
(
method_name
==
"add_vtk_writer"
) {
62
auto
vtk =
get_value<std::shared_ptr<VTKHandle>
>(params,
"vtk"
);
63
auto
const
needle
=
find_vtk
(vtk);
64
ObjectHandle::context
()->
parallel_try_catch
([&]() {
65
if
(
needle
!=
m_vtk_writers
.end()) {
66
throw std::runtime_error(
67
"VTK object is already attached to this lattice"
);
68
}
69
vtk->attach_to_lattice(
m_instance
,
70
get_lattice_to_md_units_conversion
());
71
m_vtk_writers
.emplace_back(vtk);
72
});
73
return
{};
74
}
75
if
(
method_name
==
"remove_vtk_writer"
) {
76
auto
const
vtk =
get_value<std::shared_ptr<VTKHandle>
>(params,
"vtk"
);
77
auto
const
needle
=
find_vtk
(vtk);
78
ObjectHandle::context
()->
parallel_try_catch
([&]() {
79
if
(
needle
==
m_vtk_writers
.end()) {
80
throw std::runtime_error(
81
"VTK object is not attached to this lattice"
);
82
}
83
vtk->detach_from_lattice();
84
});
85
m_vtk_writers
.erase(
needle
);
86
return
{};
87
}
88
if
(
method_name
==
"clear_vtk_writers"
) {
89
for
(
auto
const
&vtk :
m_vtk_writers
) {
90
vtk->detach_from_lattice();
91
}
92
m_vtk_writers
.clear();
93
}
94
return
{};
95
}
96
};
97
98
}
// 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::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:54
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:59
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
ScriptInterface::walberla
Definition
script_interface/walberla/EKContainer.hpp:49
ScriptInterface::get_value
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
Definition
get_value.hpp:398
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 Feb 12 2026 02:30:09 for ESPResSo by
1.9.8