summaryrefslogtreecommitdiff
path: root/c++/macroscopic.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'c++/macroscopic.hpp')
-rw-r--r--c++/macroscopic.hpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/c++/macroscopic.hpp b/c++/macroscopic.hpp
index 43c727b..e126bbe 100644
--- a/c++/macroscopic.hpp
+++ b/c++/macroscopic.hpp
@@ -9,7 +9,7 @@ namespace lbm {
*/
template<typename T, typename Desc>
void compute_rho_u (
- saw::data<sch::Cell<T, Desc, 0, 0, 1>>& dfs,
+ const saw::data<sch::Cell<T, Desc, 0, 0, 1>>& dfs,
typename saw::native_data_type<T>::type& rho,
std::array<typename saw::native_data_type<T>::type, 2>& vel
)
@@ -30,5 +30,34 @@ void compute_rho_u (
vel[i] /= rho;
}
}
+
+/**
+ * Calculate the macroscopic variables rho and u in Lattice Units.
+ */
+template<typename T, typename Desc>
+void compute_rho_u (
+ const saw::data<sch::Cell<T, Desc, 0, 0, 1>>& dfs,
+ saw::ref<saw::data<T>> rho,
+ saw::ref<saw::data<sch::FixedArray<T,Desc::D>>> vel
+ )
+{
+ using dfi = df_info<T, Desc>;
+
+ rho().set(0);
+ for(uint64_t i = 0; i < Desc::D; ++i){
+ vel().at({i}).set(0);
+ }
+
+ for(size_t j = 0; j < Desc::Q; ++j){
+ rho = rho + dfs(j);
+ for(size_t i = 0; i < Desc::D; ++i){
+ vel[i] = vel[i] + saw::data<T>{dfi::directions[j][i]} * dfs(j);
+ }
+ }
+
+ for(size_t i = 0; i < Desc::D; ++i){
+ vel[i] = vel[i] / rho;
+ }
+}
}
}