Example #1
0
def save(settings):
    """
    Write settings to native settings file

    Args:
        :settings: (object) data structure for execution settings
    """

    set_file = settings.paths('f_settings')
    logger.info(f"Saving settings to file '{truncate_filepath(set_file)}'...")

    clean_dict(settings.settings)

    with open(set_file, 'w') as fp:
        dump_pretty_json(settings.settings, fp)
Example #2
0
def save_aeroperformance_map(state, settings):
    """
    Save the aeroperformance map

    Args:
        :state: (object) data structure for operating conditions
        :settings: (object) data structure for execution settings
    """

    filepath = settings.paths('f_results_apm_global')
    logger.info(f"Writing aeroperformance map results to '{truncate_filepath(filepath)}'")

    output = {}
    for dictionary in [state.aero, state.results]:
        for k, v in dictionary.items():
            output[k] = list(v) if v is not None else []

    with open(filepath, "w") as fp:
        dump_pretty_json(output, fp)
Example #3
0
def save(state, settings):
    """
    Write flight state to PyTornado state file.

    Args:
        :state: (object) data structure for operating conditions
        :settings: (object) data structure for execution settings
    """

    state_file = settings.paths('f_state')
    logger.info(
        f"Writing flight state to file '{truncate_filepath(state_file)}'")

    output = {}

    for key in ['aero']:
        output[key] = dict(getattr(state, key))

    with open(state_file, 'w') as fp:
        dump_pretty_json(output, fp)
Example #4
0
def _save_glob_results(state, vlmdata, settings):
    """
    Save global results

    Args:
        :state: (object) data structure for operating conditions
        :vlmdata: (object) data structure for VLM calculation data
        :settings: (object) data structure for execution settings
    """

    filepath = settings.paths('f_results_global')
    logger.info(f"Writing global results to file '{truncate_filepath(filepath)}'")

    output = {}
    output['aero'] = {k: v for k, v in state.aero.items()}
    output['refs'] = {k: v for k, v in state.refs.items()}
    output['global_forces'] = {k: v for k, v in vlmdata.forces.items()}
    output['global_coeffs'] = {k: v for k, v in vlmdata.coeffs.items()}

    with open(filepath, "w") as fp:
        dump_pretty_json(output, fp)
Example #5
0
def save(aircraft, settings):
    """
    Retrieve data from aircraft model and serialise

    Args:
        :aircraft: (object) data structure for aircraft
        :settings: (object) data structure for execution settings
    """

    filepath = settings.paths('f_aircraft')
    logger.info(
        f"Writing aircraft model to file '{truncate_filepath(filepath)}'...")

    # ====== Aircraft top level =====
    output = {}
    output['uid'] = aircraft.uid

    output['refs'] = {}
    for key, value in aircraft.refs.items():
        output['refs'][key] = value

    # ====== Wings =====
    output['wings'] = []
    for wing in aircraft.wings.values():
        wing_entry = {}
        wing_entry['uid'] = wing.uid
        wing_entry['symmetry'] = wing.symmetry

        # ====== Segments =====
        wing_entry['segments'] = []
        for segment in wing.segments.values():
            segment_entry = {}
            segment_entry['uid'] = segment.uid
            segment_entry['vertices'] = dict(segment.vertices)

            segment_entry['geometry'] = {}
            for key, value in segment.geometry.items():
                segment_entry['geometry'][key] = value

            segment_entry['airfoils'] = {}
            for key, value in segment.airfoils.items():
                # If airfoil is "blade" file, make sure to save as relative path
                # Note: Airfoil definition may also be for instance "NACA1234"
                if "blade." in value:
                    # Make path relative!
                    value = os.path.join(PATHS.DIR.AIRFOILS,
                                         os.path.basename(value))
                segment_entry['airfoils'][key] = value

            segment_entry['panels'] = {}
            for key, value in segment.panels.items():
                segment_entry['panels'][key] = value

            wing_entry['segments'].append(segment_entry)

        # ====== Controls =====
        wing_entry['controls'] = []
        for control in wing.controls.values():
            control_entry = {}

            control_entry['uid'] = control.uid
            control_entry['device_type'] = control.device_type
            control_entry['deflection'] = control.deflection
            control_entry['deflection_mirror'] = control.deflection_mirror

            control_entry['segment_uid'] = {}
            for key, value in control.segment_uid.items():
                control_entry['segment_uid'][key] = value

            control_entry['rel_vertices'] = {}
            for key, value in control.rel_vertices.items():
                control_entry['rel_vertices'][key] = value

            control_entry['rel_hinge_vertices'] = {}
            for key, value in control.rel_hinge_vertices.items():
                control_entry['rel_hinge_vertices'][key] = value

            control_entry['panels'] = {}
            for key, value in control.panels.items():
                control_entry['panels'][key] = value

            wing_entry['controls'].append(control_entry)

        output['wings'].append(wing_entry)

    with open(filepath, 'w') as fp:
        dump_pretty_json(output, fp)