示例#1
0
 def alfaV(self, v0):
     """Retourne le alfa tel que V(alfa) = v0. Ne correspond pas à l'équilibre."""
     #         return newton(lambda alfa : self.V(alfa)-v0, radians(6.0), full_output=True, disp=False)
     #         except RuntimeError as msg : return nan
     alfa, res = newton(lambda alfa: self.V(alfa) - v0,
                        radians(6.0),
                        tol=self.EPS,
                        full_output=True,
                        disp=False)
     if res.converged:
         return alfa % π
     else:
         alfa = res.root
         res = dict(root=fmt(degrees(res.root)),
                    iterations=res.iterations,
                    function_calls=res.function_calls,
                    converged=res.converged,
                    cause=res.flag)
         rn = norm(self.resultante(self.normalise(alfa)))
         r = norm(self.resultante(alfa))
         cm = fmt(self.CmT(alfa))
         debug('alfaV : non CV')
         print("alfa_normalisé = %s," % fmt(degrees(alfa % π)),
               'resultante = (%s,%s),' % fmt((rn, r)), 'CmT =', cm)
         print('résultats newton = ', fmt(res))
         print()
         if abs(r) < self.EPS:
             return alfa % π
示例#2
0
    def equilibre(self, **kargs):
        """
        :param kargs: les variables à modifier, parmi self.VARIABLES
        :return:float, l'incidence alfa° telle que CmT(alfa)=0
        >>> P = Parapente('diamir')
        >>> eq = Equilibriste(P)
        >>> alfa = eq.equilibre(c=29.0, mp=100.0, S=28.0, d=10.0)
        # alfa sera l'incidence d'équilibre pour le parapente P,
        # avec un calage c, un pilote de masse mp, une surface S, et 10% de freins
        """
        objectif = self.CmT

        def objectif(alfa):
            """
            La fonction à annuler pour trouver l'équilibre
            Peut être que return self.CmT(alfa) suffit...
            """
            alfa = alfa % π
            fx, fz = self.resultante(alfa)
            return self.CmT(alfa)**2 + fx**2 + fz**2
            return fx**2 + fz**2

        if kargs: self.load(kargs)
        #disp=False pour que newton ne lève pas une exception
        alfa, res = newton(objectif,
                           radians(6.0),
                           tol=self.EPS,
                           full_output=True,
                           disp=False)
        if res.converged:
            return alfa % π
        else:
            alfa = res.root
            res = dict(root=fmt(degrees(res.root)),
                       iterations=res.iterations,
                       function_calls=res.function_calls,
                       converged=res.converged,
                       cause=res.flag)
            rn = norm(self.resultante(self.normalise(alfa)))
            r = norm(self.resultante(alfa))
            cm = self.CmT(alfa)
            debug('Non CV', resultante=(rn, r), CmT=cm, res=res)
            if abs(r) < self.EPS:
                return alfa % π
#             debug('Non CV', resultante=(fmt(rn,6), fmt(r,6)))
            return nan
示例#3
0
    def write(self, filename=None, **kargs):
        """
        :param freins:tuple, les % de freins pour lesquels on calcule l'équilibre, ∈[0.0, 100.0]
        :type filename: fichier ou str
        """
        if not kargs:
            kargs = readPyData(Path(DATA_DIR) / 'preferences' / 'aero2d.dict')

        if filename is None:
            fout = open(self.P.compfile, 'w')
#             filename=self.P.aerodir/"%s.comportement.txt"%self.session
        elif isinstance(filename, str):
            fout = open(filename, 'w')
        else:  #fichier ouvert. p. ex. sys.stdout
            fout = filename
        dump = fmt(self.toDump())
        print(sapero(), maintenant(), "\n\n", file=fout)
        with fout:
            titre = sursouligne("  Lexique et valeurs des paramètres  ", "=")
            print(titre, file=fout)
            for key in sorted(self.VARIABLES):
                print("%5s = %-6s = %s" %
                      (key, dump[key], self.VARIABLES[key]),
                      file=fout)
            print(
                "\nN.B. la valeur 'nan' (Not A Number), pour signifier que le calcul n\'a pas abouti (plantage, non convergence..)",
                file=fout)
            print(
                """\nN.B. suivant la valeur de l'incidence, le vol peut être d'un des types suivants (dans les 2 ou 3 derniers cas... à utiliser avec circonspection !):
            .   > vol normal,
            *   > vol marche arrière,
            **  > vol dos,
            *** > vol dos + marche arrière.""",
                file=fout)

            self._writeEquilibre(fout)
            for key, values in kargs.items():
                if key == 'mp':
                    self._writeVariationMassePilote(values, fout)
                if key == 'c':
                    #                     rdebug(values)
                    self._writeVariationCalage(values, fout)
