def test_basics(self): settings_scal_hist = KM.Parameters("""{ "model_part_name" : "mp_4_test", "variable_name" : "PRESSURE" }""") settings_vec_elem = KM.Parameters("""{ "model_part_name" : "mp_4_test", "variable_name" : "DISPLACEMENT", "location" : "element", "dimension" : 2 }""") coupling_data_scal = CouplingInterfaceData(settings_scal_hist, self.model) coupling_data_scal.Initialize() coupling_data_vec = CouplingInterfaceData(settings_vec_elem, self.model) coupling_data_vec.Initialize() self.assertEqual(coupling_data_scal.GetModelPart().Name, "mp_4_test") self.assertEqual(coupling_data_vec.GetModelPart().Name, "mp_4_test") self.assertFalse(coupling_data_scal.GetModelPart().IsDistributed()) self.assertFalse(coupling_data_vec.GetModelPart().IsDistributed()) self.assertEqual(coupling_data_scal.Size(), 5) # 5 nodes and scalar var self.assertEqual(coupling_data_vec.Size(), 14) # 7 elements and vector var with dim==2 self.assertEqual(coupling_data_scal.GetBufferSize(), 2) self.assertEqual(coupling_data_vec.GetBufferSize(), 1)
def test_without_initialization(self): settings = KM.Parameters("""{ "model_part_name" : "mp_4_test", "variable_name" : "DISPLACEMENT", "dimension" : 2 }""") coupling_data = CouplingInterfaceData(settings, self.model) # coupling_data.Initialize() # intentially commented to raise error with self.assertRaisesRegex(Exception, ' can onyl be called after initializing the CouplingInterfaceData!'): self.assertMultiLineEqual(str(coupling_data), coupling_interface_data_str) with self.assertRaisesRegex(Exception, ' can onyl be called after initializing the CouplingInterfaceData!'): coupling_data.PrintInfo() with self.assertRaisesRegex(Exception, ' can onyl be called after initializing the CouplingInterfaceData!'): coupling_data.GetModelPart() with self.assertRaisesRegex(Exception, ' can onyl be called after initializing the CouplingInterfaceData!'): coupling_data.IsDistributed() with self.assertRaisesRegex(Exception, ' can onyl be called after initializing the CouplingInterfaceData!'): coupling_data.Size() with self.assertRaisesRegex(Exception, ' can onyl be called after initializing the CouplingInterfaceData!'): coupling_data.GetBufferSize() with self.assertRaisesRegex(Exception, ' can onyl be called after initializing the CouplingInterfaceData!'): coupling_data.GetData() with self.assertRaisesRegex(Exception, ' can onyl be called after initializing the CouplingInterfaceData!'): coupling_data.SetData([])