Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Forbid Renaming ModelParts #12148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions kratos/containers/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,6 @@ void Model::DeleteModelPart( const std::string& rModelPartName )
KRATOS_CATCH("")
}

void Model::RenameModelPart( const std::string& OldName, const std::string& NewName )
{
KRATOS_TRY

KRATOS_ERROR_IF_NOT(this->HasModelPart(OldName)) << "The Old Name is not in model (as a root model part). Required old name was : " << OldName << std::endl;

KRATOS_ERROR_IF(this->HasModelPart(NewName)) << "The New Name is already existing in model. Proposed name was : " << NewName << std::endl;

mRootModelPartMap[OldName]->Name() = NewName; //change the name of the existing modelpart

CreateModelPart(NewName);

mRootModelPartMap[NewName].swap(mRootModelPartMap[OldName]);

mRootModelPartMap.erase(OldName);

KRATOS_CATCH("")
}


ModelPart& Model::GetModelPart(const std::string& rFullModelPartName)
{
Expand Down
8 changes: 0 additions & 8 deletions kratos/containers/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ class KRATOS_API(KRATOS_CORE) Model final
*/
void DeleteModelPart( const std::string& ModelPartName );

/**
* @brief This method renames a modelpart with a given name
* @details Raises an error in case the model part does not exists as root model part
* @param OldName The name of the model part to be renamed
* @param NewName The new name for the model part to be renamed
*/
void RenameModelPart( const std::string& OldName, const std::string& NewName );

/**
* @brief This method returns a model part given a certain name
* @details Iterates over the list of submodelparts of the root model part
Expand Down
5 changes: 0 additions & 5 deletions kratos/includes/model_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -1808,11 +1808,6 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
return mMeshes;
}

std::string& Name()
{
return mName;
}

Comment on lines -1811 to -1815
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes, time to go 👋

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particualr case yes, it makes sense

Copy link
Member

@loumalouomega loumalouomega Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_model_part_to_python.cpp:46:25: error: no match for 'operator=' (operand types are 'const std::string' {aka 'const std::__cxx11::basic_string<char>'} and 'const std::string' {aka 'const std::__cxx11::basic_string<char>'})

Looks like python binding is a bit hardcoded

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Algo agree with this one

std::string const& Name() const
{
return mName;
Expand Down
23 changes: 0 additions & 23 deletions kratos/tests/cpp_tests/containers/test_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,6 @@ KRATOS_TEST_CASE_IN_SUITE(ModelDeleteSubModelPart, KratosCoreFastSuite)
KRATOS_EXPECT_FALSE(model.HasModelPart("Main.Inlet1"));
}

KRATOS_TEST_CASE_IN_SUITE(ModelRenameModelPart, KratosCoreFastSuite)
{
Model model;

auto& model_part = model.CreateModelPart("Main");
model_part.CreateSubModelPart("Inlet1");
model_part.GetSubModelPart("Inlet1").CreateSubModelPart("SubSub");

KRATOS_EXPECT_TRUE(model.HasModelPart("Main"));
KRATOS_EXPECT_TRUE(model.HasModelPart("Main.Inlet1"));
KRATOS_EXPECT_TRUE(model.HasModelPart("Main.Inlet1.SubSub"));

model.RenameModelPart("Main", "Renamed");

KRATOS_EXPECT_FALSE(model.HasModelPart("Main"));
KRATOS_EXPECT_FALSE(model.HasModelPart("Main.Inlet1"));
KRATOS_EXPECT_FALSE(model.HasModelPart("Main.Inlet1.SubSub"));

KRATOS_EXPECT_TRUE(model.HasModelPart("Renamed"));
KRATOS_EXPECT_TRUE(model.HasModelPart("Renamed.Inlet1"));
KRATOS_EXPECT_TRUE(model.HasModelPart("Renamed.Inlet1.SubSub"));
}

KRATOS_TEST_CASE_IN_SUITE(ModelGetModel, KratosCoreFastSuite)
{
Model model;
Expand Down
Loading