Skip to content

Commit 6e51738

Browse files
authored
Merge pull request #11492 from KratosMultiphysics/Kratos_M30_Deliverable
Kratos m30 deliverable eFlows4HPC (New Node-Neighbour Element Retrieval Function)
2 parents ed44a4a + 2b5f108 commit 6e51738

File tree

5 files changed

+74
-5
lines changed

5 files changed

+74
-5
lines changed

applications/RomApplication/custom_python/add_custom_utilities_to_python.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void AddCustomUtilitiesToPython(pybind11::module& m)
5050
.def_static("SetHRomComputingModelPart", &RomAuxiliaryUtilities::SetHRomComputingModelPart)
5151
.def_static("SetHRomVolumetricVisualizationModelPart", &RomAuxiliaryUtilities::SetHRomVolumetricVisualizationModelPart)
5252
.def_static("GetHRomConditionParentsIds", &RomAuxiliaryUtilities::GetHRomConditionParentsIds)
53+
.def_static("GetNodalNeighbouringElementIdsNotInHRom", &RomAuxiliaryUtilities::GetNodalNeighbouringElementIdsNotInHRom)
5354
.def_static("GetConditionIdsNotInHRomModelPart", &RomAuxiliaryUtilities::GetConditionIdsNotInHRomModelPart)
5455
.def_static("GetElementIdsNotInHRomModelPart", &RomAuxiliaryUtilities::GetElementIdsNotInHRomModelPart)
5556
.def_static("GetHRomMinimumConditionsIds", &RomAuxiliaryUtilities::GetHRomMinimumConditionsIds)

applications/RomApplication/custom_strategies/global_rom_builder_and_solver.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,10 @@ class GlobalROMBuilderAndSolver : public ResidualBasedBlockBuilderAndSolver<TSpa
640640

641641
Build(pScheme, rModelPart, rA, rb);
642642

643-
if (!mHromSimulation)
643+
if (mMonotonicityPreservingFlag) {
644644
BaseType::ApplyDirichletConditions(pScheme, rModelPart, rA, rDx, rb);
645-
646-
if (mMonotonicityPreservingFlag)
647645
MonotonicityPreserving(rA, rb);
646+
}
648647

649648
ProjectROM(rModelPart, rA, rb);
650649

applications/RomApplication/custom_utilities/rom_auxiliary_utilities.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,34 @@ std::vector<IndexType> RomAuxiliaryUtilities::GetHRomConditionParentsIds(
335335
return parent_ids;
336336
}
337337

