Skip to content

Commit

Permalink
Add a bunch of manufactured tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbritopacheco committed Feb 10, 2025
1 parent aecc2b7 commit 3045711
Show file tree
Hide file tree
Showing 11 changed files with 1,756 additions and 51 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
-DRODIN_BUILD_BENCHMARKS=OFF
-DRODIN_BUILD_SRC=ON
-DRODIN_BUILD_UNIT_TESTS=ON
-DRODIN_BUILD_MANUFACTURED_TESTS=ON
-DRODIN_LCOV_FLAGS="--ignore-errors gcov,gcov --ignore-errors mismatch --ignore-errors unused"
-DRODIN_CODE_COVERAGE=ON
-DRODIN_MULTITHREADED=${{ matrix.multithreaded }}
Expand Down
2 changes: 1 addition & 1 deletion src/Rodin/Configure.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@
/**
* @brief Represents the constant used for fuzzy comparison.
*/
#define RODIN_FUZZY_CONSTANT 1e-3
#define RODIN_FUZZY_CONSTANT 1e-5

#endif
31 changes: 26 additions & 5 deletions src/Rodin/Math/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,25 @@
namespace Rodin::Math
{
/**
* @brief Computes the absolute value of a value of type T.
* @param[in] x Value
* @tparam T Type of value
* @returns Absolute of value
*/
* @brief Computes the absolute value of a value of type T.
* @param[in] x Value
* @tparam T Type of value
* @returns Absolute of value
*/
template <class T>
constexpr
auto abs(const T& x)
{
return std::abs(x);
}

template <class T>
constexpr
auto exp(const T& x)
{
return std::exp(x);
}

constexpr
Complex conj(const Complex& x)
{
Expand Down Expand Up @@ -108,13 +115,27 @@ namespace Rodin::Math
return std::cos(x);
}

template <class T>
constexpr
auto cosh(const T& x)
{
return std::cosh(x);
}

template <class T>
constexpr
auto sin(const T& x)
{
return std::sin(x);
}

template <class T>
constexpr
auto sinh(const T& x)
{
return std::sinh(x);
}

template <class T>
constexpr
auto tan(const T& x)
Expand Down
3 changes: 3 additions & 0 deletions src/Rodin/Variational.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "Variational/UnaryMinus.h"

#include "Variational/Abs.h"
#include "Variational/Exp.h"
#include "Variational/Conjugate.h"

#include "Variational/EQ.h"
Expand Down Expand Up @@ -69,6 +70,8 @@

#include "Variational/Sine.h"
#include "Variational/Cosine.h"
#include "Variational/Sinh.h"
#include "Variational/Cosh.h"
#include "Variational/Tangent.h"

#include "Variational/Frobenius.h"
Expand Down
96 changes: 96 additions & 0 deletions src/Rodin/Variational/Cosh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright Carlos BRITO PACHECO 2021 - 2022.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* https://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef RODIN_VARIATIONAL_COSH_H
#define RODIN_VARIATIONAL_COSH_H

#include "Rodin/Math.h"
#include "ForwardDecls.h"
#include "Function.h"
#include "RealFunction.h"

namespace Rodin::Variational
{
/**
* @defgroup CoshSpecializations Cosh Template Specializations
* @brief Template specializations of the Cosh class.
* @see Cosh
*/

/**
* @ingroup CoshSpecializations
*/
template <class NestedDerived>
class Cosh<FunctionBase<NestedDerived>> final
: public RealFunctionBase<Cosh<FunctionBase<NestedDerived>>>
{
public:
using OperandType = FunctionBase<NestedDerived>;

using Parent = RealFunctionBase<Cosh<FunctionBase<NestedDerived>>>;

Cosh(const OperandType& v)
: m_operand(v.copy())
{}

Cosh(const Cosh& other)
: Parent(other),
m_operand(other.m_operand->copy())
{}

Cosh(Cosh&& other)
: Parent(std::move(other)),
m_operand(std::move(other.m_operand))
{}

constexpr
Cosh& traceOf(Geometry::Attribute attr)
{
m_operand->traceOf(attr);
return *this;
}

constexpr
Cosh& traceOf(const FlatSet<Geometry::Attribute>& attrs)
{
m_operand->traceOf(attrs);
return *this;
}

Real getValue(const Geometry::Point& p) const
{
return Math::cosh(getOperand().getValue(p));
}

const OperandType& getOperand() const
{
assert(m_operand);
return *m_operand;
}

Cosh* copy() const noexcept override
{
return new Cosh(*this);
}

private:
std::unique_ptr<OperandType> m_operand;
};

template <class NestedDerived>
Cosh(const FunctionBase<NestedDerived>&) -> Cosh<FunctionBase<NestedDerived>>;

/**
* @brief Helper function to construct objects of type Cosh.
*/
template <class NestedDerived>
auto cosh(const FunctionBase<NestedDerived>& f)
{
return Cosh(f);
}
}

#endif
6 changes: 1 addition & 5 deletions src/Rodin/Variational/Cosine.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,32 @@ namespace Rodin::Variational
m_operand(std::move(other.m_operand))
{}

inline
constexpr
Cos& traceOf(Geometry::Attribute attr)
{
m_operand->traceOf(attr);
return *this;
}

inline
constexpr
Cos& traceOf(const FlatSet<Geometry::Attribute>& attrs)
{
m_operand->traceOf(attrs);
return *this;
}

inline
Real getValue(const Geometry::Point& p) const
{
return Math::cos(getOperand().getValue(p));
}

inline
const OperandType& getOperand() const
{
assert(m_operand);
return *m_operand;
}

inline Cos* copy() const noexcept override
Cos* copy() const noexcept override
{
return new Cos(*this);
}
Expand Down
86 changes: 86 additions & 0 deletions src/Rodin/Variational/Exp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright Carlos BRITO PACHECO 2021 - 2022.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* https://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef RODIN_VARIATIONAL_EXP_H
#define RODIN_VARIATIONAL_EXP_H

#include <cmath>
#include "ForwardDecls.h"
#include "Function.h"
#include "RealFunction.h"

namespace Rodin::Variational
{
/**
* @defgroup ExpSpecializations Exp Template Specializations
* @brief Template specializations of the Exp class.
* @see Exp
*/

/**
* @ingroup ExpSpecializations
*/
template <class NestedDerived>
class Exp<FunctionBase<NestedDerived>>
: public RealFunctionBase<Exp<FunctionBase<NestedDerived>>>
{
public:
using OperandType = FunctionBase<NestedDerived>;

using Parent = RealFunctionBase<Exp<OperandType>>;

using OperandRangeType = typename FormLanguage::Traits<OperandType>::RangeType;

Exp(const OperandType& v)
: m_v(v.copy())
{}

Exp(const Exp& other)
: Parent(other),
m_v(other.m_v->copy())
{}

Exp(Exp&& other)
: Parent(std::move(other)),
m_v(std::move(other.m_v))
{}

constexpr
auto getValue(const Geometry::Point& p) const
{
return Math::exp(getOperand().getValue(p));
}

const OperandType& getOperand() const
{
assert(m_v);
return *m_v;
}

Exp* copy() const noexcept override
{
return new Exp(*this);
}

private:
std::unique_ptr<OperandType> m_v;
};

template <class NestedDerived>
Exp(const FunctionBase<NestedDerived>&) -> Exp<FunctionBase<NestedDerived>>;

template <class NestedDerived>
constexpr auto
exp(const FunctionBase<NestedDerived>& op)
{
return Exp(op);
}
}

#endif



9 changes: 9 additions & 0 deletions src/Rodin/Variational/ForwardDecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@ namespace Rodin::Variational
template <class Operand>
class Abs;

template <class Operand>
class Exp;

/**
* @brief Represents the Frobenius norm.
* @tparam Operand Type of operand
Expand Down Expand Up @@ -691,6 +694,12 @@ namespace Rodin::Variational
template <class Operand>
class Sin;

template <class Operand>
class Cosh;

template <class Operand>
class Sinh;

/**
* @brief Represents the tangent function.
* @tparam Operand Type of operand
Expand Down
6 changes: 1 addition & 5 deletions src/Rodin/Variational/Sine.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,32 @@ namespace Rodin::Variational
m_operand(std::move(other.m_operand))
{}

inline
constexpr
Sin& traceOf(Geometry::Attribute attr)
{
m_operand->traceOf(attr);
return *this;
}

inline
constexpr
Sin& traceOf(const FlatSet<Geometry::Attribute>& attrs)
{
m_operand->traceOf(attrs);
return *this;
}

inline
Real getValue(const Geometry::Point& p) const
{
return Math::sin(getOperand().getValue(p));
}

inline
const OperandType& getOperand() const
{
assert(m_operand);
return *m_operand;
}

inline Sin* copy() const noexcept override
Sin* copy() const noexcept override
{
return new Sin(*this);
}
Expand Down
Loading

0 comments on commit 3045711

Please sign in to comment.