def setUp(self): self.model = KM.Model() self.model_part = self.model.CreateModelPart("default") self.model_part.AddNodalSolutionStepVariable(KM.PRESSURE) self.model_part.AddNodalSolutionStepVariable(KM.PARTITION_INDEX) self.dimension = 3 self.model_part.ProcessInfo[KM.DOMAIN_SIZE] = self.dimension self.my_pid = KM.DataCommunicator.GetDefault().Rank() self.num_nodes = self.my_pid % 5 + 3 # num_nodes in range (3 ... 7) if self.my_pid == 4: self.num_nodes = 0 # in order to emulate one partition not having local nodes for i in range(self.num_nodes): node = self.model_part.CreateNewNode( i, 0.1 * i, 0.0, 0.0 ) # this creates the same coords in different ranks, which does not matter for this test node.SetSolutionStepValue(KM.PARTITION_INDEX, self.my_pid) node.SetSolutionStepValue(KM.PRESSURE, uniform(-10, 50)) if KM.IsDistributedRun(): KratosMPI.ParallelFillCommunicator(self.model_part).Execute() data_settings = KM.Parameters("""{ "model_part_name" : "default", "variable_name" : "PRESSURE" }""") self.interface_data = CouplingInterfaceData(data_settings, self.model) self.interface_data.Initialize() self.dummy_solver_wrapper = DummySolverWrapper( {"data_4_testing": self.interface_data})
def setUp(self): self.model = KM.Model() self.model_part = self.model.CreateModelPart("default") self.model_part.AddNodalSolutionStepVariable(KM.PRESSURE) for i in range(10): # using 10 nodes gives suitable values in the tests node = self.model_part.CreateNewNode(i+1, 0.0, 0.0, 0.0) # position of nodes does not matter for this test node.SetSolutionStepValue(KM.PRESSURE, 1.0) data_settings = KM.Parameters("""{ "model_part_name" : "default", "variable_name" : "PRESSURE" }""") self.interface_data = CouplingInterfaceData(data_settings, self.model) self.dummy_solver_wrapper = DummySolverWrapper({"data_4_testing" : self.interface_data})
def setUp(self): self.model = KM.Model() self.model_part = self.model.CreateModelPart("default") self.model_part.AddNodalSolutionStepVariable(KM.PRESSURE) self.model_part.ProcessInfo[KM.TIME] = 0.0 self.model_part.ProcessInfo[KM.STEP] = 0 for i in range(5): new_node = self.model_part.CreateNewNode(i+1, i*0.1, 0.0, 0.0) new_node.SetSolutionStepValue(KM.PRESSURE, 0, i+1.3) data_settings = KM.Parameters("""{ "model_part_name" : "default", "variable_name" : "PRESSURE" }""") self.interface_data = CouplingInterfaceData(data_settings, self.model) self.interface_data.Initialize() self.solver_wrappers = {"dummy_solver" : DummySolverWrapper({"data_4_testing" : self.interface_data})}
def test_elemental_to_nodal_conversion(self): self.model = KM.Model() self.model_part = self.model.CreateModelPart("default") self.model_part.AddNodalSolutionStepVariable(KM.FORCE) self.model_part.ProcessInfo[KM.DOMAIN_SIZE] = 3 props = self.model_part.CreateNewProperties(1) self.model_part.CreateNewNode(1, 0.0, 0.0, 0.0) self.model_part.CreateNewNode(2, 1.0, 0.0, 0.0) self.model_part.CreateNewNode(3, 1.0, 1.0, 0.0) self.model_part.CreateNewNode(4, 0.0, 1.0, 0.0) new_element = self.model_part.CreateNewElement("Element2D4N", 1, [1, 2, 3, 4], props) new_element.SetValue(KM.FORCE, [12.0, 8.0, 0.0]) self.model_part.CreateNewNode(5, 2.0, 0.0, 0.0) self.model_part.CreateNewNode(6, 2.0, 1.0, 0.0) new_element = self.model_part.CreateNewElement("Element2D4N", 2, [2, 5, 6, 3], props) new_element.SetValue(KM.FORCE, [16.0, 4.0, 0.0]) elemental_data = KM.Parameters("""{ "model_part_name" : "default", "location" : "element", "variable_name" : "FORCE", "dimension" : 3 }""") self.interface_data = CouplingInterfaceData(elemental_data, self.model) self.solver_wrappers = { "dummy_solver": DummySolverWrapper({"elemental_data": self.interface_data}) } self.solver_process_info = KM.ProcessInfo() conversion_op_settings = KM.Parameters("""{ "type" : "elemental_data_to_nodal_data", "solver" : "dummy_solver", "data_name" : "elemental_data", "echo_level" : 0 }""") conversion_operation = coupling_operation_factory.CreateCouplingOperation( conversion_op_settings, self.solver_wrappers, self.solver_process_info) conversion_operation.Check() conversion_operation.Execute() nodal_data_output_setting = KM.Parameters("""{ "model_part_name" : "default", "variable_name" : "FORCE", "location" : "node_historical", "dimension" : 3 }""") nodal_data_output = CouplingInterfaceData(nodal_data_output_setting, self.model) expected_nodal_values = [ 3, 2, 0, 7, 3, 0, 7, 3, 0, 3, 2, 0, 4, 1, 0, 4, 1, 0 ] self.assertVectorAlmostEqual(expected_nodal_values, nodal_data_output.GetData())