示例#4
0
    def _writeVariationMassePilote(self, Ms, fout):
        eldump0 = self.toDump(
        )  #On le sauve car je crois qu'on le modifie un peu
        eldump0['mp'] = '***'
        print("\n\n", file=fout)
        titre = sursouligne("  Variation masse pilote  ", "=")
        print(titre, file=fout)
        if 0: print("paramètres :\n", fmt(eldump0), file=fout)
        eldump0 = self.toDump(
        )  #On le sauve car je crois qu'on le modifie un peu

        CZs, CXVs, CMVs, REs, Vs, VZs, CPs, FINs, CMTs = [], [], [], [], [], [], [], [], []
        THETAs, ALPHAs, vols = [], [], []
        for c in Ms:
            try:
                alfa = self.alfaEq(mp=c)
            except RuntimeError as msg:
                debug(msg, calage=c)
                alfa = nan
            idx, _ = self.typeDeVol(alfa)
            vols.append('.' if idx == 0 else idx * "*")
            ALPHAs.append(alfa * 180 / π)
            FINs.append(self.finesse(alfa))
            Vs.append(self.V(alfa) * 3.6)
            VZs.append(self.Vz(alfa))
            CPs.append(100 * self.CP(alfa))
            THETAs.append(self.θ(alfa) * 180 / π)
            r = self.resultante(alfa)
            REs.append(abs(r[0]) + abs(r[1]) + abs(self.CmT(alfa)))
            CMTs.append(self.CmT(alfa))
            CZs.append(self.Cz(alfa))
            CXVs.append(self.Cxv(alfa))
            CMVs.append(self.Cmv(alfa))
        rdebug(vols)
        print("---------------------|" + "-".join([7 * '-' for c in Ms]),
              file=fout)
        print(" masse pilote (kg)   |",
              " ".join(['%-7.2f' % c for c in Ms]),
              file=fout)
        print("---------------------|" + "-".join([7 * '-' for c in Ms]),
              file=fout)
        #         if not any(vols) :
        print(" Type de vol         |",
              " ".join(['%-7.2s' % c for c in vols]),
              file=fout)
        print(" Incidence (°)       |",
              " ".join(['%-7.2f' % c for c in ALPHAs]),
              file=fout)
        print(" Vitesse (km/h)      |",
              " ".join(['%-7.2f' % c for c in Vs]),
              file=fout)
        print(" Vz (m/s)            |",
              " ".join(['%-7.2f' % c for c in VZs]),
              file=fout)
        print(" Finesse             |",
              " ".join(['%-7.2f' % c for c in FINs]),
              file=fout)
        print(" Assiette (°)        |",
              " ".join(['%-7.2f' % c for c in THETAs]),
              file=fout)
        print(" Centre poussee (%)  |",
              " ".join(['%-7.2f' % c for c in CPs]),
              file=fout)
        print("---------------------|" + "-".join([7 * '-' for c in CPs]),
              file=fout)
        print(" Cz                  |",
              " ".join(['%-7.2f' % c for c in CZs]),
              file=fout)
        print(" Cx voile            |",
              " ".join(['%-7.2f' % c for c in CXVs]),
              file=fout)
        print(" Cm voile            |",
              " ".join(['%-7.2f' % c for c in CMVs]),
              file=fout)
        print("---------------------|" + "-".join([7 * '-' for c in CPs]),
              file=fout)
        print(" Resultante(=0 ?)    |",
              " ".join(['%-7.0g' % c for c in REs]),
              file=fout)
        print(" Moment(=0 ?)        |",
              " ".join(['%-7.0g' % c for c in CMTs]),
              file=fout)
        print("---------------------|" + "-".join([7 * '-' for c in Ms]),
              file=fout)
        self.load(eldump0)
