Пример #1
0
    def linearize(in_file, partials_file):
        doc_in = etree.parse(in_file)

        sigma_yield = float(doc_in.xpath(x_sigma_yield)[0].text)

        n_ws = len(doc_in.xpath(x_sigmas_out[0])[0].text.split(';'))

        MTOW = float(doc_in.xpath(x_m_mtow)[0].text)
        S = float(doc_in.xpath(x_ref_area)[0].text)
        WS_init = float(doc_in.xpath(x_WS_init)[0].text)

        partials = Partials()
        for i in range(4):
            partials.declare_partials(
                x_con_sigmas[i], [x_sigma_yield, x_sigmas_out[i]], [
                    -np.array(doc_in.xpath(x_sigmas_out[i])[0].text.split(';'),
                              dtype=float) / sigma_yield**2,
                    n_ws * [1. / sigma_yield]
                ])

        partials.declare_partials(
            x_con_WS, [x_WS_init, x_ref_area, x_m_mtow],
            [-MTOW / S / WS_init**2, -MTOW / S**2 / WS_init, 1. / S / WS_init])
        partials.declare_partials(x_con_buffet, [x_CL_buffet, x_fwe_CL], [
            -float(doc_in.xpath(x_fwe_CL)[0].text) /
            float(doc_in.xpath(x_CL_buffet)[0].text)**2,
            1. / float(doc_in.xpath(x_CL_buffet)[0].text)
        ])

        partials.write(partials_file)
Пример #2
0
    def read_partials_file(self, file, partials):
        # type: (Union[str, etree._ElementTree], Vector) -> None
        """Read the partials from a given XML file and store them in this `Component`'s variables.

        Parameters
        ----------
            file : str or :obj:`etree._ElementTree`
                Path to or :obj:`etree._ElementTree` of a partials XML file.

            partials : Vector
                Partials vector of this `Component`.

        """
        output_rename_map = self.output_rename_map

        _partials = Partials(file)
        for of, wrts in _partials.get_partials().items():
            for wrt, val in wrts.items():
                of = xpath_to_param(of)
                if of in output_rename_map:
                    of = output_rename_map[of][0]

                wrt = xpath_to_param(wrt)
                if (of, wrt) in partials:
                    try:
                        partials[of, wrt] = val
                    except Exception as e:
                        print(e.message)
Пример #3
0
    def generate_partials_xml(self):
        partials = Partials()
        for i, x_sigma in enumerate(x_con_sigmas):
            partials.declare_partials(x_sigma,
                                      [x_sigma_yield, x_sigmas_out[i]])

        partials.declare_partials(x_con_WS, [x_WS_init, x_ref_area, x_m_mtow])
        partials.declare_partials(x_con_buffet, [x_CL_buffet, x_fwe_CL])
        return partials.get_string()
Пример #4
0
    def declare_partials_from_xml(self, partial_xml):
        # type: (Union[str, etree._ElementTree]) -> None
        """Declare partials to the `Component` based on a partials XML template file.

        Parameters
        ----------
            partial_xml : str or :obj:`etree._ElementTree`
                Path to or an `etree._ElementTree` of a partials XML file.
        """
        self.partials_from_xml.clear()
        if partial_xml is not None:
            partials = Partials(partial_xml)
            self.partials_from_xml = partials.get_partials().copy()
Пример #5
0
    def read_partials_file(self, file, partials):
        # type: (Union[str, etree._ElementTree], Vector) -> None
        """Read the partials from a given XML file and store them in this `Component`'s variables.

        Parameters
        ----------
            file : str or :obj:`etree._ElementTree`
                Path to or :obj:`etree._ElementTree` of a partials XML file.

            partials : Vector
                Partials vector of this `Component`.

        """
        _partials = Partials(file)
        for src, partial in _partials.get_partials().items():
            for tgt, val in partial.items():
                if [src, tgt] in partials:
                    try:
                        partials[src, tgt] = val
                    except Exception as e:
                        print(e.message)
    def generate_partials_xml(self):
        # type: () -> str
        """Generate the template partials XML file for this discipline.

        This method should be implemented to define for which inputs this discipline can provide the sensitivities.

        Returns
        -------
            str
                String representation of the template partials XML file.
        """
        return Partials().get_string()
Пример #7
0
    def linearize(in_file, partials_file):
        doc = etree.parse(in_file)
        z1 = float(doc.xpath(x_z1)[0].text)

        partials = Partials()
        partials.declare_partials(x_y1, [x_x1, x_y2, x_z1, x_z2], [1., -.2, 2.*z1, 1.])
        partials.write(partials_file)
