Skip to content
Snippets Groups Projects
Commit 40493ae2 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add missing tests for InterpolateItemArray

parent d7576af8
No related branches found
No related tags found
1 merge request!167Improve fluxing based remapping
...@@ -48,6 +48,8 @@ TEST_CASE("InterpolateItemArray", "[language]") ...@@ -48,6 +48,8 @@ TEST_CASE("InterpolateItemArray", "[language]")
std::array mesh_list = MeshDataBaseForTests::get().all1DMeshes(); std::array mesh_list = MeshDataBaseForTests::get().all1DMeshes();
SECTION("from list of -> R")
{
for (const auto& named_mesh : mesh_list) { for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name()) SECTION(named_mesh.name())
{ {
...@@ -115,12 +117,74 @@ let scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; ...@@ -115,12 +117,74 @@ let scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3;
} }
} }
SECTION("from -> (R)")
{
for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name())
{
auto mesh_1d = named_mesh.mesh();
auto xj = MeshDataManager::instance().getMeshData(*mesh_1d).xj();
std::string_view data = R"(
import math;
let f_1d: R^1 -> (R), x -> (2*x[0] + 2, 2 * exp(x[0]) + 3);
)";
TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTModulesImporter{*ast};
ASTNodeTypeCleaner<language::import_instruction>{*ast};
ASTSymbolTableBuilder{*ast};
ASTNodeDataTypeBuilder{*ast};
ASTNodeTypeCleaner<language::var_declaration>{*ast};
ASTNodeTypeCleaner<language::fct_declaration>{*ast};
ASTNodeExpressionBuilder{*ast};
std::shared_ptr<SymbolTable> symbol_table = ast->m_symbol_table;
TAO_PEGTL_NAMESPACE::position position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"};
position.byte = data.size(); // ensure that variables are declared at this point
std::vector<FunctionSymbolId> function_symbol_id_list;
{
auto [i_symbol, found] = symbol_table->find("f_1d", position);
REQUIRE(found);
REQUIRE(i_symbol->attributes().dataType() == ASTNodeDataType::function_t);
function_symbol_id_list.push_back(
FunctionSymbolId(std::get<uint64_t>(i_symbol->attributes().value()), symbol_table));
}
CellArray<double> cell_array{mesh_1d->connectivity(), 2};
parallel_for(
cell_array.numberOfItems(), PUGS_LAMBDA(const CellId cell_id) {
const TinyVector<Dimension>& x = xj[cell_id];
cell_array[cell_id][0] = 2 * x[0] + 2;
cell_array[cell_id][1] = 2 * exp(x[0]) + 3;
});
CellArray<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj);
REQUIRE(same_cell_array(cell_array, interpolate_array));
}
}
}
}
SECTION("2D") SECTION("2D")
{ {
constexpr size_t Dimension = 2; constexpr size_t Dimension = 2;
std::array mesh_list = MeshDataBaseForTests::get().all2DMeshes(); std::array mesh_list = MeshDataBaseForTests::get().all2DMeshes();
SECTION("from list of -> R")
{
for (const auto& named_mesh : mesh_list) { for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name()) SECTION(named_mesh.name())
{ {
...@@ -188,12 +252,74 @@ let scalar_non_linear_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; ...@@ -188,12 +252,74 @@ let scalar_non_linear_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3;
} }
} }
SECTION("from -> (R)")
{
for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name())
{
auto mesh_2d = named_mesh.mesh();
auto xj = MeshDataManager::instance().getMeshData(*mesh_2d).xj();
std::string_view data = R"(
import math;
let f_2d: R^2 -> (R), x -> (2*x[0] + 3*x[1] + 2, 2*exp(x[0])*sin(x[1])+3);
)";
TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTModulesImporter{*ast};
ASTNodeTypeCleaner<language::import_instruction>{*ast};
ASTSymbolTableBuilder{*ast};
ASTNodeDataTypeBuilder{*ast};
ASTNodeTypeCleaner<language::var_declaration>{*ast};
ASTNodeTypeCleaner<language::fct_declaration>{*ast};
ASTNodeExpressionBuilder{*ast};
std::shared_ptr<SymbolTable> symbol_table = ast->m_symbol_table;
TAO_PEGTL_NAMESPACE::position position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"};
position.byte = data.size(); // ensure that variables are declared at this point
std::vector<FunctionSymbolId> function_symbol_id_list;
{
auto [i_symbol, found] = symbol_table->find("f_2d", position);
REQUIRE(found);
REQUIRE(i_symbol->attributes().dataType() == ASTNodeDataType::function_t);
function_symbol_id_list.push_back(
FunctionSymbolId(std::get<uint64_t>(i_symbol->attributes().value()), symbol_table));
}
CellArray<double> cell_array{mesh_2d->connectivity(), 2};
parallel_for(
cell_array.numberOfItems(), PUGS_LAMBDA(const CellId cell_id) {
const TinyVector<Dimension>& x = xj[cell_id];
cell_array[cell_id][0] = 2 * x[0] + 3 * x[1] + 2;
cell_array[cell_id][1] = 2 * exp(x[0]) * sin(x[1]) + 3;
});
CellArray<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj);
REQUIRE(same_cell_array(cell_array, interpolate_array));
}
}
}
}
SECTION("3D") SECTION("3D")
{ {
constexpr size_t Dimension = 3; constexpr size_t Dimension = 3;
std::array mesh_list = MeshDataBaseForTests::get().all3DMeshes(); std::array mesh_list = MeshDataBaseForTests::get().all3DMeshes();
SECTION("from list of -> R")
{
for (const auto& named_mesh : mesh_list) { for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name()) SECTION(named_mesh.name())
{ {
...@@ -260,6 +386,66 @@ let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; ...@@ -260,6 +386,66 @@ let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3;
} }
} }
} }
SECTION("from -> (R)")
{
for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name())
{
auto mesh_3d = named_mesh.mesh();
auto xj = MeshDataManager::instance().getMeshData(*mesh_3d).xj();
std::string_view data = R"(
import math;
let f_3d: R^3 -> (R), x -> (2 * x[0] + 3 * x[1] + 2 * x[2] - 1, 2 * exp(x[0]) * sin(x[1]) * x[2] + 3);
)";
TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTModulesImporter{*ast};
ASTNodeTypeCleaner<language::import_instruction>{*ast};
ASTSymbolTableBuilder{*ast};
ASTNodeDataTypeBuilder{*ast};
ASTNodeTypeCleaner<language::var_declaration>{*ast};
ASTNodeTypeCleaner<language::fct_declaration>{*ast};
ASTNodeExpressionBuilder{*ast};
std::shared_ptr<SymbolTable> symbol_table = ast->m_symbol_table;
TAO_PEGTL_NAMESPACE::position position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"};
position.byte = data.size(); // ensure that variables are declared at this point
std::vector<FunctionSymbolId> function_symbol_id_list;
{
auto [i_symbol, found] = symbol_table->find("f_3d", position);
REQUIRE(found);
REQUIRE(i_symbol->attributes().dataType() == ASTNodeDataType::function_t);
function_symbol_id_list.push_back(
FunctionSymbolId(std::get<uint64_t>(i_symbol->attributes().value()), symbol_table));
}
CellArray<double> cell_array{mesh_3d->connectivity(), 2};
parallel_for(
cell_array.numberOfItems(), PUGS_LAMBDA(const CellId cell_id) {
const TinyVector<Dimension>& x = xj[cell_id];
cell_array[cell_id][0] = 2 * x[0] + 3 * x[1] + 2 * x[2] - 1;
cell_array[cell_id][1] = 2 * exp(x[0]) * sin(x[1]) * x[2] + 3;
});
CellArray<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj);
REQUIRE(same_cell_array(cell_array, interpolate_array));
}
}
}
}
} }
SECTION("interpolate on items list") SECTION("interpolate on items list")
...@@ -281,6 +467,8 @@ let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; ...@@ -281,6 +467,8 @@ let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3;
std::array mesh_list = MeshDataBaseForTests::get().all1DMeshes(); std::array mesh_list = MeshDataBaseForTests::get().all1DMeshes();
SECTION("from list of -> R")
{
for (const auto& named_mesh : mesh_list) { for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name()) SECTION(named_mesh.name())
{ {
...@@ -349,19 +537,91 @@ let scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3; ...@@ -349,19 +537,91 @@ let scalar_non_linear_1d: R^1 -> R, x -> 2 * exp(x[0]) + 3;
}); });
Table<const double> interpolate_array = Table<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj, cell_id_list); InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj,
cell_id_list);
REQUIRE(same_cell_value(cell_array, interpolate_array)); REQUIRE(same_cell_value(cell_array, interpolate_array));
} }
} }
} }
SECTION("from -> (R)")
{
for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name())
{
auto mesh_1d = named_mesh.mesh();
auto xj = MeshDataManager::instance().getMeshData(*mesh_1d).xj();
Array<const CellId> cell_id_list = [&] {
Array<CellId> cell_ids{mesh_1d->numberOfCells() / 2};
for (size_t i_cell = 0; i_cell < cell_ids.size(); ++i_cell) {
cell_ids[i_cell] = static_cast<CellId>(2 * i_cell);
}
return cell_ids;
}();
std::string_view data = R"(
import math;
let f_1d: R^1 -> (R), x -> (2*x[0] + 2, 2 * exp(x[0]) + 3);
)";
TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTModulesImporter{*ast};
ASTNodeTypeCleaner<language::import_instruction>{*ast};
ASTSymbolTableBuilder{*ast};
ASTNodeDataTypeBuilder{*ast};
ASTNodeTypeCleaner<language::var_declaration>{*ast};
ASTNodeTypeCleaner<language::fct_declaration>{*ast};
ASTNodeExpressionBuilder{*ast};
std::shared_ptr<SymbolTable> symbol_table = ast->m_symbol_table;
TAO_PEGTL_NAMESPACE::position position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"};
position.byte = data.size(); // ensure that variables are declared at this point
std::vector<FunctionSymbolId> function_symbol_id_list;
{
auto [i_symbol, found] = symbol_table->find("f_1d", position);
REQUIRE(found);
REQUIRE(i_symbol->attributes().dataType() == ASTNodeDataType::function_t);
function_symbol_id_list.push_back(
FunctionSymbolId(std::get<uint64_t>(i_symbol->attributes().value()), symbol_table));
}
Table<double> cell_array{cell_id_list.size(), 2};
parallel_for(
cell_id_list.size(), PUGS_LAMBDA(const size_t i) {
const TinyVector<Dimension>& x = xj[cell_id_list[i]];
cell_array[i][0] = 2 * x[0] + 2;
cell_array[i][1] = 2 * exp(x[0]) + 3;
});
Table<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj,
cell_id_list);
REQUIRE(same_cell_value(cell_array, interpolate_array));
}
}
}
}
SECTION("2D") SECTION("2D")
{ {
constexpr size_t Dimension = 2; constexpr size_t Dimension = 2;
std::array mesh_list = MeshDataBaseForTests::get().all2DMeshes(); std::array mesh_list = MeshDataBaseForTests::get().all2DMeshes();
SECTION("from list of -> R")
{
for (const auto& named_mesh : mesh_list) { for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name()) SECTION(named_mesh.name())
{ {
...@@ -427,19 +687,88 @@ let scalar_non_linear_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3; ...@@ -427,19 +687,88 @@ let scalar_non_linear_2d: R^2 -> R, x -> 2*exp(x[0])*sin(x[1])+3;
}); });
Table<const double> interpolate_array = Table<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj, cell_id_list); InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj,
cell_id_list);
REQUIRE(same_cell_value(cell_array, interpolate_array)); REQUIRE(same_cell_value(cell_array, interpolate_array));
} }
} }
} }
SECTION("from -> (R)")
{
for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name())
{
auto mesh_2d = named_mesh.mesh();
auto xj = MeshDataManager::instance().getMeshData(*mesh_2d).xj();
Array<CellId> cell_id_list{mesh_2d->numberOfCells() / 2};
for (size_t i_cell = 0; i_cell < cell_id_list.size(); ++i_cell) {
cell_id_list[i_cell] = static_cast<CellId>(2 * i_cell);
}
std::string_view data = R"(
import math;
let f_2d: R^2 -> (R), x -> (2*x[0] + 3*x[1] + 2, 2*exp(x[0])*sin(x[1])+3);
)";
TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTModulesImporter{*ast};
ASTNodeTypeCleaner<language::import_instruction>{*ast};
ASTSymbolTableBuilder{*ast};
ASTNodeDataTypeBuilder{*ast};
ASTNodeTypeCleaner<language::var_declaration>{*ast};
ASTNodeTypeCleaner<language::fct_declaration>{*ast};
ASTNodeExpressionBuilder{*ast};
std::shared_ptr<SymbolTable> symbol_table = ast->m_symbol_table;
TAO_PEGTL_NAMESPACE::position position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"};
position.byte = data.size(); // ensure that variables are declared at this point
std::vector<FunctionSymbolId> function_symbol_id_list;
{
auto [i_symbol, found] = symbol_table->find("f_2d", position);
REQUIRE(found);
REQUIRE(i_symbol->attributes().dataType() == ASTNodeDataType::function_t);
function_symbol_id_list.push_back(
FunctionSymbolId(std::get<uint64_t>(i_symbol->attributes().value()), symbol_table));
}
Table<double> cell_array{cell_id_list.size(), 2};
parallel_for(
cell_id_list.size(), PUGS_LAMBDA(const size_t i) {
const TinyVector<Dimension>& x = xj[cell_id_list[i]];
cell_array[i][0] = 2 * x[0] + 3 * x[1] + 2;
cell_array[i][1] = 2 * exp(x[0]) * sin(x[1]) + 3;
});
Table<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj,
cell_id_list);
REQUIRE(same_cell_value(cell_array, interpolate_array));
}
}
}
}
SECTION("3D") SECTION("3D")
{ {
constexpr size_t Dimension = 3; constexpr size_t Dimension = 3;
std::array mesh_list = MeshDataBaseForTests::get().all3DMeshes(); std::array mesh_list = MeshDataBaseForTests::get().all3DMeshes();
SECTION("from list of -> R")
{
for (const auto& named_mesh : mesh_list) { for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name()) SECTION(named_mesh.name())
{ {
...@@ -505,7 +834,73 @@ let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; ...@@ -505,7 +834,73 @@ let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3;
}); });
Table<const double> interpolate_array = Table<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj, cell_id_list); InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj,
cell_id_list);
REQUIRE(same_cell_value(cell_array, interpolate_array));
}
}
}
SECTION("from -> (R)")
{
for (const auto& named_mesh : mesh_list) {
SECTION(named_mesh.name())
{
auto mesh_3d = named_mesh.mesh();
auto xj = MeshDataManager::instance().getMeshData(*mesh_3d).xj();
Array<CellId> cell_id_list{mesh_3d->numberOfCells() / 2};
for (size_t i_cell = 0; i_cell < cell_id_list.size(); ++i_cell) {
cell_id_list[i_cell] = static_cast<CellId>(2 * i_cell);
}
std::string_view data = R"(
import math;
let f_3d: R^3 -> (R), x -> (2 * x[0] + 3 * x[1] + 2 * x[2] - 1, 2 * exp(x[0]) * sin(x[1]) * x[2] + 3);
)";
TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"};
auto ast = ASTBuilder::build(input);
ASTModulesImporter{*ast};
ASTNodeTypeCleaner<language::import_instruction>{*ast};
ASTSymbolTableBuilder{*ast};
ASTNodeDataTypeBuilder{*ast};
ASTNodeTypeCleaner<language::var_declaration>{*ast};
ASTNodeTypeCleaner<language::fct_declaration>{*ast};
ASTNodeExpressionBuilder{*ast};
std::shared_ptr<SymbolTable> symbol_table = ast->m_symbol_table;
TAO_PEGTL_NAMESPACE::position position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"};
position.byte = data.size(); // ensure that variables are declared at this point
std::vector<FunctionSymbolId> function_symbol_id_list;
{
auto [i_symbol, found] = symbol_table->find("f_3d", position);
REQUIRE(found);
REQUIRE(i_symbol->attributes().dataType() == ASTNodeDataType::function_t);
function_symbol_id_list.push_back(
FunctionSymbolId(std::get<uint64_t>(i_symbol->attributes().value()), symbol_table));
}
Table<double> cell_array{cell_id_list.size(), 2};
parallel_for(
cell_id_list.size(), PUGS_LAMBDA(const size_t i) {
const TinyVector<Dimension>& x = xj[cell_id_list[i]];
cell_array[i][0] = 2 * x[0] + 3 * x[1] + 2 * x[2] - 1;
cell_array[i][1] = 2 * exp(x[0]) * sin(x[1]) * x[2] + 3;
});
Table<const double> interpolate_array =
InterpolateItemArray<double(TinyVector<Dimension>)>::interpolate(function_symbol_id_list, xj,
cell_id_list);
REQUIRE(same_cell_value(cell_array, interpolate_array)); REQUIRE(same_cell_value(cell_array, interpolate_array));
} }
...@@ -513,3 +908,4 @@ let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3; ...@@ -513,3 +908,4 @@ let scalar_non_linear_3d: R^3 -> R, x -> 2 * exp(x[0]) * sin(x[1]) * x[2] + 3;
} }
} }
} }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment