ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
EKWalberla.cpp
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#include "config/config.hpp"
21
22#ifdef WALBERLA
23
24#include "BoxGeometry.hpp"
25#include "LocalBox.hpp"
26#include "ek/EKReactions.hpp"
27#include "ek/EKWalberla.hpp"
28#include "errorhandling.hpp"
29#include "integrate.hpp"
30#include "lb/Implementation.hpp"
31#include "lb/LBWalberla.hpp"
32#include "system/System.hpp"
33
38
39#include <cstddef>
40#include <memory>
41#include <stdexcept>
42#include <variant>
43
44namespace EK {
45
46double EKWalberla::get_tau() const { return ek_container->get_tau(); }
47
49 return not ek_container->empty();
50}
51
53 std::size_t velocity_field_id{};
54 std::size_t force_field_id{};
56 using lb_value_type = std::shared_ptr<LB::LBWalberla>;
57 if (impl.solver.has_value()) {
58 if (auto const *ptr = std::get_if<lb_value_type>(&(*impl.solver))) {
59 auto const &instance = **ptr;
60 velocity_field_id = instance.lb_fluid->get_velocity_field_id();
61 force_field_id = instance.lb_fluid->get_force_field_id();
62 }
63 }
64 }
65};
66
68 // first calculate the charge for the potential, for that get all the
69 // field-ids from the ekspecies pass the potential-field-id to the
70 // flux-kernels of the eks for this the integrate function has to be split
71 // with a public interface to diffusive and advective-flux this should also
72 // allow the back-coupling to the LB with a field-id
73
74 if (ek_container->empty()) {
75 return;
76 }
77
78 ek_container->reset_charge();
79 for (auto const &ek_species : *ek_container) {
80 ek_container->add_charge(ek_species->get_density_id(),
81 ek_species->get_valency(),
82 ek_species->is_double_precision());
83 }
84 ek_container->solve_poisson();
85
86 FieldsConnector connector{};
87 System::get_system().lb.connect(connector);
88 for (auto const &ek_species : *ek_container) {
89 try {
90 ek_species->integrate(ek_container->get_potential_field_id(),
91 connector.velocity_field_id,
92 connector.force_field_id);
93 } catch (std::runtime_error const &e) {
94 runtimeErrorMsg() << e.what();
95 }
96 }
97
99
100 for (auto const &ek_species : *ek_container) {
101 ek_species->ghost_communication();
102 }
103}
104
106 for (auto const &ek_reaction : *ek_reactions) {
107 ek_reaction->perform_reaction();
108 }
109}
110
111void EKWalberla::veto_time_step(double time_step) const {
112 walberla_tau_sanity_checks("EK", ek_container->get_tau(), time_step);
113}
114
115void EKWalberla::veto_kT(double) const {
116 if (not ek_container->empty()) {
117 // can only throw, because without agrid, we can't do the unit conversion
118 throw std::runtime_error("Temperature change not supported by EK");
119 }
120}
121
122void EKWalberla::sanity_checks(System::System const &system) const {
123 auto const &box_geo = *system.box_geo;
124 auto const &lattice = ek_container->get_lattice();
125 auto const agrid = box_geo.length()[0] / lattice.get_grid_dimensions()[0];
126 auto [ek_left, ek_right] = lattice.get_local_domain();
127 ek_left *= agrid;
128 ek_right *= agrid;
129 auto const &md_left = system.local_geo->my_left();
130 auto const &md_right = system.local_geo->my_right();
131 walberla_agrid_sanity_checks("EK", md_left, md_right, ek_left, ek_right,
132 agrid);
133 // EK time step and MD time step must agree
135 system.get_time_step());
136}
137
138} // namespace EK
139
140#endif // WALBERLA
LBWalberlaBase provides the public interface of the LB waLBerla bridge.
Main system class.
auto get_time_step() const
Get time_step.
std::shared_ptr< LocalBox > local_geo
std::shared_ptr< BoxGeometry > box_geo
This file contains the defaults for ESPResSo.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
void walberla_agrid_sanity_checks(std::string method, Utils::Vector3d const &geo_left, Utils::Vector3d const &geo_right, Utils::Vector3d const &lattice_left, Utils::Vector3d const &lattice_right, double agrid)
void walberla_tau_sanity_checks(std::string method, double tau, double time_step)
Molecular dynamics integrator.
System & get_system()
void veto_kT(double kT) const
double get_tau() const
void veto_time_step(double time_step) const
void perform_reactions()
std::shared_ptr< ek_reactions_type > ek_reactions
void sanity_checks(System::System const &system) const
std::shared_ptr< ek_container_type > ek_container
bool is_ready_for_propagation() const noexcept
std::size_t velocity_field_id
void operator()(LB::Solver::Implementation const &impl)
std::size_t force_field_id
std::optional< HydrodynamicsActor > solver
Main hydrodynamics solver.
void connect(Connector &&connector) const
Connector to the implementation internal state.
Definition lb/Solver.hpp:61