Beispiel #1
0
def test_fmi3(reference_fmus_dist_dir, reference_fmus_repo_dir):

    for model_name in [
            'BouncingBall', 'Dahlquist', 'Feedthrough', 'Resource', 'Stair',
            'VanDerPol'
    ]:

        if model_name == 'Feedthrough':
            start_values = {
                'Float64_fixed_parameter': 1,
                'String_parameter': "FMI is awesome!"
            }
            output_interval = 1e-3
            in_csv = reference_fmus_repo_dir / model_name / f'{model_name}_in.csv'
            input = read_csv(in_csv) if os.path.isfile(in_csv) else None
        else:
            start_values = {}
            input = None
            output_interval = None

        filename = reference_fmus_dist_dir / '3.0' / f'{model_name}.fmu'

        ref_csv = reference_fmus_repo_dir / model_name / f'{model_name}_ref.csv'
        reference = read_csv(ref_csv)

        for fmi_type in ['ModelExchange', 'CoSimulation']:
            result = simulate_fmu(filename,
                                  fmi_type=fmi_type,
                                  start_values=start_values,
                                  input=input,
                                  output_interval=output_interval)
            rel_out = validate_result(result, reference)
            assert rel_out == 0
Beispiel #2
0
    def validate(self, build_dir, fmi_types=['ModelExchange', 'CoSimulation'], models=models, compile=False):

        from fmpy.util import read_csv, validate_result

        for model in models:

            print(model)

            fmu_filename = os.path.join(build_dir, 'dist', model + '.fmu')

            if model == 'Feedthrough':
                start_values = {'real_fixed_param': 1, 'string_param': "FMI is awesome!"}
                in_csv = os.path.join(test_fmus_dir, model, model + '_in.csv')
                input = read_csv(in_csv)
            else:
                start_values = {}
                input = None

            ref_csv = os.path.join(test_fmus_dir, model, model + '_ref.csv')

            for fmi_type in fmi_types:

                ref = read_csv(ref_csv)

                if compile:
                    compile_platform_binary(fmu_filename)

                result = simulate_fmu(fmu_filename,
                                      fmi_type=fmi_type,
                                      start_values=start_values,
                                      input=input)

                dev = validate_result(result, ref)

                self.assertLess(dev, 0.2, "Failed to validate " + model)
def validate(build_dir, fmi_types, models, compile=False):

    from fmpy.util import read_csv, validate_result

    test_fmus_dir = Path(__file__).parent

    for model in models:

        print(model)

        fmu_filename = os.path.join(build_dir, 'dist', model + '.fmu')

        problems = validate_fmu(fmu_filename)

        assert not problems

        if model == 'Feedthrough':
            start_values = {'Float64_fixed_parameter': 1, 'String_parameter': "FMI is awesome!"}
            in_csv = os.path.join(test_fmus_dir, model, model + '_in.csv')
            input = read_csv(in_csv)
        else:
            start_values = {}
            input = None

        ref_csv = os.path.join(test_fmus_dir, model, model + '_ref.csv')

        for fmi_type in fmi_types:

            ref = read_csv(ref_csv)

            if compile:
                if model == 'Resource' and os.name == 'nt':
                    continue
                compile_platform_binary(fmu_filename)

            result = simulate_fmu(fmu_filename,
                                  fmi_type=fmi_type,
                                  start_values=start_values,
                                  input=input,
                                  solver='Euler')

            dev = validate_result(result, ref)

            assert dev < 0.2, "Failed to validate " + model
Beispiel #4
0
    def test_fmi3(self):

        for model_name in [
                'BouncingBall', 'Dahlquist', 'Feedthrough', 'Resource',
                'Stair', 'VanDerPol'
        ]:

            if model_name == 'Feedthrough':
                start_values = {
                    'real_fixed_param': 1,
                    'string_param': "FMI is awesome!"
                }
                output_interval = 1e-3
                in_csv = os.path.join('Reference-FMUs-repo',
                                      'Reference-FMUs-' + v, model_name,
                                      model_name + '_in.csv')
                input = read_csv(in_csv) if os.path.isfile(in_csv) else None
            else:
                start_values = {}
                input = None
                output_interval = None

            filename = os.path.join('Reference-FMUs-dist', '3.0',
                                    model_name + '.fmu')

            ref_csv = os.path.join('Reference-FMUs-repo',
                                   'Reference-FMUs-' + v, model_name,
                                   model_name + '_ref.csv')
            reference = read_csv(ref_csv)

            for fmi_type in ['ModelExchange', 'CoSimulation']:
                result = simulate_fmu(filename,
                                      fmi_type=fmi_type,
                                      start_values=start_values,
                                      input=input,
                                      output_interval=output_interval)
                rel_out = validate_result(result, reference)
                self.assertEqual(0, rel_out)