Пример #1
0
    def get_each_wavepaddle(cls, mkprops: list) -> str:
        """ Returns a string with a list of wavepaddles (wave generators) from the received mkbasedproperties list. """
        each_template: list = []
        for prop in mkprops:
            movement = prop["movements"][0]
            mk_bound = prop["mk"] - MKFLUID_LIMIT
            if movement["generator"][
                    "type"] == MotionType.REGULAR_PISTON_WAVE_GENERATOR:
                each_template.append(
                    cls.get_regular_piston_wave_template(
                        mk_bound, movement["generator"]))
            elif movement["generator"][
                    "type"] == MotionType.IRREGULAR_PISTON_WAVE_GENERATOR:
                each_template.append(
                    cls.get_irregular_piston_wave_template(
                        mk_bound, movement["generator"]))
            elif movement["generator"][
                    "type"] == MotionType.REGULAR_FLAP_WAVE_GENERATOR:
                each_template.append(
                    cls.get_regular_flap_wave_template(mk_bound,
                                                       movement["generator"]))
            elif movement["generator"][
                    "type"] == MotionType.IRREGULAR_FLAP_WAVE_GENERATOR:
                each_template.append(
                    cls.get_irregular_flap_wave_template(
                        mk_bound, movement["generator"]))

        return LINE_END.join(each_template)
    def render(cls, data):
        """ Returns the rendered string. """
        each_damping_template: list = []

        for obj_name, dzone in data["damping_zones"].items():
            fc_object = FreeCAD.ActiveDocument.getObject(obj_name)
            dzone.update({
                "limitmin": [
                    fc_object.OutList[0].Start[0] / DIVIDER,
                    fc_object.OutList[0].Start[1] / DIVIDER,
                    fc_object.OutList[0].Start[2] / DIVIDER
                ],
                "limitmax": [
                    str(fc_object.OutList[0].End[0] / DIVIDER),
                    str(fc_object.OutList[0].End[1] / DIVIDER),
                    str(fc_object.OutList[0].End[2] / DIVIDER)
                ]
            })
            each_damping_template.append(get_template_text(cls.DAMPING_EACH).format(**dzone))

        formatter = {
            "each": LINE_END.join(each_damping_template)
        }

        return get_template_text(cls.DAMPING_BASE).format(**formatter)
Пример #3
0
    def get_zsurf_param_template(cls, zone: dict) -> str:
        """ Returns the imposezsurf inner template. """

        if zone["elevation_info"][
                "elevation_type"] == InletOutletElevationType.FIXED:
            return get_template_text(
                cls.INOUT_ZSURF_FIXED).format(**zone["elevation_info"])
        elif zone["elevation_info"][
                "elevation_type"] == InletOutletElevationType.VARIABLE and zone[
                    "elevation_info"][
                        "zsurf_mode"] == InletOutletZSurfMode.FILE:
            return get_template_text(
                cls.INOUT_ZSURF_FILE).format(**zone["elevation_info"])
        elif zone["elevation_info"][
                "elevation_type"] == InletOutletElevationType.VARIABLE and zone[
                    "elevation_info"][
                        "zsurf_mode"] == InletOutletZSurfMode.TIMELIST:
            inout_zsurf_timelist_formatter = zone["elevation_info"]
            time_value_each = []
            for zsurftimevalue in zone["elevation_info"]["zsurftimes"]:
                time_value_each.append(
                    get_template_text(
                        cls.INOUT_ZSURF_TIMELIST_TIMEVALUE_EACH).format(
                            zsurftimevalue[0], zsurftimevalue[1]))
            inout_zsurf_timelist_formatter["timevalue_each"] = LINE_END.join(
                time_value_each)
            return get_template_text(cls.INOUT_ZSURF_TIMELIST).format(
                **inout_zsurf_timelist_formatter)
        elif zone["elevation_info"][
                "elevation_type"] == InletOutletElevationType.AUTOMATIC:
            return get_template_text(
                cls.INOUT_ZSURF_AUTOMATIC).format(**zone["elevation_info"])

        # TEXTO CO INTERIOR DO TAG IMPOSEZSURF
        return ""
