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

Add tests for EmbeddedIDiscreteFunctionOperators (binary operators)

parent 45e76928
No related branches found
No related tags found
1 merge request!116Add tests for EmbeddedIDiscreteFunctionUtils
...@@ -9,17 +9,6 @@ ...@@ -9,17 +9,6 @@
#include <scheme/IDiscreteFunction.hpp> #include <scheme/IDiscreteFunction.hpp>
#include <utils/Exceptions.hpp> #include <utils/Exceptions.hpp>
template <typename LHS_T, typename RHS_T>
PUGS_INLINE std::string
invalid_operands(const LHS_T& f, const RHS_T& g)
{
std::ostringstream os;
os << "undefined binary operator\n";
os << "note: incompatible operand types " << EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f) << " and "
<< EmbeddedIDiscreteFunctionUtils::getOperandTypeName(g);
return os.str();
}
// unary operators // unary operators
template <typename UnaryOperatorT, typename DiscreteFunctionT> template <typename UnaryOperatorT, typename DiscreteFunctionT>
std::shared_ptr<const IDiscreteFunction> std::shared_ptr<const IDiscreteFunction>
...@@ -53,9 +42,11 @@ applyUnaryOperation(const std::shared_ptr<const IDiscreteFunction>& f) ...@@ -53,9 +42,11 @@ applyUnaryOperation(const std::shared_ptr<const IDiscreteFunction>& f)
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<3>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<3>>&>(*f);
return applyUnaryOperation<UnaryOperatorT>(fh); return applyUnaryOperation<UnaryOperatorT>(fh);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid operand type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::invalidOperandType(f));
} }
// LCOV_EXCL_STOP
} }
} }
case ASTNodeDataType::matrix_t: { case ASTNodeDataType::matrix_t: {
...@@ -73,14 +64,18 @@ applyUnaryOperation(const std::shared_ptr<const IDiscreteFunction>& f) ...@@ -73,14 +64,18 @@ applyUnaryOperation(const std::shared_ptr<const IDiscreteFunction>& f)
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f);
return applyUnaryOperation<UnaryOperatorT>(fh); return applyUnaryOperation<UnaryOperatorT>(fh);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid operand type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::invalidOperandType(f));
} }
// LCOV_EXCL_STOP
} }
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid operand type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::invalidOperandType(f));
} }
// LCOV_EXCL_STOP
} }
break; break;
} }
...@@ -90,15 +85,19 @@ applyUnaryOperation(const std::shared_ptr<const IDiscreteFunction>& f) ...@@ -90,15 +85,19 @@ applyUnaryOperation(const std::shared_ptr<const IDiscreteFunction>& f)
auto fh = dynamic_cast<const DiscreteFunctionP0Vector<Dimension, double>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0Vector<Dimension, double>&>(*f);
return applyUnaryOperation<UnaryOperatorT>(fh); return applyUnaryOperation<UnaryOperatorT>(fh);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid operand type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::invalidOperandType(f));
} }
// LCOV_EXCL_STOP
} }
break; break;
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid operand type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::invalidOperandType(f));
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -116,9 +115,11 @@ applyUnaryOperation(const std::shared_ptr<const IDiscreteFunction>& f) ...@@ -116,9 +115,11 @@ applyUnaryOperation(const std::shared_ptr<const IDiscreteFunction>& f)
case 3: { case 3: {
return applyUnaryOperation<UnaryOperatorT, 3>(f); return applyUnaryOperation<UnaryOperatorT, 3>(f);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid mesh dimension"); throw UnexpectedError("invalid mesh dimension");
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -138,7 +139,7 @@ innerCompositionLaw(const DiscreteFunctionT& lhs, const DiscreteFunctionT& rhs) ...@@ -138,7 +139,7 @@ innerCompositionLaw(const DiscreteFunctionT& lhs, const DiscreteFunctionT& rhs)
using data_type = typename DiscreteFunctionT::data_type; using data_type = typename DiscreteFunctionT::data_type;
if constexpr ((std::is_same_v<language::multiply_op, BinOperatorT> and is_tiny_vector_v<data_type>) or if constexpr ((std::is_same_v<language::multiply_op, BinOperatorT> and is_tiny_vector_v<data_type>) or
(std::is_same_v<language::divide_op, BinOperatorT> and not std::is_arithmetic_v<data_type>)) { (std::is_same_v<language::divide_op, BinOperatorT> and not std::is_arithmetic_v<data_type>)) {
throw NormalError(invalid_operands(lhs, rhs)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(lhs, rhs));
} else { } else {
return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(lhs, rhs))>(BinOp<BinOperatorT>{}.eval(lhs, rhs)); return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(lhs, rhs))>(BinOp<BinOperatorT>{}.eval(lhs, rhs));
} }
...@@ -172,10 +173,12 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f, ...@@ -172,10 +173,12 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f,
return innerCompositionLaw<BinOperatorT>(fh, gh); return innerCompositionLaw<BinOperatorT>(fh, gh);
} else { } else {
throw NormalError(invalid_operands(f, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, g));
} }
} else { } else {
throw UnexpectedError(invalid_operands(f, g)); // LCOV_EXCL_START
throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, g));
// LCOV_EXCL_STOP
} }
} }
case ASTNodeDataType::vector_t: { case ASTNodeDataType::vector_t: {
...@@ -199,9 +202,11 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f, ...@@ -199,9 +202,11 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f,
return innerCompositionLaw<BinOperatorT>(fh, gh); return innerCompositionLaw<BinOperatorT>(fh, gh);
} }
// LCOV_EXCL_START
default: { default: {
throw NormalError(invalid_operands(f, g)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, g));
} }
// LCOV_EXCL_STOP
} }
} }
case ASTNodeDataType::matrix_t: { case ASTNodeDataType::matrix_t: {
...@@ -226,14 +231,18 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f, ...@@ -226,14 +231,18 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f,
return innerCompositionLaw<BinOperatorT>(fh, gh); return innerCompositionLaw<BinOperatorT>(fh, gh);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::invalidOperandType(f));
} }
// LCOV_EXCL_STOP
} }
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::invalidOperandType(f));
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -247,9 +256,7 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f, ...@@ -247,9 +256,7 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f,
throw NormalError("operands are defined on different meshes"); throw NormalError("operands are defined on different meshes");
} }
if (not EmbeddedIDiscreteFunctionUtils::isSameDiscretization(f, g)) { Assert(EmbeddedIDiscreteFunctionUtils::isSameDiscretization(f, g));
throw NormalError(invalid_operands(f, g));
}
switch (mesh->dimension()) { switch (mesh->dimension()) {
case 1: { case 1: {
...@@ -261,9 +268,11 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f, ...@@ -261,9 +268,11 @@ innerCompositionLaw(const std::shared_ptr<const IDiscreteFunction>& f,
case 3: { case 3: {
return innerCompositionLaw<BinOperatorT, 3>(f, g); return innerCompositionLaw<BinOperatorT, 3>(f, g);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid mesh dimension"); throw UnexpectedError("invalid mesh dimension");
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -289,24 +298,18 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID ...@@ -289,24 +298,18 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID
switch (g->dataType()) { switch (g->dataType()) {
case ASTNodeDataType::double_t: { case ASTNodeDataType::double_t: {
if constexpr (not std::is_same_v<lhs_data_type, double>) { if constexpr (std::is_same_v<BinOperatorT, language::multiply_op> and
if constexpr (not is_tiny_matrix_v<lhs_data_type>) {
auto gh = dynamic_cast<const DiscreteFunctionP0<Dimension, double>&>(*g);
return applyBinaryOperation<BinOperatorT>(fh, gh);
} else {
throw NormalError(invalid_operands(fh, g));
}
} else if constexpr (std::is_same_v<BinOperatorT, language::multiply_op> and
std::is_same_v<DiscreteFunctionT, DiscreteFunctionP0<Dimension, double>>) { std::is_same_v<DiscreteFunctionT, DiscreteFunctionP0<Dimension, double>>) {
if (g->descriptor().type() == DiscreteFunctionType::P0Vector) { if (g->descriptor().type() == DiscreteFunctionType::P0Vector) {
auto gh = dynamic_cast<const DiscreteFunctionP0Vector<Dimension, double>&>(*g); auto gh = dynamic_cast<const DiscreteFunctionP0Vector<Dimension, double>&>(*g);
return applyBinaryOperation<BinOperatorT>(fh, gh); return applyBinaryOperation<BinOperatorT>(fh, gh);
} else { } else {
throw NormalError(invalid_operands(fh, g)); // LCOV_EXCL_START
throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(fh, g));
// LCOV_EXCL_STOP
} }
} else { } else {
throw UnexpectedError("should have called innerCompositionLaw"); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(fh, g));
} }
} }
case ASTNodeDataType::vector_t: { case ASTNodeDataType::vector_t: {
...@@ -319,7 +322,7 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID ...@@ -319,7 +322,7 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID
return applyBinaryOperation<BinOperatorT>(fh, gh); return applyBinaryOperation<BinOperatorT>(fh, gh);
} else { } else {
throw NormalError(invalid_operands(fh, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(fh, g));
} }
} }
case 2: { case 2: {
...@@ -329,7 +332,7 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID ...@@ -329,7 +332,7 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID
return applyBinaryOperation<BinOperatorT>(fh, gh); return applyBinaryOperation<BinOperatorT>(fh, gh);
} else { } else {
throw NormalError(invalid_operands(fh, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(fh, g));
} }
} }
case 3: { case 3: {
...@@ -339,15 +342,17 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID ...@@ -339,15 +342,17 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID
return applyBinaryOperation<BinOperatorT>(fh, gh); return applyBinaryOperation<BinOperatorT>(fh, gh);
} else { } else {
throw NormalError(invalid_operands(fh, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(fh, g));
} }
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid rhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(g)); throw UnexpectedError("invalid rhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(g));
} }
// LCOV_EXCL_STOP
} }
} else { } else {
throw NormalError(invalid_operands(fh, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(fh, g));
} }
} }
case ASTNodeDataType::matrix_t: { case ASTNodeDataType::matrix_t: {
...@@ -369,17 +374,21 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID ...@@ -369,17 +374,21 @@ applyBinaryOperation(const DiscreteFunctionT& fh, const std::shared_ptr<const ID
return applyBinaryOperation<BinOperatorT>(fh, gh); return applyBinaryOperation<BinOperatorT>(fh, gh);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid rhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(g)); throw UnexpectedError("invalid rhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(g));
} }
// LCOV_EXCL_STOP
} }
} else { } else {
throw NormalError(invalid_operands(fh, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(fh, g));
} }
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid rhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(g)); throw UnexpectedError("invalid rhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(g));
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -391,10 +400,10 @@ applyBinaryOperation(const std::shared_ptr<const IDiscreteFunction>& f, ...@@ -391,10 +400,10 @@ applyBinaryOperation(const std::shared_ptr<const IDiscreteFunction>& f,
Assert(f->mesh() == g->mesh()); Assert(f->mesh() == g->mesh());
Assert(not EmbeddedIDiscreteFunctionUtils::isSameDiscretization(f, g)); Assert(not EmbeddedIDiscreteFunctionUtils::isSameDiscretization(f, g));
if (f->descriptor().type() == DiscreteFunctionType::P0) {
switch (f->dataType()) { switch (f->dataType()) {
case ASTNodeDataType::double_t: { case ASTNodeDataType::double_t: {
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, double>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, double>&>(*f);
return applyBinaryOperation<BinOperatorT, Dimension>(fh, g); return applyBinaryOperation<BinOperatorT, Dimension>(fh, g);
} }
case ASTNodeDataType::matrix_t: { case ASTNodeDataType::matrix_t: {
...@@ -415,14 +424,19 @@ applyBinaryOperation(const std::shared_ptr<const IDiscreteFunction>& f, ...@@ -415,14 +424,19 @@ applyBinaryOperation(const std::shared_ptr<const IDiscreteFunction>& f,
return applyBinaryOperation<BinOperatorT, Dimension>(fh, g); return applyBinaryOperation<BinOperatorT, Dimension>(fh, g);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f));
} }
// LCOV_EXCL_STOP
} }
} }
default: { default: {
throw NormalError(invalid_operands(f, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, g));
}
} }
} else {
throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, g));
} }
} }
...@@ -448,9 +462,11 @@ applyBinaryOperation(const std::shared_ptr<const IDiscreteFunction>& f, ...@@ -448,9 +462,11 @@ applyBinaryOperation(const std::shared_ptr<const IDiscreteFunction>& f,
case 3: { case 3: {
return applyBinaryOperation<BinOperatorT, 3>(f, g); return applyBinaryOperation<BinOperatorT, 3>(f, g);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid mesh dimension"); throw UnexpectedError("invalid mesh dimension");
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -460,7 +476,7 @@ operator+(const std::shared_ptr<const IDiscreteFunction>& f, const std::shared_p ...@@ -460,7 +476,7 @@ operator+(const std::shared_ptr<const IDiscreteFunction>& f, const std::shared_p
if (EmbeddedIDiscreteFunctionUtils::isSameDiscretization(f, g)) { if (EmbeddedIDiscreteFunctionUtils::isSameDiscretization(f, g)) {
return innerCompositionLaw<language::plus_op>(f, g); return innerCompositionLaw<language::plus_op>(f, g);
} else { } else {
throw NormalError(invalid_operands(f, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, g));
} }
} }
...@@ -470,7 +486,7 @@ operator-(const std::shared_ptr<const IDiscreteFunction>& f, const std::shared_p ...@@ -470,7 +486,7 @@ operator-(const std::shared_ptr<const IDiscreteFunction>& f, const std::shared_p
if (EmbeddedIDiscreteFunctionUtils::isSameDiscretization(f, g)) { if (EmbeddedIDiscreteFunctionUtils::isSameDiscretization(f, g)) {
return innerCompositionLaw<language::minus_op>(f, g); return innerCompositionLaw<language::minus_op>(f, g);
} else { } else {
throw NormalError(invalid_operands(f, g)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, g));
} }
} }
...@@ -508,7 +524,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const DiscreteFunctionT& ...@@ -508,7 +524,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const DiscreteFunctionT&
(is_tiny_matrix_v<rhs_data_type> or is_tiny_vector_v<rhs_data_type>)) { (is_tiny_matrix_v<rhs_data_type> or is_tiny_vector_v<rhs_data_type>)) {
return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(a, f))>(BinOp<BinOperatorT>{}.eval(a, f)); return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(a, f))>(BinOp<BinOperatorT>{}.eval(a, f));
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} else if constexpr (std::is_same_v<language::plus_op, BinOperatorT> or } else if constexpr (std::is_same_v<language::plus_op, BinOperatorT> or
std::is_same_v<language::minus_op, BinOperatorT>) { std::is_same_v<language::minus_op, BinOperatorT>) {
...@@ -517,16 +533,18 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const DiscreteFunctionT& ...@@ -517,16 +533,18 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const DiscreteFunctionT&
} else if constexpr (std::is_same_v<lhs_data_type, rhs_data_type>) { } else if constexpr (std::is_same_v<lhs_data_type, rhs_data_type>) {
return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(a, f))>(BinOp<BinOperatorT>{}.eval(a, f)); return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(a, f))>(BinOp<BinOperatorT>{}.eval(a, f));
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} else if constexpr (std::is_same_v<language::divide_op, BinOperatorT>) { } else if constexpr (std::is_same_v<language::divide_op, BinOperatorT>) {
if constexpr (std::is_same_v<lhs_data_type, double> and std::is_arithmetic_v<rhs_data_type>) { if constexpr (std::is_same_v<lhs_data_type, double> and std::is_arithmetic_v<rhs_data_type>) {
return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(a, f))>(BinOp<BinOperatorT>{}.eval(a, f)); return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(a, f))>(BinOp<BinOperatorT>{}.eval(a, f));
} else { } else {
throw NormalError(invalid_operands(a, f)); // LCOV_EXCL_START
throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
// LCOV_EXCL_STOP
} }
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} }
...@@ -544,10 +562,10 @@ applyBinaryOperationToVectorWithLeftConstant(const DataType& a, const DiscreteFu ...@@ -544,10 +562,10 @@ applyBinaryOperationToVectorWithLeftConstant(const DataType& a, const DiscreteFu
(is_tiny_matrix_v<rhs_data_type> or is_tiny_vector_v<rhs_data_type>)) { (is_tiny_matrix_v<rhs_data_type> or is_tiny_vector_v<rhs_data_type>)) {
return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(a, f))>(BinOp<BinOperatorT>{}.eval(a, f)); return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(a, f))>(BinOp<BinOperatorT>{}.eval(a, f));
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} }
...@@ -567,7 +585,9 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -567,7 +585,9 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0Vector<Dimension, double>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0Vector<Dimension, double>&>(*f);
return applyBinaryOperationToVectorWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationToVectorWithLeftConstant<BinOperatorT>(a, fh);
} else { } else {
throw NormalError(invalid_operands(a, f)); // LCOV_EXCL_START
throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
// LCOV_EXCL_STOP
} }
} }
case ASTNodeDataType::vector_t: { case ASTNodeDataType::vector_t: {
...@@ -578,7 +598,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -578,7 +598,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<1>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<1>>&>(*f);
return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh);
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} }
case 2: { case 2: {
...@@ -586,7 +606,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -586,7 +606,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<2>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<2>>&>(*f);
return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh);
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} }
case 3: { case 3: {
...@@ -594,12 +614,14 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -594,12 +614,14 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<3>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<3>>&>(*f);
return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh);
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f));
} }
// LCOV_EXCL_STOP
} }
} else { } else {
switch (f->dataType().dimension()) { switch (f->dataType().dimension()) {
...@@ -615,9 +637,11 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -615,9 +637,11 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<3>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<3>>&>(*f);
return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f));
} }
// LCOV_EXCL_STOP
} }
} }
} }
...@@ -630,7 +654,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -630,7 +654,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<1>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<1>>&>(*f);
return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh);
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} }
case 2: { case 2: {
...@@ -638,7 +662,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -638,7 +662,7 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<2>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<2>>&>(*f);
return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh);
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} }
case 3: { case 3: {
...@@ -646,12 +670,14 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -646,12 +670,14 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f);
return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh);
} else { } else {
throw NormalError(invalid_operands(a, f)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f));
} }
// LCOV_EXCL_STOP
} }
} else { } else {
switch (f->dataType().numberOfRows()) { switch (f->dataType().numberOfRows()) {
...@@ -667,15 +693,19 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -667,15 +693,19 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f);
return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh); return applyBinaryOperationWithLeftConstant<BinOperatorT>(a, fh);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f));
} }
// LCOV_EXCL_STOP
} }
} }
} }
// LCOV_EXCL_START
default: { default: {
throw NormalError(invalid_operands(a, f)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(a, f));
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -693,9 +723,11 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co ...@@ -693,9 +723,11 @@ applyBinaryOperationWithLeftConstant(const DataType& a, const std::shared_ptr<co
case 3: { case 3: {
return applyBinaryOperationWithLeftConstant<BinOperatorT, 3>(a, f); return applyBinaryOperationWithLeftConstant<BinOperatorT, 3>(a, f);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid mesh dimension"); throw UnexpectedError("invalid mesh dimension");
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -710,13 +742,17 @@ applyBinaryOperationWithRightConstant(const DiscreteFunctionT& f, const DataType ...@@ -710,13 +742,17 @@ applyBinaryOperationWithRightConstant(const DiscreteFunctionT& f, const DataType
if constexpr (std::is_same_v<language::multiply_op, BinOperatorT>) { if constexpr (std::is_same_v<language::multiply_op, BinOperatorT>) {
if constexpr (is_tiny_matrix_v<lhs_data_type> and is_tiny_matrix_v<rhs_data_type>) { if constexpr (is_tiny_matrix_v<lhs_data_type> and is_tiny_matrix_v<rhs_data_type>) {
if constexpr (lhs_data_type::NumberOfColumns == rhs_data_type::NumberOfRows) {
return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a)); return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a));
} else {
throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, a));
}
} else if constexpr (std::is_same_v<lhs_data_type, double> and } else if constexpr (std::is_same_v<lhs_data_type, double> and
(is_tiny_matrix_v<rhs_data_type> or is_tiny_vector_v<rhs_data_type> or (is_tiny_matrix_v<rhs_data_type> or is_tiny_vector_v<rhs_data_type> or
std::is_arithmetic_v<rhs_data_type>)) { std::is_arithmetic_v<rhs_data_type>)) {
return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a)); return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a));
} else { } else {
throw NormalError(invalid_operands(f, a)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, a));
} }
} else if constexpr (std::is_same_v<language::plus_op, BinOperatorT> or } else if constexpr (std::is_same_v<language::plus_op, BinOperatorT> or
std::is_same_v<language::minus_op, BinOperatorT>) { std::is_same_v<language::minus_op, BinOperatorT>) {
...@@ -724,10 +760,10 @@ applyBinaryOperationWithRightConstant(const DiscreteFunctionT& f, const DataType ...@@ -724,10 +760,10 @@ applyBinaryOperationWithRightConstant(const DiscreteFunctionT& f, const DataType
(std::is_arithmetic_v<lhs_data_type> and std::is_arithmetic_v<rhs_data_type>)) { (std::is_arithmetic_v<lhs_data_type> and std::is_arithmetic_v<rhs_data_type>)) {
return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a)); return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a));
} else { } else {
throw NormalError(invalid_operands(f, a)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, a));
} }
} else { } else {
throw NormalError(invalid_operands(f, a)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, a));
} }
} }
...@@ -736,7 +772,7 @@ std::shared_ptr<const IDiscreteFunction> ...@@ -736,7 +772,7 @@ std::shared_ptr<const IDiscreteFunction>
applyBinaryOperationWithRightConstant(const std::shared_ptr<const IDiscreteFunction>& f, const DataType& a) applyBinaryOperationWithRightConstant(const std::shared_ptr<const IDiscreteFunction>& f, const DataType& a)
{ {
if (f->descriptor().type() != DiscreteFunctionType::P0) { if (f->descriptor().type() != DiscreteFunctionType::P0) {
throw NormalError(invalid_operands(f, a)); throw NormalError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, a));
} }
switch (f->dataType()) { switch (f->dataType()) {
...@@ -747,39 +783,29 @@ applyBinaryOperationWithRightConstant(const std::shared_ptr<const IDiscreteFunct ...@@ -747,39 +783,29 @@ applyBinaryOperationWithRightConstant(const std::shared_ptr<const IDiscreteFunct
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, double>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, double>&>(*f);
return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a); return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a);
} }
case ASTNodeDataType::matrix_t: { case ASTNodeDataType::vector_t: {
Assert(f->dataType().numberOfRows() == f->dataType().numberOfColumns()); switch (f->dataType().dimension()) {
if constexpr (is_tiny_matrix_v<DataType>) {
switch (f->dataType().numberOfRows()) {
case 1: { case 1: {
if constexpr (std::is_same_v<DataType, TinyMatrix<1>>) { auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<1>>&>(*f);
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<1>>&>(*f);
return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a); return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a);
} else {
throw NormalError(invalid_operands(f, a));
}
} }
case 2: { case 2: {
if constexpr (std::is_same_v<DataType, TinyMatrix<2>>) { auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<2>>&>(*f);
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<2>>&>(*f);
return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a); return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a);
} else {
throw NormalError(invalid_operands(f, a));
}
} }
case 3: { case 3: {
if constexpr (std::is_same_v<DataType, TinyMatrix<3>>) { auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyVector<3>>&>(*f);
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f);
return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a); return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a);
} else {
throw NormalError(invalid_operands(f, a));
}
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f));
} }
// LCOV_EXCL_STOP
} }
} else { }
case ASTNodeDataType::matrix_t: {
Assert(f->dataType().numberOfRows() == f->dataType().numberOfColumns());
switch (f->dataType().numberOfRows()) { switch (f->dataType().numberOfRows()) {
case 1: { case 1: {
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<1>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<1>>&>(*f);
...@@ -793,15 +819,18 @@ applyBinaryOperationWithRightConstant(const std::shared_ptr<const IDiscreteFunct ...@@ -793,15 +819,18 @@ applyBinaryOperationWithRightConstant(const std::shared_ptr<const IDiscreteFunct
auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f); auto fh = dynamic_cast<const DiscreteFunctionP0<Dimension, TinyMatrix<3>>&>(*f);
return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a); return applyBinaryOperationWithRightConstant<BinOperatorT>(fh, a);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f)); throw UnexpectedError("invalid lhs data type " + EmbeddedIDiscreteFunctionUtils::getOperandTypeName(f));
} }
// LCOV_EXCL_STOP
} }
} }
} // LCOV_EXCL_START
default: { default: {
throw NormalError(invalid_operands(f, a)); throw UnexpectedError(EmbeddedIDiscreteFunctionUtils::incompatibleOperandTypes(f, a));
} }
// LCOV_EXCL_STOP
} }
} }
...@@ -819,9 +848,11 @@ applyBinaryOperationWithRightConstant(const std::shared_ptr<const IDiscreteFunct ...@@ -819,9 +848,11 @@ applyBinaryOperationWithRightConstant(const std::shared_ptr<const IDiscreteFunct
case 3: { case 3: {
return applyBinaryOperationWithRightConstant<BinOperatorT, 3>(f, a); return applyBinaryOperationWithRightConstant<BinOperatorT, 3>(f, a);
} }
// LCOV_EXCL_START
default: { default: {
throw UnexpectedError("invalid mesh dimension"); throw UnexpectedError("invalid mesh dimension");
} }
// LCOV_EXCL_STOP
} }
} }
......
...@@ -118,6 +118,7 @@ add_executable (mpi_unit_tests ...@@ -118,6 +118,7 @@ add_executable (mpi_unit_tests
test_DiscreteFunctionP0Vector.cpp test_DiscreteFunctionP0Vector.cpp
test_DiscreteFunctionVectorInterpoler.cpp test_DiscreteFunctionVectorInterpoler.cpp
test_EmbeddedIDiscreteFunctionMathFunctions.cpp test_EmbeddedIDiscreteFunctionMathFunctions.cpp
test_EmbeddedIDiscreteFunctionOperators.cpp
test_InterpolateItemArray.cpp test_InterpolateItemArray.cpp
test_InterpolateItemValue.cpp test_InterpolateItemValue.cpp
test_ItemArray.cpp test_ItemArray.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