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.
field_utility.h
Go to the documentation of this file.
1 #ifndef KRATOS_FIELD_UTILITY_H
2 #define KRATOS_FIELD_UTILITY_H
3 // /* External includes */
4 
5 // System includes
6 
7 // Project includes
8 #include "includes/variables.h"
9 
10 /* System includes */
11 #include <limits>
12 #include <iostream>
13 #include <iomanip>
14 
15 /* External includes */
16 #ifdef _OPENMP
17 #include <omp.h>
18 #endif
19 
20 /* Project includes */
21 #include "includes/define.h"
22 #include "utilities/openmp_utils.h"
23 #include "real_field.h"
24 #include "vector_field.h"
25 #include "sets/space_time_set.h"
26 
27 namespace Kratos
28 {
29 class KRATOS_API(SWIMMING_DEM_APPLICATION) FieldUtility
30 {
31 public:
32 
34 
36 
37 FieldUtility(): mDomain(), mpVectorField(){}
38 
39 FieldUtility(SpaceTimeSet::Pointer p_sts, VectorField<3>::Pointer p_vector_field):
40  mDomain(p_sts), mpVectorField(p_vector_field){}
41 
43 
44 virtual ~FieldUtility(){}
45 
46 //***************************************************************************************************************
47 //***************************************************************************************************************
48 
49 void MarkNodesInside(ModelPart& r_model_part, const ProcessInfo& r_current_process_info)
50 {
51  const int nnodes = r_model_part.Nodes().size();
52  const double time = r_current_process_info[TIME];
53  mIsInArray.resize(nnodes);
54 
55  #pragma omp parallel for
56  for (int i = 0; i < nnodes; ++i){
57  ModelPart::NodeIterator node_it = r_model_part.NodesBegin() + i;
58  double coor_x = node_it->X();
59  double coor_y = node_it->Y();
60  double coor_z = node_it->Z();
61  bool is_in = mDomain->IsIn(time, coor_x, coor_y, coor_z);
62  node_it->Set(INSIDE, is_in);
63  mIsInArray[i] = is_in;
64  }
65 }
66 
67 //***************************************************************************************************************
68 //***************************************************************************************************************
69 
70 double EvaluateFieldAtPoint(const double& time,
71  const array_1d<double, 3>& coor,
72  RealField::Pointer formula)
73 {
74  if (mDomain->IsIn(time, coor[0], coor[1], coor[2])){
75  return(formula->Evaluate(time, coor));
76  }
77 
78  return(0.0);
79 }
80 
81 //***************************************************************************************************************
82 //***************************************************************************************************************
83 
85  const array_1d<double, 3>& coor,
87 {
88  if (mDomain->IsIn(time, coor[0], coor[1], coor[2])){
89  array_1d<double, 3> value;
90  formula->Evaluate(time, coor, value);
91  return(value);
92  }
93 
94  return(ZeroVector(3));
95 
96 }
97 
98 //***************************************************************************************************************
99 //***************************************************************************************************************
100 
101 
102 virtual void ImposeFieldOnNodes(Variable<double>& destination_variable,
103  const double default_value,
104  RealField::Pointer formula,
105  ModelPart& r_model_part,
106  const ProcessInfo& r_current_process_info,
107  const bool recalculate_domain)
108 {
109  const unsigned int nnodes = r_model_part.Nodes().size();
110  const double time = r_current_process_info[TIME];
111 
112  if (recalculate_domain || nnodes != mIsInArray.size()){
113  MarkNodesInside(r_model_part, r_current_process_info);
114  }
115 
116  #pragma omp parallel for
117  for (int i = 0; i < (int)nnodes; ++i){
118  ModelPart::NodeIterator node_it = r_model_part.NodesBegin() + i;
119  double& destination_value = node_it->FastGetSolutionStepValue(destination_variable);
120  destination_value = default_value;
121 
122  if (mIsInArray[i]){
123  array_1d<double, 3> coor;
124  coor[0] = node_it->X();
125  coor[1] = node_it->Y();
126  coor[2] = node_it->Z();
127  destination_value = formula->Evaluate(time, coor);
128  }
129  }
130 }
131 
132 //***************************************************************************************************************
133 //***************************************************************************************************************
134 
135 virtual void ImposeFieldOnNodes(Variable<array_1d<double, 3> >& destination_variable,
136  const array_1d<double, 3> default_value,
137  VectorField<3>::Pointer formula,
138  ModelPart& r_model_part,
139  const ProcessInfo& r_current_process_info,
140  const bool recalculate_domain)
141 {
142  const unsigned int nnodes = r_model_part.Nodes().size();
143  const double time = r_current_process_info[TIME];
144 
145  if (recalculate_domain || nnodes != mIsInArray.size()){
146  MarkNodesInside(r_model_part, r_current_process_info);
147  }
148 
149  #pragma omp parallel for
150  for (int i = 0; i < (int)nnodes; ++i){
151  ModelPart::NodeIterator node_it = r_model_part.NodesBegin() + i;
152  array_1d<double, 3>& destination_value = node_it->FastGetSolutionStepValue(destination_variable);
153  destination_value[0] = default_value[0];
154  destination_value[1] = default_value[1];
155  destination_value[2] = default_value[2];
156 
157  if (mIsInArray[i]){
158  array_1d<double, 3> coor;
159  coor[0] = node_it->X();
160  coor[1] = node_it->Y();
161  coor[2] = node_it->Z();
162  formula->Evaluate(time, coor, destination_value);
163  }
164  }
165 }
166 
167 //***************************************************************************************************************
168 //***************************************************************************************************************
169 
170 virtual void ImposeFieldOnNodes(ModelPart& r_model_part, const VariablesList& variables_to_be_imposed);
171 virtual void ImposeFieldOnNodes(ModelPart& r_model_part, const Variable<array_1d<double, 3> >& variable_to_be_imposed);
172 
173 //***************************************************************************************************************
174 //***************************************************************************************************************
175 
176 
180 
181 
185 
187 
188 virtual std::string Info() const
189 {
190  return "";
191 }
192 
194 
195 virtual void PrintInfo(std::ostream& rOStream) const
196 {
197 }
198 
200 
201 virtual void PrintData(std::ostream& rOStream) const
202 {
203 }
204 
205 
209 
211 
212 protected:
215 
216 
220 
221 RealField::Pointer mFormula;
222 SpaceTimeSet::Pointer mDomain;
224 std::vector<bool> mIsInArray;
228 
229 
233 
234 
238 
242 
243 
247 
248 
250 
251 private:
252 
255 
256 
260 
264 
268 
269 
273 
274 
278 
279 
283 
285 FieldUtility & operator=(FieldUtility const& rOther);
286 
287 
289 
290 }; // Class FieldUtility
291 
293 
296 
297 
301 
302 } // namespace Kratos.
303 #endif // KRATOS_FIELD_UTILITY_H
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Definition: field_utility.h:30
SpaceTimeSet::Pointer mDomain
Definition: field_utility.h:222
virtual void ImposeFieldOnNodes(Variable< array_1d< double, 3 > > &destination_variable, const array_1d< double, 3 > default_value, VectorField< 3 >::Pointer formula, ModelPart &r_model_part, const ProcessInfo &r_current_process_info, const bool recalculate_domain)
Definition: field_utility.h:135
FieldUtility(SpaceTimeSet::Pointer p_sts, VectorField< 3 >::Pointer p_vector_field)
Definition: field_utility.h:39
FieldUtility()
Default constructor.
Definition: field_utility.h:37
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: field_utility.h:201
virtual std::string Info() const
Turn back information as a stemplate<class T, std::size_t dim> tring.
Definition: field_utility.h:188
array_1d< double, 3 > EvaluateFieldAtPoint(const double &time, const array_1d< double, 3 > &coor, VectorField< 3 >::Pointer formula)
Definition: field_utility.h:84
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: field_utility.h:195
virtual void ImposeFieldOnNodes(Variable< double > &destination_variable, const double default_value, RealField::Pointer formula, ModelPart &r_model_part, const ProcessInfo &r_current_process_info, const bool recalculate_domain)
Definition: field_utility.h:102
virtual ~FieldUtility()
Destructor.
Definition: field_utility.h:44
void MarkNodesInside(ModelPart &r_model_part, const ProcessInfo &r_current_process_info)
Definition: field_utility.h:49
KRATOS_CLASS_POINTER_DEFINITION(FieldUtility)
double EvaluateFieldAtPoint(const double &time, const array_1d< double, 3 > &coor, RealField::Pointer formula)
Definition: field_utility.h:70
std::vector< bool > mIsInArray
Definition: field_utility.h:224
VectorField< 3 >::Pointer mpVectorField
Definition: field_utility.h:223
RealField::Pointer mFormula
Definition: field_utility.h:221
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Holds a list of variables and their position in VariablesListDataValueContainer.
Definition: variables_list.h:50
Definition: vector_field.h:26
virtual void Evaluate(const double time, const array_1d< double, 3 > &coor, array_1d< double, 3 > &vector, const int i_thread=0)
Definition: vector_field.h:46
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
time
Definition: face_heat.py:85
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17