コード例 #1
0
    def test_value_manipulation(self):
        val = 125.964
        val2 = 88.787
        func_str = "{}+{}".format(val, val2)
        self.assertAlmostEqual(val+val2, GenericCallFunction(func_str))

        func_str = "{}  +  {}".format(val, val2)
        self.assertAlmostEqual(val+val2, GenericCallFunction(func_str))
コード例 #2
0
ファイル: scaling.py プロジェクト: vsujeesh/Kratos
    def Execute(self):
        process_info = self.interface_data.GetModelPart().ProcessInfo
        time = process_info[KM.TIME]
        step = process_info[KM.STEP]

        if not KM.IntervalUtility(self.settings).IsInInterval(time):
            if self.echo_level > 0:
                cs_tools.cs_print_info("ScalingOperation",
                                       "Skipped, not in interval")
            return

        if isinstance(self.scaling_factor, str):
            # TODO maybe make this to use COSIM_TIME and COSIM_STEP, such that it is generic for all solvers
            scope_vars = {
                't': time,
                'step': step
            }  # make time and step useable in function
            current_scaling_factor = GenericCallFunction(
                self.scaling_factor, scope_vars,
                check=False)  # evaluating function string
        else:
            current_scaling_factor = self.scaling_factor

        if self.echo_level > 0:
            cs_tools.cs_print_info("ScalingOperation", "Scaling-Factor",
                                   current_scaling_factor)
        self.interface_data.SetData(
            current_scaling_factor *
            self.interface_data.GetData())  # setting the scaled data
コード例 #3
0
 def test_scope(self):
     val = 125.964
     val_t = 1.556
     val_tr = -2.89
     scope = {"t" : val_t, "tr" : val_tr}
     func_str = "{}*t+tr".format(val)
     self.assertAlmostEqual(val*val_t+val_tr, GenericCallFunction(func_str, scope))
コード例 #4
0
ファイル: sdof_solver.py プロジェクト: xiaoxiongnpu/Kratos
 def ApplyForceExcitation(self):
     scope_vars = {
         't': self.time,
         'omega': self.omega_force,
         'A': self.amplitude_force
     }
     return GenericCallFunction(self.excitation_function_force,
                                scope_vars,
                                check=False)
コード例 #5
0
ファイル: sdof_solver.py プロジェクト: xiaoxiongnpu/Kratos
 def ApplyRootPointExcitation(self):
     scope_vars = {
         't': self.time,
         'omega': self.omega_root_point_displacement,
         'A': self.amplitude_root_point_displacement
     }
     return GenericCallFunction(
         self.excitation_function_root_point_displacement,
         scope_vars,
         check=False)
コード例 #6
0
    def __ApplyScaling(self, interface_data, data_configuration):
        # perform scaling of data if specified
        if data_configuration["scaling_factor"].IsString():
            from KratosMultiphysics.CoSimulationApplication.function_callback_utility import GenericCallFunction
            scaling_function_string = data_configuration["scaling_factor"].GetString()
            scope_vars = {'t' : self.time} # make time useable in function
            scaling_factor = GenericCallFunction(scaling_function_string, scope_vars) # evaluating function string
        else:
            scaling_factor = data_configuration["scaling_factor"].GetDouble()

        if abs(scaling_factor-1.0) > 1E-15:
            if self.echo_level > 2:
                cs_tools.cs_print_info("  Scaling-Factor", scaling_factor)
            interface_data.InplaceMultiply(scaling_factor)
コード例 #7
0
    def __ApplyScaling(self, interface_data, data_configuration):
        # perform scaling of data if specified
        if data_configuration["scaling_factor"].IsString():
            scaling_function_string = data_configuration[
                "scaling_factor"].GetString()
            scope_vars = {'t': self.time}  # make time useable in function
            scaling_factor = GenericCallFunction(
                scaling_function_string,
                scope_vars)  # evaluating function string
        else:
            scaling_factor = data_configuration["scaling_factor"].GetDouble()

        if abs(scaling_factor - 1.0) > 1E-15:
            if self.echo_level > 2:
                cs_tools.cs_print_info("  Scaling-Factor", scaling_factor)
            interface_data.SetData(
                scaling_factor *
                interface_data.GetData())  # setting the scaled data
コード例 #8
0
ファイル: scaling.py プロジェクト: vsujeesh/Kratos
 def Check(self):
     if isinstance(self.scaling_factor, str):
         scope_vars = {'t': 0.1, 'step': 2}  # dummy for testing
         GenericCallFunction(
             self.scaling_factor, scope_vars, check=True
         )  # trying to evaluate the function string, such that the check can be disabled later
コード例 #9
0
 def test_complex_eval(self):
     val_t = 0.6289
     scope = {"t" : val_t}
     func_str = "(sin((t/0.006289)/100*pi/2))**2"
     self.assertAlmostEqual(1.0, GenericCallFunction(func_str, scope))
コード例 #10
0
 def test_math_constants(self):
     val = 125.964
     func_str = "{}+pi".format(val)
     self.assertAlmostEqual(val+pi, GenericCallFunction(func_str))
コード例 #11
0
 def test_value(self):
     val = 125.964
     func_str = str(val)
     self.assertAlmostEqual(val, GenericCallFunction(func_str))