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.
topology_updating_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: Philipp Hofer, https://github.com/PhiHo-eng
11 // Erich Wehrle, https://github.com/e-dub
12 // based on original file from
13 // Baumgärtner Daniel, https://github.com/dbaumgaertner
14 // Octaviano Malfavón Farías
15 // Eric Gonzales
16 //
17 // ==============================================================================
18 
19 #if !defined(KRATOS_TOPOLOGY_UPDATING_UTILITIES_H_INCLUDED)
20 #define KRATOS_TOPOLOGY_UPDATING_UTILITIES_H_INCLUDED
21 
22 // System includes
23 
24 // External includes
25 
26 // Project includes
27 
28 
29 // Application includes
34 
35 
36 namespace Kratos
37 {
38 
41 
45 
46 
50 
54 
58 
60 
65 {
66 public:
67 
70 
73 
77 
80  : mrModelPart(model_part)
81  {
82  }
83 
86  {
87  }
88 
89 
93 
94 
98 
99  // ---------------------------------------------------------------------------------------------------------------------------------------------
100  // --------------------------------- UPDATE DENSITIES -----------------------------------------------------------------------------------------
101  // ---------------------------------------------------------------------------------------------------------------------------------------------
102 
104  void UpdateDensitiesUsingOCMethod( char update_type[], double volfrac, double greyscale , double OptItr , double qmax)
105  {
106  KRATOS_TRY;
107 
108  if ( strcmp( update_type , "oc_algorithm" ) == 0 ){
110  KRATOS_INFO("[TopOpt]") << " Optimality Criterion Method (OC) chosen to solve the optimization problem" << std::endl;
111 
112  // Check if Grey Scale Filter should be used
113  double q = 1;
114  if (greyscale == 1)
115  {
116  if (OptItr < 10)
117  q = 1;
118  else
119  q = std::min(qmax, 1.1*q);
120 
121  KRATOS_INFO("[TopOpt]") << " Grey Scale Filter activated, q = " << q << std::endl;
122  }
123  else
124  {
125  KRATOS_INFO("[TopOpt]") << " Grey Scale Filter deactivated, q = " << q << std::endl;
126  }
127 
128  // Update Densities procedure
129  double l1 = 0.0;
130  double l2 = 1.0e12;
131  const double move = 0.2;
132  double sum_X_Phys;
133  int nele;
134  double x_new = 0.0;
135  double lmid = 0.0;
136  double model_size;
137 
138  // Bisection algorithm to find Lagrange Multiplier so that volume constraint is satisfied (lmid)
139  while ((l2-l1)/(l1+l2) > 0.001)
140  {
141  lmid = 0.5*(l2+l1);
142  sum_X_Phys = 0.0;
143  nele = 0;
144  x_new = 0.0;
145  model_size = 0.0;
146 
147  for( ModelPart::ElementIterator element_i = mrModelPart.ElementsBegin(); element_i!= mrModelPart.ElementsEnd(); element_i++ )
148  {
149  const double x_old = element_i->GetValue(X_PHYS_OLD);
150  const int solid_void = element_i->GetValue(SOLID_VOID);
151  const double dcdx = element_i->GetValue(DCDX);
152  const double dvdx = element_i->GetValue(DVDX);
153  const double initial_element_size = element_i->GetValue(INITIAL_ELEMENT_SIZE);
154 
155  // Update Density
156  // When q = 1, Grey Scale Filter is not activated, i.e., the results are in the classical OC update method
157  switch(solid_void)
158  {
159  // NORMAL elements
160  case 0:
161  {
162  x_new = std::max(0.0, std::max(x_old - move, std::min(1.0, pow(std::min(x_old + move, x_old * sqrt(-dcdx/dvdx/lmid)),q))));
163  break;
164  }
165  // ACTIVE elements (solid elements)
166  case 1:
167  {
168  x_new = 1;
169  break;
170  }
171  // PASSIVE elements (void elements)
172  case 2:
173  {
174  x_new = 0;
175  break;
176  }
177  default:
178  {
179  // If no element identification was found
180  KRATOS_INFO("[TopOpt]") << "This value for SOLID_VOID does not exist."<< std::endl;
181  }
182  }
183 
184  // Update of the calculated X_PHYS for the next iteration
185  element_i->SetValue(X_PHYS, x_new);
186 
187  // Updating additional quantities to determine the correct Lagrange Multiplier (lmid)
188  sum_X_Phys = sum_X_Phys + x_new*initial_element_size;
189  model_size += initial_element_size;
190  nele = nele + 1;
191  }
192 
193  if( sum_X_Phys > (model_size*volfrac))
194  l1=lmid;
195  else
196  l2=lmid;
197  }
198 
199  // Printing of results
200  KRATOS_INFO("[TopOpt]") << " Updating of values performed [ spent time = " << timer.ElapsedSeconds() << " ] " << std::endl;
201  } else {
202  KRATOS_ERROR << "No valid optimization_algorithm selected for the simulation. Selected one: " << update_type << std::endl;
203  }
204 
205  KRATOS_CATCH("");
206 
207  }
208 
209 
213 
214 
218 
219 
223 
225  virtual std::string Info() const
226  {
227  return "TopologyUpdatingUtilities";
228  }
229 
231  virtual void PrintInfo(std::ostream& rOStream) const
232  {
233  rOStream << "TopologyUpdatingUtilities";
234  }
235 
237  virtual void PrintData(std::ostream& rOStream) const
238  {
239  }
240 
241 
245 
246 
248 
249 protected:
252 
253 
257 
258 
262 
263 
267 
268 
272 
273 
277 
278 
282 
283 
285 
286 private:
289 
290 
294 
295  ModelPart& mrModelPart;
296 
300 
301 
305 
306 
310 
311 
315 
316 
320 
322  //TopologyUpdatingUtilities& operator=(TopologyUpdatingUtilities const& rOther);
323 
325  //TopologyUpdatingUtilities(TopologyUpdatingUtilities const& rOther);
326 
327 
329 
330 }; // Class TopologyUpdatingUtilities
331 
333 
336 
337 
341 
343 
344 
345 } // namespace Kratos.
346 
347 #endif /* KRATOS_TOPOLOGY_UPDATING_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
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
Solution utility that updates response values for next iteration.
Definition: topology_updating_utilities.h:65
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: topology_updating_utilities.h:237
void UpdateDensitiesUsingOCMethod(char update_type[], double volfrac, double greyscale, double OptItr, double qmax)
Finds the value of the X_PHYS (density) and updates it into the optimization problem.
Definition: topology_updating_utilities.h:104
TopologyUpdatingUtilities(ModelPart &model_part)
Default constructor.
Definition: topology_updating_utilities.h:79
virtual std::string Info() const
Turn back information as a string.
Definition: topology_updating_utilities.h:225
virtual ~TopologyUpdatingUtilities()
Destructor.
Definition: topology_updating_utilities.h:85
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: topology_updating_utilities.h:231
KRATOS_CLASS_POINTER_DEFINITION(TopologyUpdatingUtilities)
Pointer definition of TopologyUpdatingUtilities.
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_INFO(label)
Definition: logger.h:250
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
model_part
Definition: face_heat.py:14
q
Definition: generate_convection_diffusion_explicit_element.py:109
Definition: timer.py:1