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.
interpolate_structural_solution_for_dem_utility.h
Go to the documentation of this file.
1 /*
2  * Author: Salva Latorre and Ignasi Pouplana
3  *
4  * latorre@cimne.upc.edu
5  * ipouplana@cimne.upc.edu
6  */
7 
8 #ifndef INTERPOLATE_STRUCTURAL_SOLUTION_FOR_DEM_UTILITY_H
9 #define INTERPOLATE_STRUCTURAL_SOLUTION_FOR_DEM_UTILITY_H
10 
11 #include "includes/variables.h"
12 #include <limits>
13 #include <iostream>
14 #include <iomanip>
15 
16 #ifdef _OPENMP
17 #include <omp.h>
18 #endif
19 
20 #include "includes/define.h"
21 #include "includes/condition.h"
22 #include "includes/model_part.h"
24 
25 namespace Kratos {
26 
28 
29  public:
30 
31  typedef ModelPart::NodesContainerType::ContainerType::iterator NodesIteratorType;
32 
34 
36 
38 
39  void SaveStructuralSolution(ModelPart& r_structural_model_part) {
40 
42 
43  const int NNodes = static_cast<int>(r_structural_model_part.Nodes().size());
44  ModelPart::NodesContainerType::iterator node_begin = r_structural_model_part.NodesBegin();
45 
46  #pragma omp parallel for
47  for (int i = 0; i < NNodes; i++) {
48 
49  ModelPart::NodesContainerType::iterator itNode = node_begin + i;
50 
51  array_1d<double,3>& r_current_velocity = itNode->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_VELOCITY);
52  noalias(r_current_velocity) = itNode->FastGetSolutionStepValue(VELOCITY);
53 
54  array_1d<double,3>& r_current_displacement = itNode->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_DISPLACEMENT);
55  noalias(r_current_displacement) = itNode->FastGetSolutionStepValue(DISPLACEMENT);
56 
57  array_1d<double,3>& r_smoothed_velocity = itNode->FastGetSolutionStepValue(SMOOTHED_STRUCTURAL_VELOCITY);
58  noalias(r_smoothed_velocity) = 1.0/3.0 * (itNode->FastGetSolutionStepValue(VELOCITY) + 2.0 * itNode->FastGetSolutionStepValue(SMOOTHED_STRUCTURAL_VELOCITY, 1));
59 
60  }
61 
62  KRATOS_CATCH("")
63  }
64 
65  void InterpolateStructuralSolution(ModelPart& r_structural_model_part, const double fem_delta_time, const double fem_time, const double dem_delta_time, const double dem_time) {
66 
68 
69  const double previous_fem_time = fem_time - fem_delta_time;
70  const double time_factor = (dem_time - previous_fem_time) / fem_delta_time;
71  const double previous_time_factor = (dem_time - dem_delta_time - previous_fem_time) / fem_delta_time;
72 
73  const int NNodes = static_cast<int>(r_structural_model_part.Nodes().size());
74  ModelPart::NodesContainerType::iterator node_begin = r_structural_model_part.NodesBegin();
75 
76 
77  #pragma omp parallel for
78  for (int i = 0; i < NNodes; i++) {
79 
80  ModelPart::NodesContainerType::iterator it_node = node_begin + i;
81 
82  noalias(it_node->Coordinates()) = it_node->GetInitialPosition().Coordinates()
83  + it_node->FastGetSolutionStepValue(DISPLACEMENT,1)
84  + (it_node->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_DISPLACEMENT) - it_node->FastGetSolutionStepValue(DISPLACEMENT,1)) * time_factor;
85 
86  array_1d<double,3>& r_velocity = it_node->FastGetSolutionStepValue(VELOCITY);
87  const array_1d<double,3>& previous_velocity = it_node->FastGetSolutionStepValue(SMOOTHED_STRUCTURAL_VELOCITY,1);
88  noalias(r_velocity) = previous_velocity + (it_node->FastGetSolutionStepValue(SMOOTHED_STRUCTURAL_VELOCITY) - previous_velocity) * time_factor;
89 
90  array_1d<double,3>& r_displacement = it_node->FastGetSolutionStepValue(DISPLACEMENT);
91  noalias(r_displacement) = it_node->Coordinates() - it_node->GetInitialPosition().Coordinates();
92 
93  array_1d<double, 3> previous_coordinates;
94  noalias(previous_coordinates) = it_node->GetInitialPosition().Coordinates()
95  + it_node->FastGetSolutionStepValue(DISPLACEMENT,1)
96  + (it_node->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_DISPLACEMENT) - it_node->FastGetSolutionStepValue(DISPLACEMENT,1)) * previous_time_factor;
97 
98  array_1d<double,3>& delta_displacement = it_node->FastGetSolutionStepValue(DELTA_DISPLACEMENT);
99  noalias(delta_displacement) = it_node->Coordinates() - previous_coordinates;
100  }
101 
102  KRATOS_CATCH("")
103  }
104 
105  void RestoreStructuralSolution(ModelPart& r_structural_model_part) {
106 
107  KRATOS_TRY
108 
109  const int NNodes = static_cast<int>(r_structural_model_part.Nodes().size());
110  ModelPart::NodesContainerType::iterator node_begin = r_structural_model_part.NodesBegin();
111 
112  #pragma omp parallel for
113  for (int i = 0; i < NNodes; i++) {
114 
115  ModelPart::NodesContainerType::iterator it_node = node_begin + i;
116 
117  array_1d<double,3>& r_velocity = it_node->FastGetSolutionStepValue(VELOCITY);
118  noalias(r_velocity) = it_node->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_VELOCITY);
119 
120  array_1d<double,3>& r_displacement = it_node->FastGetSolutionStepValue(DISPLACEMENT);
121  noalias(r_displacement) = it_node->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_DISPLACEMENT);
122 
123  noalias(it_node->Coordinates()) = it_node->GetInitialPosition().Coordinates() + it_node->FastGetSolutionStepValue(DISPLACEMENT);
124  }
125 
126  KRATOS_CATCH("")
127  }
128 
129  // void SaveStructuralSolution(ModelPart& r_structural_model_part) {
130 
131  // KRATOS_TRY
132 
133  // const int NNodes = static_cast<int>(r_structural_model_part.Nodes().size());
134  // ModelPart::NodesContainerType::iterator node_begin = r_structural_model_part.NodesBegin();
135 
136  // #pragma omp parallel for
137  // for (int i = 0; i < NNodes; i++) {
138 
139  // ModelPart::NodesContainerType::iterator itNode = node_begin + i;
140 
141  // array_1d<double,3>& r_current_velocity = itNode->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_VELOCITY);
142  // noalias(r_current_velocity) = itNode->FastGetSolutionStepValue(VELOCITY);
143 
144  // array_1d<double,3>& r_current_displacement = itNode->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_DISPLACEMENT);
145  // noalias(r_current_displacement) = itNode->FastGetSolutionStepValue(DISPLACEMENT);
146 
147  // array_1d<double,3>& r_smoothed_velocity = itNode->FastGetSolutionStepValue(SMOOTHED_STRUCTURAL_VELOCITY);
148  // noalias(r_smoothed_velocity) = 1.0/3.0 * (itNode->FastGetSolutionStepValue(VELOCITY) + 2.0 * itNode->FastGetSolutionStepValue(SMOOTHED_STRUCTURAL_VELOCITY, 1));
149 
150  // }
151 
152  // KRATOS_CATCH("")
153  // }
154 
155  // void InterpolateStructuralSolution(ModelPart& r_structural_model_part, const double fem_delta_time, const double fem_time, const double dem_delta_time, const double dem_time) {
156 
157  // KRATOS_TRY
158 
159  // const double previous_fem_time = fem_time - fem_delta_time;
160  // const double time_factor = (dem_time - previous_fem_time) / fem_delta_time;
161  // const double previous_time_factor = (dem_time - dem_delta_time - previous_fem_time) / fem_delta_time;
162 
163  // const int NNodes = static_cast<int>(r_structural_model_part.Nodes().size());
164  // ModelPart::NodesContainerType::iterator node_begin = r_structural_model_part.NodesBegin();
165 
166 
167  // #pragma omp parallel for
168  // for (int i = 0; i < NNodes; i++) {
169 
170  // ModelPart::NodesContainerType::iterator it_node = node_begin + i;
171 
172  // noalias(it_node->Coordinates()) = it_node->GetInitialPosition().Coordinates()
173  // + it_node->FastGetSolutionStepValue(DISPLACEMENT,1)
174  // + (it_node->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_DISPLACEMENT) - it_node->FastGetSolutionStepValue(DISPLACEMENT,1)) * time_factor;
175 
176  // array_1d<double,3>& r_velocity = it_node->FastGetSolutionStepValue(VELOCITY);
177  // const array_1d<double,3>& previous_velocity = it_node->FastGetSolutionStepValue(SMOOTHED_STRUCTURAL_VELOCITY,1);
178  // noalias(r_velocity) = previous_velocity + (it_node->FastGetSolutionStepValue(SMOOTHED_STRUCTURAL_VELOCITY) - previous_velocity) * time_factor;
179 
180  // array_1d<double,3>& r_displacement = it_node->FastGetSolutionStepValue(DISPLACEMENT);
181  // noalias(r_displacement) = it_node->Coordinates() - it_node->GetInitialPosition().Coordinates();
182 
183  // array_1d<double, 3> previous_coordinates;
184  // noalias(previous_coordinates) = it_node->GetInitialPosition().Coordinates()
185  // + it_node->FastGetSolutionStepValue(DISPLACEMENT,1)
186  // + (it_node->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_DISPLACEMENT) - it_node->FastGetSolutionStepValue(DISPLACEMENT,1)) * previous_time_factor;
187 
188  // array_1d<double,3>& delta_displacement = it_node->FastGetSolutionStepValue(DELTA_DISPLACEMENT);
189  // noalias(delta_displacement) = it_node->Coordinates() - previous_coordinates;
190  // }
191 
192  // KRATOS_CATCH("")
193  // }
194 
195  // void RestoreStructuralSolution(ModelPart& r_structural_model_part) {
196 
197  // KRATOS_TRY
198 
199  // const int NNodes = static_cast<int>(r_structural_model_part.Nodes().size());
200  // ModelPart::NodesContainerType::iterator node_begin = r_structural_model_part.NodesBegin();
201 
202  // #pragma omp parallel for
203  // for (int i = 0; i < NNodes; i++) {
204 
205  // ModelPart::NodesContainerType::iterator it_node = node_begin + i;
206 
207  // array_1d<double,3>& r_velocity = it_node->FastGetSolutionStepValue(VELOCITY);
208  // noalias(r_velocity) = it_node->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_VELOCITY);
209 
210  // array_1d<double,3>& r_displacement = it_node->FastGetSolutionStepValue(DISPLACEMENT);
211  // noalias(r_displacement) = it_node->FastGetSolutionStepValue(BACKUP_LAST_STRUCTURAL_DISPLACEMENT);
212 
213  // noalias(it_node->Coordinates()) = it_node->GetInitialPosition().Coordinates() + it_node->FastGetSolutionStepValue(DISPLACEMENT);
214  // }
215 
216  // KRATOS_CATCH("")
217  // }
218 
219  virtual std::string Info() const { return "";}
220 
221  virtual void PrintInfo(std::ostream& rOStream) const {}
222 
223  virtual void PrintData(std::ostream& rOStream) const {}
224 
225  private:
226 
228 
229  }; // class InterpolateStructuralSolutionForDEM
230 
231 } // namespace Kratos
232 
233 #endif // INTERPOLATE_STRUCTURAL_SOLUTION_FOR_DEM_UTILITY_H
Definition: interpolate_structural_solution_for_dem_utility.h:27
ModelPart::NodesContainerType::ContainerType::iterator NodesIteratorType
Definition: interpolate_structural_solution_for_dem_utility.h:31
virtual void PrintData(std::ostream &rOStream) const
Definition: interpolate_structural_solution_for_dem_utility.h:223
void SaveStructuralSolution(ModelPart &r_structural_model_part)
Definition: interpolate_structural_solution_for_dem_utility.h:39
void RestoreStructuralSolution(ModelPart &r_structural_model_part)
Definition: interpolate_structural_solution_for_dem_utility.h:105
virtual std::string Info() const
Definition: interpolate_structural_solution_for_dem_utility.h:219
InterpolateStructuralSolutionForDEM()
Definition: interpolate_structural_solution_for_dem_utility.h:35
virtual void PrintInfo(std::ostream &rOStream) const
Definition: interpolate_structural_solution_for_dem_utility.h:221
void InterpolateStructuralSolution(ModelPart &r_structural_model_part, const double fem_delta_time, const double fem_time, const double dem_delta_time, const double dem_time)
Definition: interpolate_structural_solution_for_dem_utility.h:65
KRATOS_CLASS_POINTER_DEFINITION(InterpolateStructuralSolutionForDEM)
virtual ~InterpolateStructuralSolutionForDEM()
Definition: interpolate_structural_solution_for_dem_utility.h:37
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
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
integer i
Definition: TensorModule.f:17