Пример #1
0
    def Initialize(self):
        super().Initialize()
        self.co_sim_settings = self.project_parameters["co_sim_settings"]
        self.is_strong_coupling = self.co_sim_settings[
            "is_strong_coupling"].GetBool()

        connection_settings = CoSimIO.InfoFromParameters(
            self.project_parameters["co_sim_settings"]["io_settings"])

        info = CoSimIO.Connect(connection_settings)
        self.connection_name = info.GetString("connection_name")
        if info.GetInt(
                "connection_status") != CoSimIO.ConnectionStatus.Connected:
            raise Exception("Connecting failed!")

        self.communication_settings = self.co_sim_settings[
            "communication_settings"]

        # Exporting meshes to CoSimulation
        for model_part_name in self.communication_settings[
                "export_meshes"].GetStringArray():
            info = CoSimIO.Info()
            info.SetString("connection_name", self.connection_name)
            info.SetString("identifier", model_part_name.replace(".", "-"))

            CoSimIO.ExportMesh(info, self.model[model_part_name])
    def test_Export_Import_Mesh(self):
        model = KM.Model()

        model_part = model.CreateModelPart("for_test")
        model_part_returned = model.CreateModelPart("for_test_2")

        for i in range(15):
            model_part.CreateNewNode(i + 1, i * 1.1, 1.1**i, 0.0)
        props = model_part.CreateNewProperties(0)
        for i in range(9):  # this leaves some hanging nodes
            model_part.CreateNewElement("Element2D2N", i + 1, [i + 1, i + 2],
                                        props)

        connection_settings = CoSimIO.Info()
        connection_settings.SetString("connection_name", "im_exp_mesh")
        connection_settings.SetInt("echo_level", 0)
        info = CoSimIO.Connect(connection_settings)
        self.assertEqual(info.GetInt("connection_status"),
                         CoSimIO.ConnectionStatus.Connected)

        export_info = CoSimIO.Info()
        export_info.SetString("connection_name", "im_exp_mesh")
        export_info.SetString("identifier", "mesh_exchange_1")
        CoSimIO.ExportMesh(export_info, model_part)

        RunPythonInSubProcess("import_export_mesh")

        import_info = CoSimIO.Info()
        import_info.SetString("connection_name", "im_exp_mesh")
        import_info.SetString("identifier", "mesh_exchange_2")
        CoSimIO.ImportMesh(import_info, model_part_returned)

        disconnect_settings = CoSimIO.Info()
        disconnect_settings.SetString("connection_name", "im_exp_mesh")

        info = CoSimIO.Disconnect(disconnect_settings)
        self.assertEqual(info.GetInt("connection_status"),
                         CoSimIO.ConnectionStatus.Disconnected)

        # checking the values after disconnecting to avoid deadlock
        self.assertEqual(model_part.NumberOfNodes(),
                         model_part_returned.NumberOfNodes())
        self.assertEqual(model_part.NumberOfElements(),
                         model_part_returned.NumberOfElements())

        for node_orig, node_exchanged in zip(model_part.Nodes,
                                             model_part_returned.Nodes):
            self.assertAlmostEqual(node_orig.X0, node_exchanged.X0)
            self.assertAlmostEqual(node_orig.Y0, node_exchanged.Y0)
            self.assertAlmostEqual(node_orig.Z0, node_exchanged.Z0)

        for elem_orig, elem_exchanged in zip(model_part.Elements,
                                             model_part_returned.Elements):
            self.assertEqual(len(elem_orig.GetNodes()),
                             len(elem_exchanged.GetNodes()))
            for node_orig, node_exchanged in zip(elem_orig.GetNodes(),
                                                 elem_exchanged.GetNodes()):
                self.assertAlmostEqual(node_orig.X0, node_exchanged.X0)
                self.assertAlmostEqual(node_orig.Y0, node_exchanged.Y0)
                self.assertAlmostEqual(node_orig.Z0, node_exchanged.Z0)
Пример #3
0
    def ExportCouplingInterface(self, interface_config):
        model_part_name = interface_config["model_part_name"]

        info = CoSimIO.Info()
        info.SetString("connection_name", self.solver_name)
        info.SetString("identifier", model_part_name)

        CoSimIO.ExportMesh(info, self.model[model_part_name]
                           )  # TODO this can also be geometry at some point
Пример #4
0
        def _ExportMesh(info):
            model_part_name = info.GetString("identifier")

            export_info = CoSimIO.Info()
            export_info.SetString("connection_name", self.connection_name)
            export_info.SetString("identifier",
                                  model_part_name.replace(".", "-"))

            CoSimIO.ExportMesh(export_info, self.model[model_part_name])
            return CoSimIO.Info()
Пример #5
0
    def ExportCouplingInterface(self, interface_config):
        model_part_name = interface_config["model_part_name"]

        info = CoSimIO.Info()
        info.SetString("connection_name", self.connection_name)
        info.SetString("identifier", model_part_name.replace(
            ".", "-"))  # TODO chec if better solution can be found

        CoSimIO.ExportMesh(info, self.model[model_part_name]
                           )  # TODO this can also be geometry at some point
Пример #6
0
from KratosMultiphysics.CoSimulationApplication import CoSimIO

model = KM.Model()
model_part = model.CreateModelPart("mp_test")

connection_settings = CoSimIO.Info()
connection_settings.SetString("connection_name", "im_exp_mesh")
connection_settings.SetInt("echo_level", 0)
info = CoSimIO.Connect(connection_settings)
if info.GetInt("connection_status") != CoSimIO.ConnectionStatus.Connected:
    raise Exception("Connecting failed")

import_info = CoSimIO.Info()
import_info.SetString("connection_name", "im_exp_mesh")
import_info.SetString("identifier", "mesh_exchange_1")
CoSimIO.ImportMesh(import_info, model_part)

# print(model_part)

export_info = CoSimIO.Info()
export_info.SetString("connection_name", "im_exp_mesh")
export_info.SetString("identifier", "mesh_exchange_2")
CoSimIO.ExportMesh(export_info, model_part)

disconnect_settings = CoSimIO.Info()
disconnect_settings.SetString("connection_name", "im_exp_mesh")

info = CoSimIO.Disconnect(disconnect_settings)
if info.GetInt("connection_status") != CoSimIO.ConnectionStatus.Disconnected:
    raise Exception("Disconnecting failed")