Пример #4
0
    def get_movement_template_list(cls, mk_based_prop: dict) -> str:
        """ Returns a rendered list of movements. """
        counter: int = 1
        each_movement_template: list = list()
        if mk_based_prop["mlayerpiston"]:
            formatter: dict = {
                "count": counter,
                "motions_list": get_template_text(cls.MOTION_NULL_TEMPLATE)
            }
            each_movement_template.append(
                get_template_text(
                    cls.MOTION_EACH_MOVEMENT_LIST_XML).format(**formatter))
        else:
            for mov in mk_based_prop["movements"]:
                formatter: dict = {
                    "count": counter,
                    "motions_list": cls.get_each_motion_template(mov, counter),
                }
                each_movement_template.append(
                    get_template_text(
                        cls.MOTION_EACH_MOVEMENT_LIST_XML).format(**formatter))
                counter += len(
                    mov["motion_list"]) if "motion_list" in mov.keys() else 1

        return LINE_END.join(each_movement_template)
Пример #5
0
    def render(cls, data):
        """ Returns the rendered string. """
        each_objreal_template: list = list()
        for prop in data["mkbasedproperties"].values():
            if not prop["movements"] and not prop["mlayerpiston"]:
                continue

            formatter: dict = {
                "ref": prop["mk"] - MKFLUID_LIMIT,
                "movements_list": cls.get_movement_template_list(prop)
            }

            each_objreal_template.append(
                get_template_text(
                    cls.MOTION_EACH_BASE_XML).format(**formatter))

        if not each_objreal_template:
            # There are no movements in the case. Do not bother rendering the <motion> tag.
            return ""

        formatter: dict = {
            "each_objreal": LINE_END.join(each_objreal_template)
        }

        return get_template_text(cls.MOTION_BASE_XML).format(**formatter)
    def render(cls, data):
        """ Returns the rendered string. """
        periodicity_fragments: list = list()
        mode_3d: bool = data["mode3d"] == "true"

        if data["periodicity"]["x_periodicity"]["enabled"].lower() == "true":
            periodicity_fragments.append(
                get_template_text(cls.XINCY_XML).format(
                    value=data["periodicity"]["x_periodicity"]["y_increment"]
                ) if mode_3d else "")
            periodicity_fragments.append(
                get_template_text(cls.XINCZ_XML).format(
                    value=data["periodicity"]["x_periodicity"]["z_increment"]))

        if mode_3d and data["periodicity"]["y_periodicity"]["enabled"].lower(
        ) == "true":
            periodicity_fragments.append(
                get_template_text(cls.YINCX_XML).format(
                    value=data["periodicity"]["y_periodicity"]["x_increment"]))
            periodicity_fragments.append(
                get_template_text(cls.YINCZ_XML).format(
                    value=data["periodicity"]["y_periodicity"]["z_increment"]))

        if data["periodicity"]["z_periodicity"]["enabled"].lower() == "true":
            periodicity_fragments.append(
                get_template_text(cls.ZINCX_XML).format(
                    value=data["periodicity"]["z_periodicity"]["x_increment"]))
            periodicity_fragments.append(
                get_template_text(cls.ZINCY_XML).format(
                    value=data["periodicity"]["z_periodicity"]["y_increment"]
                ) if mode_3d else "")

        return LINE_END.join(periodicity_fragments)
    def render(cls, data):
        """ Returns the rendered string. """
        moorings: dict = data["moorings"]

        if moorings["enabled"] == "false":
            return ""

        each_mooredfloatings_templates: list = list(
            map(
                lambda mkbound: get_template_text(cls.MOORINGS_MOORED_FLOATING)
                .format(**{"mkbound": mkbound}), moorings["moored_floatings"]))

        formatter: dict = {
            "savevtk_moorings":
            moorings["saveoptions"]["savevtk_moorings"],
            "savecsv_points":
            moorings["saveoptions"]["savecsv_points"],
            "savevtk_points":
            moorings["saveoptions"]["savevtk_points"],
            "each_mooredfloatings_template":
            LINE_END.join(each_mooredfloatings_templates),
            "moordyn_template":
            cls.get_moordyn_embedded_template(data)
            if moorings["configuration_method"]
            == MooringsConfigurationMethod.EMBEDDED else get_template_text(
                cls.MOORDYN_EXTERNAL_CONFIG).format(moorings["moordyn_xml"])
        }

        return get_template_text(cls.MOORINGS_BASE).format(**formatter)