示例#5
0
 def _writeEquilibre(self, fout):
     eldump0 = self.toDump(
     )  #On le sauve car je crois qu'on le modifie un peu
     titre = sursouligne('  Equilibre  ', "=")
     print('\n\n', file=fout)
     print(titre, file=fout)
     if 0: print("Paramètres:\n%s" % fmt(self.toDump()), file=fout)
     CZs, CXVs, CMVs, REs, Vs, VZs, CPs, FINs, CMTs = [], [], [], [], [], [], [], [], []
     DELTAs, THETAs, ALPHAs = [], [], []
     alfa = self.equilibre()
     ALPHAs.append(alfa * 180 / π)
     FINs.append(self.finesse(alfa))
     Vs.append(self.V(alfa) * 3.6)
     VZs.append(self.Vz(alfa))
     CPs.append(100 * self.CP(alfa))
     THETAs.append(self.θ(alfa) * 180 / π)
     r = self.resultante(alfa)
     REs.append(abs(r[0]) + abs(r[1]) + abs(self.CmT(alfa)))
     CMTs.append(self.CmT(alfa))
     CZs.append(self.Cz(alfa))
     CXVs.append(self.Cxv(alfa))
     CMVs.append(self.Cmv(alfa))
     # debug(titre="Je ne sais plus d'ou vient la formule pour simuler les freins !!")
     print(" Frein (%)           |",
           " ".join(['%-7.1f' % c for c in DELTAs]),
           file=fout)
     print("---------------------|" + "-".join([7 * '-' for c in CPs]),
           file=fout)
     print(" Incidence (°)       |",
           " ".join(['%-7.2f' % c for c in ALPHAs]),
           file=fout)
     print(" Vitesse (km/h)      |",
           " ".join(['%-7.2f' % c for c in Vs]),
           file=fout)
     print(" Vz (m/s)            |",
           " ".join(['%-7.2f' % c for c in VZs]),
           file=fout)
     print(" Finesse             |",
           " ".join(['%-7.2f' % c for c in FINs]),
           file=fout)
     print(" Assiette (°)        |",
           " ".join(['%-7.2f' % c for c in THETAs]),
           file=fout)
     print(" Centre poussee (%)  |",
           " ".join(['%-7.2f' % c for c in CPs]),
           file=fout)
     print("---------------------|" + "-".join([7 * '-' for c in CPs]),
           file=fout)
     print(" Cz                  |",
           " ".join(['%-7.2f' % c for c in CZs]),
           file=fout)
     print(" Cx voile            |",
           " ".join(['%-7.2f' % c for c in CXVs]),
           file=fout)
     print(" Cm voile            |",
           " ".join(['%-7.2f' % c for c in CMVs]),
           file=fout)
     print("---------------------|" + "-".join([7 * '-' for c in CPs]),
           file=fout)
     print(" Resultante(=0 ?)    |",
           " ".join(['%-7.0g' % c for c in REs]),
           file=fout)
     print(" Moment(=0 ?)        |",
           " ".join(['%-7.0g' % c for c in CMTs]),
           file=fout)
     self.load(eldump0)
示例#6
0
    def plot(self, **kargs):
        """TODO : tracés pour variation calage, longueur cône suspentage, CxV, Cxs, Cxp,..."""
        #         csfont = {'fontname':'Comic Sans MS'}
        hfont = {'fontname': 'Liberation Serif'}

        if not kargs:
            kargs = readPyData(Path(DATA_DIR) / 'preferences' / 'aero2d.dict')

        if 'mp' in kargs:
            Vs, VZs, CPs, FINs, ALPHAs = [], [], [], [], []
            Mp = kargs['mp']
            for m in Mp:
                alfa = self.alfaEq(mp=m)
                if alfa < 0:
                    #                     alfa = self.normalise(alfa)
                    debug('Fermeture, vol impossible; alfa=%s' %
                          fmt(degrees(alfa)))
                    alfa = nan
                    alfa = alfa % π
#                 idx, _ = self.typeDeVol(alfa)
#                 typevols.append('  .' if idx==0 else ' '+idx*"*")
                ALPHAs.append(alfa * 180 / π)
                FINs.append(self.finesse(alfa))
                Vs.append(self.V(alfa) * 3.6)
                VZs.append(self.Vz(alfa))
                CPs.append(100 * self.CP(alfa))
                r = self.resultante(alfa)


