def test_kratos_mapping_transfer_operator(self):
        if using_pykratos:
            self.skipTest("This test cannot be run with pyKratos!")
        if not mapping_app_available:
            self.skipTest("MappingApplication not available!")

        data_transfer_op_settings_missing = KM.Parameters("""{
            "type" : "kratos_mapping"
        }""")

        exp_error = 'No "mapper_settings" provided!'
        with self.assertRaisesRegex(Exception, exp_error):
            data_transfer_operator_factory.CreateDataTransferOperator(
                data_transfer_op_settings_missing)

        data_transfer_op_settings = KM.Parameters("""{
            "type" : "kratos_mapping",
            "mapper_settings" : {
                "mapper_type" : "nearest_neighbor"
            }
        }""")

        data_transfer_op = data_transfer_operator_factory.CreateDataTransferOperator(
            data_transfer_op_settings)

        self.__TestTransferMatching(data_transfer_op)
        self.__TestTransferMatchingSwapSign(data_transfer_op)
        self.__TestTransferMatchingAddValues(data_transfer_op)
        self.__TestTransferMatchingAddValuesAdSwapSign(data_transfer_op)
    def test_kratos_mapping_transfer_operator(self):
        if not mapping_app_available:
            self.skipTest("MappingApplication not available!")

        data_transfer_op_settings_missing = KM.Parameters("""{
            "type" : "kratos_mapping"
        }""")

        exp_error = 'No "mapper_settings" provided!'
        with self.assertRaisesRegex(Exception, exp_error):
            data_transfer_operator_factory.CreateDataTransferOperator(data_transfer_op_settings_missing)

        data_transfer_op_settings = KM.Parameters("""{
            "type" : "kratos_mapping",
            "mapper_settings" : {
                "mapper_type" : "nearest_neighbor"
            }
        }""")

        data_transfer_op = data_transfer_operator_factory.CreateDataTransferOperator(data_transfer_op_settings)

        self.__TestTransferMatching(data_transfer_op)
        self.__TestTransferMatchingSwapSign(data_transfer_op)
        self.__TestTransferMatchingAddValues(data_transfer_op)
        self.__TestTransferMatchingAddValuesAndSwapSign(data_transfer_op)

        # with this we make sure that only one mapper is created (and not several ones for each mapping operation!)
        # Hint: requires access to private member
        self.assertEqual(len(data_transfer_op._KratosMappingDataTransferOperator__mappers), 1)

        self.__TestTransferMatchingInverse(data_transfer_op)
        # here we check explicitly the InverseMap fct
        self.assertEqual(len(data_transfer_op._KratosMappingDataTransferOperator__mappers), 1)

        transfer_options_empty = KM.Parameters(""" [] """)
        data_transfer_op.TransferData(self.origin_data_scalar, self.destination_non_matching_data_scalar, transfer_options_empty)
        # here we check explicitly the creation of a second mapper, which is required since the interfaces are not the same this time
        self.assertEqual(len(data_transfer_op._KratosMappingDataTransferOperator__mappers), 2)

        data_settings_model_part = KM.Parameters("""{
            "model_part_name" : "mp_single_node",
            "variable_name"   : "TEMPERATURE",
            "location"        : "model_part"
        }""")

        data_model_part = CouplingInterfaceData(data_settings_model_part, self.model)

        with self.assertRaisesRegex(Exception, 'Currently only historical nodal values are supported'):
            data_transfer_op.TransferData(self.origin_data_scalar, data_model_part, transfer_options_empty)
Beispiel #3
0
    def test_sum_dist_to_single(self):
        data_transfer_op_settings = KM.Parameters("""{
            "type" : "sum_distributed_to_single"
        }""")

        data_transfer_op = data_transfer_operator_factory.CreateDataTransferOperator(
            data_transfer_op_settings)
        transfer_options = KM.Parameters(""" [] """)

        for node in self.origin_data_scalar.GetModelPart().Nodes:
            node.SetSolutionStepValue(KM.PRESSURE, 0, 100.0)

        data_transfer_op.TransferData(self.origin_data_scalar,
                                      self.destination_data_single_node,
                                      transfer_options)

        self.__CompareScalarNodalValues(
            self.destination_data_single_node.GetModelPart().Nodes,
            self.origin_data_scalar.GetModelPart().Nodes, KMC.SCALAR_FORCE,
            KM.PRESSURE, 5)

        with self.assertRaisesRegex(
                Exception,
                'Interface data "default" of solver "default_solver" requires to be of size 1, got: 5'
        ):
            data_transfer_op.TransferData(
                self.origin_data_scalar, self.destination_matching_data_scalar,
                transfer_options)