Пример #8
0
    def check_and_filter(self):
        """ Filters the executable removing those not matching the correct application.
            Returns whether or not all of them were correctly set. """
        execs_correct: bool = True
        execs_to_check = {
            "gencase": self.gencase,
            "dualsphysics": self.dsphysics,
            "partvtk": self.partvtk,
            "floatinginfo": self.floatinginfo,
            "computeforces": self.computeforces,
            "measuretool": self.measuretool,
            "isosurface": self.isosurface,
            "boundaryvtk": self.boundaryvtk,
            "flowtool": self.flowtool
        }

        bad_executables: list = list()

        for word, executable in execs_to_check.items():
            if not executable_contains_string(executable, word):
                debug("Executable {} does not contain the word {}".format(
                    executable, word))
                execs_correct = False
                bad_executables.append(executable)

        if not execs_correct:
            error_dialog(
                "One or more of the executables set on the configuration is not correct. Please see the details below.",
                "These executables do not correspond to their appropriate tool or don't have execution permissions:\n\n{}"
                .format(LINE_END.join(bad_executables)))

        self.persist()
        return execs_correct
Пример #9
0
    def get_bodies_template(cls, data) -> str:
        """ Returns a list of <body> tags for moordyn. """
        each_body_template: list = list()

        for body in data["moorings"]["moordyn_configuration"]["bodies"]:
            each_body_template.append(get_template_text(cls.MOORDYN_BODY_COMPACT_TEMPLATE if body["depth"] == "false" else cls.MOORDYN_BODY_EXTENDED_TEMPLATE).format(**body))

        return LINE_END.join(each_body_template)
Пример #10
0
 def render(cls, data):
     """ Returns the rendered string. """
     template = get_template_text(cls.INITIALS_XML)
     initials = map(
         lambda y: template.format(**y["initials"]),
         filter(lambda x: x["initials"] is not None,
                data["mkbasedproperties"].values()))
     return LINE_END.join(initials) if initials else ""
    def render(cls, data):
        """ Returns the rendered string. """

        for x in data["mkbasedproperties"].values():
            if not "bound_initials" in x:
                x["bound_initials"] = None

        suitable_mkbasedproperties = filter(
            lambda x: x["initials"] is not None or x["bound_initials"] is
            not None, data["mkbasedproperties"].values())

        if not suitable_mkbasedproperties:
            return ""

        initials_templates = list()
        for mkbasedproperty in suitable_mkbasedproperties:
            initials = mkbasedproperty["initials"]
            if initials is not None:
                if initials["initials_type"] == InitialsType.UNIFORM:
                    initials_templates.append(
                        get_template_text(cls.UNIFORM_XML).format(**initials))
                elif initials["initials_type"] == InitialsType.LINEAR:
                    initials_templates.append(
                        get_template_text(cls.LINEAR_XML).format(**initials))
                elif initials["initials_type"] == InitialsType.PARABOLIC:
                    initials_templates.append(
                        get_template_text(
                            cls.PARABOLIC_XML).format(**initials))

            bound_initials = mkbasedproperty["bound_initials"]
            if bound_initials is not None:
                if bound_initials["initials_type"] == BoundInitialsType.SET:
                    initials_templates.append(
                        get_template_text(
                            cls.SET_XML).format(**bound_initials))
                elif bound_initials[
                        "initials_type"] == BoundInitialsType.PLANE:
                    initials_templates.append(
                        get_template_text(
                            cls.PLANE_XML).format(**bound_initials))
                elif bound_initials[
                        "initials_type"] == BoundInitialsType.SPHERE:
                    initials_templates.append(
                        get_template_text(
                            cls.SPHERE_XML).format(**bound_initials))
                elif bound_initials[
                        "initials_type"] == BoundInitialsType.CYLINDER:
                    initials_templates.append(
                        get_template_text(
                            cls.CYLINDER_XML).format(**bound_initials))
                elif bound_initials[
                        "initials_type"] == BoundInitialsType.PARTS:
                    initials_templates.append(
                        get_template_text(
                            cls.PARTS_XML).format(**bound_initials))

        return get_template_text(cls.BASE_XML).format(
            initials_each=LINE_END.join(initials_templates))
