Skip to content

Commit

Permalink
Applying intermediate comments
Browse files Browse the repository at this point in the history
  • Loading branch information
loumalouomega committed Jul 10, 2023
1 parent c1bb3f1 commit b8d8192
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 85 deletions.
149 changes: 73 additions & 76 deletions kratos/modeler/create_entities_from_geometries_modeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element>(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<Element>(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<Condition>(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<Element>(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<Condition>(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<Element>(r_model_part);

template <>
void CreateEntitiesFromGeometriesModeler::LoopEntitiesList<Element>(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<Element>(r_model_part);

// Create submodelpart elements from geometries
CreateEntitiesFromGeometries<Element, ModelPart::ElementsContainerType>(entity_name, r_model_part);
}
// Create submodelpart elements from geometries
CreateEntitiesFromGeometries<Element, ModelPart::ElementsContainerType>(r_entity_name, r_model_part);
}
}

template <>
void CreateEntitiesFromGeometriesModeler::LoopEntitiesList<Condition>(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<Condition>(r_model_part);

// Create submodelpart conditions from geometries
CreateEntitiesFromGeometries<Condition, ModelPart::ConditionsContainerType>(entity_name, r_model_part);
}
}
template <>
void CreateEntitiesFromGeometriesModeler::LoopEntitiesList<Condition>(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<Element>(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<Condition>(r_conditions_list);
// Wipe current model part entities
RemoveModelPartEntities<Condition>(r_model_part);

// Create submodelpart conditions from geometries
CreateEntitiesFromGeometries<Condition, ModelPart::ConditionsContainerType>(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<Element>(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<Condition>(r_conditions_list);
}

} // namespace Kratos.

Expand Down
35 changes: 26 additions & 9 deletions kratos/modeler/create_entities_from_geometries_modeler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
///@{
Expand Down Expand Up @@ -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 <class TEntityType>
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 <class TEntityType>
void RemoveModelPartEntities(ModelPart& rModelPart);

/**
* @brief Create entities from geometries.
* @param EntityName the name of the entity
* @param rModelPart the model part
*/
template <class TEntityType, class TEntitiesContainerType>
void CreateEntitiesFromGeometries(
const std::string EntityName,
ModelPart& rModelPart)
ModelPart& rModelPart
)
{
// Get entity prototype from KratosComponents
const auto &r_ref_entity = KratosComponents<TEntityType>::Get(EntityName);
const auto& r_ref_entity = KratosComponents<TEntityType>::Get(EntityName);

// Create the entities container and allocate space
TEntitiesContainerType entities_to_add;
Expand All @@ -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);
}
Expand Down

0 comments on commit b8d8192

Please sign in to comment.