Skip to content

Commit

Permalink
Merge pull request #12218 from KratosMultiphysics/optapp/utils/rename…
Browse files Browse the repository at this point in the history
…_modelpart_utils

[OptApp] Rename OptApp/ModelPartUtils to OptAppModelPartUtils
  • Loading branch information
sunethwarna authored Mar 21, 2024
2 parents 62246ff + b572a2f commit 08c546a
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "custom_utilities/collective_expression.h"
#include "custom_utilities/collective_expression_io.h"
#include "custom_utilities/container_expression_utils.h"
#include "custom_utilities/geometrical/model_part_utils.h"
#include "custom_utilities/geometrical/opt_app_model_part_utils.h"
#include "custom_utilities/geometrical/symmetry_utility.h"
#include "custom_utilities/implicit_filter_utils.h"
#include "custom_utilities/optimization_utils.h"
Expand Down Expand Up @@ -129,10 +129,10 @@ void AddCustomUtilitiesToPython(pybind11::module& m)
.def("ApplyOnScalarField", &SymmetryUtility::ApplyOnScalarField)
;

m.def_submodule("ModelPartUtils")
.def("LogModelPartStatus", &ModelPartUtils::LogModelPartStatus, py::arg("model_part"), py::arg("status_to_log"))
.def("GetModelPartStatusLog", &ModelPartUtils::GetModelPartStatusLog, py::arg("model_part"))
.def("CheckModelPartStatus", &ModelPartUtils::CheckModelPartStatus, py::arg("model_part"), py::arg("status_to_check"))
m.def_submodule("OptAppModelPartUtils")
.def("LogModelPartStatus", &OptAppModelPartUtils::LogModelPartStatus, py::arg("model_part"), py::arg("status_to_log"))
.def("GetModelPartStatusLog", &OptAppModelPartUtils::GetModelPartStatusLog, py::arg("model_part"))
.def("CheckModelPartStatus", &OptAppModelPartUtils::CheckModelPartStatus, py::arg("model_part"), py::arg("status_to_check"))
.def("GetModelPartsWithCommonReferenceEntities", [](
const std::vector<ModelPart*>& rEvaluatedModelPartsList,
const std::vector<ModelPart*>& rReferenceModelPartsList,
Expand All @@ -141,7 +141,7 @@ void AddCustomUtilitiesToPython(pybind11::module& m)
const bool AreElementsConsidered,
const bool AreParentsConsidered,
const IndexType EchoLevel){
const auto& r_model_parts = ModelPartUtils::GetModelPartsWithCommonReferenceEntities(
const auto& r_model_parts = OptAppModelPartUtils::GetModelPartsWithCommonReferenceEntities(
rEvaluatedModelPartsList,
rReferenceModelPartsList,
AreNodesConsidered,
Expand All @@ -164,11 +164,11 @@ void AddCustomUtilitiesToPython(pybind11::module& m)
"are_elements_considered"_a,
"are_parents_considered"_a,
"echo_level"_a = 0)
.def("RemoveModelPartsWithCommonReferenceEntitiesBetweenReferenceListAndExaminedList", &ModelPartUtils::RemoveModelPartsWithCommonReferenceEntitiesBetweenReferenceListAndExaminedList,
.def("RemoveModelPartsWithCommonReferenceEntitiesBetweenReferenceListAndExaminedList", &OptAppModelPartUtils::RemoveModelPartsWithCommonReferenceEntitiesBetweenReferenceListAndExaminedList,
"model_parts_list"_a)
.def("GenerateModelPart",
[](ModelPart::ConditionsContainerType& rOriginConditions, ModelPart& rDestinationModelPart, const std::string& rElementName) {
ModelPartUtils::GenerateModelPart(rOriginConditions, rDestinationModelPart, KratosComponents<Element>::Get(rElementName));
OptAppModelPartUtils::GenerateModelPart(rOriginConditions, rDestinationModelPart, KratosComponents<Element>::Get(rElementName));
},
"conditions_container"_a,
"destination_model_part"_a,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "optimization_application_variables.h"

// Include base h
#include "model_part_utils.h"
#include "opt_app_model_part_utils.h"

namespace Kratos {

Expand Down Expand Up @@ -502,7 +502,7 @@ void PopulateModelPart(

} // namespace ModelPartHelperUtils

std::vector<ModelPart*> ModelPartUtils::GetModelPartsWithCommonReferenceEntities(
std::vector<ModelPart*> OptAppModelPartUtils::GetModelPartsWithCommonReferenceEntities(
const std::vector<ModelPart*>& rExaminedModelPartsList,
const std::vector<ModelPart*>& rReferenceModelParts,
const bool AreNodesConsidered,
Expand Down Expand Up @@ -558,7 +558,7 @@ std::vector<ModelPart*> ModelPartUtils::GetModelPartsWithCommonReferenceEntities
examined_node_ids, examined_condition_geometry_node_ids,
examined_element_geometry_node_ids);

KRATOS_INFO_IF("ModelPartUtils", EchoLevel > 0)
KRATOS_INFO_IF("OptAppModelPartUtils", EchoLevel > 0)
<< "Created common entity model part using "
<< r_reference_model_part.FullName() << " for "
<< GetExaminedModelPartsInfo(
Expand All @@ -569,7 +569,7 @@ std::vector<ModelPart*> ModelPartUtils::GetModelPartsWithCommonReferenceEntities
auto p_model_part = &r_reference_model_part.GetSubModelPart(unique_mp_name);
output_model_parts[i] = p_model_part;

KRATOS_INFO_IF("ModelPartUtils", EchoLevel > 1)
KRATOS_INFO_IF("OptAppModelPartUtils", EchoLevel > 1)
<< "Retrieved common entity model part using "
<< r_reference_model_part.FullName() << " for "
<< GetExaminedModelPartsInfo(
Expand Down Expand Up @@ -602,7 +602,7 @@ std::vector<ModelPart*> ModelPartUtils::GetModelPartsWithCommonReferenceEntities
return output_model_parts;
}

void ModelPartUtils::RemoveModelPartsWithCommonReferenceEntitiesBetweenReferenceListAndExaminedList(
void OptAppModelPartUtils::RemoveModelPartsWithCommonReferenceEntitiesBetweenReferenceListAndExaminedList(
const std::vector<ModelPart*> rModelParts)
{
using namespace ModelPartHelperUtils;
Expand All @@ -619,7 +619,7 @@ void ModelPartUtils::RemoveModelPartsWithCommonReferenceEntitiesBetweenReference
}
}

void ModelPartUtils::LogModelPartStatus(
void OptAppModelPartUtils::LogModelPartStatus(
ModelPart& rModelPart,
const std::string& rStatus)
{
Expand All @@ -636,7 +636,7 @@ void ModelPartUtils::LogModelPartStatus(
}
}

std::vector<std::string> ModelPartUtils::GetModelPartStatusLog(ModelPart& rModelPart)
std::vector<std::string> OptAppModelPartUtils::GetModelPartStatusLog(ModelPart& rModelPart)
{
using namespace ModelPartHelperUtils;

Expand All @@ -647,7 +647,7 @@ std::vector<std::string> ModelPartUtils::GetModelPartStatusLog(ModelPart& rModel
}
}

bool ModelPartUtils::CheckModelPartStatus(
bool OptAppModelPartUtils::CheckModelPartStatus(
const ModelPart& rModelPart,
const std::string& rStatus)
{
Expand All @@ -662,7 +662,7 @@ bool ModelPartUtils::CheckModelPartStatus(
}
}

void ModelPartUtils::GenerateModelPart(
void OptAppModelPartUtils::GenerateModelPart(
ModelPart::ConditionsContainerType& rOriginContainer,
ModelPart& rDestinationModelPart,
const Element& rReferenceElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Kratos {
///@name Kratos Classes
///@{

class KRATOS_API(OPTIMIZATION_APPLICATION) ModelPartUtils
class KRATOS_API(OPTIMIZATION_APPLICATION) OptAppModelPartUtils
{
public:
///@name Type definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "utilities/openmp_utils.h"

// Application includes
#include "custom_utilities/geometrical/model_part_utils.h"
#include "custom_utilities/geometrical/opt_app_model_part_utils.h"
#include "optimization_application_variables.h"

// Include base h
Expand Down Expand Up @@ -99,7 +99,7 @@ void MaxOverhangAngleResponseUtils::CalculateSensitivity(
// calculate sensitivities for each and every model part w.r.t. their sensitivity variables list
for (const auto& it : rSensitivityVariableModelPartInfo) {
std::visit([&](auto&& r_variable) {
const auto& r_sensitivity_model_parts = ModelPartUtils::GetModelPartsWithCommonReferenceEntities(
const auto& r_sensitivity_model_parts = OptAppModelPartUtils::GetModelPartsWithCommonReferenceEntities(
it.second, rEvaluatedModelParts, false, true, false, false, 0);

// reset nodal common interface values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def __init__(self, name: str, model: Kratos.Model, parameters: Kratos.Parameters
def Initialize(self) -> None:
self.model_part = self.model_part_operation.GetModelPart()

if not KratosOA.ModelPartUtils.CheckModelPartStatus(self.model_part, "element_specific_properties_created"):
if not KratosOA.OptAppModelPartUtils.CheckModelPartStatus(self.model_part, "element_specific_properties_created"):
KratosOA.OptimizationUtils.CreateEntitySpecificPropertiesForContainer(self.model_part, self.model_part.Elements)
KratosOA.ModelPartUtils.LogModelPartStatus(self.model_part, "element_specific_properties_created")
KratosOA.OptAppModelPartUtils.LogModelPartStatus(self.model_part, "element_specific_properties_created")

def Check(self) -> None:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def __init__(self, name: str, model: Kratos.Model, parameters: Kratos.Parameters
def Initialize(self) -> None:
self.model_part = self.model_part_operation.GetModelPart()

if not KratosOA.ModelPartUtils.CheckModelPartStatus(self.model_part, "element_specific_properties_created"):
if not KratosOA.OptAppModelPartUtils.CheckModelPartStatus(self.model_part, "element_specific_properties_created"):
KratosOA.OptimizationUtils.CreateEntitySpecificPropertiesForContainer(self.model_part, self.model_part.Elements)
KratosOA.ModelPartUtils.LogModelPartStatus(self.model_part, "element_specific_properties_created")
KratosOA.OptAppModelPartUtils.LogModelPartStatus(self.model_part, "element_specific_properties_created")

# initiliaze the filter
self.filter.Initialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ def _FillComputingModelPart(self) -> None:
# here we have conditions in the origin model part. Now we have to create elements using
# the geometries of the conditions. There cannot be volume conditions in Kratos, therefore,
# there can be only surface conditions, hence only required to create surface elements.
KOA.ModelPartUtils.GenerateModelPart(self.GetOriginModelPart().Conditions, self.GetComputingModelPart(), f"HelmholtzSurfaceElement3D{self._GetContainerTypeNumNodes(self.GetOriginModelPart().Conditions)}N")
KOA.OptAppModelPartUtils.GenerateModelPart(self.GetOriginModelPart().Conditions, self.GetComputingModelPart(), f"HelmholtzSurfaceElement3D{self._GetContainerTypeNumNodes(self.GetOriginModelPart().Conditions)}N")
else:
raise RuntimeError(f"No elements or conditions found in {self.GetOriginModelPart()}.")
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ def _FillComputingModelPart(self) -> None:
# here we have conditions in the origin model part. Now we have to create elements using
# the geometries of the conditions. There cannot be volume conditions in Kratos, therefore,
# there can be only surface conditions, hence only required to create surface elements.
KOA.ModelPartUtils.GenerateModelPart(self.GetOriginModelPart().Conditions, self.GetComputingModelPart(), f"HelmholtzVectorSurfaceElement3D{self._GetContainerTypeNumNodes(self.GetOriginModelPart().Conditions)}N")
KOA.OptAppModelPartUtils.GenerateModelPart(self.GetOriginModelPart().Conditions, self.GetComputingModelPart(), f"HelmholtzVectorSurfaceElement3D{self._GetContainerTypeNumNodes(self.GetOriginModelPart().Conditions)}N")
else:
raise RuntimeError(f"No elements or conditions found in {self.GetOriginModelPart()}.")
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def GetModelPartFullName(self) -> str:
# now check in the status messages of the root model part whether this operation is already added.
status_msg_prefix = "ModelPartUtilities_created#"
status_msg_suffix = f"#{self.operation_type.name}#{self.add_neighbours:d}#" + "#".join(self.list_of_operation_model_part_full_names)
status_msg_log = KratosOA.ModelPartUtils.GetModelPartStatusLog(self.GetRootModelPart())
status_msg_log = KratosOA.OptAppModelPartUtils.GetModelPartStatusLog(self.GetRootModelPart())
for status_msg in status_msg_log:
if status_msg.startswith(status_msg_prefix) and status_msg.endswith(status_msg_suffix):
# found the same operation done on a different model part, hence sending that name
Expand All @@ -56,7 +56,7 @@ def GetModelPartFullName(self) -> str:
raise RuntimeError(f"Found an already existing submodel part named \"{self.suggested_model_part_name}\" in {self.root_model_part.FullName()} without the required operation identifier = \"{status_msg_suffix}\".")

self.status_msg = f"{status_msg_prefix}{self.suggested_model_part_name}{status_msg_suffix}"
KratosOA.ModelPartUtils.LogModelPartStatus(self.GetRootModelPart(), self.status_msg)
KratosOA.OptAppModelPartUtils.LogModelPartStatus(self.GetRootModelPart(), self.status_msg)
return f"{self.GetRootModelPart().FullName()}.{self.suggested_model_part_name}"

def GetModelPart(self) -> Kratos.ModelPart:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def AssembleTestSuites():
smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_component_data_view.TestComponentDataView]))
smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_optimization_info.TestOptimizationInfo]))
smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_optimization_utils.TestOptimizationUtils]))
smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_model_part_utils.TestModelPartUtils]))
smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_model_part_utils.TestOptAppModelPartUtils]))
smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_model_part_utils.TestModelPartUtilities]))
smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_container_expression_utils.TestContainerExpressionUtils]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def AssembleTestSuites():
smallMPISuite = suites['mpi_small']

# adding custom process tests
smallMPISuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_model_part_utils.TestModelPartUtils]))
smallMPISuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_model_part_utils.TestOptAppModelPartUtils]))
smallMPISuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_container_expression_utils.TestContainerExpressionUtils]))

smallMPISuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_container_expression.TestConditionPropertiesExpression]))
Expand Down
Loading

0 comments on commit 08c546a

Please sign in to comment.