ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
EKSpeciesSlice.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-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 "EKSpeciesSlice.hpp"
25#include "errorhandling.hpp"
26
27#include "LatticeSlice.impl.hpp"
28
29#include <stdexcept>
30#include <string>
31#include <type_traits>
32#include <vector>
33
35
37 VariantMap const &params) {
38 if (name == "get_slice_size") {
40 }
41 if (name == "get_slice_ranges") {
42 return {std::vector<Variant>{m_slice_lower_corner, m_slice_upper_corner}};
43 }
44 if (name == "get_ek_sip") {
45 return {m_ek_sip};
46 }
47 if (name == "get_value_shape") {
48 auto const name = get_value<std::string>(params, "name");
49 if (not m_shape_val.contains(name)) {
51 throw std::runtime_error("Unknown EK property '" + name + "'");
52 });
53 }
54 return m_shape_val.at(name);
55 }
56
57 // slice getter/setter callback
58 auto const call = [this, params](auto method_ptr,
59 std::vector<int> const &data_dims,
60 double units = 1.) -> Variant {
61 auto &obj = *m_ek_species;
62 if constexpr (std::is_invocable_v<decltype(method_ptr), LatticeModel *,
63 Utils::Vector3i const &,
64 Utils::Vector3i const &>) {
66 } else {
68 return {};
69 }
70 };
71
72 if (name == "get_density") {
73 return call(&LatticeModel::get_slice_density, {1}, 1. / m_conv_dens);
74 }
75 if (name == "set_density") {
76 return call(&LatticeModel::set_slice_density, {1}, m_conv_dens);
77 }
78 if (name == "get_flux") {
79 return call(&LatticeModel::get_slice_flux_vector, {3}, 1. / m_conv_flux);
80 }
81 if (name == "get_is_boundary") {
82 return call(&LatticeModel::get_slice_is_boundary, {1});
83 }
84 if (name == "get_flux_at_boundary") {
86 1. / m_conv_flux);
87 }
88 if (name == "set_flux_at_boundary") {
90 if (get_lattice().get_ghost_layers() < 2) {
91 if (context()->get_comm().size() > 1) {
92 throw std::runtime_error("The number of ghostlayers should be > 1 "
93 "when using flux boundaries and mpi.");
94 }
95 runtimeWarningMsg() << "The number of ghostlayers should be > 1 when "
96 "using flux boundaries and mpi.";
97 }
98 });
99 return call(&LatticeModel::set_slice_flux_boundary, {1}, m_conv_flux);
100 }
101 if (name == "get_density_at_boundary") {
103 1. / m_conv_dens);
104 }
105 if (name == "set_density_at_boundary") {
106 return call(&LatticeModel::set_slice_density_boundary, {1}, m_conv_dens);
107 }
108
109 return {};
110}
111
112} // namespace ScriptInterface::walberla
113
114#endif // ESPRESSO_WALBERLA
Interface of a lattice-based electrokinetic model.
virtual std::vector< std::optional< double > > get_slice_density_at_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice density boundary conditions.
virtual std::vector< bool > get_slice_is_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Check if slice has any boundary conditions.
virtual void set_slice_density_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< std::optional< double > > const &density)=0
Set slice density boundary conditions.
virtual void set_slice_flux_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< std::optional< Utils::Vector3d > > const &flux)=0
Set slice flux boundary conditions.
virtual std::vector< double > get_slice_flux_vector(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice density.
virtual std::vector< std::optional< Utils::Vector3d > > get_slice_flux_at_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice flux boundary conditions.
virtual std::vector< double > get_slice_density(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice density.
virtual void set_slice_density(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &density)=0
Set slice density.
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
::LatticeWalberla const & get_lattice() const override
Variant gather_3d(std::vector< int > const &data_dims, LatticeModel const &lattice_model, std::vector< T >(LatticeModel::*getter)(Utils::Vector3i const &, Utils::Vector3i const &) const, double units_conversion=1.) const
void scatter_3d(Variant const &grid_values, std::vector< int > const &data_dims, LatticeModel &lattice_model, void(LatticeModel::*setter)(Utils::Vector3i const &, Utils::Vector3i const &, std::vector< T > const &), double units_conversion=1.)
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeWarningMsg()
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
static SteepestDescentParameters params
Currently active steepest descent instance.
Recursive variant implementation.
Definition Variant.hpp:84