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)
Пример #2
0
 def get_useboxlimit_template(cls, iodata: dict) -> str:
     if iodata["useboxlimit_freecentre_enabled"] == "true":
         return get_template_text(
             cls.INOUT_USEBOXLIMITWITHFREECENTRE).format(**iodata)
     else:
         return get_template_text(
             cls.INOUT_USEBOXLIMITWITHOUTFREECENTRE).format(**iodata)
    def render(cls, data, rz_type: str):
        """ Returns the rendered string. """
        template = get_template_text(cls.RZONES_XML)
        rz_templates = {
            "RelaxationZoneRegular": cls.RZONE_REGULAR_XML,
            "RelaxationZoneIrregular": cls.RZONE_IRREGULAR_XML,
            "RelaxationZoneFile": cls.RZONE_FILE_XML,
            "RelaxationZoneUniform": cls.RZONE_UNIFORM_XML
        }
        rzone_formatter = {}

        if rz_type == "RelaxationZoneUniform":
            if data["relaxation_zone"]["use_velocity"] == "true":
                rzone_formatter["rzuniform_velocity"] = get_template_text(
                    cls.RZONE_UNIFORM_VELOCITY_XML).format(
                        data["relaxation_zone"]["velocity"])
            else:
                rzone_formatter[
                    "rzuniform_velocity"] = cls.get_velocity_times_template(
                        data["relaxation_zone"]["velocity_times"])

        rzone_formatter.update(data["relaxation_zone"])
        formatter = {
            "rzone":
            get_template_text(rz_templates[rz_type]).format(**rzone_formatter)
        }
        return template.format(**formatter)
    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)
Пример #5
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 ""
Пример #6
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)
Пример #7
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 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)
Пример #9
0
    def get_awas_template(cls, awas: dict) -> str:
        """ Renders the <awas_zsurf> tag for a piston generator. """

        awas["correction"]["correction_enabled"] = "" if awas["correction"][
            "enabled"] == "true" else "_"

        awas["correction_template"] = get_template_text(
            cls.WAVEPADDLES_PISTON_AWAS_CORRECTION).format(
                **awas["correction"])

        return get_template_text(cls.WAVEPADDLES_PISTON_AWAS).format(**awas)
    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))
Пример #11
0
    def get_special_motion_template(cls, motion_generator: dict) -> str:
        """ Renders an SpecialMovement motion inside a movement. """
        if not motion_generator:
            raise ValueError(
                "Generator for an SpecialMovement should always have a value")

        if motion_generator[
                "type"] not in cls.MOTION_GENERATORS_TEMPLATES.keys():
            return get_template_text(cls.MOTION_NULL_TEMPLATE)

        return get_template_text(
            cls.MOTION_GENERATORS_TEMPLATES[motion_generator["type"]]).format(
                **motion_generator)
Пример #12
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)
Пример #13
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)
Пример #14
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 ""
Пример #15
0
    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__))
Пример #16
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)
Пример #17
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)
Пример #18
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)
Пример #19
0
    def get_regular_piston_wave_template(cls, mk: int, generator: dict) -> str:
        """ Renders a <piston> tag from a regular piston wave generator. """
        generator["mk"] = mk

        generator["awas_template"] = cls.get_awas_template(
            generator["awas"]
        ) if generator["awas"]["enabled"] == "true" else ""

        return get_template_text(
            cls.WAVEPADDLES_REGULAR_PISTON).format(**generator)
Пример #20
0
    def generate(self, case) -> str:
        """ Returns the GenCase-compatible XML resulting from the case """
        final_xml: str = get_template_text(
            self.BASE_XML).format(**self.get_adapted_case_data(case))

        # 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
Пример #21
0
    def get_specific_motion_template(cls, motion, first_index: int, index: int,
                                     is_last: bool, loops: bool):
        """ Renders an individual motion based on its type. """
        if motion["type"] not in cls.MOTION_TEMPLATES.keys():
            return get_template_text(cls.MOTION_NULL_TEMPLATE)

        motion.update({
            "index":
            index,
            "next_attr":
            get_template_text(cls.MOTION_NEXT_ATTR).format(next_index=index +
                                                           1)
        })

        if is_last:
            motion["next_attr"] = "" if not loops else get_template_text(
                cls.MOTION_NEXT_ATTR).format(next_index=first_index)

        return get_template_text(
            cls.MOTION_TEMPLATES[motion["type"]]).format(**motion)
Пример #22
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)
Пример #23
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)
    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. """
        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)
Пример #26
0
    def get_moordyn_embedded_template(cls, data: dict) -> str:
        """ Returns the rendered embedded config for a moordyn configuration. """
        moordyn = data["moorings"]["moordyn_configuration"]

        formatter: dict = {
            "endTime": data["execution_parameters"]["timemax"],
            "dtOut": data["execution_parameters"]["timeout"],
            "bodies_template": cls.get_bodies_template(data),
            "lines_template": cls.get_lines_template(data)
        }

        formatter.update(moordyn)

        return get_template_text(cls.MOORDYN_EMBEDDED_CONFIG).format(**formatter)
Пример #27
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)
Пример #28
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)
Пример #29
0
 def render(cls, data):
     """ Returns the rendered string. """
     template = get_template_text(cls.DEFINITION_XML)
     fc_object = FreeCAD.ActiveDocument.getObject("Case_Limits")
     min_point = fc_object.Placement.Base
     formatter = {
         "dp": data["dp"],
         "pointmin": [min_point.x / DIVIDER, min_point.y / DIVIDER, min_point.z / DIVIDER],
         "pointmax": [
             min_point.x / DIVIDER + fc_object.Length.Value / DIVIDER,
             min_point.y / DIVIDER + fc_object.Width.Value / DIVIDER if data["mode3d"] == "true" else min_point.y / DIVIDER,
             min_point.z / DIVIDER + fc_object.Height.Value / DIVIDER
         ]
     }
     return template.format(**formatter)
Пример #30
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)