Пример #8
0
    def linearize(in_file, partials_file):
        doc_in = etree.parse(in_file)

        partials = Partials()
        partials.declare_partials(x_obj_m_fuel, [x_m_fuel_init, x_m_fuel], [
            -float(doc_in.xpath(x_m_fuel)[0].text) /
            float(doc_in.xpath(x_m_fuel_init)[0].text)**2,
            1. / float(doc_in.xpath(x_m_fuel_init)[0].text)
        ])
        partials.declare_partials(x_obj_m_wing, [x_m_wing_init, x_m_wing], [
            -float(doc_in.xpath(x_m_wing)[0].text) /
            float(doc_in.xpath(x_m_wing_init)[0].text)**2,
            1. / float(doc_in.xpath(x_m_wing_init)[0].text)
        ])

        partials.write(partials_file)
Пример #9
0
    def linearize(in_file, partials_file):
        doc = etree.parse(in_file)
        y1 = float(doc.xpath(x_y1)[0].text)

        dy2_dy1 = .5 * float(((y1 > 0) - (y1 < 0))) / abs(y1)**.5

        partials = Partials()
        partials.declare_partials(x_y2, [x_y1, x_z1, x_z2], [dy2_dy1, 1., 1.])
        partials.write(partials_file)
Пример #10
0
    def linearize(in_file, partials_file):
        doc = etree.parse(in_file)
        x1 = float(doc.xpath(x_x1)[0].text)
        y2 = float(doc.xpath(x_y2)[0].text)

        partials = Partials()
        partials.declare_partials(x_f1, [x_x1, x_y1, x_y2, x_z2],
                                  [2. * x1, 1., -exp(-y2), 1.])
        partials.write(partials_file)
    def linearize(in_file, partials_file):
        # type: (str, str) -> None
        """Compute the sensitivities of a given input XML file and write them to a given partials XML file.

        This method should be implemented to define the linearization of a specific discipline. By default a discipline
        is considered a 'black box', and no sensitivities are provided.

        Parameters
        ----------
            in_file : str
                Path to the input XML file.

            partials_file : str
                Path to the sensitivities XML file.
        """
        Partials().write(partials_file)
Пример #12
0
    def linearize(in_file, partials_file):
        doc = etree.parse(in_file)
        c = float(doc.xpath(x_c)[0].text)
        z1 = float(doc.xpath(x_z1)[0].text)
        z2 = float(doc.xpath(x_z2)[0].text)
        x1 = float(doc.xpath(x_x1)[0].text)
        y2 = float(doc.xpath(x_y2)[0].text)

        partials = Partials()
        partials.declare_partials(x_y1, [x_c, x_x1, x_y2, x_z1, x_z2],
                                  [z1**2. + x1 + z2 - .2*y2, c, -.2*c, 2.*z1*c, c])
        partials.write(partials_file)
Пример #13
0
    def linearize(in_file, partials_file):
        doc = etree.parse(in_file)
        c = float(doc.xpath(x_c)[0].text)
        z1 = float(doc.xpath(x_z1)[0].text)
        z2 = float(doc.xpath(x_z2)[0].text)
        y1 = float(doc.xpath(x_y1)[0].text)

        dy2_dy1 = c * (.5 * float(((y1 > 0) - (y1 < 0))) / abs(y1)**.5)

        partials = Partials()
        partials.declare_partials(x_y2, [x_c, x_y1, x_z1, x_z2],
                                  [abs(y1)**.5 + z1 + z2, dy2_dy1, c, c])
        partials.write(partials_file)
Пример #14
0
 def generate_partials_xml(self):
     partials = Partials()
     partials.declare_partials(x_y2, [x_y1, x_z1, x_z2])
     return partials.get_string()
Пример #15
0
 def linearize(in_file, partials_file):
     partials = Partials()
     partials.declare_partials(x_g2, x_y2, 1. / 24.)
     partials.write(partials_file)
Пример #16
0
 def generate_partials_xml(self):
     partials = Partials()
     partials.declare_partials(x_obj_m_fuel, [x_m_fuel_init, x_m_fuel])
     partials.declare_partials(x_obj_m_wing, [x_m_wing_init, x_m_wing])
     return partials.get_string()
Пример #17
0
 def linearize(in_file, partials_file):
     partials = Partials()
     partials.declare_partials(x_g1, x_y1, -1. / 3.16)
     partials.write(partials_file)
Пример #18
0
 def generate_partials_xml(self):
     partials = Partials()
     partials.declare_partials(x_CD, [x_CDi % 1, x_CDf % 1, x_CDfus, x_CDother])
     partials.declare_partials(x_LD, [x_CDi % 1, x_CDf % 1, x_CDfus, x_CDother, x_CL % 1])
     partials.declare_partials(x_fwe_CL, x_CL % 1)
     partials.declare_partials(x_m_fuel, [x_CDi % 1, x_CDf % 1, x_CDfus, x_CDother, x_CL % 1,
                                          x_M % 1, x_H % 1, x_R, x_SFC, x_m_fuel_res, x_m_fixed, x_m_wing])
     partials.declare_partials(x_m_mtow, [x_CDi % 1, x_CDf % 1, x_CDfus, x_CDother, x_CL % 1,
                                          x_M % 1, x_H % 1, x_R, x_SFC, x_m_fuel_res, x_m_fixed, x_m_wing])
     return partials.get_string()
