Skip to content
Snippets Groups Projects
Commit bd46f5bf authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Add test case for vector extraction

parent 4ab9613b
1 merge request!26Fixes to postprocessing: Remove unused code, test vector extraction, unify treatment of scalar fields
Pipeline #77178 passed with stages
in 4 minutes and 23 seconds
......@@ -84,6 +84,7 @@ NestedNamespaces:
ScaleKernel:
JacobiMdspan:
StlContainers1D:
VectorExtraction:
# std::mdspan
......
#include "VectorExtraction.hpp"
#include <experimental/mdspan>
#include <memory>
#include <vector>
#undef NDEBUG
#include <cassert>
namespace stdex = std::experimental;
using extents_t = stdex::extents<std::int64_t, std::dynamic_extent, std::dynamic_extent, 3>;
using vector_field_t = stdex::mdspan<double, extents_t, stdex::layout_right>;
constexpr size_t N{41};
int main(void)
{
auto u_data = std::make_unique<double[]>(N * N * 3);
vector_field_t u_field{u_data.get(), extents_t{N, N}};
std::vector<double> v{3.1, 3.2, 3.4};
gen::invoke(u_field, v);
for (size_t j = 0; j < N; ++j)
for (size_t i = 0; i < N; ++i)
{
assert(u_field(j, i, 0) == v[0]);
assert(u_field(j, i, 1) == v[1]);
assert(u_field(j, i, 2) == v[2]);
}
}
\ No newline at end of file
from pystencilssfg import SourceFileGenerator
from pystencilssfg.lang.cpp import std
import pystencils as ps
import sympy as sp
std.mdspan.configure(namespace="std::experimental", header="<experimental/mdspan>")
with SourceFileGenerator() as sfg:
sfg.namespace("gen")
u_field = ps.fields("u(3): double[2D]", layout="c")
u = sp.symbols("u_:3")
asms = [ps.Assignment(u_field(i), u[i]) for i in range(3)]
ker = sfg.kernels.create(asms)
sfg.function("invoke")(
sfg.map_field(u_field, std.mdspan.from_field(u_field, layout_policy="layout_right")),
sfg.map_vector(u, std.vector("double", const=True, ref=True).var("vel")),
sfg.call(ker)
)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment