summaryrefslogtreecommitdiff
path: root/modules/core
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core')
-rw-r--r--modules/core/c++/abstract/schema.hpp6
-rw-r--r--modules/core/c++/abstract/stringify_schema.hpp20
-rw-r--r--modules/core/c++/fplbm.hpp107
-rw-r--r--modules/core/c++/macroscopic.hpp25
-rw-r--r--modules/core/tests/schema.cpp2
5 files changed, 40 insertions, 120 deletions
diff --git a/modules/core/c++/abstract/schema.hpp b/modules/core/c++/abstract/schema.hpp
index 8bc23b4..89d9c2e 100644
--- a/modules/core/c++/abstract/schema.hpp
+++ b/modules/core/c++/abstract/schema.hpp
@@ -42,12 +42,6 @@ using Float16 = Primitive<FloatingPoint,2u>;
using Float32 = Primitive<FloatingPoint,4u>;
using Float64 = Primitive<FloatingPoint,8u>;
-template<typename Sch, uint64_t StorageBytes, uint64_t InterfaceBytes>
-struct MixedPrecision {
- using Meta = Void;
- using Inner = Sch;
-};
-
template<typename T, uint64_t... Dims>
struct FixedArray {
using Meta = Void;
diff --git a/modules/core/c++/abstract/stringify_schema.hpp b/modules/core/c++/abstract/stringify_schema.hpp
index 3d6b1d1..dd218d0 100644
--- a/modules/core/c++/abstract/stringify_schema.hpp
+++ b/modules/core/c++/abstract/stringify_schema.hpp
@@ -10,36 +10,36 @@ template<class T>
struct schema_to_string_helper {
static_assert(always_false<T>, "schema_to_string_helper specialization not handled.");
- static constexpr string_literal apply(){
- return {};
+ static constexpr auto apply(){
+ return string_literal{""};
}
};
template<>
struct schema_to_string_helper<sch::SignedInteger> final {
- static constexpr string_literal apply(){
- return "SignedInteger";
+ static constexpr auto apply(){
+ return string_literal{"SignedInteger"};
}
};
template<>
struct schema_to_string_helper<sch::UnsignedInteger> final {
- static constexpr string_literal apply(){
- return "UnsignedInteger";
+ static constexpr auto apply(){
+ return string_literal{"UnsignedInteger"};
}
};
template<>
struct schema_to_string_helper<sch::FloatingPoint> final {
- static constexpr string_literal apply(){
- return "FloatingPoint";
+ static constexpr auto apply(){
+ return string_literal{"FloatingPoint"};
}
};
template<typename T, uint64_t N>
struct schema_to_string_helper<sch::Primitive<T,N>> final {
- static constexpr string_literal apply(){
- return "Primitive<"+schema_to_string_helper<T>::apply()+","+N+">";
+ static constexpr auto apply(){
+ return string_literal{"Primitive<"}+schema_to_string_helper<T>::apply()+string_literal{","}+N+string_literal{">"};
}
};
}
diff --git a/modules/core/c++/fplbm.hpp b/modules/core/c++/fplbm.hpp
index 382d067..d8c075b 100644
--- a/modules/core/c++/fplbm.hpp
+++ b/modules/core/c++/fplbm.hpp
@@ -92,7 +92,7 @@ public:
auto& force_f = macros.template get<"force">();
auto& force = force_f.at(index);
- vel = vel + force * half;
+ vel = vel + force * half / rho;
// compute_rho_u<T,Descriptor>(dfs,rho,vel);
auto eq = equilibrium<T,Descriptor>(rho,vel);
@@ -204,119 +204,18 @@ public:
// vel_s is technically time the density of the particle?
- force = ( vel_s * rho - vel * rho ) /* two */ * flip_por;
+ force = ( vel_s * rho - vel * rho ) * two * flip_por;
force_p = force_p - force;
}, aabb.template get<"a">(), aabb.template get<"b">());
auto& pirb_acc = pirb.template get<"acceleration">();
- pirb_acc = force_p / pg.template get<"total_mass">().at({});
+ pirb_acc = force_p / (two * pg.template get<"total_mass">().at({}));
for(saw::data<sch::UInt64> i{0u}; i < sub_steps; ++i){
verlet_step_lambda<T,Descriptor::D>(pi,sss);
}
}
};
-
-template<typename T, typename Descriptor, typename Encode>
-class component<T, Descriptor, cmpt::FpLbmOneParticleNoVelocity, Encode> final {
-private:
- saw::data<T> relaxation_;
- saw::data<T> frequency_;
-public:
- component(typename saw::native_data_type<T>::type relaxation__):
- relaxation_{{relaxation__}},
- frequency_{saw::data<T>{1} / relaxation_}
- {}
-
- component(const saw::data<T>& relaxation__):
- relaxation_{relaxation__},
- frequency_{saw::data<T>{1} / relaxation_}
- {}
-
- using Component = cmpt::FpLbmOneParticleNoVelocity;
-
- template<typename CellFieldSchema, typename MacroFieldSchema>
- void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, saw::data<sch::UInt64> time_step) const {
- // void apply(saw::data<CellFieldSchema, Encode>& field, saw::data<sch::FixedArray<sch::UInt64, Descriptor::D>> index, saw::data<sch::UInt64> time_step){
- bool is_even = ((time_step.get() % 2) == 0);
-
- auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
- auto& dfs = dfs_old_f.at(index);
-
- auto& rho_f = macros.template get<"density">();
- auto& vel_f = macros.template get<"momentum">();
- auto& por_f = macros.template get<"porosity">();
-
- // Temporary find a better way
- auto& force_f = macros.template get<"force">();
-
-
- /**
- * The other methods all work with a flipped porosity.
- * For compat reasons this is also flipped
- */
- auto porosity = por_f.at(index);
- saw::data<sch::Scalar<T>> one;
- one.at({}) = 1.0;
- auto flip_porosity = one - porosity;
-
- saw::data<sch::Scalar<T>>& rho = rho_f.at(index);
-
- saw::data<sch::Scalar<T>> half;
- half.at({}).set(0.5);
- saw::data<sch::Vector<T,Descriptor::D>>& vel = vel_f.at(index);// + total_force * ( half / rho );
-
- compute_rho_u<T,Descriptor>(dfs_old_f.at(index),rho,vel);
- auto eq = equilibrium<T,Descriptor>(rho,vel);
-
- using dfi = df_info<T,Descriptor>;
-
- saw::data<sch::Scalar<T>> min_two;
- min_two.at({}).set(-2);
-
- auto& force = force_f.at(index);
- force = vel * rho * min_two * flip_porosity;
-
- saw::data<sch::Scalar<T>> dfi_inv_cs2;
- dfi_inv_cs2.at({}).set(dfi::inv_cs2);
-
- for(uint64_t i = 0u; i < Descriptor::Q; ++i){
- // saw::data<T> ci_min_u{0};
- saw::data<sch::Vector<T,Descriptor::D>> ci;
- for(uint64_t d = 0u; d < Descriptor::D; ++d){
- ci.at({{d}}).set(static_cast<typename saw::native_data_type<T>::type>(dfi::directions[i][d]));
- }
- auto ci_dot_u = saw::math::dot(ci,vel);
-
- // saw::data<sch::Vector<T,Descriptor::D>> F_i;
- // F_i = f * ((c_i - u) * ics2 + <c_i,u> * c_i * ics2 * ics2) * w_i;
- saw::data<sch::Scalar<T>> w;
- w.at({}).set(dfi::weights[i]);
-
- /*
- saw::data<sch::Scalar<T>> F_i_sum;
- for(uint64_t d = 0u; d < Descriptor::D; ++d){
- saw::data<sch::Scalar<T>> F_i_d;
- F_i_d.at({}) = F_i.at({{d}});
- F_i_sum = F_i_sum + F_i_d;
- }
- */
- auto term1 = (ci-vel) * dfi_inv_cs2;
- auto term2 = ci * (ci_dot_u * dfi_inv_cs2 * dfi_inv_cs2);
-
- auto force_projection = saw::math::dot(term1 + term2, force);
-
- auto F_i = w * force_projection;
-
- dfs.at({i}) = dfs.at({i})
- + frequency_
- * (eq.at(i) - dfs.at({i}) )
- + F_i.at({})
- * (saw::data<T>{1} - saw::data<T>{0.5f} * frequency_);
- }
- }
-
-};
}
}
diff --git a/modules/core/c++/macroscopic.hpp b/modules/core/c++/macroscopic.hpp
index 768fef0..9db1538 100644
--- a/modules/core/c++/macroscopic.hpp
+++ b/modules/core/c++/macroscopic.hpp
@@ -33,5 +33,30 @@ void compute_rho_u (
vel().at({{i}}) = vel().at({{i}}) / rho().at({});
}
}
+
+/**
+ * Calculate the macroscopic variables rho and u in Lattice Units.
+ */
+template<typename T, typename Desc>
+void compute_rho_momentum (
+ const saw::data<sch::FixedArray<T,Desc::Q>>& dfs,
+ saw::ref<saw::data<sch::Scalar<T>>> rho,
+ saw::ref<saw::data<sch::Vector<T,Desc::D>>> mom
+ )
+{
+ using dfi = df_info<T, Desc>;
+
+ rho().at({}).set(0);
+ for(uint64_t i = 0; i < Desc::D; ++i){
+ mom().at({{i}}).set(0);
+ }
+
+ for(size_t j = 0; j < Desc::Q; ++j){
+ rho().at({}) = rho().at({}) + dfs.at({j});
+ for(size_t i = 0; i < Desc::D; ++i){
+ mom().at({{i}}) = mom().at({{i}}) + saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[j][i])} * dfs.at({j});
+ }
+ }
+}
}
}
diff --git a/modules/core/tests/schema.cpp b/modules/core/tests/schema.cpp
index db82b97..6649bad 100644
--- a/modules/core/tests/schema.cpp
+++ b/modules/core/tests/schema.cpp
@@ -18,6 +18,7 @@ SAW_TEST("Abstract/Schema/Ptr"){
}
*/
+/*
SAW_TEST("Abstract/SchemaStringify/PrimitiveKind"){
using namespace kel::lbm;
@@ -25,4 +26,5 @@ SAW_TEST("Abstract/SchemaStringify/PrimitiveKind"){
static constexpr auto str = schema_to_string<TSch>::value;
}
+*/
}