Пример #19
0
    def linearize(in_file, partials_file):
        tree = etree.parse(in_file)

        M = H = C_D_f = C_D_i = C_L = 0
        for i in range(1, LoadCaseSpecific.get_n_loadcases(tree) + 1):
            M = float(tree.xpath(x_M % i)[0].text)  # Mach number, [-]
            H = float(tree.xpath(x_H % i)[0].text)  # Altitude, [m]
            C_D_f = float(tree.xpath(x_CDf % i)[0].text)  # Friction drag coefficient, [-]
            C_D_i = float(tree.xpath(x_CDi % i)[0].text)  # Induced drag coefficient, [-]
            C_L = float(tree.xpath(x_CL % i)[0].text)  # Lift coefficient, [-]

            if round(float(tree.xpath(x_n % i)[0].text)) == 1.:
                break

        C_D_fus = float(tree.xpath(x_CDfus)[0].text)  # Fuselage drag coefficient, [-]
        C_D_other = float(tree.xpath(x_CDother)[0].text)  # Remaining drag coefficient, [-]
        R = float(tree.xpath(x_R)[0].text)  # Range, [m]
        SFC = float(tree.xpath(x_SFC)[0].text)  # Specific fuel consumption, [kg/N/s]
        m_fuel_res = float(tree.xpath(x_m_fuel_res)[0].text)  # Reserve fuel weight, [kg]
        m_fixed = float(tree.xpath(x_m_fixed)[0].text)  # Fixed weight, [kg]
        m_wing = float(tree.xpath(x_m_wing)[0].text)  # Wing weight, [kg]

        C_D = C_D_i + C_D_f + C_D_fus + C_D_other               # Total drag coefficient, [-]
        L_D = C_L / C_D  # Aerodynamic efficiency, L/D, [-]
        LW = m_fixed + m_wing + m_fuel_res  # Landing weight, [kg]
        T = T0 + beta * H  # Temperature at altitude, [K]
        a = sqrt(kappa * R_air * T)  # Speed of sound at altitude, [m/s]

        if L_D == 0:
            dLD_dd = 5*[1.]
            dmfuel_d2 = 12*[1.]
            dmmtow_dd = 12*[1.]
        else:
            m_fuel = LW * expm1(R * g0 * SFC / (a * M) / L_D)       # Required fuel weight, [kg]

            dmfuel_dd = LW*R*g0*SFC/(a*M*L_D)*exp(R*g0*SFC/(a*M*L_D))
            da_dH = .5*kappa*R_air/a

            dLD_dd = 4*[1./C_L] + [-C_D/C_L**2]
            dmfuel_d2 = 4*[dmfuel_dd/C_D] + [-dmfuel_dd/C_L, -dmfuel_dd/M,
                                             -dmfuel_dd/a*da_dH, dmfuel_dd/R,
                                             dmfuel_dd/SFC, 1., m_fuel/m_fuel_res,
                                             m_fuel/m_fixed, m_fuel/m_wing]
            dmmtow_dd = 4 * [dmfuel_dd / C_D] + [-dmfuel_dd / C_L, -dmfuel_dd / M,
                                                 -dmfuel_dd / a * da_dH, dmfuel_dd / R,
                                                 dmfuel_dd / SFC, 1., dmfuel_dd / m_fuel_res + 1.,
                                                 m_fuel / m_fixed + 1., m_fuel / m_wing + 1.]

        partials = Partials()
        partials.declare_partials(x_CD, [x_CDi % 1, x_CDf % 1, x_CDfus, x_CDother], 4*[1.])
        partials.declare_partials(x_LD, [x_CDi % 1, x_CDf % 1, x_CDfus, x_CDother, x_CL % 1], dLD_dd)
        partials.declare_partials(x_fwe_CL, x_CL % 1, 1.)
        partials.declare_partials(x_m_fuel, [x_CDi % 1, x_CDf % 1, x_CDfus, x_CDother, x_CL % 1,
                                             x_M % 1, x_H % 1, x_R, x_SFC, x_m_fuel_res, x_m_fixed, x_m_wing],
                                  dmfuel_d2)
        partials.declare_partials(x_m_mtow, [x_CDi % 1, x_CDf % 1, x_CDfus, x_CDother, x_CL % 1,
                                             x_M % 1, x_H % 1, x_R, x_SFC, x_m_fuel_res, x_m_fixed, x_m_wing],
                                  dmmtow_dd)

        partials.write(partials_file)
Пример #20
0
 def generate_partials_xml(self):
     partials = Partials()
     partials.declare_partials(x_g2, x_y2)
     return partials.get_string()
Пример #21
0
 def generate_partials_xml(self):
     partials = Partials()
     partials.declare_partials(x_x1, [x_x0])
     return partials.get_string()
Пример #22
0
 def linearize(in_file, partials_file):
     partials = Partials()
     partials.declare_partials(x_x1, x_x0, 1.)
     partials.write(partials_file)