KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
expression.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Suneth Warnakulasuriya
11 // Máté Kelemen
12 //
13 
14 #pragma once
15 
16 // System includes
17 #include <atomic>
18 #include <ostream>
19 #include <string>
20 #include <vector>
21 #include <iterator>
22 
23 // Project includes
24 #include "includes/define.h"
25 #include "intrusive_ptr/intrusive_ptr.hpp"
26 
27 namespace Kratos {
28 
31 
38 class KRATOS_API(KRATOS_CORE) Expression {
39 public:
40 
43 
44  using Pointer = Kratos::intrusive_ptr<Expression>;
45 
46  using ConstPointer = Kratos::intrusive_ptr<const Expression>;
47 
48  using IndexType = std::size_t;
49 
53 
55  public:
58 
60 
61  using value_type = double;
62 
63  using pointer = double*;
64 
65  using reference = double&;
66 
67  using iterator_category = std::input_iterator_tag;
68 
70 
74 
76 
78 
85 
89 
90  Expression::ConstPointer GetExpression() const;
91 
95 
96  double operator*() const;
97 
98  bool operator==(const ExpressionIterator& rOther) const;
99 
100  bool operator!=(const ExpressionIterator& rOther) const;
101 
103 
104  ExpressionIterator& operator++();
105 
106  ExpressionIterator operator++(int);
107 
109 
110  private:
113 
114  Expression::ConstPointer mpExpression;
115 
116  IndexType mEntityIndex;
117 
118  IndexType mEntityDataBeginIndex;
119 
120  IndexType mItemComponentIndex;
121 
122  IndexType mItemComponentCount;
123 
127 
128  friend class Expression;
129 
131  };
132 
136 
138 
140 
142 
146 
147  Expression(const IndexType NumberOfEntities) : mNumberOfEntities(NumberOfEntities) {}
148 
149  virtual ~Expression() = default;
150 
154 
164  virtual double Evaluate(
165  const IndexType EntityIndex,
166  const IndexType EntityDataBeginIndex,
167  const IndexType ComponentIndex) const = 0;
168 
174  virtual const std::vector<IndexType> GetItemShape() const = 0;
175 
181  inline IndexType NumberOfEntities() const { return mNumberOfEntities; };
182 
188  IndexType GetItemComponentCount() const;
189 
200  virtual IndexType GetMaxDepth() const = 0;
201 
205 
206  IndexType size() const;
207 
208  const_iterator begin() const;
209 
210  const_iterator end() const;
211 
212  const_iterator cbegin() const;
213 
214  const_iterator cend() const;
215 
216  virtual std::string Info() const = 0;
217 
219 
220 private:
221  friend class ExpressionInput;
222 
223  friend class ExpressionOutput;
224 
227 
228  const IndexType mNumberOfEntities;
229 
233 
234  //*********************************************
235  // this block is needed for refcounting in the @ref intrusive ptr
236  mutable std::atomic<int> mReferenceCounter{0};
237 
238  friend void intrusive_ptr_add_ref(const Expression* x)
239  {
240  x->mReferenceCounter.fetch_add(1, std::memory_order_relaxed);
241  }
242 
243  friend void intrusive_ptr_release(const Expression* x)
244  {
245  if (x->mReferenceCounter.fetch_sub(1, std::memory_order_release) == 1) {
246  std::atomic_thread_fence(std::memory_order_acquire);
247  delete x;
248  }
249  }
250 
251  //*********************************************
252 
254 };
255 
258 inline std::ostream& operator<<(
259  std::ostream& rOStream,
260  const Expression& rThis)
261 {
262  return rOStream << rThis.Info();
263 }
264 
265 } // namespace Kratos
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Definition: expression.h:54
double value_type
Definition: expression.h:61
std::input_iterator_tag iterator_category
Definition: expression.h:67
IndexType difference_type
Definition: expression.h:59
double & reference
Definition: expression.h:65
KRATOS_CLASS_POINTER_DEFINITION(ExpressionIterator)
double * pointer
Definition: expression.h:63
Base class or all the expression types.
Definition: expression.h:38
virtual double Evaluate(const IndexType EntityIndex, const IndexType EntityDataBeginIndex, const IndexType ComponentIndex) const =0
Evalute the expression for the given entity data start index and component index and returns the valu...
virtual const std::vector< IndexType > GetItemShape() const =0
Get the Shape of the expression.
virtual std::string Info() const =0
IndexType size_type
Definition: expression.h:139
double value_type
Definition: expression.h:137
friend void intrusive_ptr_release(const Expression *x)
Definition: expression.h:243
Expression(const IndexType NumberOfEntities)
Definition: expression.h:147
virtual ~Expression()=default
virtual IndexType GetMaxDepth() const =0
Get the Max Depth of the lazy expression tree.
IndexType NumberOfEntities() const
Get the maximum number of entities allowed for this expression.
Definition: expression.h:181
Kratos::intrusive_ptr< Expression > Pointer
Definition: expression.h:44
std::size_t IndexType
Definition: expression.h:48
Kratos::intrusive_ptr< const Expression > ConstPointer
Definition: expression.h:46
friend void intrusive_ptr_add_ref(const Expression *x)
Definition: expression.h:238
Definition: expression_io.h:25
Definition: expression_io.h:69
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
end
Definition: DEM_benchmarks.py:180
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Expression::Pointer operator*(const Expression::ConstPointer &rpLeft, const double Right)
bool operator==(const Flags &Left, const Flags &Right)
Definition: flags.cpp:45
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
bool operator!=(const Flags &Left, const Flags &Right)
Definition: flags.cpp:50
x
Definition: sensitivityMatrix.py:49