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.
literal_flat_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 //
12 
13 #pragma once
14 
15 // System includes
16 #include <vector>
17 #include <string>
18 
19 // Project includes
20 #include "includes/define.h"
22 #include "expression/expression.h"
23 
24 namespace Kratos {
25 
28 
38 template<class TRawDataType = double>
39 class KRATOS_API(KRATOS_CORE) LiteralFlatExpression : public Expression {
40 public:
43 
44  using Pointer = Kratos::intrusive_ptr<LiteralFlatExpression<TRawDataType>>;
45 
46  using value_type = TRawDataType;
47 
48  using size_type = std::size_t;
49 
50  using iterator = TRawDataType*;
51 
52  using const_iterator = TRawDataType const*;
53 
57 
59  const IndexType NumberOfEntities,
60  const std::vector<IndexType>& rShape);
61 
63  TRawDataType* pDataBegin,
64  const IndexType NumberOfEntities,
65  const std::vector<IndexType>& rShape);
66 
70 
83  const IndexType NumberOfEntities,
84  const std::vector<IndexType>& rShape);
85 
87  TRawDataType* pDataBegin,
88  const IndexType NumberOfEntities,
89  const std::vector<IndexType>& rShape);
90 
91  void SetData(
92  const IndexType EntityDataBeginIndex,
93  const IndexType ComponentIndex,
94  const TRawDataType Value);
95 
96  const std::vector<IndexType> GetItemShape() const override;
97 
98  IndexType GetMaxDepth() const override { return 1; }
99 
100  IndexType size() const noexcept { return mData.size(); }
101 
102  iterator begin() noexcept { return mData.begin(); }
103 
104  iterator end() noexcept { return mData.end(); }
105 
106  const_iterator begin() const noexcept { return mData.begin(); }
107 
108  const_iterator end() const noexcept { return mData.end(); }
109 
110  const_iterator cbegin() const noexcept { return mData.begin(); }
111 
112  const_iterator cend() const noexcept { return mData.end(); }
113 
114  std::string Info() const override;
115 
117 protected:
120 
136  class Data
137  {
138  public:
142 
148  Data(const IndexType Size): mpBegin(new TRawDataType[Size]), mIsManaged(true), mSize(Size) {}
149 
155  Data(TRawDataType* pBegin, const IndexType Size): mpBegin(pBegin), mIsManaged(false), mSize(Size) {}
156 
157  ~Data() { if (mIsManaged) { delete[] mpBegin; } }
158 
162 
163  inline iterator begin() noexcept { return mpBegin; }
164 
165  inline iterator end() noexcept { return mpBegin + mSize; }
166 
167  inline const_iterator begin() const noexcept { return mpBegin; }
168 
169  inline const_iterator end() const noexcept { return mpBegin + mSize; }
170 
171  inline const_iterator cbegin() const noexcept { return mpBegin; }
172 
173  inline const_iterator cend() const noexcept { return mpBegin + mSize; }
174 
175  inline IndexType size() const noexcept { return mSize; }
176 
178  private:
181 
182  TRawDataType* mpBegin;
183 
184  const bool mIsManaged;
185 
186  const IndexType mSize;
187 
189  };
190 
194 
195  const std::vector<IndexType> mShape;
196 
198 
200 };
201 
202 template<class TRawDataType = double>
204 {
205 public:
206 
207  using IndexType = std::size_t;
208 
210 
211  double Evaluate(
212  const IndexType EntityIndex,
213  const IndexType EntityDataBeginIndex,
214  const IndexType ComponentIndex) const override;
215 
216 };
217 
218 template<class TRawDataType = double>
220 {
221 public:
222 
223  using IndexType = std::size_t;
224 
226 
227  double Evaluate(
228  const IndexType EntityIndex,
229  const IndexType EntityDataBeginIndex,
230  const IndexType ComponentIndex) const override;
231 
232 };
233 
234 } // namespace Kratos
Definition: expression.h:54
Base class or all the expression types.
Definition: expression.h:38
IndexType size_type
Definition: expression.h:139
double value_type
Definition: expression.h:137
Kratos::intrusive_ptr< Expression > Pointer
Definition: expression.h:44
std::size_t IndexType
Definition: expression.h:48
This class is used represent the flattened data array.
Definition: literal_flat_expression.h:137
const_iterator begin() const noexcept
Definition: literal_flat_expression.h:167
const_iterator end() const noexcept
Definition: literal_flat_expression.h:169
const_iterator cend() const noexcept
Definition: literal_flat_expression.h:173
Data(TRawDataType *pBegin, const IndexType Size)
Construct a new Data object, where the underlying array memory is not managed by the object.
Definition: literal_flat_expression.h:155
iterator begin() noexcept
Definition: literal_flat_expression.h:163
~Data()
Definition: literal_flat_expression.h:157
iterator end() noexcept
Definition: literal_flat_expression.h:165
Data(const IndexType Size)
Construct a new Data object where the array memory is managed by the object.
Definition: literal_flat_expression.h:148
IndexType size() const noexcept
Definition: literal_flat_expression.h:175
const_iterator cbegin() const noexcept
Definition: literal_flat_expression.h:171
Expression to hold a literal with a flattened data structure.
Definition: literal_flat_expression.h:39
Data mData
Definition: literal_flat_expression.h:197
TRawDataType * iterator
Definition: literal_flat_expression.h:50
const_iterator cbegin() const noexcept
Definition: literal_flat_expression.h:110
Kratos::intrusive_ptr< LiteralFlatExpression< TRawDataType > > Pointer
Definition: literal_flat_expression.h:44
const_iterator cend() const noexcept
Definition: literal_flat_expression.h:112
const_iterator end() const noexcept
Definition: literal_flat_expression.h:108
IndexType size() const noexcept
Definition: literal_flat_expression.h:100
const_iterator begin() const noexcept
Definition: literal_flat_expression.h:106
iterator begin() noexcept
Definition: literal_flat_expression.h:102
iterator end() noexcept
Definition: literal_flat_expression.h:104
std::string Info() const override
IndexType GetMaxDepth() const override
Get the Max Depth of the lazy expression tree.
Definition: literal_flat_expression.h:98
const std::vector< IndexType > mShape
Definition: literal_flat_expression.h:195
Definition: literal_flat_expression.h:220
Definition: literal_flat_expression.h:204
std::string GetItemShape(const std::vector< IndexType > &rShape)
Definition: binary_expression.cpp:27
Modeler::Pointer Create(const std::string &ModelerName, Model &rModel, const Parameters ModelParameters)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:30
double Evaluate(const PolynomialType &rPolynomial, double x)
Definition: polynomial_utilities.cpp:77
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
tuple const
Definition: ode_solve.py:403