Skip to content

Commit cff388e

Browse files
committed
Update kernels and walberla bridge headers
Lees Edwards collison model now takes kT and seed parameters for thermalization.
1 parent 7103468 commit cff388e

File tree

78 files changed

+25720
-83445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+25720
-83445
lines changed

maintainer/walberla_kernels/generate_lb_kernels.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ def generate_init_kernels(ctx, method):
135135
def generate_stream_collide_lees_edwards_kernels(
136136
ctx, method, data_type, fields):
137137
precision_prefix = pystencils_espresso.precision_prefix[ctx.double_accuracy]
138-
lbm_opt = lbmpy.LBMOptimisation(symbolic_field=fields["pdfs"],
139-
symbolic_temporary_field=fields["pdfs_tmp"])
140-
shear_dir_normal = 1 # y-axis
141138
precision_rng = pystencils_espresso.precision_rng[ctx.double_accuracy]
139+
shear_dir_normal = 1 # y-axis
142140
block_offsets = tuple(
143141
ps.TypedSymbol(f"block_offset_{i}", np.uint32)
144142
for i in range(3))
@@ -150,6 +148,8 @@ def generate_stream_collide_lees_edwards_kernels(
150148
force=fields["force"].center_vector,
151149
kernel_type="stream_pull_collide",
152150
**lbm_config_kwargs)
151+
lbm_opt = lbmpy.LBMOptimisation(symbolic_field=fields["pdfs"],
152+
symbolic_temporary_field=fields["pdfs_tmp"])
153153
optimization = {"cse_global": True,
154154
"double_precision": ctx.double_accuracy}
155155
le_collision_rule_thermalized = lbmpy.creationfunctions.create_lb_collision_rule(
@@ -160,6 +160,7 @@ def generate_stream_collide_lees_edwards_kernels(
160160
"block_offsets": block_offsets,
161161
"rng_node": precision_rng
162162
},
163+
lbm_optimisation=lbm_opt,
163164
optimization=optimization
164165
)
165166
le_collision_rule_thermalized = lees_edwards.add_lees_edwards_to_collision(
@@ -175,7 +176,8 @@ def generate_stream_collide_lees_edwards_kernels(
175176
le_collision_rule_thermalized,
176177
stem,
177178
optimization,
178-
params
179+
params,
180+
block_offset=block_offsets
179181
)
180182
ctx.patch_file(stem, get_ext_source(target_suffix),
181183
patch_openmp_kernels)

src/core/lb/LBWalberla.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void LBWalberla::update_collision_model(LBWalberlaBase &lb,
171171
return get_shear_velocity(system.get_sim_time(), *le_protocol) *
172172
(params.get_tau() / params.get_agrid());
173173
});
174-
lb.set_collision_model(std::move(lees_edwards_object));
174+
lb.set_collision_model(std::move(lees_edwards_object), kT, seed);
175175
} else {
176176
lb.set_collision_model(kT, seed);
177177
}

