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
29
#include <algorithm>
30
#include <memory>
31
#include <stdexcept>
32
#include <string>
33
#include <vector>
34
35
namespace
ScriptInterface::walberla
{
36
37
template
<
class
Method,
class
VTKHandle>
38
class
LatticeModel
:
public
AutoParameters
<LatticeModel<Method, VTKHandle>> {
39
protected
:
40
std::shared_ptr<LatticeWalberla>
m_lattice
;
41
std::shared_ptr<Method>
m_instance
;
42
std::vector<std::shared_ptr<VTKHandle>>
m_vtk_writers
;
43
44
virtual ::LatticeModel::units_map
45
get_lattice_to_md_units_conversion
()
const
= 0;
46
virtual
void
make_instance
(
VariantMap
const
&
params
) = 0;
47
48
auto
find_vtk
(std::shared_ptr<VTKHandle>
const
&vtk)
const
{
49
return
std::ranges::find(
m_vtk_writers
, vtk);
50
}
51
52
auto
serialize_vtk_writers
()
const
{
53
return
make_vector_of_variants
(
m_vtk_writers
);
54
}
55
56
public
:
57
Variant
do_call_method
(std::string
const
&
method_name
,
58
VariantMap
const
&
params
)
override
{
59
if
(
method_name
==
"add_vtk_writer"
) {
60
auto
vtk =
get_value<std::shared_ptr<VTKHandle>
>(
params
,
"vtk"
);
61
auto
const
needle
=
find_vtk
(vtk);
62
ObjectHandle::context
()->
parallel_try_catch
([&]() {
63
if
(
needle
!=
m_vtk_writers
.end()) {
64
throw std::runtime_error(
65
"VTK object is already attached to this lattice"
);
66
}
67
vtk->attach_to_lattice(
m_instance
,
68
get_lattice_to_md_units_conversion
());
69
m_vtk_writers
.emplace_back(vtk);
70
});
71
return
{};
72
}
73
if
(
method_name
==
"remove_vtk_writer"
) {
74
auto
const
vtk =
get_value<std::shared_ptr<VTKHandle>
>(
params
,
"vtk"
);
75
auto
const
needle
=
find_vtk
(vtk);
76
ObjectHandle::context
()->
parallel_try_catch
([&]() {
77
if
(
needle
==
m_vtk_writers
.end()) {
78
throw std::runtime_error(
79
"VTK object is not attached to this lattice"
);
80
}
81
vtk->detach_from_lattice();
82
});
83
m_vtk_writers
.erase(
needle
);
84
return
{};
85
}
86
if
(
method_name
==
"clear_vtk_writers"
) {
87
for
(
auto
const
&vtk :
m_vtk_writers
) {
88
vtk->detach_from_lattice();
89
}
90
m_vtk_writers
.clear();
91
}
92
return
{};
93
}
94
};
95
96
}
// 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:38
ScriptInterface::walberla::LatticeModel::m_instance
std::shared_ptr< Method > m_instance
Definition
script_interface/walberla/LatticeModel.hpp:41
ScriptInterface::walberla::LatticeModel::serialize_vtk_writers
auto serialize_vtk_writers() const
Definition
script_interface/walberla/LatticeModel.hpp:52
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:57
ScriptInterface::walberla::LatticeModel::m_vtk_writers
std::vector< std::shared_ptr< VTKHandle > > m_vtk_writers
Definition
script_interface/walberla/LatticeModel.hpp:42
ScriptInterface::walberla::LatticeModel::m_lattice
std::shared_ptr< LatticeWalberla > m_lattice
Definition
script_interface/walberla/LatticeModel.hpp:40
ScriptInterface::walberla::LatticeModel::find_vtk
auto find_vtk(std::shared_ptr< VTKHandle > const &vtk) const
Definition
script_interface/walberla/LatticeModel.hpp:48
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
params
static SteepestDescentParameters params
Currently active steepest descent instance.
Definition
steepest_descent.cpp:44
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
LatticeModel.hpp
LatticeWalberla.hpp
src
script_interface
walberla
LatticeModel.hpp
Generated on Mon Dec 8 2025 02:32:30 for ESPResSo by
1.9.8