From b8d8192a9b368d5ec3c1e60f7cf0f03ce4867e4c Mon Sep 17 00:00:00 2001 From: Vicente Mataix Ferrandiz Date: Mon, 10 Jul 2023 14:52:49 +0200 Subject: [PATCH] Applying intermediate comments --- ...reate_entities_from_geometries_modeler.cpp | 149 +++++++++--------- .../create_entities_from_geometries_modeler.h | 35 ++-- 2 files changed, 99 insertions(+), 85 deletions(-) diff --git a/kratos/modeler/create_entities_from_geometries_modeler.cpp b/kratos/modeler/create_entities_from_geometries_modeler.cpp index 18bedf48c308..a1362ef5b076 100644 --- a/kratos/modeler/create_entities_from_geometries_modeler.cpp +++ b/kratos/modeler/create_entities_from_geometries_modeler.cpp @@ -12,98 +12,95 @@ // System includes - // External includes - // Project includes #include "includes/parallel_environment.h" #include "utilities/variable_utils.h" #include "create_entities_from_geometries_modeler.h" - namespace Kratos { - template <> - void CreateEntitiesFromGeometriesModeler::RemoveModelPartEntities(ModelPart &rModelPart) - { - const SizeType n_elements = rModelPart.NumberOfElements(); - KRATOS_WARNING_IF("CreateEntitiesFromGeometriesModeler", n_elements != 0) - << "There are " << n_elements << " elements in '" << rModelPart.FullName() << "' model part. These are to be removed." << std::endl; - VariableUtils().SetFlag(TO_ERASE, true, rModelPart.Elements()); - rModelPart.RemoveElementsFromAllLevels(TO_ERASE); - } +template <> +void CreateEntitiesFromGeometriesModeler::RemoveModelPartEntities(ModelPart &rModelPart) +{ + const SizeType n_elements = rModelPart.NumberOfElements(); + KRATOS_WARNING_IF("CreateEntitiesFromGeometriesModeler", n_elements != 0) + << "There are " << n_elements << " elements in '" << rModelPart.FullName() << "' model part. These are to be removed." << std::endl; + VariableUtils().SetFlag(TO_ERASE, true, rModelPart.Elements()); + rModelPart.RemoveElementsFromAllLevels(TO_ERASE); +} + +template <> +void CreateEntitiesFromGeometriesModeler::RemoveModelPartEntities(ModelPart &rModelPart) +{ + const SizeType n_conditions = rModelPart.NumberOfConditions(); + KRATOS_WARNING_IF("CreateEntitiesFromGeometriesModeler", n_conditions != 0) + << "There are " << n_conditions << " conditions in '" << rModelPart.FullName() << "' model part. These are to be removed." << std::endl; + VariableUtils().SetFlag(TO_ERASE, true, rModelPart.Conditions()); + rModelPart.RemoveConditionsFromAllLevels(TO_ERASE); +} + +template <> +void CreateEntitiesFromGeometriesModeler::LoopEntitiesList(Parameters EntitiesList) +{ + for (auto& r_data : EntitiesList) { + // Get current substitution settings + const std::string& r_entity_name = r_data["element_name"].GetString(); + const std::string& r_model_part_name = r_data["model_part_name"].GetString(); + auto& r_model_part = mpModel->GetModelPart(r_model_part_name); - template <> - void CreateEntitiesFromGeometriesModeler::RemoveModelPartEntities(ModelPart &rModelPart) - { - const SizeType n_conditions = rModelPart.NumberOfConditions(); - KRATOS_WARNING_IF("CreateEntitiesFromGeometriesModeler", n_conditions != 0) - << "There are " << n_conditions << " conditions in '" << rModelPart.FullName() << "' model part. These are to be removed." << std::endl; - VariableUtils().SetFlag(TO_ERASE, true, rModelPart.Conditions()); - rModelPart.RemoveConditionsFromAllLevels(TO_ERASE); - } + // Wipe current model part entities + RemoveModelPartEntities(r_model_part); - template <> - void CreateEntitiesFromGeometriesModeler::LoopEntitiesList(Parameters EntitiesList) - { - for (auto& r_data : EntitiesList) { - // Get current substitution settings - const std::string entity_name = r_data["element_name"].GetString(); - const std::string model_part_name = r_data["model_part_name"].GetString(); - auto &r_model_part = mpModel->GetModelPart(model_part_name); - - // Wipe current model part entities - RemoveModelPartEntities(r_model_part); - - // Create submodelpart elements from geometries - CreateEntitiesFromGeometries(entity_name, r_model_part); - } + // Create submodelpart elements from geometries + CreateEntitiesFromGeometries(r_entity_name, r_model_part); } +} - template <> - void CreateEntitiesFromGeometriesModeler::LoopEntitiesList(Parameters EntitiesList) - { - for (auto& r_data : EntitiesList) { - // Get current substitution settings - const std::string entity_name = r_data["condition_name"].GetString(); - const std::string model_part_name = r_data["model_part_name"].GetString(); - auto &r_model_part = mpModel->GetModelPart(model_part_name); - - // Wipe current model part entities - RemoveModelPartEntities(r_model_part); - - // Create submodelpart conditions from geometries - CreateEntitiesFromGeometries(entity_name, r_model_part); - } - } +template <> +void CreateEntitiesFromGeometriesModeler::LoopEntitiesList(Parameters EntitiesList) +{ + for (auto& r_data : EntitiesList) { + // Get current substitution settings + const std::string& r_entity_name = r_data["condition_name"].GetString(); + const std::string& r_model_part_name = r_data["model_part_name"].GetString(); + auto& r_model_part = mpModel->GetModelPart(r_model_part_name); - void CreateEntitiesFromGeometriesModeler::SetupModelPart() - { - // Check parallelism - //TODO: Make this MPI compatible by renumbering the local ids - KRATOS_ERROR_IF(ParallelEnvironment::GetDefaultDataCommunicator().IsDistributed()) - << "CreateEntitiesFromGeometriesModeler is not MPI compatible yet." << std::endl; - - // Get the elements list from input settings - const auto &r_elements_list = mParameters.GetValue("elements_list"); - const SizeType n_element_pairs = r_elements_list.size(); - KRATOS_WARNING_IF("CreateEntitiesFromGeometriesModeler", mEchoLevel != 0 && n_element_pairs == 0) - << "No elements found in element list." << std::endl; - - // Loop the element list to create the correspoding entities - LoopEntitiesList(r_elements_list); - - // Get the conditions list from input settings - const auto &r_conditions_list = mParameters.GetValue("conditions_list"); - const SizeType n_condition_pairs = r_conditions_list.size(); - KRATOS_WARNING_IF("CreateEntitiesFromGeometriesModeler", mEchoLevel != 0 && n_condition_pairs == 0) - << "No conditions found in condition list." << std::endl; - - // Loop the condition list to create the correspoding entities - LoopEntitiesList(r_conditions_list); + // Wipe current model part entities + RemoveModelPartEntities(r_model_part); + + // Create submodelpart conditions from geometries + CreateEntitiesFromGeometries(r_entity_name, r_model_part); } +} + +void CreateEntitiesFromGeometriesModeler::SetupModelPart() +{ + // Check parallelism + //TODO: Make this MPI compatible by renumbering the local ids + KRATOS_ERROR_IF(ParallelEnvironment::GetDefaultDataCommunicator().IsDistributed()) + << "CreateEntitiesFromGeometriesModeler is not MPI compatible yet." << std::endl; + + // Get the elements list from input settings + const auto& r_elements_list = mParameters.GetValue("elements_list"); + const SizeType n_element_pairs = r_elements_list.size(); + KRATOS_WARNING_IF("CreateEntitiesFromGeometriesModeler", mEchoLevel != 0 && n_element_pairs == 0) + << "No elements found in element list." << std::endl; + + // Loop the element list to create the correspoding entities + LoopEntitiesList(r_elements_list); + + // Get the conditions list from input settings + const auto& r_conditions_list = mParameters.GetValue("conditions_list"); + const SizeType n_condition_pairs = r_conditions_list.size(); + KRATOS_WARNING_IF("CreateEntitiesFromGeometriesModeler", mEchoLevel != 0 && n_condition_pairs == 0) + << "No conditions found in condition list." << std::endl; + + // Loop the condition list to create the correspoding entities + LoopEntitiesList(r_conditions_list); +} } // namespace Kratos. diff --git a/kratos/modeler/create_entities_from_geometries_modeler.h b/kratos/modeler/create_entities_from_geometries_modeler.h index 5a2276de7fe6..2d2e5ead9200 100644 --- a/kratos/modeler/create_entities_from_geometries_modeler.h +++ b/kratos/modeler/create_entities_from_geometries_modeler.h @@ -32,11 +32,15 @@ namespace Kratos ///@{ /** + * @class CreateEntitiesFromGeometriesModeler + * @ingroup KratosCore * @brief Modeler to create element/condition entities from geometries - * Given a list of pairs of the type submodelpart name and entity (element/condition) name, + * @details Given a list of pairs of the type submodelpart name and entity (element/condition) name, * this modeler creates the corresponding entities from the submodelpart geometries. + * @author Ruben Zorrilla */ -class CreateEntitiesFromGeometriesModeler : public Modeler +class KRATOS_API(KRATOS_CORE) CreateEntitiesFromGeometriesModeler + : public Modeler { public: ///@name Type Definitions @@ -45,9 +49,6 @@ class CreateEntitiesFromGeometriesModeler : public Modeler /// Pointer definition of Modeler KRATOS_CLASS_POINTER_DEFINITION(CreateEntitiesFromGeometriesModeler); - // typedef std::size_t SizeType; - // typedef std::size_t IndexType; - ///@} ///@name Life Cycle ///@{ @@ -122,25 +123,41 @@ class CreateEntitiesFromGeometriesModeler : public Modeler ///@name Private members ///@{ - Model* mpModel = nullptr; + Model* mpModel = nullptr; /// The model considered in the geometry replacement ///@} ///@name Private Operations ///@{ + /** + * @brief Loops through a list of entities. + * @tparam TEntityType The type of entity. + * @param EntitiesList The list of entities. + */ template void LoopEntitiesList(Parameters EntitiesList); + /** + * @brief Removes entities from a model part. + * @tparam TEntityType The type of entity. + * @param rModelPart The model part from which entities will be removed. + */ template void RemoveModelPartEntities(ModelPart& rModelPart); + /** + * @brief Create entities from geometries. + * @param EntityName the name of the entity + * @param rModelPart the model part + */ template void CreateEntitiesFromGeometries( const std::string EntityName, - ModelPart& rModelPart) + ModelPart& rModelPart + ) { // Get entity prototype from KratosComponents - const auto &r_ref_entity = KratosComponents::Get(EntityName); + const auto& r_ref_entity = KratosComponents::Get(EntityName); // Create the entities container and allocate space TEntitiesContainerType entities_to_add; @@ -160,7 +177,7 @@ class CreateEntitiesFromGeometriesModeler : public Modeler } // Loop geometries to create the corresponding entities from them - for (auto &r_geom : rModelPart.Geometries()) { + for (auto& r_geom : rModelPart.Geometries()) { auto p_entity = r_ref_entity.Create(++max_id, r_geom, nullptr); entities_to_add.push_back(p_entity); }