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.
unary_reshape_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 <string>
17 #include <iterator>
18 
19 // Project includes
20 #include "expression/expression.h"
21 
22 namespace Kratos {
23 
26 
32 public:
35 
36  using IndexType = std::size_t;
37 
41 
42  template<class TIteratorType>
44  Expression::ConstPointer pExpression,
45  TIteratorType Begin,
46  TIteratorType End)
47  : Expression(pExpression->NumberOfEntities()),
48  mpSourceExpression(pExpression),
49  mShape(Begin, End)
50  {
51  KRATOS_ERROR_IF_NOT(this->GetItemComponentCount() == mpSourceExpression->GetItemComponentCount())
52  << "The source and destination should have same stride. [ source stride = "
53  << mpSourceExpression->GetItemComponentCount() << ", destination stride = "
54  << this->GetItemComponentCount() << " ].\n"
55  << "Source expression:\n"
56  << *mpSourceExpression << "\n";
57  }
58 
62 
63  template<class TIteratorType>
65  Expression::ConstPointer pExpression,
66  TIteratorType Begin,
67  TIteratorType End)
68  {
69  return Kratos::make_intrusive<UnaryReshapeExpression>(std::move(pExpression), Begin, End);
70  }
71 
72  double Evaluate(
73  const IndexType EntityIndex,
74  const IndexType EntityDataBeginIndex,
75  const IndexType ComponentIndex) const override
76  {
77  return mpSourceExpression->Evaluate(EntityIndex, EntityDataBeginIndex, ComponentIndex);
78  }
79 
80  const std::vector<IndexType> GetItemShape() const override
81  {
82  return mShape;
83  }
84 
85  IndexType GetMaxDepth() const override
86  {
87  return mpSourceExpression->GetMaxDepth() + 1;
88  }
89 
90  std::string Info() const override
91  {
92  std::stringstream msg;
93  msg << mpSourceExpression << "-> [";
94  for (const auto v : mShape) {
95  msg << " " << v;
96  }
97  msg << " ]";
98  return msg.str();
99  }
100 
102 protected:
105 
107 
108  const std::vector<IndexType> mShape;
109 
111 };
112 
113 } // namespace Kratos
Base class or all the expression types.
Definition: expression.h:38
IndexType GetItemComponentCount() const
Get the Local Size of the expression.
Definition: expression.cpp:104
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
Used to create lazy expression to reshape given expression to a new shape.
Definition: unary_reshape_expression.h:31
UnaryReshapeExpression(Expression::ConstPointer pExpression, TIteratorType Begin, TIteratorType End)
Definition: unary_reshape_expression.h:43
static Expression::Pointer Create(Expression::ConstPointer pExpression, TIteratorType Begin, TIteratorType End)
Definition: unary_reshape_expression.h:64
const std::vector< IndexType > GetItemShape() const override
Get the Shape of the expression.
Definition: unary_reshape_expression.h:80
double Evaluate(const IndexType EntityIndex, const IndexType EntityDataBeginIndex, const IndexType ComponentIndex) const override
Evalute the expression for the given entity data start index and component index and returns the valu...
Definition: unary_reshape_expression.h:72
const Expression::ConstPointer mpSourceExpression
Definition: unary_reshape_expression.h:106
std::string Info() const override
Definition: unary_reshape_expression.h:90
const std::vector< IndexType > mShape
Definition: unary_reshape_expression.h:108
IndexType GetMaxDepth() const override
Get the Max Depth of the lazy expression tree.
Definition: unary_reshape_expression.h:85
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
v
Definition: generate_convection_diffusion_explicit_element.py:114