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

Add tests for DiscreteFunctionInterpoler

parent cc37bd6d
No related branches found
No related tags found
1 merge request!116Add tests for EmbeddedIDiscreteFunctionUtils
......@@ -4,7 +4,7 @@
#include <scheme/DiscreteFunctionP0.hpp>
#include <utils/Exceptions.hpp>
template <size_t Dimension, typename DataType>
template <size_t Dimension, typename DataType, typename ValueType>
std::shared_ptr<IDiscreteFunction>
DiscreteFunctionInterpoler::_interpolate() const
{
......@@ -12,10 +12,25 @@ DiscreteFunctionInterpoler::_interpolate() const
using MeshDataType = MeshData<Dimension>;
MeshDataType& mesh_data = MeshDataManager::instance().getMeshData(*mesh);
if constexpr (std::is_same_v<DataType, ValueType>) {
return std::make_shared<
DiscreteFunctionP0<Dimension, DataType>>(mesh,
DiscreteFunctionP0<Dimension, ValueType>>(mesh,
InterpolateItemValue<DataType(TinyVector<Dimension>)>::
template interpolate<ItemType::cell>(m_function_id, mesh_data.xj()));
} else {
static_assert(std::is_convertible_v<DataType, ValueType>);
CellValue<DataType> cell_data =
InterpolateItemValue<DataType(TinyVector<Dimension>)>::template interpolate<ItemType::cell>(m_function_id,
mesh_data.xj());
CellValue<ValueType> cell_value{mesh->connectivity()};
parallel_for(
mesh->numberOfCells(), PUGS_LAMBDA(const CellId cell_id) { cell_value[cell_id] = cell_data[cell_id]; });
return std::make_shared<DiscreteFunctionP0<Dimension, ValueType>>(mesh, cell_value);
}
}
template <size_t Dimension>
......@@ -29,13 +44,13 @@ DiscreteFunctionInterpoler::_interpolate() const
switch (data_type) {
case ASTNodeDataType::bool_t: {
return this->_interpolate<Dimension, bool>();
return this->_interpolate<Dimension, bool, double>();
}
case ASTNodeDataType::unsigned_int_t: {
return this->_interpolate<Dimension, uint64_t>();
return this->_interpolate<Dimension, uint64_t, double>();
}
case ASTNodeDataType::int_t: {
return this->_interpolate<Dimension, int64_t>();
return this->_interpolate<Dimension, int64_t, double>();
}
case ASTNodeDataType::double_t: {
return this->_interpolate<Dimension, double>();
......@@ -51,12 +66,14 @@ DiscreteFunctionInterpoler::_interpolate() const
case 3: {
return this->_interpolate<Dimension, TinyVector<3>>();
}
// LCOV_EXCL_START
default: {
std::ostringstream os;
os << "invalid vector dimension " << rang::fgB::red << data_type.dimension() << rang::style::reset;
throw UnexpectedError(os.str());
}
// LCOV_EXCL_STOP
}
}
case ASTNodeDataType::matrix_t: {
......@@ -71,20 +88,24 @@ DiscreteFunctionInterpoler::_interpolate() const
case 3: {
return this->_interpolate<Dimension, TinyMatrix<3>>();
}
// LCOV_EXCL_START
default: {
std::ostringstream os;
os << "invalid vector dimension " << rang::fgB::red << data_type.dimension() << rang::style::reset;
throw UnexpectedError(os.str());
}
// LCOV_EXCL_STOP
}
}
// LCOV_EXCL_START
default: {
std::ostringstream os;
os << "invalid interpolation value type: " << rang::fgB::red << dataTypeName(data_type) << rang::style::reset;
throw UnexpectedError(os.str());
}
// LCOV_EXCL_STOP
}
}
......@@ -102,9 +123,10 @@ DiscreteFunctionInterpoler::interpolate() const
case 3: {
return this->_interpolate<3>();
}
// LCOV_EXCL_START
default: {
throw UnexpectedError("invalid dimension");
}
// LCOV_EXCL_STOP
}
return nullptr;
}
......@@ -15,7 +15,7 @@ class DiscreteFunctionInterpoler
std::shared_ptr<const IDiscreteFunctionDescriptor> m_discrete_function_descriptor;
const FunctionSymbolId m_function_id;
template <size_t Dimension, typename DataType>
template <size_t Dimension, typename DataType, typename ValueType = DataType>
std::shared_ptr<IDiscreteFunction> _interpolate() const;
template <size_t Dimension>
......
......@@ -108,6 +108,7 @@ add_executable (unit_tests
add_executable (mpi_unit_tests
mpi_test_main.cpp
test_DiscreteFunctionInterpoler.cpp
test_DiscreteFunctionP0.cpp
test_DiscreteFunctionP0Vector.cpp
test_InterpolateItemArray.cpp
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment