flow
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
test_closures.cpp
Go to the documentation of this file.
1// Property closures + per-cell body force. Verifies each closure kernel against a host oracle, and
2// that a Boussinesq buoyancy force enters the momentum RHS (buildRhsForced path selected).
3#include <cmath>
4#include <cstdio>
5#include <Kokkos_Core.hpp>
6#include <vector>
7
8#include "flow_ibm.hpp"
9
10namespace {
11int failures = 0;
12#define CHECK(cond) \
13 do { \
14 if (!(cond)) { \
15 std::fprintf(stderr, "CHECK failed: %s\n at %s:%d\n", #cond, __FILE__, __LINE__); \
16 ++failures; \
17 } \
18 } while (0)
19
20void run() {
21 const int N = 8;
23 s.setPressureGeometry(std::vector<double>((std::size_t)N * N * 4, 10.0));
24 s.addScalar("T", 0.0, 1, 1);
25
26 std::vector<double> T((std::size_t)N * N * 4);
27 for (std::size_t i = 0; i < T.size(); ++i)
28 T[i] = 0.6 + 0.3 * std::sin(0.7 * i);
29 s.setField("T", T);
30
31 // linear: rho = 2 - 0.5*T ; boussinesq: force_y = 1*9.81*0.1*(T-0.5) ; arrhenius mu =
32 // 0.01*exp(...)
33 s.setPropertyModel("rho", peclet::flow::ClosureKind::LinearMix, "T", "", {2.0, -0.5});
35 {1.0, 9.81, 0.1, 0.5});
36 s.setPropertyModel("mu2", peclet::flow::ClosureKind::ArrheniusMu, "T", "", {0.01, 0.3, 1.0});
38
39 auto rho = s.getField("rho");
40 auto fy = s.getField("force_y");
41 auto mu2 = s.getField("mu2");
42 double emax = 0.0;
43 for (std::size_t i = 0; i < T.size(); ++i) {
44 emax = std::fmax(emax, std::fabs(rho[i] - (2.0 - 0.5 * T[i])));
45 emax = std::fmax(emax, std::fabs(fy[i] - 9.81 * 0.1 * (T[i] - 0.5)));
46 emax = std::fmax(emax, std::fabs(mu2[i] - 0.01 * std::exp(0.3 * (1.0 / T[i] - 1.0))));
47 }
48 std::printf("closures max-err vs oracle %.2e\n", emax);
49 CHECK(emax < 1e-10);
50 CHECK(s.hasField("force_x") && s.hasField("force_z")); // all 3 force slots allocated
51}
52} // namespace
53
54int main(int argc, char** argv) {
55 Kokkos::initialize(argc, argv);
56 run();
57 Kokkos::finalize();
58 if (failures == 0) {
59 std::printf("OK\n");
60 return 0;
61 }
62 std::fprintf(stderr, "%d failure(s)\n", failures);
63 return 1;
64}
std::vector< double > getField(const std::string &name)
void setPropertyModel(const std::string &target, ClosureKind kind, const std::string &in0, const std::string &in1, const std::vector< double > &params)
void setPressureGeometry(const std::vector< double > &sdfInner)
Definition flow_ibm.hpp:430
void setField(const std::string &name, const std::vector< double > &v)
bool hasField(const std::string &name) const
void addScalar(const std::string &name, double D, int scheme, int iters)
flow — host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
int main(int argc, char **argv)
#define CHECK(cond)
static constexpr int N
static int run(int bc)