#                 REs.append(abs(r[0]) + abs(r[1]) + abs(self.CmT(alfa)))
#                 CMTs.append(self.CmT(alfa))
#                 CZs.append(self.Cz(alfa))
#                 CXVs.append(self.Cxv(alfa))
#                 CMVs.append(self.Cmv(alfa))

#         adeg = linspace(min(self.alfadegs), max(self.alfadegs), 100)
#         arad = linspace(min(self.alfas), max(self.alfas), 100)
#         Cxs, Czs = self.Cx(arad), self.Cz(arad)
        debug(finesses=fmt(FINs))
        debug(Vz=fmt(VZs))
        fig = plt.figure()
        ax1 = fig.add_subplot(221)
        ax2 = fig.add_subplot(222, sharex=ax1)
        ax3 = fig.add_subplot(223, sharex=ax1)
        ax4 = fig.add_subplot(224, sharex=ax1)
        #         ax4.set_xlim(left=0.0, right=max(Cxs))
        #         ax4.set_ylim(bottom=0.0, top=max(Czs))
        ax1.plot(Mp, FINs, 'b.-')  #, label='$ \\phi $')
        #         ax1.plot(self.alfadegs, self.Czs, 'b.', label='data')
        #         ax1.legend()
        ax1.set_xlabel('$ m_p (kg) $')
        ax1.set_ylabel('$ \\phi $')
        ax1.set_title('Finesses', **hfont)

        ax2.plot(Mp, Vs, 'b.-')  #, label='$V$')
        ax2.set_xlabel('$ m_p (kg) $ ')
        ax2.set_ylabel('$ V (km/h) $')
        ax2.set_title('Vitesse sur trajectoire (km/h)', **hfont)
        #         ax2.legend()
        ax3.plot(Mp, VZs, 'b.-')  #, label='data')
        ax3.set_ylabel('$ V_z (m/s) $')
        ax3.set_title('Taux de chute (m/s)', **hfont)
        if 0:
            ax4.plot(Mp, ALPHAs, 'b.-')  #, label='data')
            ax4.set_ylabel('$ \\alpha (°) $')
            ax4.set_title('Incidences', **hfont)
        if 1:
            ax4.plot(Mp, CPs, 'b.-')  #, label='data')
            ax4.set_ylabel('$ CP $ ')
            ax4.set_title('Centre de poussée % de corde', **hfont)
        fig.suptitle(
            'Session %s : variation de la masse pilote $m_p$\n' % AC.SESSION,
            **hfont)
        plt.tight_layout()
        plt.show()
