blitzdg
an open-source project aiming to implement parallel discontinuous Galerkin (dg) solvers for common partial differential equations systems using blitz++ for array and tensor manipulations and MPI for distributed parallelism.
equalswithdeltaconstraint.h
1 
2 // Copyright Joakim Karlsson & Kim Gräsman 2010-2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef IGLOO_EQUALSWITHDELTACONSTRAINT_H
8 #define IGLOO_EQUALSWITHDELTACONSTRAINT_H
9 
10 #include "./expressions/expression.h"
11 
12 namespace snowhouse {
13 
14  template< typename ExpectedType, typename DeltaType >
15  struct EqualsWithDeltaConstraint : Expression< EqualsWithDeltaConstraint<ExpectedType, DeltaType> >
16  {
17  EqualsWithDeltaConstraint(const ExpectedType& expected, const DeltaType& delta)
18  : m_expected(expected), m_delta(delta)
19  {
20  }
21 
22  template<typename ActualType>
23  bool operator()(const ActualType& actual) const
24  {
25  return ((m_expected <= (actual + m_delta)) && (m_expected >= (actual - m_delta)));
26  }
27 
28  ExpectedType m_expected;
29  DeltaType m_delta;
30  };
31 
32  template< typename ExpectedType, typename DeltaType >
33  inline EqualsWithDeltaConstraint<ExpectedType, DeltaType> EqualsWithDelta(const ExpectedType& expected, const DeltaType& delta)
34  {
36  }
37 
38  template< typename ExpectedType, typename DeltaType >
39  struct Stringizer< EqualsWithDeltaConstraint< ExpectedType, DeltaType > >
40  {
41  static std::string ToString(const EqualsWithDeltaConstraint<ExpectedType, DeltaType>& constraint)
42  {
43  std::ostringstream builder;
44  builder << "equal to " << snowhouse::Stringize(constraint.m_expected) << " (+/- " << snowhouse::Stringize(constraint.m_delta) << ")";
45 
46  return builder.str();
47  }
48  };
49 }
50 
51 #endif
Definition: assert.h:13
Definition: equalswithdeltaconstraint.h:15
Definition: stringize.h:71
Definition: expression.h:17