src/walberla_bridge/include/walberla_bridge/lattice_boltzmann/LBWalberlaBase.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class LBWalberlaBase : public LatticeModel {
241241

242242
/** @brief Configure a thermalized collision model for Lees-Edwards. */
243243
virtual void
244-
set_collision_model(std::unique_ptr<LeesEdwardsPack> &&lees_edwards_pack) = 0;
244+
set_collision_model(std::unique_ptr<LeesEdwardsPack> &&lees_edwards_pack, double kT, unsigned int seed) = 0;
245245

246246
/** @brief Check Lees-Edwards boundary conditions. */
247247
virtual void check_lebc(unsigned int shear_direction,

src/walberla_bridge/src/lattice_boltzmann/LBWalberlaImpl.hpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class LBWalberlaImpl : public LBWalberlaBase {
210210
}
211211

212212
void operator()(StreamCollisionModelLeesEdwards &cm, IBlock *b) {
213+
cm.configure(m_storage, b);
213214
cm.setV_s(static_cast<decltype(cm.getV_s())>(
214215
m_lees_edwards_callbacks->get_shear_velocity()));
215216
cm(b);
@@ -531,9 +532,7 @@ class LBWalberlaImpl : public LBWalberlaBase {
531532
auto const block_variant = std::variant<IBlock *>(&block);
532533
std::visit(m_run_stream_collide_sweep, cm_variant, block_variant);
533534
}
534-
if (auto *cm = std::get_if<StreamCollisionModelThermalized>(&cm_variant)) {
535-
cm->setTime_step(cm->getTime_step() + 1u);
536-
}
535+
std::visit([](auto& cm) {cm.setTime_step(cm.getTime_step() + 1u);}, cm_variant);
537536
}
538537

539538
auto has_lees_edwards_bc() const {
@@ -701,8 +700,7 @@ class LBWalberlaImpl : public LBWalberlaBase {
701700
}
702701

703702
void set_collision_model(
704-
std::unique_ptr<LeesEdwardsPack> &&lees_edwards_pack) override {
705-
assert(m_kT == 0.);
703+
std::unique_ptr<LeesEdwardsPack> &&lees_edwards_pack, double kT, unsigned int seed) override {
706704
#if defined(__CUDACC__)
707705
if constexpr (Architecture == lbmpy::Arch::GPU) {
708706
throw std::runtime_error("Lees-Edwards LB doesn't support GPU yet");
@@ -712,6 +710,7 @@ class LBWalberlaImpl : public LBWalberlaBase {
712710
auto const shear_plane_normal = lees_edwards_pack->shear_plane_normal;
713711
auto const shear_vel = FloatType_c(lees_edwards_pack->get_shear_velocity());
714712
auto const omega = shear_mode_relaxation_rate();
713+
auto const omega_odd = odd_mode_relaxation_rate(omega);
715714
if (shear_plane_normal != 1u) {
716715
throw std::domain_error(
717716
"Lees-Edwards LB only supports shear_plane_normal=\"y\"");
@@ -728,10 +727,12 @@ class LBWalberlaImpl : public LBWalberlaBase {
728727
}
729728
auto const grid_dimensions = lattice.get_grid_dimensions();
730729
auto const grid_size = FloatType_c(grid_dimensions[shear_plane_normal]);
730+
m_kT = FloatType_c(kT);
731+
m_seed = seed;
731732
m_collision_model =
732733
std::make_shared<CollisionModel>(StreamCollisionModelLeesEdwards(
733-
m_last_applied_force_field_id, m_pdf_field_id, grid_size, omega,
734-
shear_vel));
734+
m_last_applied_force_field_id, m_pdf_field_id, grid_size, zero_centered_to_lb(m_kT), omega, omega, omega_odd, omega,
735+
seed, uint32_t{0u}, shear_vel));
735736
m_lees_edwards_callbacks = std::move(lees_edwards_pack);
736737
m_run_stream_collide_sweep =
737738
StreamCollideSweepVisitor(blocks, m_lees_edwards_callbacks);
@@ -1771,23 +1772,19 @@ class LBWalberlaImpl : public LBWalberlaBase {
17711772
}
17721773

17731774
[[nodiscard]] std::optional<uint64_t> get_rng_state() const override {
1774-
auto const cm =
1775-
std::get_if<StreamCollisionModelThermalized>(&*m_collision_model);
1776-
if (!cm or m_kT == 0.) {
1775+
if (m_kT == 0.) {
17771776
return std::nullopt;
17781777
}
1779-
return {static_cast<uint64_t>(cm->getTime_step())};
1778+
return std::visit([](auto const& cm) {return static_cast<uint64_t>(cm.getTime_step());},*m_collision_model);
17801779
}
17811780

17821781
void set_rng_state(uint64_t counter) override {
1783-
auto const cm =
1784-
std::get_if<StreamCollisionModelThermalized>(&*m_collision_model);
1785-
if (!cm or m_kT == 0.) {
1782+
if (m_kT == 0.) {
17861783
throw std::runtime_error("This LB instance is unthermalized");
17871784
}
17881785
assert(counter <=
17891786
static_cast<uint32_t>(std::numeric_limits<uint_t>::max()));
1790-
cm->setTime_step(static_cast<uint32_t>(counter));
1787+
std::visit([counter](auto& cm) {cm.setTime_step(static_cast<uint32_t>(counter));},*m_collision_model);
17911788
}
17921789

17931790
[[nodiscard]] LatticeWalberla const &get_lattice() const noexcept override {

0 commit comments

Comments
 (0)