338+
std::vector<IndexType> RomAuxiliaryUtilities::GetNodalNeighbouringElementIdsNotInHRom(
339+
ModelPart& rModelPart,
340+
ModelPart& rGivenModelPart,
341+
const std::map<std::string, std::map<IndexType, double>>& rHRomWeights)
342+
{
343+
std::vector<IndexType> new_element_ids;
344+
const auto& r_elem_weights = rHRomWeights.at("Elements");
345+
346+
FindGlobalNodalEntityNeighboursProcess<ModelPart::ElementsContainerType> find_nodal_elements_neighbours_process(rModelPart);
347+
find_nodal_elements_neighbours_process.Execute();
348+
349+
for (const auto& r_node : rGivenModelPart.Nodes()) {
350+
const auto& r_neigh = r_node.GetValue(NEIGHBOUR_ELEMENTS);
351+
352+
// Add the neighbour elements to the HROM weights
353+
for (size_t i = 0; i < r_neigh.size(); ++i) {
354+
const auto& r_elem = r_neigh[i];
355+
356+
// Note that we check if the element has been already added by the HROM element selection strategy
357+
if (r_elem_weights.find(r_elem.Id() - 1) == r_elem_weights.end()) { //FIXME: FIX THE + 1 --> WE NEED TO WRITE REAL IDS IN THE WEIGHTS!!
358+
new_element_ids.push_back(r_elem.Id() - 1); //FIXME: FIX THE + 1 --> WE NEED TO WRITE REAL IDS IN THE WEIGHTS!!
359+
}
360+
}
361+
}
362+
363+
return new_element_ids;
364+
}
365+
338366
std::vector<IndexType> RomAuxiliaryUtilities::GetElementIdsNotInHRomModelPart(
339367
const ModelPart& rModelPart,
340368
const ModelPart& rModelPartWithElementsToInclude,

applications/RomApplication/custom_utilities/rom_auxiliary_utilities.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "includes/model_part.h"
2727
#include "includes/ublas_interface.h"
2828
#include "modified_shape_functions/modified_shape_functions.h"
29+
#include "processes/find_nodal_neighbours_process.h"
2930

3031
// Application includes
3132
#include "rom_application_variables.h"
@@ -106,6 +107,25 @@ class KRATOS_API(ROM_APPLICATION) RomAuxiliaryUtilities
106107
static std::vector<IndexType> GetHRomConditionParentsIds(
107108
const ModelPart& rModelPart,
108109
const std::map<std::string, std::map<IndexType, double>>& rHRomWeights);
110+
111+
/**
112+
* @brief Retrieve the IDs of elements neighboring nodes in a given sub-model part but not present in HRom weights.
113+
*
114+
* This function iterates over all the nodes in the provided sub-model part (`rGivenModelPart`) and collects
115+
* the IDs of the elements neighboring each node. The neighboring elements are determined using the
116+
* 'NEIGHBOUR_ELEMENTS' value attached to each node. The function then checks if these elements are already
117+
* present in `rHRomWeights`. If not, their IDs are added to the return vector. It's important to note that
118+
* this function assumes that the 'NEIGHBOUR_ELEMENTS' values are already computed for the nodes in the model part.
119+
*
120+
* @param rModelPart The complete model part which houses all the elements.
121+
* @param rGivenModelPart The sub-model part with nodes for which neighboring elements should be fetched.
122+
* @param rHRomWeights Map containing the original HROM conditions and elements weights.
123+
* @return std::vector<IndexType> A list of unique neighboring element IDs not already present in HRom weights.
124+
*/
125+
static std::vector<IndexType> GetNodalNeighbouringElementIdsNotInHRom(
126+
ModelPart& rModelPart,
127+
ModelPart& rGivenModelPart,
128+
const std::map<std::string, std::map<IndexType, double>>& rHRomWeights);
109129

110130
/**
111131
* @brief Identifies condition IDs from a given ModelPart that are not in the HROM weights

applications/RomApplication/python_scripts/hrom_training_utility.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self, solver, custom_settings):
4949
# Retrieve list of model parts from settings
5050
self.include_conditions_model_parts_list = settings["include_conditions_model_parts_list"].GetStringArray()
5151
self.include_elements_model_parts_list = settings["include_elements_model_parts_list"].GetStringArray()
52+
self.include_nodal_neighbouring_elements_model_parts_list = settings["include_nodal_neighbouring_elements_model_parts_list"].GetStringArray()
5253

5354
# Check if the model parts exist
5455
for model_part_name in self.include_conditions_model_parts_list:
@@ -132,7 +133,7 @@ def CreateHRomModelParts(self):
132133

133134
# Output the HROM model part in mdpa format
134135
hrom_output_name = "{}HROM".format(model_part_output_name)
135-
model_part_io = KratosMultiphysics.ModelPartIO(hrom_output_name, KratosMultiphysics.IO.WRITE | KratosMultiphysics.IO.MESH_ONLY)
136+
model_part_io = KratosMultiphysics.ModelPartIO(hrom_output_name, KratosMultiphysics.IO.WRITE | KratosMultiphysics.IO.MESH_ONLY | KratosMultiphysics.IO.SCIENTIFIC_PRECISION)
136137
model_part_io.WriteModelPart(hrom_main_model_part)
137138
KratosMultiphysics.kratos_utilities.DeleteFileIfExisting("{}.time".format(hrom_output_name))
138139
if self.echo_level > 0:
@@ -153,7 +154,7 @@ def CreateHRomModelParts(self):
153154

154155
# Write the HROM visualization mesh
155156
hrom_vis_output_name = "{}HROMVisualization".format(model_part_output_name)
156-
model_part_io = KratosMultiphysics.ModelPartIO(hrom_vis_output_name, KratosMultiphysics.IO.WRITE | KratosMultiphysics.IO.MESH_ONLY)
157+
model_part_io = KratosMultiphysics.ModelPartIO(hrom_vis_output_name, KratosMultiphysics.IO.WRITE | KratosMultiphysics.IO.MESH_ONLY | KratosMultiphysics.IO.SCIENTIFIC_PRECISION)
157158
model_part_io.WriteModelPart(hrom_visualization_model_part)
158159
KratosMultiphysics.kratos_utilities.DeleteFileIfExisting("{}.time".format(hrom_vis_output_name))
159160
if self.echo_level > 0:
@@ -170,6 +171,7 @@ def __GetHRomTrainingDefaultSettings(cls):
170171
"projection_strategy": "galerkin",
171172
"include_conditions_model_parts_list": [],
172173
"include_elements_model_parts_list": [],
174+
"include_nodal_neighbouring_elements_model_parts_list":[],
173175
"include_minimum_condition": false,
174176
"include_condition_parents": true
175177
}""")
@@ -247,6 +249,25 @@ def AppendHRomWeightsToRomParameters(self):
247249

248250
# If needed, update your weights and indexes using __AddSelectedElementsWithZeroWeights function with the new_elements
249251
weights, indexes = self.__AddSelectedElementsWithZeroWeights(weights, indexes, new_elements)
252+
253+
# Add nodal neighbouring elements
254+
for model_part_name in self.include_nodal_neighbouring_elements_model_parts_list:
255+
# Check if the sub model part exists
256+
if self.solver.model.HasModelPart(model_part_name):
257+
nodal_neighbours_model_part = self.solver.model.GetModelPart(model_part_name)
258+
259+
# Call the GetNodalNeighbouringElementIdsNotInHRom function
260+
new_nodal_neighbours = KratosROM.RomAuxiliaryUtilities.GetNodalNeighbouringElementIdsNotInHRom(
261+
root_model_part, # The complete model part
262+
nodal_neighbours_model_part, # The model part containing the nodal neighbouring elements to be included
263+
hrom_weights)
264+
265+
# Add the new nodal neighbouring elements to the elements dict with a null weight
266+
for element_id in new_nodal_neighbours:
267+
hrom_weights["Elements"][element_id] = 0.0
268+
269+
# If needed, update your weights and indexes using __AddSelectedElementsWithZeroWeights function with the new_nodal_neighbours
270+
weights, indexes = self.__AddSelectedElementsWithZeroWeights(weights, indexes, new_nodal_neighbours)
250271

251272
# If required, keep at least one condition per submodelpart
252273
# This might be required by those BCs involving the faces (e.g. slip BCs)

0 commit comments

Comments
 (0)