def __init__(self, model_part_to_be_filled, lower_corner_coordinates, higher_corner_coordinates, number_of_divisions_per_dimension, element_name='VMS3D', condition_name='WallCondition3D'): self.lc = lower_corner_coordinates self.hc = higher_corner_coordinates self.n_divisions = number_of_divisions_per_dimension self.mp = model_part_to_be_filled parameters = Parameters("{}") parameters.AddEmptyValue("element_name").SetString(element_name) parameters.AddEmptyValue("condition_name").SetString(condition_name) parameters.AddEmptyValue("create_skin_sub_model_part").SetBool(False) parameters.AddEmptyValue("number_of_divisions").SetInt(self.n_divisions) domain_geometry = Kratos.Hexahedra3D8(Node(1, self.hc[0], self.hc[1], self.lc[2]), Node(2, self.lc[0], self.hc[1], self.lc[2]), Node(3, self.lc[0], self.lc[1], self.lc[2]), Node(4, self.hc[0], self.lc[1], self.lc[2]), Node(5, self.hc[0], self.hc[1], self.hc[2]), Node(6, self.lc[0], self.hc[1], self.hc[2]), Node(7, self.lc[0], self.lc[1], self.hc[2]), Node(8, self.hc[0], self.lc[1], self.hc[2])) self.mesh_generator_process = Kratos.StructuredMeshGeneratorProcess(domain_geometry, self.mp, parameters)
def test_matrix_interface(self): # Read and check a Matrix from a Parameters-Object tmp = Parameters("""{ "false_matrix_value": [[2, 1.5,3.3],[1,2]] }""") # Manually assign and check a Matrix mat = Matrix(3, 2) mat[0, 0] = 1.0 mat[0, 1] = 2.0 mat[1, 0] = 3.0 mat[1, 1] = 4.0 mat[2, 0] = 5.0 mat[2, 1] = 6.0 tmp.AddEmptyValue("matrix_value") tmp["matrix_value"].SetMatrix(mat) self.assertTrue(tmp["matrix_value"].IsMatrix()) A2 = tmp["matrix_value"].GetMatrix() self.assertEqual(A2[0, 0], 1.0) self.assertEqual(A2[0, 1], 2.0) self.assertEqual(A2[1, 0], 3.0) self.assertEqual(A2[1, 1], 4.0) self.assertEqual(A2[2, 0], 5.0) self.assertEqual(A2[2, 1], 6.0) # Check the IsMatrix Method self.assertFalse( tmp["false_matrix_value"].IsMatrix()) # Mis-sized Matrix # check that the errors of the GetMatrix method are thrown correctly with self.assertRaises(RuntimeError): tmp["false_matrix_value"].GetMatrix() # Mis-sized Matrix
def test_matrix_interface(self): # Read and check Matrices from a Parameters-Object tmp = Parameters("""{ "valid_matrices" : [ [[]], [[],[]], [[-9.81,8, 5.47]] ], "false_matrices" : [ [], [[[]]], [[3.3] , [1,2]], [[2,1.5,3.3] , [3,{"key":3},2]], [[2,1.5,3.3] , [5,false,2]], [[2,1.5,3.3] , [[2,3],1,2]], [[2,1.5,3.3] , ["string",2,9]] ] }""") # Check the IsMatrix Method for i in range(tmp["valid_matrices"].size()): valid_matrix = tmp["valid_matrices"][i] self.assertTrue(valid_matrix.IsMatrix()) for i in range(tmp["false_matrices"].size()): false_matrix = tmp["false_matrices"][i] self.assertFalse(false_matrix.IsMatrix()) # Check the GetMatrix Method also on the valid Matrices for i in range(tmp["valid_matrices"].size()): valid_matrix = tmp["valid_matrices"][i] valid_matrix.GetMatrix() # Check that the errors of the GetMatrix method are thrown correctly for i in range(tmp["false_matrices"].size()): false_matrix = tmp["false_matrices"][i] with self.assertRaises(RuntimeError): false_matrix.GetMatrix() # Manually assign and check a Matrix mat = Matrix(3, 2) mat[0, 0] = 1.0 mat[0, 1] = 2.0 mat[1, 0] = 3.0 mat[1, 1] = 4.0 mat[2, 0] = 5.0 mat[2, 1] = 6.0 tmp.AddEmptyValue("matrix_value") tmp["matrix_value"].SetMatrix(mat) self.assertTrue(tmp["matrix_value"].IsMatrix()) A2 = tmp["matrix_value"].GetMatrix() self.assertEqual(A2[0, 0], 1.0) self.assertEqual(A2[0, 1], 2.0) self.assertEqual(A2[1, 0], 3.0) self.assertEqual(A2[1, 1], 4.0) self.assertEqual(A2[2, 0], 5.0) self.assertEqual(A2[2, 1], 6.0)
def test_vector_interface(self): # Read and check Vectors from a Parameters-Object tmp = Parameters("""{ "valid_vectors" : [ [] ], "false_vectors" : [ [[]], [[2,3],2], [2,3,[2]], [2,3,[]], [{"key":3},2], [2,3,{"key":3}], [true,2], [2,3,true], [5,"string",2] ] }""") # Check the IsVector Method for i in range(tmp["valid_vectors"].size()): valid_vector = tmp["valid_vectors"][i] self.assertTrue(valid_vector.IsVector()) for i in range(tmp["false_vectors"].size()): false_vector = tmp["false_vectors"][i] self.assertFalse(false_vector.IsVector()) # Check the GetVector Method also on the valid Matrices for i in range(tmp["valid_vectors"].size()): valid_vector = tmp["valid_vectors"][i] valid_vector.GetVector() # Check that the errors of the GetVector method are thrown correctly for i in range(tmp["false_vectors"].size()): false_vector = tmp["false_vectors"][i] with self.assertRaises(RuntimeError): false_vector.GetVector() # Manually assign and check a Vector vec = Vector(3) vec[0] = 1.32 vec[1] = -2.22 vec[2] = 5.5 tmp.AddEmptyValue("vector_value") tmp["vector_value"].SetVector(vec) self.assertTrue(tmp["vector_value"].IsVector()) V2 = tmp["vector_value"].GetVector() self.assertEqual(V2[0],1.32) self.assertEqual(V2[1],-2.22) self.assertEqual(V2[2],5.5)
def test_set_string_array_valid(self): initial = Parameters("""{ "parameter": ["foo", "bar"] } """) string_array = initial["parameter"].GetStringArray() new_param = Parameters() new_param.AddEmptyValue("new_parameter") new_param["new_parameter"].SetStringArray(string_array) new_string_array = initial["parameter"].GetStringArray() self.assertListEqual(new_string_array, string_array)
def test_vector_interface(self): tmp = Parameters("""{ }""") # Manually assign and check a Vector vec = Vector(3) vec[0] = 1.32 vec[1] = -2.22 vec[2] = 5.5 tmp.AddEmptyValue("vector_value") tmp["vector_value"].SetVector(vec) self.assertTrue(tmp["vector_value"].IsVector()) V2 = tmp["vector_value"].GetVector() self.assertEqual(V2[0], 1.32) self.assertEqual(V2[1], -2.22) self.assertEqual(V2[2], 5.5)
def test_add_value(self): kp = Parameters("{}") kp.AddEmptyValue("new_double").SetDouble(1.0) self.assertTrue(kp.Has("new_double")) self.assertEqual(kp["new_double"].GetDouble(), 1.0)