示例#7
0
    def _writeVariationCalage(self, Cs, fout):
        eldump0 = self.toDump()
        eldump0['c'] = '###'
        titre = sursouligne("  Variation calage  ", "=")
        print("\n\n", file=fout)
        print(titre, file=fout)
        if 0: print("paramètres:\n", fmt(eldump0), file=fout)
        eldump0 = self.toDump()
        CZs, CXVs, CMVs, REs, Vs, VZs, CPs, FINs, CMTs = [], [], [], [], [], [], [], [], []
        THETAs, ALPHAs, typevols = [], [], []
        for c in Cs:
            try:
                alfa = self.alfaEq(c=c)
            except RuntimeError as msg:
                debug(msg, calage=c)
                alfa = nan
                # continue
            if alfa < 0:
                alfa = nan
                alfa = alfa % π
                debug('Fermeture, vol impossible')
            idx, _ = self.typeDeVol(alfa)
            typevols.append('  .' if idx == 0 else ' ' + idx * "*")
            ALPHAs.append(alfa * 180 / π)
            FINs.append(self.finesse(alfa))
            Vs.append(self.V(alfa) * 3.6)
            VZs.append(self.Vz(alfa))
            CPs.append(100 * self.CP(alfa))
            THETAs.append(self.θ(alfa) * 180 / π)
            r = self.resultante(alfa)
            REs.append(abs(r[0]) + abs(r[1]) + abs(self.CmT(alfa)))
            CMTs.append(self.CmT(alfa))
            CZs.append(self.Cz(alfa))
            CXVs.append(self.Cxv(alfa))
            CMVs.append(self.Cmv(alfa))
        print("---------------------|" + "-".join([7 * '-' for c in CPs]),
              file=fout)
        print(" Calage (% de corde) |",
              " ".join(['%-7.1f' % (100 * c) for c in Cs]),
              file=fout)
        print(" Type de vol         |" +
              " ".join(['%-7s' % c for c in typevols]),
              file=fout)
        print("---------------------|" + "-".join([7 * '-' for c in CPs]),
              file=fout)
        print(" Incidence (°)       |",
              " ".join(['%-7.2f' % c for c in ALPHAs]),
              file=fout)
        print(" Vitesse (km/h)      |",
              " ".join(['%-7.2f' % c for c in Vs]),
              file=fout)
        print(" Vz (m/s)            |",
              " ".join(['%-7.2f' % c for c in VZs]),
              file=fout)
        print(" Finesse             |",
              " ".join(['%-7.2f' % c for c in FINs]),
              file=fout)
        print(" Assiette (°)        |",
              " ".join(['%-7.2f' % c for c in THETAs]),
              file=fout)
        print(" Centre poussee (%)  |",
              " ".join(['%-7.2f' % c for c in CPs]),
              file=fout)
        print("---------------------|" + "-".join([7 * '-' for c in CPs]),
              file=fout)
        print(" Cz                  |",
              " ".join(['%-7.2f' % c for c in CZs]),
              file=fout)
        print(" Cx voile            |",
              " ".join(['%-7.2f' % c for c in CXVs]),
              file=fout)
        print(" Cm voile            |",
              " ".join(['%-7.2f' % c for c in CMVs]),
              file=fout)
        print("---------------------|" + "-".join([7 * '-' for c in CPs]),
              file=fout)
        print(" Resultante(=0 ?)    |",
              " ".join(['%-7.0g' % c for c in REs]),
              file=fout)
        print(" Moment(=0 ?)        |",
              " ".join(['%-7.0g' % c for c in CMTs]),
              file=fout)
        print("---------------------|" + "-".join([7 * '-' for c in CPs]),
              file=fout)

        #On rétablit dans sa config originale
        self.load(eldump0)
示例#8
0
 def __str__(self):
     return "(" + str(fmt(self.x)) + ", " + str(fmt(self.y)) + ", " + str(
         fmt(self.z)) + ")"
示例#9
0
     print(souligne('Pour B = (x,y,z) on doit trouver T(B) = (z,1,1-x)'))
     for B in (Point(1, 0, 0), Point(0, 0, 1), Point(0, 1,
                                                     0), Point(1, 1, 0),
               Point(0, 1, 1), Point(1, 0, 1), Point(1, 1,
                                                     1), Point(1, 2, 3),
               Point(random(), random(), random())):
         print('B = %s' % B, '=> T(B) = %s' % T(B))
     print('T = %r' % T)
 if 0:
     debug(paragraphe="l'invariant est-il invariant ?")
     T1 = Torseur(A=Point(random(), random(), random()),
                  R=Vecteur(random(), random(), random()),
                  M=Vecteur(random(), random(), random()))
     for i in range(10):
         P = Point(random(), random(), random())
         print("T1.invariant(P)", fmt(T1.invariant(P), 10))
 #################################################################
 ## VECTEUR TEST, NE PAS MODIFIER
 T1 = Torseur(Point(1, 1, 1), Vecteur(1, 2, -1), Vecteur(-1, 1, -2))
 #################################################################
 ## VECTEUR TEST, NE PAS MODIFIER
 if 0:
     debug(titre='somme de Torseurs T+=T1')
     print('T  = %r' % (T), 'invariant=%s' % fmt(T.invariant()))
     print('T1 = %r' % (T1), 'invariant=%s' % fmt(T1.invariant()))
     T += T1
     print('T += T1')  # =>\nT  = %r'%(T))
     print('T  après : %r' % T,
           'invariant=%s' % fmt(T.invariant()))  # =>\nT  = %r'%(T))
     print('T1 après : %r' % T1,
           'invariant=%s' % fmt(T1.invariant()))  # =>\nT  = %r'%(T))