Пример #12
0
    def get_linearspring_each_template(cls, chrono: dict) -> str:
        """ Renders the link_linearspring part of the chrono template. """
        link_linearspring_each_templates: list = list()

        for link in chrono["link_linearspring"]:
            link_linearspring_each_templates.append(
                get_template_text(cls.LINEARSPRING_BASE).format(**link))

        return LINE_END.join(link_linearspring_each_templates)
Пример #13
0
    def get_pointline_each_template(cls, chrono: dict) -> str:
        """ Renders the link_pointline part of the chrono template. """
        link_pointline_each_templates: list = list()

        for link in chrono["link_pointline"]:
            link_pointline_each_templates.append(
                get_template_text(cls.POINTLINE_BASE).format(**link))

        return LINE_END.join(link_pointline_each_templates)
Пример #14
0
 def get_velocity_times_template(cls, times: list) -> str:
     """ Renders the velocity times template for a uniform relaxation zone. """
     timevalues = LINE_END.join(
         map(
             lambda tv: get_template_text(
                 cls.RZONE_UNIFORM_VELOCITYTIMES_EACH_XML).format(
                     tv[0], tv[1]), times))
     return get_template_text(
         cls.RZONE_UNIFORM_VELOCITYTIMES_XML).format(each=timevalues)
Пример #15
0
    def get_objects_each_template(cls, chrono: dict) -> str:
        """ Renders the bodyfixed/floating part of the chrono template. """
        object_each_template_list: list = list()

        for chrono_object in chrono["objects"]:
            formatter: dict = chrono_object
            formatter["modelnormal_template"] = cls.get_modelnormal_fragment(
                chrono_object)
            object_each_template_list.append(
                get_template_text(cls.OBJECTS_BASE).format(**formatter))

        return LINE_END.join(object_each_template_list)
Пример #16
0
    def get_spheric_each_template(cls, chrono: dict) -> str:
        """ Renders the link_spheric part of the chrono template. """
        link_spheric_each_templates: list = list()

        for link in chrono["link_spheric"]:
            formatter: dict = link
            formatter["idbody2_template"] = cls.get_spheric_idbody2_fragment(
                link)
            link_spheric_each_templates.append(
                get_template_text(cls.SPHERIC_BASE).format(**link))

        return LINE_END.join(link_spheric_each_templates)
    def render(cls, data):
        """ Returns the rendered string. """
        float_properties = list(map(lambda x: x["float_property"], filter(lambda x: x["float_property"] is not None, data["mkbasedproperties"].values())))
        if not float_properties:
            return ""
        float_properties_xmls = []
        for fp in float_properties:
            float_property_attributes = []
            class_attributes = {
                cls.FLOATINGS_CENTER_XML: "gravity_center",
                cls.FLOATINGS_INERTIA_XML: "inertia",
                cls.FLOATINGS_LINEARVELINI_XML: "initial_linear_velocity",
                cls.FLOATINGS_ANGULARVELINI_XML: "initial_angular_velocity",
                cls.FLOATINGS_TRANSLATION_XML: "translation_restriction",
                cls.FLOATINGS_ROTATION_XML: "rotation_restriction",
                cls.FLOATINGS_MATERIAL_XML: "material"
            }
            for xml, attr in class_attributes.items():
                if fp[attr]:
                    if isinstance(fp[attr], list):
                        float_property_attributes.append(get_template_text(xml).format(*fp[attr]))
                    else:
                        float_property_attributes.append(get_template_text(xml).format(**{attr: fp[attr]}))

            formatter = {
                "floating_mk": fp["mk"],
                "rhopbody": "",
                "massbody": "",
                "float_property_attributes": LINE_END.join(float_property_attributes)
            }

            if fp["mass_density_type"] == FloatingDensityType.MASSBODY:
                formatter["massbody"] = get_template_text(cls.FLOATINGS_MASSBODY_XML).format(floating_density_value=fp["mass_density_value"])
            elif fp["mass_density_type"] == FloatingDensityType.RHOPBODY:
                formatter["rhopbody"] = get_template_text(cls.FLOATINGS_RHOPBODY_XML).format(floating_density_value=fp["mass_density_value"])

            float_properties_xmls.append(get_template_text(cls.FLOATINGS_EACH_XML).format(**formatter))

        formatter = {"floatings_each": LINE_END.join(float_properties_xmls) if float_properties_xmls else ""}
        return get_template_text(cls.FLOATINGS_XML).format(**formatter)
    def render(cls, data):
        """ Returns the rendered string. """
        ml_pistons: dict = dict()
        for mk, mk_prop in data["mkbasedproperties"].items():
            if mk_prop["mlayerpiston"]:
                ml_pistons[mk] = mk_prop["mlayerpiston"]

        if not ml_pistons.values():
            return ""

        each_mlpiston_template: list = list()
        for mk, mlpiston in ml_pistons.items():
            if mlpiston["type"] == MLPistonType.MLPISTON1D:
                mlpiston.update({"mk": mk})
                each_mlpiston_template.append(
                    get_template_text(
                        cls.MLPISTONS_EACH_1D).format(**mlpiston))
            elif mlpiston["type"] == MLPistonType.MLPISTON2D:
                each_veldata_templates: list = list()
                for veldata in mlpiston["veldata"]:
                    each_veldata_templates.append(
                        get_template_text(
                            cls.MLPISTONS_EACH_2D_VELDATA).format(**veldata))
                mlpiston.update({
                    "mk":
                    mk,
                    "each_veldata":
                    LINE_END.join(each_veldata_templates)
                })
                each_mlpiston_template.append(
                    get_template_text(
                        cls.MLPISTONS_EACH_2D).format(**mlpiston))

        formatter = {"each": LINE_END.join(each_mlpiston_template)}

        return get_template_text(cls.MLPISTONS_BASE).format(**formatter)