Beispiel #4
0
    def test_copy_single_to_dist_transfer_operator_distribute_values_swap_sign_add_values(
            self):
        data_transfer_op_settings = KM.Parameters("""{
            "type" : "copy_single_to_distributed"
        }""")

        data_transfer_op = data_transfer_operator_factory.CreateDataTransferOperator(
            data_transfer_op_settings)
        transfer_options = KM.Parameters(
            """ ["distribute_values", "swap_sign"] """)
        transfer_options_with_add_vals = KM.Parameters(
            """ ["distribute_values", "swap_sign", "add_values"] """)

        for node in self.origin_data_single_node.GetModelPart().Nodes:
            node.SetSolutionStepValue(KMC.SCALAR_DISPLACEMENT, 0, 100.0)

        data_transfer_op.TransferData(self.origin_data_single_node,
                                      self.destination_matching_data_scalar,
                                      transfer_options)

        self.__CompareScalarNodalValues(
            self.destination_matching_data_scalar.GetModelPart().Nodes,
            self.origin_data_single_node.GetModelPart().Nodes, KM.TEMPERATURE,
            KMC.SCALAR_DISPLACEMENT, -0.2)

        data_transfer_op.TransferData(self.origin_data_single_node,
                                      self.destination_matching_data_scalar,
                                      transfer_options_with_add_vals)

        self.__CompareScalarNodalValues(
            self.destination_matching_data_scalar.GetModelPart().Nodes,
            self.origin_data_single_node.GetModelPart().Nodes, KM.TEMPERATURE,
            KMC.SCALAR_DISPLACEMENT, -0.4)
Beispiel #5
0
    def test_copy_transfer_operator(self):
        data_transfer_op_settings = KM.Parameters("""{
            "type" : "copy"
        }""")

        data_transfer_op = data_transfer_operator_factory.CreateDataTransferOperator(
            data_transfer_op_settings)

        self.__TestTransferMatching(data_transfer_op)
        self.__TestTransferMatchingSwapSign(data_transfer_op)
        self.__TestTransferMatchingAddValues(data_transfer_op)
        self.__TestTransferMatchingAddValuesAndSwapSign(data_transfer_op)

        transfer_options_empty = KM.Parameters(""" [] """)
        exp_error = 'The sizes of the data are not matching: {} != {} for interface data "{}" of solver "{}" and interface data "{}" of solver "{}"!'.format(
            self.origin_data_scalar.Size(),
            self.destination_non_matching_data_scalar.Size(),
            self.origin_data_scalar.name, self.origin_data_scalar.solver_name,
            self.destination_non_matching_data_scalar.name,
            self.destination_non_matching_data_scalar.solver_name)
        with self.assertRaisesRegex(Exception, exp_error):
            data_transfer_op.TransferData(
                self.origin_data_scalar,
                self.destination_non_matching_data_scalar,
                transfer_options_empty)
    def test_copy_single_to_dist_check_var(self):
        data_transfer_op_settings = KM.Parameters("""{
            "type" : "copy_single_to_distributed"
        }""")

        data_transfer_op = data_transfer_operator_factory.CreateDataTransferOperator(data_transfer_op_settings)
        transfer_options = KM.Parameters(""" [] """)

        with self.assertRaisesRegex(Exception, 'Variable of interface data "default" of solver "default_solver" has to be a scalar!'):
            data_transfer_op.TransferData(self.destination_data_single_node,
                                        self.destination_matching_data_vector,
                                        transfer_options)
    def test_sum_dist_to_single_swap_sign(self):
        data_transfer_op_settings = KM.Parameters("""{
            "type" : "sum_distributed_to_single"
        }""")

        data_transfer_op = data_transfer_operator_factory.CreateDataTransferOperator(data_transfer_op_settings)
        transfer_options = KM.Parameters(""" ["swap_sign"] """)

        for node in self.origin_data_scalar.GetModelPart().Nodes:
            node.SetSolutionStepValue(KM.PRESSURE, 0, 100.0)

        data_transfer_op.TransferData(self.origin_data_scalar,
                                      self.destination_data_single_node,
                                      transfer_options)

        self.__CompareScalarNodalValues(self.destination_data_single_node.GetModelPart().Nodes,
                                        self.origin_data_scalar.GetModelPart().Nodes,
                                        KMC.SCALAR_FORCE, KM.PRESSURE, -5)