Skip to content

Commit d3cd6d1

Browse files
committed
Make waLBerla dependency private
1 parent 06689c1 commit d3cd6d1

28 files changed

+312
-327
lines changed

src/core/lb/particle_coupling.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Utils::Vector3d lb_drag_force(LB::Solver const &lb, double lb_gamma,
8686
/**
8787
* @brief Check if a position is within the local box + halo.
8888
*
89+
* @param local_box Local geometry
8990
* @param pos Position to check
9091
* @param halo Halo
9192
*

src/core/unit_tests/ek_interface_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static auto make_ek_actor() {
8585
ek_lattice = std::make_shared<LatticeWalberla>(
8686
params.grid_dimensions, ::communicator.node_grid, n_ghost_layers);
8787
ek_container = std::make_shared<EK::EKWalberla::ek_container_type>(
88-
params.tau, new_ek_poisson_none(ek_lattice, single_precision));
88+
params.tau, walberla::new_ek_poisson_none(ek_lattice, single_precision));
8989
ek_reactions = std::make_shared<EK::EKWalberla::ek_reactions_type>();
9090
ek_instance = std::make_shared<EK::EKWalberla>(ek_container, ek_reactions);
9191
#endif
@@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE(ek_interface_walberla) {
146146
auto constexpr single_precision = true;
147147
auto constexpr stoich = 1.;
148148
auto constexpr order = 2.;
149-
auto ek_species = new_ek_walberla(
149+
auto ek_species = walberla::new_ek_walberla(
150150
espresso::ek_lattice, params.diffusion, params.kT, params.valency,
151151
params.ext_efield, params.density, false, false, single_precision);
152152
auto ek_reactant = std::make_shared<EKReactant>(ek_species, stoich, order);

src/script_interface/walberla/EKFFT.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class EKFFT : public EKPoissonSolver {
5555
auto const permittivity =
5656
get_value<double>(args, "permittivity") * m_conv_permittivity;
5757

58-
m_instance = new_ek_poisson_fft(m_lattice->lattice(), permittivity,
59-
m_single_precision);
58+
m_instance = ::walberla::new_ek_poisson_fft(
59+
m_lattice->lattice(), permittivity, m_single_precision);
6060

6161
add_parameters({
6262
{"permittivity",

src/script_interface/walberla/EKNone.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class EKNone : public EKPoissonSolver {
4545
m_single_precision = get_value_or<bool>(args, "single_precision", false);
4646
m_lattice = get_value<std::shared_ptr<LatticeWalberla>>(args, "lattice");
4747

48-
m_instance = new_ek_poisson_none(m_lattice->lattice(), m_single_precision);
48+
m_instance = ::walberla::new_ek_poisson_none(m_lattice->lattice(),
49+
m_single_precision);
4950

5051
add_parameters({
5152
{"single_precision", AutoParameter::read_only,

src/script_interface/walberla/EKReaction.hpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#include "LatticeIndices.hpp"
2828
#include "LatticeWalberla.hpp"
2929

30+
#include <walberla_bridge/electrokinetics/ek_walberla_init.hpp>
3031
#include <walberla_bridge/electrokinetics/reactions/EKReactionBase.hpp>
31-
#include <walberla_bridge/src/electrokinetics/reactions/EKReactionImplBulk.hpp>
32-
#include <walberla_bridge/src/electrokinetics/reactions/EKReactionImplIndexed.hpp>
32+
#include <walberla_bridge/electrokinetics/reactions/EKReactionBaseIndexed.hpp>
3333

3434
#include <script_interface/ScriptInterface.hpp>
3535
#include <script_interface/auto_parameters/AutoParameters.hpp>
@@ -80,22 +80,21 @@ class EKReaction : public AutoParameters<EKReaction, LatticeIndices> {
8080
return tau / std::pow(Utils::int_pow<3>(agrid), sum_alphas - 1.);
8181
}
8282

83-
template <typename T>
84-
std::shared_ptr<T> make_instance(VariantMap const &args) const {
83+
template <typename F>
84+
auto make_instance(VariantMap const &args, F &allocator) const {
8585
auto lattice = get_value<std::shared_ptr<LatticeWalberla>>(args, "lattice");
86-
auto reactant = get_value<std::vector<Variant>>(args, "reactants");
87-
auto output =
88-
std::vector<std::shared_ptr<::walberla::EKReactant>>(reactant.size());
86+
auto reactants = get_value<std::vector<Variant>>(args, "reactants");
87+
auto output = ::walberla::EKReactionBase::reactants_type(reactants.size());
8988
auto get_instance = [](Variant const &v) {
9089
return get_value<std::shared_ptr<EKReactant>>(v)->get_instance();
9190
};
92-
std::transform(reactant.begin(), reactant.end(), output.begin(),
91+
std::transform(reactants.begin(), reactants.end(), output.begin(),
9392
get_instance);
9493

9594
auto const coefficient =
9695
get_value<double>(args, "coefficient") * get_conversion_coefficient();
9796

98-
return std::make_shared<T>(lattice->lattice(), output, coefficient);
97+
return allocator(lattice->lattice(), output, coefficient);
9998
}
10099

101100
std::shared_ptr<::walberla::EKReactionBase> m_ekreaction;
@@ -118,7 +117,7 @@ class EKBulkReaction : public EKReaction {
118117

119118
void do_construct(VariantMap const &args) override {
120119
m_conv_coefficient = calculate_bulk_conversion_factor(args);
121-
m_ekreaction = make_instance<::walberla::EKReactionImplBulk>(args);
120+
m_ekreaction = make_instance(args, ::walberla::new_ek_reaction_bulk);
122121
}
123122
};
124123

@@ -143,10 +142,9 @@ class EKIndexedReaction : public EKReaction {
143142
void do_construct(VariantMap const &args) override {
144143
auto const agrid = get_agrid(args);
145144
m_conv_coefficient = calculate_bulk_conversion_factor(args) / agrid;
146-
m_ekreaction = make_instance<::walberla::EKReactionImplIndexed>(args);
147145
m_ekreaction_impl =
148-
std::dynamic_pointer_cast<::walberla::EKReactionImplIndexed>(
149-
get_instance());
146+
make_instance(args, ::walberla::new_ek_reaction_indexed);
147+
m_ekreaction = m_ekreaction_impl;
150148
}
151149

152150
[[nodiscard]] Variant do_call_method(std::string const &method,
@@ -170,7 +168,7 @@ class EKIndexedReaction : public EKReaction {
170168
}
171169

172170
private:
173-
std::shared_ptr<::walberla::EKReactionImplIndexed> m_ekreaction_impl;
171+
std::shared_ptr<::walberla::EKReactionBaseIndexed> m_ekreaction_impl;
174172
};
175173

176174
} // namespace ScriptInterface::walberla

src/script_interface/walberla/EKSpecies.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "EKWalberlaNodeState.hpp"
2525
#include "WalberlaCheckpoint.hpp"
2626

27-
#include <walberla_bridge/LatticeWalberla.hpp>
2827
#include <walberla_bridge/electrokinetics/ek_walberla_init.hpp>
2928

3029
#include <boost/mpi.hpp>
@@ -119,7 +118,7 @@ void EKSpecies::do_construct(VariantMap const &args) {
119118
auto const ek_ext_efield = ext_efield * m_conv_ext_efield;
120119
auto const ek_density = m_density = density * m_conv_density;
121120
auto const ek_kT = kT * m_conv_energy;
122-
m_instance = new_ek_walberla(
121+
m_instance = ::walberla::new_ek_walberla(
123122
m_lattice->lattice(), ek_diffusion, ek_kT,
124123
get_value<double>(args, "valency"), ek_ext_efield, ek_density,
125124
get_value<bool>(args, "advection"),

src/walberla_bridge/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ if(ESPRESSO_BUILD_WITH_CUDA AND WALBERLA_BUILD_WITH_CUDA)
4242
PRIVATE ${WALBERLA_LIBS})
4343
target_include_directories(espresso_walberla_cuda PUBLIC include)
4444
target_include_directories(
45-
espresso_walberla_cuda PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
46-
PRIVATE ${WALBERLA_INCLUDE_DIRS} ${walberla_BINARY_DIR}/src)
45+
espresso_walberla_cuda PRIVATE ${WALBERLA_INCLUDE_DIRS}
46+
${walberla_BINARY_DIR}/src)
4747
install(TARGETS espresso_walberla_cuda
4848
LIBRARY DESTINATION ${ESPRESSO_INSTALL_PYTHON}/espressomd)
4949
target_link_libraries(espresso_walberla PUBLIC espresso::walberla_cuda)
@@ -52,9 +52,8 @@ endif()
5252
target_link_libraries(
5353
espresso_walberla PUBLIC MPI::MPI_CXX espresso::utils
5454
PRIVATE espresso::cpp_flags espresso::walberla::cpp_flags ${WALBERLA_LIBS})
55-
target_include_directories(
56-
espresso_walberla PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
57-
PRIVATE ${WALBERLA_INCLUDE_DIRS} ${walberla_BINARY_DIR}/src)
55+
target_include_directories(espresso_walberla PRIVATE ${WALBERLA_INCLUDE_DIRS}
56+
${walberla_BINARY_DIR}/src)
5857

5958
add_subdirectory(src)
6059

src/walberla_bridge/include/walberla_bridge/electrokinetics/ek_poisson_fft_init.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
#pragma once
2121

2222
#include <walberla_bridge/LatticeWalberla.hpp>
23-
24-
#include "PoissonSolver/PoissonSolver.hpp"
23+
#include <walberla_bridge/electrokinetics/PoissonSolver/PoissonSolver.hpp>
2524

2625
#include <memory>
2726

27+
namespace walberla {
28+
2829
std::shared_ptr<walberla::PoissonSolver>
2930
new_ek_poisson_fft(std::shared_ptr<LatticeWalberla> const &lattice,
3031
double permittivity, bool single_precision);
32+
33+
} // namespace walberla

src/walberla_bridge/include/walberla_bridge/electrokinetics/ek_poisson_none_init.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
#pragma once
2121

2222
#include <walberla_bridge/LatticeWalberla.hpp>
23-
24-
#include "PoissonSolver/PoissonSolver.hpp"
23+
#include <walberla_bridge/electrokinetics/PoissonSolver/PoissonSolver.hpp>
2524

2625
#include <memory>
2726

27+
namespace walberla {
28+
2829
std::shared_ptr<walberla::PoissonSolver>
2930
new_ek_poisson_none(std::shared_ptr<LatticeWalberla> const &lattice,
3031
bool single_precision);
32+
33+
} // namespace walberla

src/walberla_bridge/include/walberla_bridge/electrokinetics/ek_walberla_init.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,29 @@
2222
#include "EKinWalberlaBase.hpp"
2323

2424
#include <walberla_bridge/LatticeWalberla.hpp>
25+
#include <walberla_bridge/electrokinetics/reactions/EKReactionBase.hpp>
26+
#include <walberla_bridge/electrokinetics/reactions/EKReactionBaseIndexed.hpp>
2527

2628
#include <utils/Vector.hpp>
2729

2830
#include <memory>
2931

32+
namespace walberla {
33+
3034
std::shared_ptr<EKinWalberlaBase>
3135
new_ek_walberla(std::shared_ptr<LatticeWalberla> const &lattice,
3236
double diffusion, double kT, double valency,
3337
Utils::Vector3d ext_efield, double density, bool advection,
3438
bool friction_coupling, bool single_precision);
39+
40+
std::shared_ptr<EKReactionBase>
41+
new_ek_reaction_bulk(std::shared_ptr<LatticeWalberla> const &lattice,
42+
typename EKReactionBase::reactants_type const &reactants,
43+
double coefficient);
44+
45+
std::shared_ptr<EKReactionBaseIndexed> new_ek_reaction_indexed(
46+
std::shared_ptr<LatticeWalberla> const &lattice,
47+
typename EKReactionBase::reactants_type const &reactants,
48+
double coefficient);
49+
50+
} // namespace walberla

src/walberla_bridge/include/walberla_bridge/electrokinetics/reactions/EKReactionBase.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@
2929
namespace walberla {
3030

3131
class EKReactionBase {
32-
private:
33-
std::vector<std::shared_ptr<EKReactant>> m_reactants;
34-
double m_coefficient;
32+
public:
33+
using reactants_type = std::vector<std::shared_ptr<EKReactant>>;
3534

35+
private:
3636
std::shared_ptr<LatticeWalberla> m_lattice;
37+
reactants_type m_reactants;
38+
double m_coefficient;
3739

3840
public:
3941
EKReactionBase(std::shared_ptr<LatticeWalberla> lattice,
40-
std::vector<std::shared_ptr<EKReactant>> reactants,
41-
double coefficient)
42-
: m_reactants(std::move(reactants)), m_coefficient(coefficient),
43-
m_lattice(std::move(lattice)) {}
42+
reactants_type reactants, double coefficient)
43+
: m_lattice(std::move(lattice)), m_reactants(std::move(reactants)),
44+
m_coefficient(coefficient) {}
4445

4546
virtual ~EKReactionBase() = default;
4647

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022-2023 The ESPResSo project
2+
* Copyright (C) 2024 The ESPResSo project
33
*
44
* This file is part of ESPResSo.
55
*
@@ -17,26 +17,24 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
#include "EKReactionImplBulk.hpp"
20+
#pragma once
2121

22-
#include "generated_kernels/ReactionKernelBulk_all.h"
22+
#include "EKReactionBase.hpp"
2323

24-
#include <blockforest/StructuredBlockForest.h>
24+
#include <utils/Vector.hpp>
2525

26-
namespace walberla {
26+
#include <optional>
2727

28-
void EKReactionImplBulk::perform_reaction() {
29-
// TODO: if my understanding is correct:
30-
// the kernels need to either run in the ghost layers and do the
31-
// synchronization before or not run and do a synchronization afterwards.
32-
// The better solution is probably the latter one. Not sure why it fails
33-
// atm.
28+
namespace walberla {
3429

35-
auto kernel = detail::ReactionKernelBulkSelector::get_kernel(
36-
get_reactants(), get_coefficient());
30+
class EKReactionBaseIndexed : public EKReactionBase {
31+
public:
32+
using EKReactionBase::EKReactionBase;
33+
~EKReactionBaseIndexed() override = default;
34+
virtual void set_node_is_boundary(Utils::Vector3i const &node,
35+
bool is_boundary) = 0;
36+
virtual std::optional<bool>
37+
get_node_is_boundary(Utils::Vector3i const &node) = 0;
38+
};
3739

38-
for (auto &block : *get_lattice()->get_blocks()) {
39-
kernel(&block);
40-
}
41-
}
4240
} // namespace walberla

src/walberla_bridge/src/BoundaryHandling.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#pragma once
2121

2222
#include <walberla_bridge/BlockAndCell.hpp>
23-
#include <walberla_bridge/utils/walberla_utils.hpp>
23+
24+
#include "utils/types_conversion.hpp"
2425

2526
#include <blockforest/StructuredBlockForest.h>
2627
#include <domain_decomposition/BlockDataID.h>
@@ -38,12 +39,13 @@
3839

3940
namespace walberla {
4041

41-
/// Flag for domain cells, i.e. all cells
42-
FlagUID const Domain_flag("domain");
43-
/// Flag for boundary cells
44-
FlagUID const Boundary_flag("boundary");
45-
4642
template <typename T, typename BoundaryClass> class BoundaryHandling {
43+
private:
44+
/** Flag for domain cells, i.e. all cells. */
45+
FlagUID const Domain_flag{"domain"};
46+
/** Flag for boundary cells. */
47+
FlagUID const Boundary_flag{"boundary"};
48+
4749
/** Container for the map between cells and values. */
4850
class DynamicValueCallback {
4951
public:
@@ -172,7 +174,7 @@ template <typename T, typename BoundaryClass> class BoundaryHandling {
172174
std::shared_ptr<BoundaryClass> m_boundary;
173175
bool m_pending_changes;
174176

175-
/** Register flags and set all cells to @ref Domain_flag. */
177+
/** Register flags and reset all cells. */
176178
void flag_reset_kernel(IBlock *const block) {
177179
auto flag_field = block->template getData<FlagField>(m_flag_field_id);
178180
// register flags

src/walberla_bridge/src/BoundaryPackInfo.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <core/mpi/RecvBuffer.h>
2424
#include <core/mpi/SendBuffer.h>
2525
#include <domain_decomposition/IBlock.h>
26+
#include <field/FlagUID.h>
2627
#include <field/communication/PackInfo.h>
2728
#include <stencil/Directions.h>
2829

@@ -38,6 +39,10 @@ template <typename GhostLayerField_T, typename Boundary_T>
3839
class BoundaryPackInfo : public PackInfo<GhostLayerField_T> {
3940
protected:
4041
using PackInfo<GhostLayerField_T>::bdId_;
42+
/** Flag for domain cells, i.e. all cells. */
43+
FlagUID const Domain_flag{"domain"};
44+
/** Flag for boundary cells. */
45+
FlagUID const Boundary_flag{"boundary"};
4146

4247
public:
4348
using PackInfo<GhostLayerField_T>::PackInfo;

src/walberla_bridge/src/LatticeWalberla.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
#include <walberla_bridge/BlockAndCell.hpp>
2121
#include <walberla_bridge/LatticeWalberla.hpp>
22-
#include <walberla_bridge/utils/walberla_utils.hpp>
22+
23+
#include "utils/types_conversion.hpp"
2324

2425
#include <blockforest/Initialization.h>
2526
#include <blockforest/StructuredBlockForest.h>

0 commit comments

Comments
 (0)