diff options
Diffstat (limited to 'modules/core/tests')
| -rw-r--r-- | modules/core/tests/cell_list.cpp | 3 | ||||
| -rw-r--r-- | modules/core/tests/component_instantiation.cpp | 6 | ||||
| -rw-r--r-- | modules/core/tests/contact_dynamics.cpp | 5 | ||||
| -rw-r--r-- | modules/core/tests/descriptor.cpp | 84 | ||||
| -rw-r--r-- | modules/core/tests/macroscopic.cpp | 113 | ||||
| -rw-r--r-- | modules/core/tests/mask.cpp | 6 | ||||
| -rw-r--r-- | modules/core/tests/particle_3d.cpp | 3 | ||||
| -rw-r--r-- | modules/core/tests/particle_consistency.cpp | 3 | ||||
| -rw-r--r-- | modules/core/tests/particle_edges.cpp | 3 | ||||
| -rw-r--r-- | modules/core/tests/particle_gaps.cpp | 3 | ||||
| -rw-r--r-- | modules/core/tests/particles.cpp | 24 | ||||
| -rw-r--r-- | modules/core/tests/rotation.cpp | 3 | ||||
| -rw-r--r-- | modules/core/tests/rotation_3d.cpp | 254 | ||||
| -rw-r--r-- | modules/core/tests/unit.cpp | 343 | ||||
| -rw-r--r-- | modules/core/tests/voxel_narrow.cpp | 3 | ||||
| -rw-r--r-- | modules/core/tests/vtk_write.cpp | 6 |
16 files changed, 838 insertions, 24 deletions
diff --git a/modules/core/tests/cell_list.cpp b/modules/core/tests/cell_list.cpp index 00b260c..f04e065 100644 --- a/modules/core/tests/cell_list.cpp +++ b/modules/core/tests/cell_list.cpp @@ -17,7 +17,8 @@ constexpr uint64_t Cap = 8u; template<uint64_t PC> auto make_group(double radius){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(1.0); return kel::lbm::create_spheroid_particle_group<sch::T,D,PC>(r,d,{4u}); diff --git a/modules/core/tests/component_instantiation.cpp b/modules/core/tests/component_instantiation.cpp index 94d0536..e4a890b 100644 --- a/modules/core/tests/component_instantiation.cpp +++ b/modules/core/tests/component_instantiation.cpp @@ -33,7 +33,8 @@ using GroupSch = kel::lbm::sch::ParticleGroup<sch::T,D,2u,kel::lbm::coll::Sphero using GroupView = kel::lbm::data<sch::Ptr<GroupSch>, kel::lbm::enc::Native>; auto make_group(double radius){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(1.0); return kel::lbm::create_spheroid_particle_group<sch::T,D,2u>(r,d,{8u}); @@ -102,7 +103,8 @@ SAW_TEST("Component / ParticleIntegrate instantiates and moves the body"){ auto mass = rb.template get<"mass">().at({}).get(); rb.template get<"force">().at({{0u}}).set(mass); // unit acceleration - kel::lbm::data<sch::Vector<sch::T,D>> gravity; + // Gravity is an acceleration, and now has to say so. + kel::lbm::data<sch::LbmAcceleration<sch::Vector<sch::T,D>>> gravity; gravity.at({{1u}}).set(-0.5); lbm::component<sch::T,TestDesc,lbm::cmpt::ParticleIntegrate,lbm::enc::Native> integrate{gravity}; diff --git a/modules/core/tests/contact_dynamics.cpp b/modules/core/tests/contact_dynamics.cpp index b6545b9..b918bc1 100644 --- a/modules/core/tests/contact_dynamics.cpp +++ b/modules/core/tests/contact_dynamics.cpp @@ -17,7 +17,8 @@ constexpr uint64_t D = 2u; template<uint64_t PC> auto make_group(double radius, double density){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(density); return kel::lbm::create_spheroid_particle_group<sch::T,D,PC>(r,d,{8u}); @@ -138,7 +139,7 @@ SAW_TEST("Dynamics / resting contact settles at the force balance"){ kel::lbm::data<sch::FixedArray<sch::UInt64,D>> extent{{64u,32u}}; // Gravity pointing at the wall, as a body acceleration. - kel::lbm::data<sch::Vector<sch::T,D>> body_acc; + kel::lbm::data<sch::LbmAcceleration<sch::Vector<sch::T,D>>> body_acc; body_acc.at({{0u}}).set(-gravity); body_acc.at({{1u}}).set(0.0); diff --git a/modules/core/tests/descriptor.cpp b/modules/core/tests/descriptor.cpp index 7f743ce..96d6531 100644 --- a/modules/core/tests/descriptor.cpp +++ b/modules/core/tests/descriptor.cpp @@ -2,8 +2,63 @@ #include "../c++/descriptor.hpp" +#include <cmath> + namespace { +/** + * The lattice moment conditions: + * + * sum_i w_i = 1 + * sum_i w_i e_ia = 0 + * sum_i w_i e_ia e_ib = cs^2 * delta_ab + * + * A weight table that violates these still compiles and still passes an + * opposite-index check, but it makes the equilibrium return the wrong mass and + * momentum, and the only symptom is a simulation that diverges within a few + * steps. D3Q27 carried exactly that bug: its six face weights read 1/36 rather + * than 2/27, so the weights summed to 13/18. + * + * The second moment is the useful one -- it pins the weights per shell, where + * the plain sum only pins them in aggregate. + */ +template<typename Descriptor> +void check_weight_moments(){ + using namespace kel; + + using dfi = lbm::df_info<lbm::sch::Float64, Descriptor>; + + constexpr double tol = 1e-12; + + double sum_w = 0.0; + for(uint64_t k = 0u; k < Descriptor::Q; ++k){ + sum_w += dfi::weights[k]; + } + SAW_EXPECT(std::abs(sum_w - 1.0) < tol, "Weights have to sum to 1"); + + for(uint64_t a = 0u; a < Descriptor::D; ++a){ + double first = 0.0; + for(uint64_t k = 0u; k < Descriptor::Q; ++k){ + first += dfi::weights[k] * static_cast<double>(dfi::directions[k][a]); + } + SAW_EXPECT(std::abs(first) < tol, "First moment has to vanish"); + } + + for(uint64_t a = 0u; a < Descriptor::D; ++a){ + for(uint64_t b = 0u; b < Descriptor::D; ++b){ + double second = 0.0; + for(uint64_t k = 0u; k < Descriptor::Q; ++k){ + second += + dfi::weights[k] + * static_cast<double>(dfi::directions[k][a]) + * static_cast<double>(dfi::directions[k][b]); + } + const double expected = (a == b) ? static_cast<double>(dfi::cs2) : 0.0; + SAW_EXPECT(std::abs(second - expected) < tol, "Second moment has to be cs^2 delta_ab"); + } + } +} + template<typename Descriptor> void check_opposite_dirs(){ using namespace kel; @@ -32,8 +87,37 @@ SAW_TEST("Opposites and Dirs D2Q9"){ using namespace kel; check_opposite_dirs<lbm::sch::Descriptor<2,9>>(); } +SAW_TEST("Opposites and Dirs D3Q19"){ + using namespace kel; + check_opposite_dirs<lbm::sch::Descriptor<3,19>>(); +} SAW_TEST("Opposites and Dirs D3Q27"){ using namespace kel; check_opposite_dirs<lbm::sch::Descriptor<3,27>>(); } + +/** + * D2Q4 is deliberately absent: it is experimental and its weights sum to 5/6, + * so it would fail these outright. + */ +SAW_TEST("Weight moments D1Q3"){ + using namespace kel; + check_weight_moments<lbm::sch::Descriptor<1,3>>(); +} +SAW_TEST("Weight moments D2Q5"){ + using namespace kel; + check_weight_moments<lbm::sch::Descriptor<2,5>>(); +} +SAW_TEST("Weight moments D2Q9"){ + using namespace kel; + check_weight_moments<lbm::sch::Descriptor<2,9>>(); +} +SAW_TEST("Weight moments D3Q19"){ + using namespace kel; + check_weight_moments<lbm::sch::Descriptor<3,19>>(); +} +SAW_TEST("Weight moments D3Q27"){ + using namespace kel; + check_weight_moments<lbm::sch::Descriptor<3,27>>(); +} } diff --git a/modules/core/tests/macroscopic.cpp b/modules/core/tests/macroscopic.cpp new file mode 100644 index 0000000..9184819 --- /dev/null +++ b/modules/core/tests/macroscopic.cpp @@ -0,0 +1,113 @@ +#include <forstio/test/suite.hpp> + +#include <cmath> + +#include "../c++/macroscopic.hpp" +#include "../c++/equilibrium.hpp" + +namespace { +namespace sch { +using namespace kel::lbm::sch; +using T = Float64; +} + +/** + * The macro field used to be called "momentum" while holding velocity: + * compute_rho_u divides the first moment by the density (macroscopic.hpp). + * These pin that the name now matches the content, so the rename cannot be + * quietly undone by removing the division. + */ + +template<typename Desc> +void roundtrip(double rho_in, double ux_in){ + using namespace kel; + + lbm::data<sch::Scalar<sch::T>> rho; + rho.at({}).set(rho_in); + + lbm::data<sch::Vector<sch::T,Desc::D>> vel; + for(uint64_t i = 0u; i < Desc::D; ++i){ + vel.at({{i}}).set(0.0); + } + vel.at({{0u}}).set(ux_in); + + auto dfs = lbm::equilibrium<sch::T,Desc>(rho,vel); + + lbm::data<sch::Scalar<sch::T>> rho_out; + lbm::data<sch::Vector<sch::T,Desc::D>> vel_out; + lbm::compute_rho_u<sch::T,Desc>(dfs,rho_out,vel_out); + + SAW_EXPECT(std::abs(rho_out.at({}).get() - rho_in) < 1e-12, + "density must round trip through equilibrium"); + SAW_EXPECT(std::abs(vel_out.at({{0u}}).get() - ux_in) < 1e-12, + "velocity must round trip through equilibrium"); +} + +SAW_TEST("Macroscopic / the field holds velocity, not momentum"){ + using namespace kel; + using Desc = sch::D2Q9; + + // Density deliberately not 1, which is the only case where velocity and + // momentum differ numerically. + const double rho_in = 2.0; + const double ux_in = 0.1; + + lbm::data<sch::Scalar<sch::T>> rho; + rho.at({}).set(rho_in); + lbm::data<sch::Vector<sch::T,Desc::D>> vel; + vel.at({{0u}}).set(ux_in); + vel.at({{1u}}).set(0.0); + + auto dfs = lbm::equilibrium<sch::T,Desc>(rho,vel); + + lbm::data<sch::Scalar<sch::T>> rho_out; + lbm::data<sch::Vector<sch::T,Desc::D>> vel_out; + lbm::compute_rho_u<sch::T,Desc>(dfs,rho_out,vel_out); + + const double got = vel_out.at({{0u}}).get(); + + SAW_EXPECT(std::abs(got - ux_in) < 1e-12, "must be the velocity u"); + // rho*u would be 0.2 here. If the division by rho were dropped, this is + // the assertion that would catch it. + SAW_EXPECT(std::abs(got - rho_in * ux_in) > 1e-3, + "must NOT be the momentum rho*u"); +} + +SAW_TEST("Macroscopic / round trip D2Q9"){ + roundtrip<sch::D2Q9>(1.0, 0.05); + roundtrip<sch::D2Q9>(2.0, 0.05); +} + +SAW_TEST("Macroscopic / round trip D2Q5"){ + roundtrip<sch::Descriptor<2,5>>(1.0, 0.0); +} + +SAW_TEST("Macroscopic / round trip D3Q27"){ + // The 3D path divides by rho too -- it is the same loop. + roundtrip<sch::D3Q27>(1.0, 0.05); + roundtrip<sch::D3Q27>(1.7, 0.03); +} + +SAW_TEST("Macroscopic / a quiescent field has zero velocity at any density"){ + using namespace kel; + using Desc = sch::D2Q9; + + for(double r : {0.5, 1.0, 3.0}){ + lbm::data<sch::Scalar<sch::T>> rho; + rho.at({}).set(r); + lbm::data<sch::Vector<sch::T,Desc::D>> vel; + vel.at({{0u}}).set(0.0); + vel.at({{1u}}).set(0.0); + + auto dfs = lbm::equilibrium<sch::T,Desc>(rho,vel); + + lbm::data<sch::Scalar<sch::T>> rho_out; + lbm::data<sch::Vector<sch::T,Desc::D>> vel_out; + lbm::compute_rho_u<sch::T,Desc>(dfs,rho_out,vel_out); + + SAW_EXPECT(std::abs(rho_out.at({}).get() - r) < 1e-12, "density preserved"); + SAW_EXPECT(std::abs(vel_out.at({{0u}}).get()) < 1e-12, "no x velocity at rest"); + SAW_EXPECT(std::abs(vel_out.at({{1u}}).get()) < 1e-12, "no y velocity at rest"); + } +} +} diff --git a/modules/core/tests/mask.cpp b/modules/core/tests/mask.cpp index dfb5ef8..f67cc78 100644 --- a/modules/core/tests/mask.cpp +++ b/modules/core/tests/mask.cpp @@ -15,7 +15,8 @@ using T = Float64; constexpr uint64_t D = 2u; auto make_one(double radius){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(1.0); return kel::lbm::create_spheroid_particle_group<sch::T,D,1u>(r,d,{32u}); @@ -209,7 +210,8 @@ SAW_TEST("Mask / porosity agrees with the analytic sphere"){ kel::lbm::data<sch::Scalar<sch::T>> eps; eps.at({}).set(1.5); - auto rad = p.template get<"collision">().template get<"radius">(); + // The analytic porosity works on raw lengths, as the solvers do. + auto rad = p.template get<"collision">().template get<"radius">().handle(); double worst = 0.0; for(int i = 0; i <= 40; ++i){ diff --git a/modules/core/tests/particle_3d.cpp b/modules/core/tests/particle_3d.cpp index 8c3e579..a169f10 100644 --- a/modules/core/tests/particle_3d.cpp +++ b/modules/core/tests/particle_3d.cpp @@ -26,7 +26,8 @@ constexpr uint64_t D = 3u; template<uint64_t PC> auto make_group(double radius, double density, uint64_t res = 12u){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(density); return kel::lbm::create_spheroid_particle_group<sch::T,D,PC>(r,d,{res}); diff --git a/modules/core/tests/particle_consistency.cpp b/modules/core/tests/particle_consistency.cpp index ae40aa8..7e84ab5 100644 --- a/modules/core/tests/particle_consistency.cpp +++ b/modules/core/tests/particle_consistency.cpp @@ -19,7 +19,8 @@ constexpr uint64_t Cap = 16u; template<uint64_t PC> auto make_group(double radius, uint64_t res = 24u){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(1.0); return kel::lbm::create_spheroid_particle_group<sch::T,D,PC>(r,d,{res}); diff --git a/modules/core/tests/particle_edges.cpp b/modules/core/tests/particle_edges.cpp index cbc1bab..e39817b 100644 --- a/modules/core/tests/particle_edges.cpp +++ b/modules/core/tests/particle_edges.cpp @@ -17,7 +17,8 @@ constexpr uint64_t D = 2u; template<uint64_t PC> auto make_group(double radius){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(1.0); return kel::lbm::create_spheroid_particle_group<sch::T,D,PC>(r,d,{8u}); diff --git a/modules/core/tests/particle_gaps.cpp b/modules/core/tests/particle_gaps.cpp index 3db831e..f7213a6 100644 --- a/modules/core/tests/particle_gaps.cpp +++ b/modules/core/tests/particle_gaps.cpp @@ -18,7 +18,8 @@ constexpr uint64_t D = 2u; template<uint64_t PC> auto make_group(double radius, uint64_t res = 32u){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(1.0); return kel::lbm::create_spheroid_particle_group<sch::T,D,PC>(r,d,{res}); diff --git a/modules/core/tests/particles.cpp b/modules/core/tests/particles.cpp index 2105abc..1bc5d46 100644 --- a/modules/core/tests/particles.cpp +++ b/modules/core/tests/particles.cpp @@ -26,7 +26,8 @@ SAW_TEST("Verlet step 2D - Planar"){ acc.at({{0}}).set({1.0}); - kel::lbm::data<sch::Scalar<sch::T>> dt; + // A timestep is a lattice time. + kel::lbm::data<sch::LbmSecond<sch::Scalar<sch::T>>> dt; dt.at({}).set(0.5); lbm::verlet_step_lambda<sch::T,2u>(particle,dt); @@ -131,7 +132,8 @@ SAW_TEST("Moving particles 2D"){ acc.at({{0u}}) = -0.1; } - kel::lbm::data<sch::Scalar<sch::T>> dt; + // A timestep is a lattice time. + kel::lbm::data<sch::LbmSecond<sch::Scalar<sch::T>>> dt; dt.at({}).set(0.5); bool has_collided = false; for(uint64_t i = 0u; i < 32u; ++i){ @@ -284,7 +286,8 @@ SAW_TEST("Spheroid Particle / AABB"){ constexpr uint64_t D = 2u; constexpr uint64_t PC = 1u; - kel::lbm::data<sch::Scalar<T>> radi,dense; + kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> radi; + kel::lbm::data<sch::Scalar<T>> dense; radi.at({}) = 2.2f; dense.at({}) = 1.0f; auto spheroid_pgrp = lbm::create_spheroid_particle_group<T,D,PC>(radi,dense,{8u}); @@ -331,7 +334,8 @@ SAW_TEST("Spheroid Particle / AABB per particle"){ constexpr uint64_t D = 2u; constexpr uint64_t PC = 3u; - kel::lbm::data<sch::Scalar<T>> radi,dense; + kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> radi; + kel::lbm::data<sch::Scalar<T>> dense; radi.at({}) = 2.2f; dense.at({}) = 1.0f; auto pgrp = lbm::create_spheroid_particle_group<T,D,PC>(radi,dense,{8u}); @@ -390,7 +394,8 @@ SAW_TEST("Spheroid Particle / per-particle inertial fan-out"){ constexpr uint64_t D = 2u; constexpr uint64_t PC = 4u; - kel::lbm::data<sch::Scalar<T>> radi,dense; + kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> radi; + kel::lbm::data<sch::Scalar<T>> dense; radi.at({}) = 2.0; dense.at({}) = 3.0; auto pgrp = lbm::create_spheroid_particle_group<T,D,PC>(radi,dense,{8u}); @@ -466,7 +471,8 @@ SAW_TEST("Particle / force accumulates then integrates"){ - kel::lbm::data<sch::Scalar<T>> radi,dense; + kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> radi; + kel::lbm::data<sch::Scalar<T>> dense; radi.at({}) = 1.0; dense.at({}) = 1.0 / 3.14159265358979323846; // gives mass == 1 auto pgrp = lbm::create_spheroid_particle_group<T,D,PC>(radi,dense,{4u}); @@ -502,7 +508,8 @@ SAW_TEST("Particle / zero sub steps still advances"){ - kel::lbm::data<sch::Scalar<T>> radi,dense; + kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> radi; + kel::lbm::data<sch::Scalar<T>> dense; radi.at({}) = 1.0; dense.at({}) = 1.0 / 3.14159265358979323846; auto pgrp = lbm::create_spheroid_particle_group<T,D,PC>(radi,dense,{4u}); @@ -530,7 +537,8 @@ constexpr uint64_t D = 2u; template<uint64_t PC> auto make_group(double radius, double density){ - kel::lbm::data<sch::Scalar<T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> r; + kel::lbm::data<sch::Scalar<T>> d; r.at({}).set(radius); d.at({}).set(density); return kel::lbm::create_spheroid_particle_group<T,D,PC>(r,d,{4u}); diff --git a/modules/core/tests/rotation.cpp b/modules/core/tests/rotation.cpp index e1e8c46..a4bab33 100644 --- a/modules/core/tests/rotation.cpp +++ b/modules/core/tests/rotation.cpp @@ -18,7 +18,8 @@ constexpr uint64_t D = 2u; template<uint64_t PC> auto make_group(double radius, double density){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(density); return kel::lbm::create_spheroid_particle_group<sch::T,D,PC>(r,d,{16u}); diff --git a/modules/core/tests/rotation_3d.cpp b/modules/core/tests/rotation_3d.cpp new file mode 100644 index 0000000..4bfb067 --- /dev/null +++ b/modules/core/tests/rotation_3d.cpp @@ -0,0 +1,254 @@ +#include <forstio/test/suite.hpp> + +#include <cmath> + +#include "../c++/particle/particle.hpp" +#include "../c++/particle/integrate.hpp" + +namespace { +namespace sch { +using namespace kel::lbm::sch; +using T = Float64; +} + +constexpr uint64_t D = 3u; + +/** + * The fixed-axis rotor: a body pinned in place, free to spin about one axis. + * + * particle_angular_supported<3> is false and stays false -- general 3D spin + * needs a quaternion and an inertia tensor. These cover the constrained case + * instead, which is exact rather than approximate because the axis never + * moves. See particle_fixed_axis_supported for the argument. + */ + +auto make_rotor(double radius = 2.0, double density = 1.0){ + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; + r.at({}).set(radius); + d.at({}).set(density); + return kel::lbm::create_spheroid_particle_group<sch::T,D,1u>(r,d,{8u}); +} + +template<typename G> +auto& body(G& g){ + return g.template get<"particles">().at({0u}).template get<"rigid_body">(); +} + +template<typename G> +void place_at_rest(G& g, double x, double y, double z){ + auto& rb = body(g); + auto& pos = rb.template get<"position">(); + auto& old = rb.template get<"position_old">(); + const double v[3] = {x,y,z}; + for(uint64_t i = 0u; i < 3u; ++i){ + pos.at({{i}}).set(v[i]); + // position_old == position is what makes the pin exact. + old.at({{i}}).set(v[i]); + } + auto& rot = rb.template get<"rotation">(); + auto& rot_old = rb.template get<"rotation_old">(); + auto& ang = rb.template get<"angular_acceleration">(); + for(uint64_t i = 0u; i < 3u; ++i){ + rot.at({{i}}).set(0); + rot_old.at({{i}}).set(0); + ang.at({{i}}).set(0); + } +} + +kel::lbm::data<sch::Vector<sch::T,3u>> vec3(double x, double y, double z){ + kel::lbm::data<sch::Vector<sch::T,3u>> v; + v.at({{0u}}).set(x); + v.at({{1u}}).set(y); + v.at({{2u}}).set(z); + return v; +} + +template<typename G> +void set_torque(G& g, double x, double y, double z){ + auto& t = body(g).template get<"torque">(); + t.at({{0u}}).set(x); + t.at({{1u}}).set(y); + t.at({{2u}}).set(z); +} + +SAW_TEST("Rotor 3D / fixed axis is supported where general spin is not"){ + using namespace kel; + static_assert(not lbm::particle_angular_supported<3u>, + "General 3D spin must stay gated off"); + static_assert(lbm::particle_fixed_axis_supported<3u>, + "Fixed axis spin must be available in 3D"); + static_assert(lbm::particle_fixed_axis_supported<2u>, + "Fixed axis spin must also cover 2D"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Rotor 3D / position is pinned bitwise under load"){ + using namespace kel; + + auto g = make_rotor(); + place_at_rest(g, 7.0, 11.0, 13.0); + + auto& rb = body(g); + // A force far larger than anything the fluid would produce. + auto& f = rb.template get<"force">(); + f.at({{0u}}).set(1.0e6); + f.at({{1u}}).set(-5.0e5); + f.at({{2u}}).set(2.5e5); + + set_torque(g, 0.0, 3.0, 0.0); + + auto axis = vec3(0.0,1.0,0.0); + auto& pi = g.template get<"particles">().at({0u}); + + for(uint64_t s = 0u; s < 64u; ++s){ + lbm::integrate_particle_fixed_axis<sch::T,D>(pi, axis, {4u}); + } + + auto& pos = rb.template get<"position">(); + // Exact equality, not a tolerance: 2x - x_old + 0 reproduces x bitwise. + SAW_EXPECT(pos.at({{0u}}).get() == 7.0, "x must not drift"); + SAW_EXPECT(pos.at({{1u}}).get() == 11.0, "y must not drift"); + SAW_EXPECT(pos.at({{2u}}).get() == 13.0, "z must not drift"); +} + +SAW_TEST("Rotor 3D / only the on-axis torque component spins it"){ + using namespace kel; + + auto g = make_rotor(); + place_at_rest(g, 0.0, 0.0, 0.0); + + // Mostly off-axis: only the y component should drive a y-axis rotor. + set_torque(g, 9.0, 2.0, -4.0); + + auto axis = vec3(0.0,1.0,0.0); + auto& pi = g.template get<"particles">().at({0u}); + lbm::integrate_particle_fixed_axis<sch::T,D>(pi, axis, {1u}); + + auto& ang = body(g).template get<"angular_acceleration">(); + const double inertia = body(g).template get<"inertia">().at({}).get(); + + SAW_EXPECT(std::abs(ang.at({{0u}}).get()) < 1e-12, "No spin off the axis in x"); + SAW_EXPECT(std::abs(ang.at({{2u}}).get()) < 1e-12, "No spin off the axis in z"); + SAW_EXPECT(std::abs(ang.at({{1u}}).get() - (2.0 / inertia)) < 1e-12, + "On-axis component must give tau/I"); +} + +SAW_TEST("Rotor 3D / rotation stays parallel to the axis"){ + using namespace kel; + + auto g = make_rotor(); + place_at_rest(g, 0.0, 0.0, 0.0); + + // A deliberately tilted, non-unit axis: the component must normalise it. + auto axis = vec3(1.0, 2.0, -2.0); + auto& pi = g.template get<"particles">().at({0u}); + + for(uint64_t s = 0u; s < 128u; ++s){ + set_torque(g, 0.5, 1.0, 0.25); + lbm::integrate_particle_fixed_axis<sch::T,D>(pi, axis, {2u}); + } + + auto& rot = body(g).template get<"rotation">(); + + // |rot| must equal |rot . axis_hat|: no component ever grows off-axis. + const double n = std::sqrt(1.0 + 4.0 + 4.0); + const double ax[3] = {1.0/n, 2.0/n, -2.0/n}; + + double along = 0.0; + double len2 = 0.0; + for(uint64_t i = 0u; i < 3u; ++i){ + along += rot.at({{i}}).get() * ax[i]; + len2 += rot.at({{i}}).get() * rot.at({{i}}).get(); + } + const double len = std::sqrt(len2); + + SAW_EXPECT(len > 1e-9, "The rotor should actually have turned"); + SAW_EXPECT(std::abs(len - std::abs(along)) < 1e-9, + "Rotation must stay parallel to the spin axis"); +} + +SAW_TEST("Rotor 3D / constant torque spins up linearly"){ + using namespace kel; + + auto g = make_rotor(); + place_at_rest(g, 0.0, 0.0, 0.0); + + auto axis = vec3(0.0,0.0,1.0); + auto& pi = g.template get<"particles">().at({0u}); + auto& rb = body(g); + + const double inertia = rb.template get<"inertia">().at({}).get(); + const double tau = 3.0; + + // One sub step, so a step is a unit of time and omega is rot - rot_old. + auto omega_z = [&](){ + return rb.template get<"rotation">().at({{2u}}).get() + - rb.template get<"rotation_old">().at({{2u}}).get(); + }; + + for(uint64_t s = 0u; s < 8u; ++s){ + set_torque(g, 0.0, 0.0, tau); + lbm::integrate_particle_fixed_axis<sch::T,D>(pi, axis, {1u}); + } + const double w8 = omega_z(); + + for(uint64_t s = 0u; s < 8u; ++s){ + set_torque(g, 0.0, 0.0, tau); + lbm::integrate_particle_fixed_axis<sch::T,D>(pi, axis, {1u}); + } + const double w16 = omega_z(); + + SAW_EXPECT(w8 > 0.0, "A positive torque must spin it positively"); + // Constant angular acceleration: omega is linear in step count, so + // doubling the steps doubles omega. + SAW_EXPECT(std::abs(w16 - 2.0 * w8) < 1e-9 * std::abs(w16), + "Angular velocity must grow linearly under constant torque"); + SAW_EXPECT(std::abs(w8 - 8.0 * (tau / inertia)) < 1e-9, + "Angular velocity must match tau/I per step"); +} + +SAW_TEST("Rotor 3D / no torque means no spin"){ + using namespace kel; + + auto g = make_rotor(); + place_at_rest(g, 0.0, 0.0, 0.0); + set_torque(g, 0.0, 0.0, 0.0); + + auto axis = vec3(0.0,1.0,0.0); + auto& pi = g.template get<"particles">().at({0u}); + + for(uint64_t s = 0u; s < 32u; ++s){ + lbm::integrate_particle_fixed_axis<sch::T,D>(pi, axis, {4u}); + } + + auto& rot = body(g).template get<"rotation">(); + for(uint64_t i = 0u; i < 3u; ++i){ + SAW_EXPECT(rot.at({{i}}).get() == 0.0, "A torque free rotor must not turn"); + } +} + +SAW_TEST("Rotor 3D / a zero axis is inert rather than NaN"){ + using namespace kel; + + auto g = make_rotor(); + place_at_rest(g, 0.0, 0.0, 0.0); + set_torque(g, 1.0, 1.0, 1.0); + + // math::normalize returns a zero vector unchanged, so this must produce a + // body that never spins -- not one that poisons the run with NaN. + auto axis = vec3(0.0,0.0,0.0); + auto& pi = g.template get<"particles">().at({0u}); + + for(uint64_t s = 0u; s < 8u; ++s){ + lbm::integrate_particle_fixed_axis<sch::T,D>(pi, axis, {2u}); + } + + auto& rot = body(g).template get<"rotation">(); + for(uint64_t i = 0u; i < 3u; ++i){ + const double v = rot.at({{i}}).get(); + SAW_EXPECT(v == v, "Rotation must not be NaN"); + SAW_EXPECT(std::abs(v) < 1e-12, "A zero axis must not spin the body"); + } +} +} diff --git a/modules/core/tests/unit.cpp b/modules/core/tests/unit.cpp new file mode 100644 index 0000000..1c187c0 --- /dev/null +++ b/modules/core/tests/unit.cpp @@ -0,0 +1,343 @@ +#include <forstio/test/suite.hpp> + +#include <sstream> +#include <type_traits> + +#include "../c++/abstract/unit.hpp" +#include "../c++/abstract/unit_print.hpp" +#include "../c++/lbm_unit.hpp" +#include "../c++/particle/schema.hpp" + +namespace { +namespace sch { +using namespace kel::lbm::sch; +using T = Float64; +} + +using kel::lbm::si_type::meter; +using kel::lbm::si_type::second; +using lbm_meter = kel::lbm::lbm_type::meter; + +template <int64_t E, int64_t S = 0> +using Met = sch::UnitElement<meter, E, S>; + +template <int64_t E, int64_t S = 0> +using Sec = sch::UnitElement<second, E, S>; + +template <typename... Ele> using U = sch::Unit<sch::T, Ele...>; + +template <typename A, typename B> +using Mul = typename kel::lbm::unit_multiplication<A, B>::Schema; + +template <typename A, typename B> +using Div = typename kel::lbm::unit_division<A, B>::Schema; + +/** + * The unit algebra had no direct coverage: converter.cpp asserts one + * conversion and args.cpp exercises unit_division once. Nothing pinned + * multiplication, exponent cancellation, or the scaling comparison -- and the + * scaling path could not even be instantiated, because unit_multiplication, + * unit_division and the three print patterns all matched the two argument + * form, which means scale 0 after the default argument is substituted. + */ + +SAW_TEST("Unit / multiplication folds same base and same scale"){ + static_assert(std::is_same_v<Mul<U<Met<1>>, U<Met<1>>>, U<Met<2>>>, + "m * m must fold to m^2"); + static_assert(std::is_same_v<Mul<U<Met<1,3>>, U<Met<1,3>>>, U<Met<2,3>>>, + "km * km must fold to km^2, keeping the scale"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / different scales do not fold"){ + // Same base quantity, different prefix: the factors must both survive + // rather than silently combining, because nothing rescales the value. + using Mixed = Mul<U<Met<1,0>>, U<Met<1,3>>>; + static_assert(!std::is_same_v<Mixed, U<Met<2,0>>>, "must not fold to m^2"); + static_assert(!std::is_same_v<Mixed, U<Met<2,3>>>, "must not fold to km^2"); + static_assert(std::is_same_v<Mixed, U<Met<1,0>, Met<1,3>>>, + "both factors must survive, in order"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / division negates the exponent but keeps the scale"){ + // (km)^-1 is scale 3 exponent -1. Negating the scale too would quietly + // mean (mm)^-1. + static_assert(std::is_same_v<Div<U<Met<2,3>>, U<Met<1,3>>>, U<Met<1,3>>>, + "km^2 / km must be km"); + static_assert(std::is_same_v<Div<U<>, U<Met<1,3>>>, U<Met<-1,3>>>, + "1 / km must be km^-1, not mm^-1"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / cancelling exponents drop out entirely"){ + // m/m must be genuinely dimensionless, not m^0. + static_assert(std::is_same_v<Div<U<Met<1>>, U<Met<1>>>, sch::Pure<sch::T>>, + "m / m must reduce to Pure"); + static_assert(std::is_same_v<Div<U<Met<1,3>>, U<Met<1,3>>>, sch::Pure<sch::T>>, + "km / km must reduce to Pure"); + // But only when the scales agree. + static_assert(!std::is_same_v<Div<U<Met<1,3>>, U<Met<1,0>>>, sch::Pure<sch::T>>, + "km / m must not cancel"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / lattice and SI metres never fold"){ + // This is what actually separates lattice from SI -- distinct base tag + // types, not the scale. + using LbmMet = sch::UnitElement<lbm_meter, 1>; + using Mixed = Mul<U<Met<1>>, U<LbmMet>>; + static_assert(!std::is_same_v<Mixed, U<Met<2>>>, "must not fold"); + // Canonical order, not encounter order: "meter_lbm" sorts before "meter_si". + static_assert(std::is_same_v<Mixed, U<LbmMet, Met<1>>>, "both survive, sorted"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / existing aliases are unchanged"){ + // Regression pin: widening the patterns must not have altered any + // composition that lbm_unit.hpp already produced. + static_assert(std::is_same_v<sch::SiMeter<sch::T>, U<Met<1>>>, "SiMeter"); + static_assert(std::is_same_v<sch::SiVelocity<sch::T>, U<Met<1>, Sec<-1>>>, + "SiVelocity"); + static_assert( + std::is_same_v<sch::SiKinematicViscosity<sch::T>, U<Met<2>, Sec<-1>>>, + "SiKinematicViscosity"); + static_assert( + std::is_same_v<Div<sch::SiMeter<sch::T>, sch::SiSecond<sch::T>>, + sch::SiVelocity<sch::T>>, + "m / s must be the velocity alias exactly"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / a scaled unit prints with its prefix"){ + std::stringstream plain, kilo, milli; + + kel::lbm::data<U<Met<1>>> p{2.0}; + kel::lbm::data<U<Met<1,3>>> k{2.0}; + kel::lbm::data<U<Met<1,-3>>> m{2.0}; + + plain << p; + kilo << k; + milli << m; + + SAW_EXPECT(plain.str() == "2 [m_si]", "unscaled prints bare"); + SAW_EXPECT(kilo.str() == "2 [km_si]", "kilo prints a k prefix"); + SAW_EXPECT(milli.str() == "2 [mm_si]", "milli prints an m prefix"); + // The whole point: a scaled unit must not render identically to an + // unscaled one, or the output lies about the value. + SAW_EXPECT(plain.str() != kilo.str(), "scaled must differ from unscaled"); +} + +SAW_TEST("Unit / an off table scale prints explicitly"){ + std::stringstream o; + kel::lbm::data<U<Met<1,4>>> odd{2.0}; + o << odd; + // No SI letter exists for 10^4, so it must say so rather than drop it. + SAW_EXPECT(o.str() == "2 [10^(4)*m_si]", "unknown scale prints as a power"); +} +} + +namespace { +/** + * The particle position is unit typed. These pin the two things that are easy + * to break without noticing. + */ +SAW_TEST("Unit / a united wrapper is layout compatible with its base"){ + // The whole device path depends on this and nothing else checks it: the + // particle group crosses to the GPU through sycl_copy_helper<FixedArray>, + // which is a bulk h.copy of the element block and never recurses into the + // element schema. A unit wrapper that changed the size would corrupt every + // particle silently rather than failing to compile. + using Raw = kel::lbm::data<sch::Vector<sch::T,3u>>; + using United = kel::lbm::data<sch::LbmMeter<sch::Vector<sch::T,3u>>>; + + static_assert(sizeof(Raw) == sizeof(United), + "A unit wrapper must not change the layout"); + static_assert(std::is_trivially_copyable_v<United>, + "A unit wrapper must stay memcpy-able"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / particle position carries lattice metres"){ + kel::lbm::data<sch::ParticleRigidBody<sch::T,3u>> rb; + + auto &pos = rb.template get<"position">(); + auto &pos_old = rb.template get<"position_old">(); + auto &acc = rb.template get<"acceleration">(); + + static_assert( + std::is_same_v<std::remove_cvref_t<decltype(pos)>, + kel::lbm::data<sch::LbmMeter<sch::Vector<sch::T,3u>>>>, + "position must be a lattice length"); + static_assert( + std::is_same_v<std::remove_cvref_t<decltype(pos_old)>, + std::remove_cvref_t<decltype(pos)>>, + "position_old must match position"); + static_assert( + std::is_same_v<std::remove_cvref_t<decltype(acc)>, + kel::lbm::data<sch::LbmAcceleration<sch::Vector<sch::T,3u>>>>, + "acceleration must be a lattice acceleration"); + + // Element access still reaches the raw component. + pos.at({{0u}}).set(3.0); + SAW_EXPECT(pos.at({{0u}}).get() == 3.0, "element access must still work"); + + // A difference of two lengths is a length; its dot product is an area. + auto delta = pos - pos_old; + static_assert(std::is_same_v<decltype(delta), std::remove_cvref_t<decltype(pos)>>, + "length minus length is a length"); + + auto area = kel::lbm::math::dot(delta, delta); + static_assert( + std::is_same_v<decltype(area), + kel::lbm::data<sch::Unit<sch::Scalar<sch::T>, + sch::UnitElement<kel::lbm::lbm_type::meter,2>>>>, + "dot of two lengths must be an area"); + SAW_EXPECT(area.at({}).get() == 9.0, "and the value must be right"); +} +} + +namespace { +/** + * Commutativity at the type level. + * + * m * s and s * m are the same physical unit. If the reduction preserves + * encounter order rather than imposing a canonical one, they become distinct + * C++ types and the same quantity reached two different ways stops matching. + */ +SAW_TEST("Unit / multiplication is commutative in the type"){ + using A = Mul<U<Met<1>>, U<Sec<-1>>>; + using B = Mul<U<Sec<-1>>, U<Met<1>>>; + static_assert(std::is_same_v<A,B>, "m*s and s*m must be the same type"); + SAW_EXPECT(true, "static assert carries this one"); +} +} + +namespace { +/** + * An alias written by hand must already be in canonical order, or it will not + * match the same unit arrived at by arithmetic. + * + * Multiplying by a dimensionless unit runs the alias back through the + * reduction and the sort, so if its factors were declared out of order the + * round trip changes the type and this fails. + */ +template <typename Alias> +inline constexpr bool is_canonical = + std::is_same_v<Mul<U<>, Alias>, Alias>; + +SAW_TEST("Unit / division is commutative in the type too"){ + // a/b reached two ways must agree. + using A = Div<Mul<U<Met<1>>, U<Sec<1>>>, U<Sec<2>>>; + using B = Div<Mul<U<Sec<1>>, U<Met<1>>>, U<Sec<2>>>; + static_assert(std::is_same_v<A,B>, "operand order must not change the type"); + SAW_EXPECT(true, "static assert carries this one"); +} + +SAW_TEST("Unit / three factors sort canonically whatever the order"){ + using Kv = sch::UnitElement<kel::lbm::lbm_type::meter, 2>; + using Sl = sch::UnitElement<kel::lbm::lbm_type::second, -1>; + + using One = Mul<Mul<U<Met<1>>, U<Kv>>, U<Sl>>; + using Two = Mul<Mul<U<Sl>, U<Met<1>>>, U<Kv>>; + using Three = Mul<Mul<U<Kv>, U<Sl>>, U<Met<1>>>; + + static_assert(std::is_same_v<One,Two>, "any permutation must agree"); + static_assert(std::is_same_v<Two,Three>, "any permutation must agree"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / every lbm_unit alias is already canonical"){ + static_assert(is_canonical<sch::SiMeter<sch::T>>, "SiMeter"); + static_assert(is_canonical<sch::LbmMeter<sch::T>>, "LbmMeter"); + static_assert(is_canonical<sch::SiSecond<sch::T>>, "SiSecond"); + static_assert(is_canonical<sch::LbmSecond<sch::T>>, "LbmSecond"); + static_assert(is_canonical<sch::SiVelocity<sch::T>>, "SiVelocity"); + static_assert(is_canonical<sch::LbmVelocity<sch::T>>, "LbmVelocity"); + static_assert(is_canonical<sch::SiAcceleration<sch::T>>, "SiAcceleration"); + static_assert(is_canonical<sch::LbmAcceleration<sch::T>>, "LbmAcceleration"); + static_assert(is_canonical<sch::SiKinematicViscosity<sch::T>>, "SiKinematicViscosity"); + static_assert(is_canonical<sch::LbmKinematicViscosity<sch::T>>, "LbmKinematicViscosity"); + SAW_EXPECT(true, "static asserts carry this one"); +} +} + +namespace { +/** + * Velocity is typed through the kinematics and unwrapped at the force law, + * because force needs a mass base unit that does not exist yet. + */ +SAW_TEST("Unit / a length over a time is a velocity"){ + using Vel = Div<sch::LbmMeter<sch::T>, sch::LbmSecond<sch::T>>; + static_assert(std::is_same_v<Vel, sch::LbmVelocity<sch::T>>, + "m / s must be exactly the LbmVelocity alias"); + + // And a velocity times a time is back to a length. + using Len = Mul<sch::LbmVelocity<sch::T>, sch::LbmSecond<sch::T>>; + static_assert(std::is_same_v<Len, sch::LbmMeter<sch::T>>, + "velocity * time must be a length again"); + SAW_EXPECT(true, "static asserts carry this one"); +} + +SAW_TEST("Unit / a normalised vector is Pure, not merely unannotated"){ + kel::lbm::data<sch::LbmMeter<sch::Vector<sch::T,3u>>> v; + v.at({{0u}}).set(3.0); + v.at({{1u}}).set(4.0); + v.at({{2u}}).set(0.0); + + auto dir = kel::lbm::math::normalize(v); + static_assert( + std::is_same_v<decltype(dir), + kel::lbm::data<sch::Pure<sch::Vector<sch::T,3u>>>>, + "a direction must be Pure"); + + SAW_EXPECT(std::abs(dir.at({{0u}}).get() - 0.6) < 1e-12, "x component"); + SAW_EXPECT(std::abs(dir.at({{1u}}).get() - 0.8) < 1e-12, "y component"); + + // The length keeps the unit it measured. + auto len = kel::lbm::math::norm(v); + static_assert(std::is_same_v<decltype(len), kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>>>, + "a length must stay a length"); + SAW_EXPECT(std::abs(len.at({}).get() - 5.0) < 1e-12, "norm value"); +} +} + +namespace { +/** + * sqrt halves the exponents, so the root of an area is a length. This is what + * lets `pos_rel / sqrt(distance_squared)` come out as a dimensionless + * direction rather than an unlabelled vector. + */ +SAW_TEST("Unit / sqrt of an area is a length"){ + using Area = Mul<sch::LbmMeter<sch::Scalar<sch::T>>, sch::LbmMeter<sch::Scalar<sch::T>>>; + + kel::lbm::data<Area> a; + a.at({}).set(9.0); + + auto len = kel::lbm::math::sqrt(a); + static_assert( + std::is_same_v<decltype(len), kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>>>, + "sqrt(m^2) must be m"); + SAW_EXPECT(std::abs(len.at({}).get() - 3.0) < 1e-12, "and the value must be right"); + + // A length divided by a length is a direction scale: dimensionless. + using Ratio = Div<sch::LbmMeter<sch::Scalar<sch::T>>, sch::LbmMeter<sch::Scalar<sch::T>>>; + static_assert(std::is_same_v<Ratio, sch::Pure<sch::Scalar<sch::T>>>, + "m / m must be Pure"); + SAW_EXPECT(true, "static asserts carry the rest"); +} + +SAW_TEST("Unit / sqrt refuses an odd exponent"){ + // m^3 has no expressible square root in this system. The static_assert in + // math::sqrt is what stops it, so this test records the intent rather + // than invoking it -- instantiating it would fail the build by design. + using Cube = Mul<Mul<sch::LbmMeter<sch::Scalar<sch::T>>, + sch::LbmMeter<sch::Scalar<sch::T>>>, + sch::LbmMeter<sch::Scalar<sch::T>>>; + static_assert(std::is_same_v<Cube, + kel::lbm::sch::Unit<sch::Scalar<sch::T>, + sch::UnitElement<kel::lbm::lbm_type::meter,3>>>, + "m*m*m must be m^3"); + SAW_EXPECT(true, "sqrt of this would not compile, by design"); +} +} diff --git a/modules/core/tests/voxel_narrow.cpp b/modules/core/tests/voxel_narrow.cpp index 5cffc76..08c1c1f 100644 --- a/modules/core/tests/voxel_narrow.cpp +++ b/modules/core/tests/voxel_narrow.cpp @@ -15,7 +15,8 @@ using T = Float64; constexpr uint64_t D = 2u; auto make_pair(double radius, uint64_t res = 32u){ - kel::lbm::data<sch::Scalar<sch::T>> r,d; + kel::lbm::data<sch::LbmMeter<sch::Scalar<sch::T>>> r; + kel::lbm::data<sch::Scalar<sch::T>> d; r.at({}).set(radius); d.at({}).set(1.0); return kel::lbm::create_spheroid_particle_group<sch::T,D,2u>(r,d,{res}); diff --git a/modules/core/tests/vtk_write.cpp b/modules/core/tests/vtk_write.cpp index b2a5682..61fb548 100644 --- a/modules/core/tests/vtk_write.cpp +++ b/modules/core/tests/vtk_write.cpp @@ -31,7 +31,7 @@ using CellStruct = Struct< template<typename T, uint64_t D> using MacroStruct = Struct< - Member<FixedArray<T,D>, "momentum">, + Member<FixedArray<T,D>, "velocity">, Member<T, "pressure"> >; @@ -47,7 +47,7 @@ SAW_TEST("VTK Write test example"){ kel::lbm::data<sch::Array<sch::MacroStruct<sch::T,2>, 2>> cells{{{2u,2u}}}; auto& cell_0 = cells.at({{{0,0}}}); - cell_0.template get<"momentum">()= {{0.5,-0.1}}; + cell_0.template get<"velocity">()= {{0.5,-0.1}}; cell_0.template get<"pressure">().set(1.1); auto eov = lbm::impl::lbm_vtk_writer<sch::Array<sch::MacroStruct<sch::T,2>, 2>>::apply(sstream, cells); @@ -74,7 +74,7 @@ SAW_TEST("VTK Write raw test example"){ auto meta = cells.dims(); auto& cell_0 = cells.at({{{0,0}}}); - cell_0.template get<"momentum">()= {{0.5,-0.1}}; + cell_0.template get<"velocity">()= {{0.5,-0.1}}; cell_0.template get<"pressure">().set(1.1); auto eov = lbm::impl::lbm_vtk_writer_raw<sch::MacroStruct<sch::T,2u>,2u>::apply(sstream, &cell_0, meta); |
