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
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
36namespace ScriptInterface {
37namespace Shapes {
38
39class Shape : public AutoParameters<Shape> {
40public:
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 &params) override {
48 if (name == "calc_distance") {
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;
57 shape()->calculate_dist(pos, dist, vec);
58 return std::vector<Variant>{dist, vec};
59 }
60
61 if (name == "is_inside") {
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 */
Vector implementation and trait types for boost qvm interoperability.
Bind parameters in the script interface.
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Context * context() const
Responsible context.
std::string_view name() const
Variant do_call_method(std::string const &name, VariantMap const &params) override
virtual std::shared_ptr<::Shapes::Shape > shape() const =0
Return the Shape that we are wrapping.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
Recursive variant implementation.
Definition Variant.hpp:84