ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/shapes/Shape.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2010-2026 The ESPResSo project
3
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4
* Max-Planck-Institute for Polymer Research, Theory Group
5
*
6
* This file is part of ESPResSo.
7
*
8
* ESPResSo is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
12
*
13
* ESPResSo is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*/
21
22
#pragma once
23
24
#include "
script_interface/ScriptInterface.hpp
"
25
#include "
script_interface/auto_parameters/AutoParameters.hpp
"
26
27
#include <shapes/Shape.hpp>
28
29
#include <
utils/Vector.hpp
>
30
31
#include <memory>
32
#include <stdexcept>
33
#include <string>
34
#include <vector>
35
36
namespace
ScriptInterface
{
37
namespace
Shapes
{
38
39
class
Shape
:
public
AutoParameters
<Shape> {
40
public
:
41
/**
42
* @brief Return the Shape that we are wrapping.
43
*/
44
virtual
std::shared_ptr<::Shapes::Shape>
shape
()
const
= 0;
45
46
Variant
do_call_method
(std::string
const
&
name
,
47
VariantMap
const
¶ms)
override
{
48
if
(
name
==
"calc_distance"
) {
49
context
()->
parallel_try_catch
([&]() {
50
if
(
not
params.contains(
"position"
)) {
51
throw std::runtime_error(
"Parameter 'position' is missing"
);
52
}
53
});
54
auto
const
pos =
get_value<Utils::Vector3d>
(params.at(
"position"
));
55
double
dist
;
56
Utils::Vector3d
vec
;
57
shape
()->calculate_dist(pos,
dist
,
vec
);
58
return
std::vector<Variant>{
dist
,
vec
};
59
}
60
61
if
(
name
==
"is_inside"
) {
62
context
()->
parallel_try_catch
([&]() {
63
if
(
not
params.contains(
"position"
)) {
64
throw std::runtime_error(
"Parameter 'position' is missing"
);
65
}
66
});
67
auto
const
pos =
get_value<Utils::Vector3d>
(params.at(
"position"
));
68
auto
is_in
=
shape
()->is_inside(pos);
69
return
{
is_in
};
70
}
71
72
if
(
name
==
"rasterize"
) {
73
auto
const
grid_size
=
get_value<Utils::Vector3i>
(params.at(
"grid_size"
));
74
auto
const
grid_spacing =
get_value<double>
(params.at(
"grid_spacing"
));
75
auto
const
grid_offset
=
get_value<double>
(params.at(
"grid_offset"
));
76
auto
raster =
shape
()->rasterize(
grid_size
, grid_spacing,
grid_offset
);
77
return
{raster};
78
}
79
80
return
{};
81
}
82
};
83
84
}
/* namespace Shapes */
85
}
/* namespace ScriptInterface */
AutoParameters.hpp
ScriptInterface.hpp
Vector.hpp
Vector implementation and trait types for boost qvm interoperability.
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::ObjectHandle::name
std::string_view name() const
Definition
ObjectHandle.cpp:117
ScriptInterface::Shapes::Shape
Definition
script_interface/shapes/Shape.hpp:39
ScriptInterface::Shapes::Shape::do_call_method
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
Definition
script_interface/shapes/Shape.hpp:46
ScriptInterface::Shapes::Shape::shape
virtual std::shared_ptr<::Shapes::Shape > shape() const =0
Return the Shape that we are wrapping.
Utils::Vector
Definition
Vector.hpp:50
stream
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Definition
common_cuda.cu:34
ScriptInterface
Definition
script_interface/accumulators/AccumulatorBase.hpp:33
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:133
Shapes
Definition
shapes/include/shapes/Cylinder.hpp:30
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
src
script_interface
shapes
Shape.hpp
Generated on Tue Jun 16 2026 01:34:35 for ESPResSo by
1.9.8