Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
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 Particles {
40class ParticleHandle;
41class ParticleSlice;
42} // namespace Particles
43namespace CellSystem {
44
45class CellSystem : public AutoParameters<CellSystem, System::Leaf> {
46 std::unordered_map<CellStructureType, std::string> const cs_type_to_name = {
47 {CellStructureType::REGULAR, "regular_decomposition"},
48 {CellStructureType::NSQUARE, "n_square"},
49 {CellStructureType::HYBRID, "hybrid_decomposition"},
50 };
51
52 std::unordered_map<std::string, CellStructureType> const cs_name_to_type = {
53 {"regular_decomposition", CellStructureType::REGULAR},
54 {"n_square", CellStructureType::NSQUARE},
55 {"hybrid_decomposition", CellStructureType::HYBRID},
56 };
57
58 std::shared_ptr<::CellStructure> m_cell_structure;
59 std::unique_ptr<VariantMap> m_params;
60
62 m_cell_structure = system.cell_structure;
63 m_cell_structure->bind_system(m_system.lock());
64 auto const &params = *m_params;
65 if (not params.empty()) {
66 auto const cs_name = get_value<std::string>(params, "decomposition_type");
67 auto const cs_type = cs_name_to_type.at(cs_name);
68 initialize(cs_type, params);
69 do_set_parameter("skin", params.at("skin"));
70 do_set_parameter("node_grid", params.at("node_grid"));
71 }
72 m_params.reset();
73 }
74
75public:
76 CellSystem();
77
78 void do_construct(VariantMap const &params) override {
79 m_params = std::make_unique<VariantMap>(params);
80 }
81
82 Variant do_call_method(std::string const &name,
83 VariantMap const &params) override;
84
85 auto &get_cell_structure() const { return *m_cell_structure; }
86
89
90private:
91 /**
92 * @brief Resort the particles.
93 *
94 * This function resorts the particles on the nodes.
95 *
96 * @param global_flag If true a global resort is done, if false particles
97 * are only exchanges between neighbors.
98 * @return The number of particles on the nodes after the resort.
99 */
100 std::vector<int> mpi_resort_particles(bool global_flag) const;
101
102 void initialize(CellStructureType const &cs_type, VariantMap const &params);
103
104 auto const &get_regular_decomposition() const {
105 return dynamic_cast<RegularDecomposition const &>(
106 std::as_const(get_cell_structure()).decomposition());
107 }
108
109 auto const &get_hybrid_decomposition() const {
110 return dynamic_cast<HybridDecomposition const &>(
111 std::as_const(get_cell_structure()).decomposition());
112 }
113};
114
115} // namespace CellSystem
116} // 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 configure(Particles::ParticleHandle &)
void do_construct(VariantMap const &params) override
boost::string_ref name() const
std::weak_ptr<::System::System > m_system
Main system class.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
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:67
static SteepestDescentParameters params
Currently active steepest descent instance.
Regular decomposition cell system.