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.
structure_response_function_utilities.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: Baumgärtner Daniel, https://github.com/dbaumgaertner
11 // Octaviano Malfavón Farías
12 // Eric Gonzales
13 // Philipp Hofer
14 // Erich Wehrle
15 //
16 // ==============================================================================
17 
18 #if !defined(KRATOS_STRUCTURE_RESPONSE_FUNCTION_UTILITIES_H_INCLUDED)
19 #define KRATOS_STRUCTURE_RESPONSE_FUNCTION_UTILITIES_H_INCLUDED
20 
21 // System includes
22 
23 // External includes
24 
25 // Project includes
26 
27 // Application includes
30 
31 
32 namespace Kratos
33 {
34 
37 
41 
42 
46 
50 
54 
56 
61 {
62 public:
63 
66 
69 
73 
76  : mr_structure_model_part(model_part)
77  {
78  }
79 
82  {
83  }
84 
85 
89 
90 
94 
95  // ---------------------------------------------------------------------------------------------------------------------------------------------
96  // --------------------------------- COMPUTE STRAIN ENERGY -------------------------------------------------------------------------------------
97  // ---------------------------------------------------------------------------------------------------------------------------------------------
98 
101  {
102  KRATOS_TRY;
103 
105  KRATOS_INFO("[TopOpt]") << " Start calculating strain energy."<<std::endl;
106 
107  double Out = 0.0;
108  double Global_Strain_Energy = 0.0;
109 
110  // Loop over all elements to calculate their local objective function and sum it into the global objective function (Global Strain Energy)
111  for( ModelPart::ElementIterator element_i = mr_structure_model_part.ElementsBegin(); element_i!= mr_structure_model_part.ElementsEnd();
112  element_i++ )
113  {
114 
115  element_i->Calculate(LOCAL_STRAIN_ENERGY, Out, mr_structure_model_part.GetProcessInfo());
116 
117  Global_Strain_Energy += element_i->GetValue(LOCAL_STRAIN_ENERGY);
118 
119  }
120 
121  KRATOS_INFO("[TopOpt]") << " Strain energy calculated [ spent time = " << timer.ElapsedSeconds() << " ] " << std::endl;
122 
123  // Return this obtained Global Strain Energy value as the objective function of the complete system
124  return Global_Strain_Energy;
125 
126  KRATOS_CATCH("");
127  }
128 
130  {
131  KRATOS_TRY;
132 
134  KRATOS_INFO("[TopOpt]") <<" Start calculating volume fraction."<<std::endl;
135 
136  double Global_Volume_Fraction = 0.0;
137  double elemental_volume = 0.0;
138  double design_variable = 0.0;
139  double Total_volume = 0.0;
140 
141 
142  // Loop over all elements to obtain their X_PHYS and know how many elements the model has
143  for( ModelPart::ElementIterator element_i = mr_structure_model_part.ElementsBegin(); element_i!= mr_structure_model_part.ElementsEnd();
144  element_i++ )
145  {
146 
147  elemental_volume = element_i->GetValue(INITIAL_ELEMENT_SIZE);
148  design_variable = element_i->GetValue(X_PHYS);
149  Global_Volume_Fraction += (elemental_volume*design_variable); //
150  Total_volume += elemental_volume;
151  }
152 
153  // Calculate and return the Global Volume Fraction by knowing how many elements the model has
154  Global_Volume_Fraction = Global_Volume_Fraction/Total_volume;
155  KRATOS_INFO("[TopOpt]") <<" Global Volume Fraction: " << Global_Volume_Fraction << std::endl;
156  KRATOS_INFO("[TopOpt]") <<" Volume fraction calculated [ spent time = " << timer.ElapsedSeconds() << " ] " << std::endl;
157  return Global_Volume_Fraction;
158 
159  KRATOS_CATCH("");
160  }
161 
162 
166 
167 
171 
172 
176 
178  virtual std::string Info() const
179  {
180  return "StructureResponseFunctionUtilities";
181  }
182 
184  virtual void PrintInfo(std::ostream& rOStream) const
185  {
186  rOStream << "StructureResponseFunctionUtilities";
187  }
188 
190  virtual void PrintData(std::ostream& rOStream) const
191  {
192  }
193 
194 
198 
199 
201 
202 protected:
205 
206 
210 
211 
215 
216 
220 
221 
225 
226 
230 
231 
235 
236 
238 
239 private:
242 
243 
247 
248  ModelPart& mr_structure_model_part;
249 
253 
254 
258 
259 
263 
264 
268 
269 
273 
275  //StructureResponseFunctionUtilities& operator=(StructureResponseFunctionUtilities const& rOther);
276 
278  //StructureResponseFunctionUtilities(StructureResponseFunctionUtilities const& rOther);
279 
280 
282 
283 }; // Class StructureResponseFunctionUtilities
284 
286 
289 
290 
294 
296 
297 
298 } // namespace Kratos.
299 
300 #endif /* KRATOS_STRUCTURE_RESPONSE_FUNCTION_UTILITIES_H_INCLUDED */
Definition: builtin_timer.h:26
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
Solution utility to compute structural analysis responses.
Definition: structure_response_function_utilities.h:61
double ComputeVolumeFraction()
Definition: structure_response_function_utilities.h:129
KRATOS_CLASS_POINTER_DEFINITION(StructureResponseFunctionUtilities)
Pointer definition of StructureResponseFunctionUtilities.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: structure_response_function_utilities.h:184
virtual std::string Info() const
Turn back information as a string.
Definition: structure_response_function_utilities.h:178
StructureResponseFunctionUtilities(ModelPart &model_part)
Default constructor.
Definition: structure_response_function_utilities.h:75
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: structure_response_function_utilities.h:190
double ComputeStrainEnergy()
Computes the strain energy as the objective function of the optimization problem.
Definition: structure_response_function_utilities.h:100
virtual ~StructureResponseFunctionUtilities()
Destructor.
Definition: structure_response_function_utilities.h:81
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO(label)
Definition: logger.h:250
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
model_part
Definition: face_heat.py:14
Definition: timer.py:1