Пример #19
0
    def render(cls, data):
        """ Returns the rendered string. """
        if data["acceleration_input"]["enabled"] == "false":
            return ""

        accinput_template_list: list = list()

        for accinput in data["acceleration_input"]["acclist"]:
            accinput["globalgravity_int"] = 1 if accinput["globalgravity"] else 0
            accinput_template_list.append(get_template_text(cls.ACCINPUT_EACH).format(**accinput))

        formatter: dict = {
            "each": LINE_END.join(accinput_template_list)
        }

        return get_template_text(cls.ACCINPUT_BASE).format(**formatter)
Пример #20
0
    def get_lines_template(cls, data) -> str:
        """ Returns a list of <line> tags for moordyn. """
        each_line_template: list = list()

        for line in data["moorings"]["moordyn_configuration"]["lines"]:
            line.update({
                "vessel1_template": get_template_text(cls.MOORDYN_LINE_VESSEL_CONNECTION_TEMPLATE).format(**line["vessel_connection"]) if line["vessel_connection"] else "",
                "vessel2_template": get_template_text(cls.MOORDYN_LINE_VESSEL_CONNECTION_TEMPLATE).format(**line["vessel2_connection"]) if line["vessel2_connection"] else "",
                "fix_template": get_template_text(cls.MOORDYN_LINE_FIX_CONNECTION_TEMPLATE).format(**line["fix_connection"]) if line["fix_connection"] else "",
                "ea_template": get_template_text(cls.MOORDYN_LINE_EA_TEMPLATE).format(**line) if line["ea"] else "",
                "diameter_template": get_template_text(cls.MOORDYN_LINE_DIAMETER_TEMPLATE).format(**line) if line["diameter"] else "",
                "massDenInAir_template": get_template_text(cls.MOORDYN_LINE_MASSDENINAIR_TEMPLATE).format(**line) if line["massDenInAir"] else "",
                "ba_template": get_template_text(cls.MOORDYN_LINE_BA_TEMPLATE).format(**line) if line["ba"] else "",
            })
            each_line_template.append(get_template_text(cls.MOORDYN_LINE_TEMPLATE).format(**line))

        return LINE_END.join(each_line_template)
