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] Expose HasMasterSlaveConstraint from ModelPart to python #11582

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 5 additions & 7 deletions kratos/python/add_model_part_to_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
#include "python/add_model_part_to_python.h"
#include "python/containers_interface.h"

namespace Kratos
{

namespace Python
namespace Kratos::Python
{

template<class TDataType>
Expand Down Expand Up @@ -938,6 +935,9 @@ void AddModelPartToPython(pybind11::module& m)
.def("GetNonHistoricalVariablesNames", [](ModelPart& rModelPart, ModelPart::ConditionsContainerType& rContainer, bool doFullSearch=false) -> std::unordered_set<std::string> {
return GetNonHistoricalVariablesNames(rModelPart, rContainer, doFullSearch);
})
.def("HasMasterSlaveConstraint", [](ModelPart& rModelPart, ModelPart::IndexType MasterSlaveConstraintId) -> bool {
return rModelPart.HasMasterSlaveConstraint(MasterSlaveConstraintId);
})
Comment on lines +938 to +940
Copy link
Member

Choose a reason for hiding this comment

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

Can't we do it without the lambda in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because of the mesh index...

Copy link
Member

Choose a reason for hiding this comment

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

Argggg... 😡

Copy link
Member Author

Choose a reason for hiding this comment

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

Mesh index delenda est

.def("GetMasterSlaveConstraint", ModelPartGetMasterSlaveConstraint1)
.def("GetMasterSlaveConstraints", ModelPartGetMasterSlaveConstraints1)
.def("RemoveMasterSlaveConstraint", ModelPartRemoveMasterSlaveConstraint1)
Expand All @@ -954,6 +954,4 @@ void AddModelPartToPython(pybind11::module& m)
;
}

} // namespace Python.

} // Namespace Kratos
} // namespace Kratos::Python.
13 changes: 13 additions & 0 deletions kratos/tests/test_model_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
import KratosMultiphysics

class TestModelPart(KratosUnittest.TestCase):
"""
This class defines a set of unit tests for the ModelParts. ModelParts are hierarchical structures within the Kratos simulation framework that allow for organizing and managing various aspects of a computational model, such as nodes, elements, conditions, constraints, and subdomains.
The tests within this class cover a range of ModelPart-related operations, including the creation of ModelParts, retrieval of parent and root ModelParts, the creation and removal of sub-model parts, and verification of ModelPart hierarchy and structure.
By running these tests, it is possible to ensure that the ModelPart management features in KratosMultiphysics are functioning as expected, facilitating the setup and manipulation of complex computational models for various engineering and scientific simulations.
"""

def test_model_part_sub_model_parts(self):
current_model = KratosMultiphysics.Model()

Expand Down Expand Up @@ -910,6 +918,8 @@ def test_model_part_master_slave_constraint(self):

c1 = KratosMultiphysics.MasterSlaveConstraint(10)
model_part.CreateNewMasterSlaveConstraint("LinearMasterSlaveConstraint", 1, n1, KratosMultiphysics.PRESSURE, n2, KratosMultiphysics.PRESSURE, 0.5, 0.0)
self.assertTrue(model_part.HasMasterSlaveConstraint(1))
self.assertFalse(model_part.HasMasterSlaveConstraint(2))

model_part.AddMasterSlaveConstraint(c1)

Expand All @@ -925,6 +935,8 @@ def test_model_part_master_slave_constraint(self):
subsub1 = sub1.CreateSubModelPart("subsub1")

ss1 = subsub1.CreateNewMasterSlaveConstraint("LinearMasterSlaveConstraint", 2, n1, KratosMultiphysics.PRESSURE, n2, KratosMultiphysics.PRESSURE, 0.5, 0.0)
self.assertTrue(model_part.HasMasterSlaveConstraint(1))
self.assertTrue(model_part.HasMasterSlaveConstraint(2))

self.assertTrue(ss1 in subsub1.MasterSlaveConstraints)
self.assertTrue(ss1 in sub1.MasterSlaveConstraints)
Expand Down Expand Up @@ -993,4 +1005,5 @@ def test_remove_nodes(self):
self.assertEqual(model_part.NumberOfNodes(0), 4)

if __name__ == '__main__':
KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(KratosMultiphysics.Logger.Severity.WARNING)
KratosUnittest.main()
Loading