Skip to content

Commit

Permalink
Merge pull request #11568 from KratosMultiphysics/core/document-missi…
Browse files Browse the repository at this point in the history
…ng-check-dof-test
  • Loading branch information
loumalouomega authored Sep 18, 2023
2 parents f72bc3d + d4d7c45 commit b10d5cb
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions kratos/tests/test_dofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
import KratosMultiphysics

class TestDofs(KratosUnittest.TestCase):
"""
This module contains unit tests for KratosMultiphysics DOF-related functionality.
It covers DOF creation, manipulation, and DOF lists.
"""

def __SetUpTestModelPart(self, model):
"""
Set up a test ModelPart with nodes and DOFs.
Args:
model (KratosMultiphysics.Model): The Kratos model to create the ModelPart in.
Returns:
KratosMultiphysics.ModelPart: The created ModelPart with nodes and DOFs.
"""
mp = model.CreateModelPart("Main")
mp.AddNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT)
mp.AddNodalSolutionStepVariable(KratosMultiphysics.REACTION)
Expand All @@ -24,6 +37,13 @@ def __SetUpTestModelPart(self, model):
return mp

def testDofExport(self):
"""
Test the export of DOF information.
This test creates a ModelPart with nodes and DOFs, exports and manipulates DOFs,
and performs various assertions.
"""
current_model = KratosMultiphysics.Model()
test_model_part = self.__SetUpTestModelPart(current_model)

Expand All @@ -35,11 +55,29 @@ def testDofExport(self):
dz = n.GetDof(KratosMultiphysics.DISPLACEMENT_Z)
p2 = n2.GetDof(KratosMultiphysics.PRESSURE)

# Fixing only displacement in X
n.Fix(KratosMultiphysics.DISPLACEMENT_X)
self.assertTrue(n.IsFixed(KratosMultiphysics.DISPLACEMENT_X))
self.assertFalse(n.IsFixed(KratosMultiphysics.DISPLACEMENT_Y))
self.assertFalse(n.IsFixed(KratosMultiphysics.DISPLACEMENT_Z))
self.assertFalse(n.IsFixed(KratosMultiphysics.PRESSURE))

# Release the displacement in X and checking again
n.Free(KratosMultiphysics.DISPLACEMENT_X)
self.assertFalse(n.IsFixed(KratosMultiphysics.DISPLACEMENT_X))
self.assertFalse(n.IsFixed(KratosMultiphysics.DISPLACEMENT_Y))
self.assertFalse(n.IsFixed(KratosMultiphysics.DISPLACEMENT_Z))
self.assertFalse(n.IsFixed(KratosMultiphysics.PRESSURE))

# Fixing again dof
n.Fix(KratosMultiphysics.DISPLACEMENT_X)

# Assign equation Id
dx.EquationId = 5
dy.EquationId = 6
dz.EquationId = 7

# Checks
self.assertEqual(p.GetVariable(), KratosMultiphysics.PRESSURE)
self.assertEqual(dx.GetVariable(), KratosMultiphysics.DISPLACEMENT_X)
self.assertEqual(dx.GetReaction(), KratosMultiphysics.REACTION_X)
Expand All @@ -50,6 +88,13 @@ def testDofExport(self):
self.assertGreater(p2,dz)

def testDofListValues(self):
"""
Test DOF list values and manipulation.
This test creates a ModelPart with nodes and DOFs, creates a DOF list, sets and
retrieves values, and performs assertions.
"""
current_model = KratosMultiphysics.Model()
test_model_part = self.__SetUpTestModelPart(current_model)

Expand Down Expand Up @@ -83,6 +128,13 @@ def testDofListValues(self):
self.assertEqual(p.GetSolutionStepValue(), 14.0)

def testDofListAppend(self):
"""
Test appending DOFs to a list.
This test creates a ModelPart with nodes and DOFs and appends DOFs to a list,
asserting the length of the list.
"""
current_model = KratosMultiphysics.Model()
test_model_part = self.__SetUpTestModelPart(current_model)

Expand All @@ -93,6 +145,13 @@ def testDofListAppend(self):
self.assertEqual(len(dofs_vector), test_model_part.NumberOfNodes())

def testDofListUnique(self):
"""
Test making a DOF list unique.
This test creates a ModelPart with nodes and DOFs, appends multiple copies of
the same DOF to a list, makes the list unique, and asserts its length.
"""
current_model = KratosMultiphysics.Model()
test_model_part = self.__SetUpTestModelPart(current_model)

Expand All @@ -107,4 +166,5 @@ def testDofListUnique(self):
self.assertEqual(len(dofs_vector), test_model_part.NumberOfNodes())

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

0 comments on commit b10d5cb

Please sign in to comment.