Пример #21
0
    def render(cls, data):
        """ Returns the rendered string. """
        if not data["inlet_outlet"]["zones"]:
            return ""

        inout_zone_template_list: list = list()

        for zone in data["inlet_outlet"]["zones"]:
            each_formatter = zone
            each_formatter["zone"] = cls.get_zone_template(zone)
            each_formatter["imposevelocity_param"] = cls.get_imposevelocity_param_template(zone)
            each_formatter["zsurf_param"] = cls.get_zsurf_param_template(zone)
            inout_zone_template_list.append(get_template_text(cls.INOUT_EACH).format(**each_formatter))

        formatter: dict = data["inlet_outlet"]
        formatter["each_zone"] = LINE_END.join(inout_zone_template_list)

        return get_template_text(cls.INOUT_BASE).format(**formatter)
Пример #22
0
    def get_each_motion_template(cls, movement: dict, counter: int) -> str:
        """ Renders the list of motions inside a movement. """
        if "generator" in movement.keys():
            # Is a SpecialMovement
            return cls.get_special_motion_template(movement["generator"])

        # If this code path is followed, is a regular movement
        if not movement["motion_list"]:
            return ""

        motion_templates: list = list()
        first_index = counter
        index = counter

        for it_index, motion in enumerate(movement["motion_list"]):
            is_last = it_index == len(movement["motion_list"]) - 1
            loops = is_last and movement["loop"]
            motion_templates.append(
                cls.get_specific_motion_template(motion, first_index, index,
                                                 is_last, loops))
            index += 1

        return LINE_END.join(motion_templates)
    def render(cls, data):
        """ Returns the rendered string. """
        each_link_templates: list = list()

        for mkreal, mkbasedproperty in data["mkbasedproperties"].items():
            if mkbasedproperty["property"]:
                each_formatter: dict = {
                    "mkbound": mkreal - MKFLUID_LIMIT,
                    "property_name": mkbasedproperty["property"]["name"],
                }
                each_link_templates.append(
                    get_template_text(
                        cls.EACH_LINK_XML).format(**each_formatter))

        if not each_link_templates:
            return ""

        if data["execution_parameters"]["rigidalgorithm"] not in (2, 3):
            return ""

        formatter: dict = {"each_link": LINE_END.join(each_link_templates)}

        return get_template_text(cls.PROPERTIES_BASE).format(**formatter)
Пример #24
0
    def render(cls, data):
        """ Returns the rendered string. """
        if not data["inlet_outlet"]["zones"]:
            return ""

        inout_zone_template_list: list = list()

        for zone in data["inlet_outlet"]["zones"]:
            each_formatter = zone
            each_formatter["zoneinfo"] = cls.get_zone_template(zone)
            each_formatter[
                "imposevelocity_param"] = cls.get_imposevelocity_param_template(
                    zone)
            each_formatter["zsurf_param"] = cls.get_zsurf_param_template(zone)
            inout_zone_template_list.append(
                get_template_text(cls.INOUT_EACH).format(**each_formatter))

        formatter: dict = data["inlet_outlet"]
        # 16/09/2021 Remove useboxlimit from the XML as Alex stated
        # formatter["useboxlimit_template"] = cls.get_useboxlimit_template(data["inlet_outlet"])
        formatter["useboxlimit_template"] = ""
        formatter["each_zone"] = LINE_END.join(inout_zone_template_list)

        return get_template_text(cls.INOUT_BASE).format(**formatter)
Пример #25
0
    def render(cls, data):
        """ Returns the rendered string. """
        suitable_mkbasedproperties = filter(
            lambda x: x["initials"] is not None,
            data["mkbasedproperties"].values())

        if not suitable_mkbasedproperties:
            return ""

        initials_templates = list()
        for mkbasedproperty in suitable_mkbasedproperties:
            initials = mkbasedproperty["initials"]

            if initials["initials_type"] == InitialsType.UNIFORM:
                initials_templates.append(
                    get_template_text(cls.UNIFORM_XML).format(**initials))
            elif initials["initials_type"] == InitialsType.LINEAR:
                initials_templates.append(
                    get_template_text(cls.LINEAR_XML).format(**initials))
            elif initials["initials_type"] == InitialsType.PARABOLIC:
                initials_templates.append(
                    get_template_text(cls.PARABOLIC_XML).format(**initials))

        return LINE_END.join(initials_templates)
