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 ESPRESSO_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
46bool EKWalberla::is_gpu() const { return ek_container->is_gpu(); }
47
48double EKWalberla::get_tau() const { return ek_container->get_tau(); }
49
51 return not ek_container->empty();
52}
53
55 std::size_t velocity_field_id{};
56 std::size_t force_field_id{};
57 double lb_density;
59 using lb_value_type = std::shared_ptr<LB::LBWalberla>;
60 if (impl.solver.has_value()) {
61 if (auto const *ptr = std::get_if<lb_value_type>(&(*impl.solver))) {
62 auto const &instance = **ptr;
63 velocity_field_id = instance.lb_fluid->get_velocity_field_id();
64 force_field_id = instance.lb_fluid->get_force_field_id();
65 lb_density = instance.lb_fluid->get_density();
66 }
67 }
68 }
69};
70
72 // first calculate the charge for the potential, for that get all the
73 // field-ids from the ekspecies pass the potential-field-id to the
74 // flux-kernels of the eks for this the integrate function has to be split
75 // with a public interface to diffusive and advective-flux this should also
76 // allow the back-coupling to the LB with a field-id
77
78 if (ek_container->empty()) {
79 return;
80 }
81
82 ek_container->reset_charge();
83 for (auto const &ek_species : *ek_container) {
84 ek_container->add_charge(ek_species->get_density_id(),
85 ek_species->get_valency());
86 }
87 ek_container->solve_poisson();
88
89 FieldsConnector connector{};
90 System::get_system().lb.connect(connector);
91 for (auto const &ek_species : *ek_container) {
92 try {
93 ek_species->integrate(ek_container->get_potential_field_id(),
94 connector.velocity_field_id,
95 connector.force_field_id, connector.lb_density);
96 } catch (std::runtime_error const &e) {
97 runtimeErrorMsg() << e.what();
98 }
99 }
100
102
103 for (auto const &ek_species : *ek_container) {
104 ek_species->ghost_communication();
105 }
106}
107
109 for (auto const &ek_reaction : *ek_reactions) {
110 ek_reaction->perform_reaction();
111 }
112}
113
114void EKWalberla::veto_time_step(double time_step) const {
115 walberla_tau_sanity_checks("EK", ek_container->get_tau(), time_step);
116}
117
118void EKWalberla::veto_kT(double) const {
119 if (not ek_container->empty()) {
120 // can only throw, because without agrid, we can't do the unit conversion
121 throw std::runtime_error("Temperature change not supported by EK");
122 }
123}
124
125void EKWalberla::sanity_checks(System::System const &system) const {
126 auto const &box_geo = *system.box_geo;
127 auto const &lattice = ek_container->get_lattice();
128 auto const agrid = box_geo.length()[0] / lattice.get_grid_dimensions()[0];
129 auto [ek_left, ek_right] = lattice.get_local_domain();
130 ek_left *= agrid;
131 ek_right *= agrid;
132 auto const &md_left = system.local_geo->my_left();
133 auto const &md_right = system.local_geo->my_right();
134 walberla_agrid_sanity_checks("EK", md_left, md_right, ek_left, ek_right,
135 agrid);
136 // EK time step and MD time step must agree
138 system.get_time_step());
139}
140
141} // namespace EK
142
143#endif // ESPRESSO_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 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
bool is_gpu() const
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:63