ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CellSystem.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 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
26
31
32#include <memory>
33#include <string>
34#include <unordered_map>
35#include <utility>
36#include <vector>
37
38namespace ScriptInterface {
39namespace CellSystem {
40
41class CellSystem : public AutoParameters<CellSystem, System::Leaf> {
42 std::unordered_map<CellStructureType, std::string> const cs_type_to_name = {
43 {CellStructureType::REGULAR, "regular_decomposition"},
44 {CellStructureType::NSQUARE, "n_square"},
45 {CellStructureType::HYBRID, "hybrid_decomposition"},
46 };
47
48 std::unordered_map<std::string, CellStructureType> const cs_name_to_type = {
49 {"regular_decomposition", CellStructureType::REGULAR},
50 {"n_square", CellStructureType::NSQUARE},
51 {"hybrid_decomposition", CellStructureType::HYBRID},
52 };
53
54 std::shared_ptr<::CellStructure> m_cell_structure;
55 std::unique_ptr<VariantMap> m_params;
56
57 void on_bind_system(::System::System &system) override {
58 m_cell_structure = system.cell_structure;
59 m_cell_structure->bind_system(m_system.lock());
60 auto const &params = *m_params;
61 if (not params.empty()) {
62 auto const cs_name = get_value<std::string>(params, "decomposition_type");
63 auto const cs_type = cs_name_to_type.at(cs_name);
64 initialize(cs_type, params);
65 do_set_parameter("skin", params.at("skin"));
66 do_set_parameter("node_grid", params.at("node_grid"));
67 }
68 m_params.reset();
69 }
70
71public:
72 CellSystem();
73
74 void do_construct(VariantMap const &params) override {
75 m_params = std::make_unique<VariantMap>(params);
76 }
77
78 Variant do_call_method(std::string const &name,
79 VariantMap const &params) override;
80
81private:
82 /**
83 * @brief Resort the particles.
84 *
85 * This function resorts the particles on the nodes.
86 *
87 * @param global_flag If true a global resort is done, if false particles
88 * are only exchanges between neighbors.
89 * @return The number of particles on the nodes after the resort.
90 */
91 std::vector<int> mpi_resort_particles(bool global_flag) const;
92
93 void initialize(CellStructureType const &cs_type, VariantMap const &params);
94
95 auto &get_cell_structure() const { return *m_cell_structure; }
96
97 auto const &get_regular_decomposition() const {
98 return dynamic_cast<RegularDecomposition const &>(
99 std::as_const(get_cell_structure()).decomposition());
100 }
101
102 auto const &get_hybrid_decomposition() const {
103 return dynamic_cast<HybridDecomposition const &>(
104 std::as_const(get_cell_structure()).decomposition());
105 }
106};
107
108} // namespace CellSystem
109} // namespace ScriptInterface
CellStructureType
Cell structure topology.
@ NSQUARE
Atom decomposition (N-square).
@ HYBRID
Hybrid decomposition.
@ REGULAR
Regular decomposition.
Hybrid decomposition cell system.
Bind parameters in the script interface.
void do_set_parameter(const std::string &name, const Variant &value) final
void on_bind_system(::System::System &system) override
Variant do_call_method(std::string const &name, VariantMap const &params) override
void do_construct(VariantMap const &params) override
boost::string_ref name() const
std::weak_ptr<::System::System > m_system
Main system class.
std::shared_ptr< CellStructure > cell_structure
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:80
static SteepestDescentParameters params
Currently active steepest descent instance.
Regular decomposition cell system.