Пример #26
0
    def get_imposevelocity_param_template(cls, zone: dict) -> str:
        """ Returns the imposevelocity inner template. """
        velocity_type = zone["velocity_info"]["velocity_type"]
        if velocity_type == InletOutletVelocityType.EXTRAPOLATED:
            return ""

        if velocity_type == InletOutletVelocityType.INTERPOLATED:
            raise Exception(
                "Inlet/Outlet Velocity type INTERPOLATED is not implemented on the XML renderer"
            )

        spec_type = zone["velocity_info"]["velocity_specification_type"]

        if velocity_type == InletOutletVelocityType.FIXED:
            if spec_type == InletOutletVelocitySpecType.FIXED_CONSTANT:
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_FIXED_CONSTANT).format(
                        zone["velocity_info"]["fixed_constant_value"])
            elif spec_type == InletOutletVelocitySpecType.FIXED_LINEAR:
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_FIXED_LINEAR).format(
                        **zone["velocity_info"]["fixed_linear_value"])
            elif spec_type == InletOutletVelocitySpecType.FIXED_PARABOLIC:
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_FIXED_PARABOLIC).format(
                        **zone["velocity_info"]["fixed_parabolic_value"])
        elif velocity_type == InletOutletVelocityType.VARIABLE:
            if spec_type == InletOutletVelocitySpecType.FILE_UNIFORM:
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_FILE_UNIFORM).format(
                        **zone["velocity_info"])
            elif spec_type == InletOutletVelocitySpecType.FILE_LINEAR:
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_FILE_LINEAR).format(
                        **zone["velocity_info"])
            elif spec_type == InletOutletVelocitySpecType.FILE_PARABOLIC:
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_FILE_PARABOLIC).format(
                        **zone["velocity_info"])
            elif spec_type == InletOutletVelocitySpecType.VARIABLE_UNIFORM:
                each_template = list()
                for each in zone["velocity_info"]["variable_uniform_values"]:
                    each_template.append(
                        get_template_text(
                            cls.INOUT_IMPOSEVELOCITY_VARIABLE_UNIFORM_EACH).
                        format(time=each[0], v=each[1]))
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_VARIABLE_UNIFORM).format(
                        variable_uniform_each=LINE_END.join(each_template))
            elif spec_type == InletOutletVelocitySpecType.VARIABLE_LINEAR:
                each_template = list()
                for each in zone["velocity_info"]["variable_linear_values"]:
                    each_template.append(
                        get_template_text(
                            cls.INOUT_IMPOSEVELOCITY_VARIABLE_LINEAR_EACH).
                        format(time=each[0], **each[1]))
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_VARIABLE_LINEAR).format(
                        variable_linear_each=LINE_END.join(each_template))
            elif spec_type == InletOutletVelocitySpecType.VARIABLE_PARABOLIC:
                each_template = list()
                for each in zone["velocity_info"]["variable_parabolic_values"]:
                    each_template.append(
                        get_template_text(
                            cls.INOUT_IMPOSEVELOCITY_VARIABLE_PARABOLIC_EACH).
                        format(time=each[0], **each[1]))
                return get_template_text(
                    cls.INOUT_IMPOSEVELOCITY_VARIABLE_PARABOLIC).format(
                        variable_parabolic_each=LINE_END.join(each_template))
Пример #27
0
        # Strip empty lines from the final XML to clean it up.
        while "\n\n" in final_xml:
            final_xml = final_xml.replace("\n\n", "\n")

        return final_xml

    def generate_material(self, case) -> str:
        """ Returns a material XML definition for DualSPHysics from the data available on the given case. """

        properties_list: list = list()
        for mkbasedproperty in case.mkbasedproperties.values():
            if mkbasedproperty.property:
                properties_list.append(
                    get_template_text(self.PROPERTY_MATERIALS_XML).format(
                        **mkbasedproperty.property.__dict__))

        formatter: dict = {"each_property": LINE_END.join(properties_list)}

        return get_template_text(self.BASE_MATERIALS_XML).format(**formatter)

    def save_to_disk(self, path, case: "Case") -> None:
        """ Creates a file on disk with the contents of the GenCase generated XML. """
        with open("{}/{}".format(path, self.MATERIAL_FILE_NAME),
                  "w",
                  encoding="utf-8") as file:
            file.write(self.generate_material(case))
        with open("{}/{}{}".format(path, case.name, self.GENCASE_XML_SUFFIX),
                  "w",
                  encoding="utf-8") as file:
            file.write(self.generate(case))