Skip to content

Commit

Permalink
walberla: Remove Boost dependency
Browse files Browse the repository at this point in the history
The waLBerla module now only uses Boost in the unit tests.
  • Loading branch information
jngrad committed Aug 9, 2023
1 parent 4ae3f40 commit 3dfaa9f
Show file tree
Hide file tree
Showing 27 changed files with 194 additions and 205 deletions.
11 changes: 5 additions & 6 deletions src/core/grid_based_algorithms/lb_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
#include "grid.hpp"

#include <utils/Vector.hpp>
#include <utils/mpi/reduce_optional.hpp>

#include <boost/optional.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/mpi/collectives/reduce.hpp>
#include <boost/mpi/communicator.hpp>

#include <cmath>
#include <functional>
#include <limits>
#include <optional>
#include <stdexcept>
#include <string>
#include <vector>
Expand Down Expand Up @@ -147,7 +146,7 @@ Utils::Vector3d calc_fluid_momentum() {
throw NoLBActive();
}

boost::optional<Utils::Vector3d>
std::optional<Utils::Vector3d>
get_interpolated_velocity(Utils::Vector3d const &pos) {
if (lattice_switch == ActiveLB::WALBERLA_LB) {
#ifdef WALBERLA
Expand All @@ -158,7 +157,7 @@ get_interpolated_velocity(Utils::Vector3d const &pos) {
throw NoLBActive();
}

boost::optional<double> get_interpolated_density(Utils::Vector3d const &pos) {
std::optional<double> get_interpolated_density(Utils::Vector3d const &pos) {
if (lattice_switch == ActiveLB::WALBERLA_LB) {
#ifdef WALBERLA
auto const folded_pos = folded_position(pos, box_geo) / get_agrid();
Expand Down
7 changes: 3 additions & 4 deletions src/core/grid_based_algorithms/lb_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

#include <utils/Vector.hpp>

#include <boost/optional.hpp>

#include <optional>
#include <stdexcept>

// Forward Declarations
Expand Down Expand Up @@ -116,7 +115,7 @@ Utils::Vector3d calc_fluid_momentum();
* @param pos Position at which the velocity is to be calculated.
* @retval optional interpolated fluid velocity.
*/
boost::optional<Utils::Vector3d>
std::optional<Utils::Vector3d>
get_interpolated_velocity(Utils::Vector3d const &pos);

/**
Expand All @@ -125,7 +124,7 @@ get_interpolated_velocity(Utils::Vector3d const &pos);
* @param pos Position at which the density is to be calculated.
* @retval optional interpolated fluid density.
*/
boost::optional<double> get_interpolated_density(Utils::Vector3d const &pos);
std::optional<double> get_interpolated_density(Utils::Vector3d const &pos);

} // namespace LB

Expand Down
3 changes: 2 additions & 1 deletion src/script_interface/particle_data/ParticleHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <cmath>
#include <cstddef>
#include <memory>
#include <optional>
#include <set>
#include <sstream>
#include <stdexcept>
Expand Down Expand Up @@ -134,7 +135,7 @@ template <typename T, class F>
T ParticleHandle::get_particle_property(F const &fun) const {
auto const &comm = context()->get_comm();
auto const ptr = const_cast<Particle const *>(get_real_particle(comm, m_pid));
boost::optional<T> ret;
std::optional<T> ret;
if (ptr == nullptr) {
ret = {};
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/script_interface/walberla/EKContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#include <script_interface/ObjectList.hpp>
#include <script_interface/ScriptInterface.hpp>

#include <cassert>
#include <memory>
#include <optional>
#include <string>

namespace ScriptInterface::walberla {
Expand Down Expand Up @@ -132,7 +134,7 @@ class EKContainer : public ObjectList<EKSpecies> {
}

void set_solver(Variant const &solver_variant) {
boost::optional<decltype(m_poisson_solver)> solver;
std::optional<decltype(m_poisson_solver)> solver;
if (is_none(solver_variant)) {
solver = std::shared_ptr<EKNone>();
} else {
Expand All @@ -146,6 +148,7 @@ class EKContainer : public ObjectList<EKSpecies> {
solver = get_value<std::shared_ptr<EKNone>>(solver_variant);
}
}
assert(solver.has_value());
m_poisson_solver = *solver;
auto const visitor = GetPoissonSolverInstance();
auto const instance = boost::apply_visitor(visitor, m_poisson_solver);
Expand Down
10 changes: 5 additions & 5 deletions src/script_interface/walberla/EKSpecies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
#ifdef WALBERLA

#include "EKSpecies.hpp"
#include "EKWalberlaNodeState.hpp"
#include "WalberlaCheckpoint.hpp"

#include <walberla_bridge/LatticeWalberla.hpp>
#include <walberla_bridge/electrokinetics/EKWalberlaNodeState.hpp>
#include <walberla_bridge/electrokinetics/ek_walberla_init.hpp>

#include <boost/mpi.hpp>
#include <boost/mpi/collectives/all_reduce.hpp>
#include <boost/mpi/collectives/broadcast.hpp>
#include <boost/optional.hpp>

#include <algorithm>
#include <cassert>
#include <functional>
#include <memory>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -207,8 +207,8 @@ void EKSpecies::save_checkpoint(std::string const &filename, int mode) {
auto const write_data = [&ek_obj,
mode](std::shared_ptr<CheckpointFile> cpfile_ptr,
Context const &context) {
auto const get_node_checkpoint = [&](Utils::Vector3i const &ind)
-> boost::optional<EKWalberlaNodeState> {
auto const get_node_checkpoint =
[&](Utils::Vector3i const &ind) -> std::optional<EKWalberlaNodeState> {
auto const density = ek_obj.get_node_density(ind);
auto const is_b_d = ek_obj.get_node_is_density_boundary(ind);
auto const dens_b = ek_obj.get_node_density_at_boundary(ind);
Expand All @@ -229,7 +229,7 @@ void EKSpecies::save_checkpoint(std::string const &filename, int mode) {
}
return cpnode;
}
return {boost::none};
return std::nullopt;
};

auto failure = false;
Expand Down
4 changes: 2 additions & 2 deletions src/script_interface/walberla/EKSpeciesNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
#include <utils/mpi/reduce_optional.hpp>

#include <boost/mpi/collectives/all_reduce.hpp>
#include <boost/optional.hpp>
#include <boost/serialization/vector.hpp>

#include <cassert>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>

namespace ScriptInterface::walberla {

static bool is_boundary_all_reduce(boost::mpi::communicator const &comm,
boost::optional<bool> const &is_boundary) {
std::optional<bool> const &is_boundary) {
return boost::mpi::all_reduce(comm, is_boundary ? *is_boundary : false,
std::logical_or<>());
}
Expand Down
9 changes: 5 additions & 4 deletions src/script_interface/walberla/EKSpeciesSlice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@

#include <cassert>
#include <memory>
#include <optional>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>

namespace ScriptInterface::walberla {

using DensityBoundaryType = boost::optional<double>;
using FluxBoundaryType = boost::optional<Utils::Vector3d>;
using DensityBoundaryType = std::optional<double>;
using FluxBoundaryType = std::optional<Utils::Vector3d>;

struct EKFieldSerializer {

Expand Down Expand Up @@ -77,7 +78,7 @@ struct EKFieldSerializer {
auto const vector_variants = get_value<std::vector<Variant>>(variant);
for (auto const &value : vector_variants) {
if (is_none(value)) {
values.emplace_back(boost::none);
values.emplace_back(std::nullopt);
} else {
values.emplace_back(get_value<Utils::Vector3d>(value));
}
Expand All @@ -86,7 +87,7 @@ struct EKFieldSerializer {
auto const vector_variants = get_value<std::vector<Variant>>(variant);
for (auto const &value : vector_variants) {
if (is_none(value)) {
values.emplace_back(boost::none);
values.emplace_back(std::nullopt);
} else {
values.emplace_back(get_value<double>(value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <utils/Vector.hpp>

#include <boost/serialization/access.hpp>

/** Checkpoint data for a EK node. */
struct EKWalberlaNodeState {
double density;
Expand All @@ -32,7 +34,7 @@ struct EKWalberlaNodeState {
private:
friend boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, long int /* version */) {
void serialize(Archive &ar, unsigned int /* version */) {
ar &density &is_boundary_density &density_boundary &is_boundary_flux
&flux_boundary;
}
Expand Down
12 changes: 6 additions & 6 deletions src/script_interface/walberla/LBFluid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifdef WALBERLA

#include "LBFluid.hpp"
#include "LBWalberlaNodeState.hpp"
#include "WalberlaCheckpoint.hpp"

#include "core/BoxGeometry.hpp"
Expand All @@ -34,7 +35,6 @@
#include <script_interface/communication.hpp>

#include <walberla_bridge/LatticeWalberla.hpp>
#include <walberla_bridge/lattice_boltzmann/LBWalberlaNodeState.hpp>
#include <walberla_bridge/lattice_boltzmann/LeesEdwardsPack.hpp>
#include <walberla_bridge/lattice_boltzmann/lb_walberla_init.hpp>

Expand All @@ -45,13 +45,13 @@
#include <boost/mpi.hpp>
#include <boost/mpi/collectives/all_reduce.hpp>
#include <boost/mpi/collectives/broadcast.hpp>
#include <boost/optional.hpp>

#include <algorithm>
#include <cassert>
#include <cstddef>
#include <functional>
#include <memory>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -299,8 +299,8 @@ void LBFluid::save_checkpoint(std::string const &filename, int mode) {
auto const write_data = [&lb_obj,
mode](std::shared_ptr<CheckpointFile> cpfile_ptr,
Context const &context) {
auto const get_node_checkpoint = [&](Utils::Vector3i const &ind)
-> boost::optional<LBWalberlaNodeState> {
auto const get_node_checkpoint =
[&](Utils::Vector3i const &ind) -> std::optional<LBWalberlaNodeState> {
auto const pop = lb_obj.get_node_population(ind);
auto const laf = lb_obj.get_node_last_applied_force(ind);
auto const lbb = lb_obj.get_node_is_boundary(ind);
Expand All @@ -313,9 +313,9 @@ void LBFluid::save_checkpoint(std::string const &filename, int mode) {
if (*lbb) {
cpnode.slip_velocity = *vbb;
}
return cpnode;
return {cpnode};
}
return {boost::none};
return std::nullopt;
};

auto failure = false;
Expand Down
1 change: 0 additions & 1 deletion src/script_interface/walberla/LBFluid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include <walberla_bridge/LatticeModel.hpp>
#include <walberla_bridge/lattice_boltzmann/LBWalberlaBase.hpp>
#include <walberla_bridge/lattice_boltzmann/LBWalberlaNodeState.hpp>

#include <utils/Vector.hpp>
#include <utils/math/int_pow.hpp>
Expand Down
6 changes: 3 additions & 3 deletions src/script_interface/walberla/LBFluidNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@

#include <boost/mpi/collectives/all_reduce.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/optional.hpp>

#include <optional>
#include <string>
#include <vector>

namespace ScriptInterface::walberla {

static bool is_boundary_all_reduce(boost::mpi::communicator const &comm,
boost::optional<bool> const &is_boundary) {
std::optional<bool> const &is_boundary) {
return boost::mpi::all_reduce(comm, is_boundary ? *is_boundary : false,
std::logical_or<>());
}
Expand Down Expand Up @@ -113,7 +113,7 @@ Variant LBFluidNode::do_call_method(std::string const &name,
}
if (name == "get_pressure_tensor" or name == "get_pressure_tensor_neq") {
auto const result = m_lb_fluid->get_node_pressure_tensor(m_index);
auto value = boost::optional<std::vector<double>>{};
auto value = std::optional<std::vector<double>>{};
if (result) {
value = (*result / m_conv_press).as_vector();
}
Expand Down
5 changes: 3 additions & 2 deletions src/script_interface/walberla/LBFluidSlice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@

#include <cassert>
#include <memory>
#include <optional>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>

namespace ScriptInterface::walberla {

using VelocityBounceBackType = boost::optional<Utils::Vector3d>;
using VelocityBounceBackType = std::optional<Utils::Vector3d>;

struct LBFieldSerializer {
template <typename T> static Variant serialize(std::vector<T> const &values) {
Expand Down Expand Up @@ -74,7 +75,7 @@ struct LBFieldSerializer {
auto const vector_variants = get_value<std::vector<Variant>>(variant);
for (auto const &value : vector_variants) {
if (is_none(value)) {
values.emplace_back(boost::none);
values.emplace_back(std::nullopt);
} else {
values.emplace_back(get_value<Utils::Vector3d>(value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <utils/Vector.hpp>

#include <boost/serialization/access.hpp>

#include <vector>

/** Checkpoint data for a LB node. */
Expand All @@ -33,7 +35,7 @@ struct LBWalberlaNodeState {
private:
friend boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, long int /* version */) {
void serialize(Archive &ar, unsigned int /* version */) {
ar &populations &last_applied_force &slip_velocity &is_boundary;
}
};
Loading

0 comments on commit 3dfaa9f

Please sign in to comment.