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.
constraintoperator.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_CONTRAINTOPERATOR_H
8 #define IGLOO_CONTRAINTOPERATOR_H
9 
10 namespace snowhouse {
11 
13  {
14  InvalidExpressionException(const std::string& message) : m_message(message)
15  {
16  }
17 
18  const std::string& Message() const
19  {
20  return m_message;
21  }
22 
23  std::string m_message;
24  };
25 
27  {
28  virtual ~ConstraintOperator() {}
29 
30  virtual void PerformOperation(ResultStack& result) = 0;
31  virtual int Precedence() const = 0;
32 
33  template <typename ConstraintListType, typename ActualType>
34  static bool EvaluateElementAgainstRestOfExpression(ConstraintListType& list, const ActualType& actual)
35  {
36  ResultStack innerResult;
37  OperatorStack innerOperators;
38 
39  EvaluateConstraintList(list.m_tail, innerResult, innerOperators, actual);
40  EvaluateAllOperatorsOnStack(innerOperators, innerResult);
41 
42  if(innerResult.empty())
43  {
44  throw InvalidExpressionException("The expression after \"" + snowhouse::Stringize(list.m_head) + "\" operator does not yield any result");
45  }
46 
47  return innerResult.top();
48  }
49 
50  static void EvaluateOperatorsWithLessOrEqualPrecedence(const ConstraintOperator& op, OperatorStack& operators, ResultStack& result)
51  {
52  while(!operators.empty())
53  {
54  ConstraintOperator* op_from_stack = operators.top();
55 
56  if(op_from_stack->Precedence() > op.Precedence())
57  {
58  break;
59  }
60 
61  op_from_stack->PerformOperation(result);
62  operators.pop();
63  }
64  }
65 
66  static void EvaluateAllOperatorsOnStack(OperatorStack& operators, ResultStack& result)
67  {
68  while(!operators.empty())
69  {
70  ConstraintOperator* op = operators.top();
71  op->PerformOperation(result);
72  operators.pop();
73  }
74  }
75  };
76 
77 }
78 
79 #endif
Definition: assert.h:13
Definition: constraintoperator.h:26
Definition: constraintoperator.h:12