2222#include " boost/range/adaptor/filtered.hpp"
2323#include " custom_elements/steady_state_Pw_piping_element.hpp"
2424#include " custom_strategies/strategies/geo_mechanics_newton_raphson_strategy.hpp"
25+ #include " custom_utilities/transport_equation_utilities.hpp"
2526#include " geo_mechanics_application_variables.h"
2627
2728#include < chrono>
@@ -45,11 +46,9 @@ class GeoMechanicsNewtonRaphsonErosionProcessStrategy
4546 using DofsArrayType = typename BaseType::DofsArrayType;
4647 using TSystemMatrixType = typename BaseType::TSystemMatrixType;
4748 using TSystemVectorType = typename BaseType::TSystemVectorType;
48- using filtered_elements =
49- typename boost::range_detail::filtered_range<std::function<bool (Element*)>, std::vector<Element*>>;
50- using PropertiesType = Properties;
51- using NodeType = Node;
52- using GeometryType = Geometry<NodeType>;
49+ using PropertiesType = Properties;
50+ using NodeType = Node;
51+ using GeometryType = Geometry<NodeType>;
5352
5453 GeoMechanicsNewtonRaphsonErosionProcessStrategy (ModelPart& model_part,
5554 typename TSchemeType::Pointer pScheme,
@@ -76,7 +75,17 @@ class GeoMechanicsNewtonRaphsonErosionProcessStrategy
7675
7776 // get piping elements
7877 std::vector<Element*> PipeElements = GetPipingElements ();
79- unsigned int n_el = PipeElements.size (); // number of piping elements
78+
79+ auto piping_interface_elements = std::vector<SteadyStatePwPipingElement<2 , 4 >*>{};
80+ std::transform (
81+ PipeElements.begin (), PipeElements.end (), std::back_inserter (piping_interface_elements),
82+ [](auto p_element) { return dynamic_cast <SteadyStatePwPipingElement<2 , 4 >*>(p_element); });
83+ KRATOS_DEBUG_ERROR_IF (std::any_of (piping_interface_elements.begin (),
84+ piping_interface_elements.end (), [](auto p_element) {
85+ return p_element == nullptr ;
86+ })) << " Not all open piping elements could be downcast to SteadyStatePwPipingElement<2, 4>*\n " ;
87+
88+ unsigned int n_el = PipeElements.size (); // number of piping elements
8089
8190 // get initially open pipe elements
8291 unsigned int openPipeElements = this ->InitialiseNumActivePipeElements (PipeElements);
@@ -104,7 +113,7 @@ class GeoMechanicsNewtonRaphsonErosionProcessStrategy
104113 std::function<bool (Element*)> filter = [](Element* i) {
105114 return i->Has (PIPE_ACTIVE) && i->GetValue (PIPE_ACTIVE);
106115 };
107- filtered_elements OpenPipeElements = PipeElements | boost::adaptors::filtered (filter);
116+ auto OpenPipeElements = piping_interface_elements | boost::adaptors::filtered (filter);
108117 KRATOS_INFO_IF (" PipingLoop" , this ->GetEchoLevel () > 0 && rank == 0 )
109118 << " Number of Open Pipe Elements: " << boost::size (OpenPipeElements) << std::endl;
110119
@@ -242,21 +251,6 @@ class GeoMechanicsNewtonRaphsonErosionProcessStrategy
242251 return nOpenElements;
243252 }
244253
245- // / <summary>
246- // / Calculates the pipe particle diameter according to the modified Sellmeijer rule if selected.
247- // / Else the pipe particle diameter is equal to the d70.
248- // / </summary>
249- // / <param name="Prop"></param>
250- // / <returns></returns>
251- double CalculateParticleDiameter (const PropertiesType& Prop)
252- {
253- double diameter;
254-
255- if (Prop[PIPE_MODIFIED_D]) diameter = 2.08e-4 * pow ((Prop[PIPE_D_70] / 2.08e-4 ), 0.4 );
256- else diameter = Prop[PIPE_D_70];
257- return diameter;
258- }
259-
260254 // / <summary>
261255 // / Calculates the maximum pipe height which the algorithm will allow
262256 // / </summary>
@@ -270,8 +264,8 @@ class GeoMechanicsNewtonRaphsonErosionProcessStrategy
270264 // loop over all elements
271265 for (Element* pipe_element : pipe_elements) {
272266 // calculate pipe particle diameter of pipe element
273- PropertiesType prop = pipe_element->GetProperties ();
274- double particle_diameter = this -> CalculateParticleDiameter (prop);
267+ PropertiesType prop = pipe_element->GetProperties ();
268+ double particle_diameter = GeoTransportEquationUtilities:: CalculateParticleDiameter (prop);
275269
276270 // get maximum pipe particle diameter of all pipe elements
277271 if (particle_diameter > max_diameter) {
@@ -310,7 +304,8 @@ class GeoMechanicsNewtonRaphsonErosionProcessStrategy
310304 GeoMechanicsNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>::FinalizeSolutionStep ();
311305 }
312306
313- bool check_pipe_equilibrium (filtered_elements open_pipe_elements, double amax, unsigned int mPipingIterations )
307+ template <typename FilteredElementType>
308+ bool check_pipe_equilibrium (const FilteredElementType& open_pipe_elements, double amax, unsigned int mPipingIterations )
314309 {
315310 bool equilibrium = false ;
316311 bool converged = true ;
@@ -338,13 +333,12 @@ class GeoMechanicsNewtonRaphsonErosionProcessStrategy
338333 // Update depth of open piping Elements
339334 equilibrium = true ;
340335 for (auto OpenPipeElement : open_pipe_elements) {
341- auto pElement = static_cast <SteadyStatePwPipingElement<2 , 4 >*>(OpenPipeElement);
342336 // get open pipe element geometry and properties
343337 auto & Geom = OpenPipeElement->GetGeometry ();
344338 auto & prop = OpenPipeElement->GetProperties ();
345339
346340 // calculate equilibrium pipe height and get current pipe height
347- double eq_height = pElement ->CalculateEquilibriumPipeHeight (
341+ double eq_height = OpenPipeElement ->CalculateEquilibriumPipeHeight (
348342 prop, Geom, OpenPipeElement->GetValue (PIPE_ELEMENT_LENGTH));
349343 double current_height = OpenPipeElement->GetValue (PIPE_HEIGHT);
350344
@@ -420,13 +414,14 @@ class GeoMechanicsNewtonRaphsonErosionProcessStrategy
420414 // / <param name="open_pipe_elements"> open pipe elements</param>
421415 // / <param name="grow"> boolean to check if pipe grows</param>
422416 // / <returns></returns>
423- void save_or_reset_pipe_heights (filtered_elements open_pipe_elements, bool grow)
417+ template <typename FilteredElementType>
418+ void save_or_reset_pipe_heights (const FilteredElementType& open_pipe_elements, bool grow)
424419 {
425- for (Element* OpenPipeElement : open_pipe_elements) {
420+ for (auto p_element : open_pipe_elements) {
426421 if (grow) {
427- OpenPipeElement ->SetValue (PREV_PIPE_HEIGHT, OpenPipeElement ->GetValue (PIPE_HEIGHT));
422+ p_element ->SetValue (PREV_PIPE_HEIGHT, p_element ->GetValue (PIPE_HEIGHT));
428423 } else {
429- OpenPipeElement ->SetValue (PIPE_HEIGHT, OpenPipeElement ->GetValue (PREV_PIPE_HEIGHT));
424+ p_element ->SetValue (PIPE_HEIGHT, p_element ->GetValue (PREV_PIPE_HEIGHT));
430425 }
431426 }
432427 }
0 commit comments