IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

retour à la ligne


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    étudiante
    Inscrit en
    Mai 2011
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante

    Informations forums :
    Inscription : Mai 2011
    Messages : 41
    Par défaut retour à la ligne
    Bonjour,

    j'ai un script qui contient plusieurs expressions et équations longues, je veux écrire ces équations en deux ligne mais je connais pas le symbole à mettre pour le retour à la ligne pour que l'expression soit valide.
    les expressions sont dans les lignes 73 ,74 et 121,122 et 167
    le script est le suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
     
    # import statements
    # import abaqus
     
    from odbAccess import*
    from abaqusConstants import*
    from odbMaterial import*
    from odbSection import*
    from math import*
     
     
    # open  text files  in which we'll put and display the results 
    f10=open('GAG.txt','w')
    f11=open('LMC.txt','w')
    f12=open('CC.txt','w')
    f13=open('OO.txt','w')
    f14=open('SS.txt','w')
     
     
    # open DATABASE
    odb = openOdb(path='hcf.odb')
    lcf = openOdb(path='lcf.odb')
     
     
    # determine the number and names of instances in the odb 
    myAssembly = odb.rootAssembly
    for instanceName in odb.rootAssembly.instances.keys():
        print 'Instance Name : ',instanceName
     
     
    # determine the materials of each instance in the odb
    allMaterials = odb.materials
    for materialName in allMaterials.keys():
        print 'Material Name : ',materialName
     
     
    # determine the number and names of steps in the odb
    for stepName in odb.steps.keys():
        print stepName
     
     
    # determine the node sets and the element sets in the odb    
    print 'Node sets = ',odb.rootAssembly.instances['V20110406-1-1'].nodeSets.keys()
    print 'element sets = ',odb.rootAssembly.instances['V20110406-1-1'].elementSets.keys()
     
     
    # define the material parameters
    Rm = 470
    Re = 390
    sig_D_mean = 120.317804382247
     
     
    # define the model chosen
    modele = ['Goodman', 'Gerber', 'Soderberg']
    print modele
    choix = input ('Entrer le nom du modele choisi parmi la liste precedante')
    def sig_Goodman(Rm, dyn, stat, alpha):
        return (Rm*dyn)/(Rm-(stat/alpha))
    def sig_Gerber(Re, dyn, stat):
        return ((Re**2)*dyn)/(Re**2-(stat)**2)
    def sig_Soderberg(Re, dyn, stat, alpha):
        return (Re*dyn)/(Re-(stat/alpha))
     
     
    # define the Damage Tolerance curve and the Flaw Tolerance curve
    Ratio = [-1,-0.8,-0.6,-0.4,-0.2,0,0.2,0.4,0.6,0.8,1]
    DTA1 = [66.8,64.4,61.3,57.4,52.7,47.3,39.0,32.9,27.2,16.8,0]
    DTA2 = [56.3,54.3,51.7,48.4,44.4,39.8,32.9,27.8,22.9,14.2,0]
    FTA = [194.2,187.4,178.4,167.0,153.4,137.5,113.6,95.8,79.0,48.9,0]
     
     
    # define the safe curve
    x = [1,1666,16666,100000,200000,300000,400000,500000,700000,1000000,2000000,3000000,4000000,7000000,10000000,20000000,30000000,40000000,50000000,80000000,100000000,200000000,300000000,400000000,700000000,1000000000,10000000000]
    y = [333.487953502046,333.487953502046,252.023589004762,144.841143106185,134.316479532823,128.773084241854,125.091228664023,122.370855728624,118.481010326472,114.620454409826,107.826945429572,104.248768756484,101.872187428479,97.605392834564,95.113463177554,90.728357283851,88.418699099329,86.884652288088,85.751207659768,83.515504894025,82.521999403873,79.691480778685,78.200631830545,77.210428132759,75.432666212810,74.394402580963,69.148163438073]
     
     
    # define the list of target cycle of HCF and LCF
    T_cycle = [28555200,28555200,19036800,590140800,28555200,38073600,76147200,95184000,47592000,20000,100,40000,10000,40000]
     
    # calculate the mean, alternating and equivalent stresses
    # and the service life and the damage
    def calcul(k,f):
        maxStress=0
        for idx, value in enumerate(Stress) :
            S11 = value.data[0]
            S22 = value.data[1]
            S12 = value.data[3]
            e = Stress1[idx]
            S_11 = e.data[0]
            S_22 = e.data[1]
            S_12 = e.data[3]
            # calculate the alternating stress tensor and its eigenvalues
            D11 = (S11-S_11)/2
            D22 = (S22-S_22)/2
            D12 = (S12-S_12)/2
            Dyn1 = ((D11+D22)-sqrt(D11**2+D22**2+4*D12**2-2*D11*D22))/2
            Dyn2 = ((D11+D22)+sqrt(D11**2+D22**2+4*D12**2-2*D11*D22))/2
            # calculate the mean stress tensor and its eigenvalues
            St11 = (S11+S_11)/2
            St22 = (S22+S_22)/2
            St12 = (S12+S_12)/2
            Stat1 = ((St11+St22)+sqrt(St11**2+St22**2+4*St12**2-2*St11*St22))/2
            Stat2 = ((St11+St22)-sqrt(St11**2+St22**2+4*St12**2-2*St11*St22))/2
            # calculate the alternating stress and the mean stress
            if abs(Dyn1)>=abs(Dyn2):
                sig_dyn = abs(Dyn1)
            else:
                sig_dyn = abs(Dyn2)
     
            if abs(Stat1)>=abs(Stat2):
                signe = Stat1/abs(Stat1)
                sig_stat = signe*sqrt(Stat1**2-Stat1*Stat2+Stat2**2)
            else:
                signe = Stat2/abs(Stat2)
                sig_stat = signe*sqrt(Stat2**2-Stat1*Stat2+Stat1**2)
            # calculate the maximum and minimum stress and the ratio
            Max = sig_dyn+sig_stat
            Min = sig_stat-sig_dyn
            R = Min/Max
            # calculate the equivalent stress
            alpha_G = abs(sig_D_mean/((sig_dyn/sig_stat)+(sig_D_mean/Rm)))*((1+(sig_dyn/sig_stat)**2)/(sig_dyn**2+sig_stat**2))**0.5
            alpha_S = abs(sig_D_mean/((sig_dyn/sig_stat)+(sig_D_mean/Re)))*((1+(sig_dyn/sig_stat)**2)/(sig_dyn**2+sig_stat**2))**0.5
            if choix == 'Goodman':
                sig_eq = sig_Goodman(Rm, sig_dyn, sig_stat, alpha_G)
            elif choix == 'Gerber':
                sig_eq = sig_Gerber(Re, sig_dyn, sig_stat)
            elif choix == 'Soderberg':
                sig_eq = sig_Soderberg(Re, sig_dyn, sig_stat, alpha_S)
            else:
                print ('Votre choix n appartient pas a la liste precedante')
            if sig_eq > maxStress:
                maxStress = sig_eq
            # determination of the service life
            if sig_eq > y[0]:
                N_cycle = 0
            elif sig_eq <= y[-1]:
                N_cycle = 1.0E+10
            else:
                i=0
                len_y=len(y)
                while (i < len_y - 1):
                    if (sig_eq < y[i]) and (sig_eq > y[i+1]):
                        N_cycle = x[i+1]-((y[i+1]-sig_eq)*(x[i+1]-x[i])/(y[i+1]-y[i]))
                        break
                    i=i+1
            # calculate the damage
            Damage = T_cycle[k-1]/N_cycle
            # projection of the alternating stresses on the DTA and FTA curves
            if (R<-1) or (R>1):
                propa_DTA1=-1.0E-01
                propa_DTA2=-1.0E-01
                propa_FTA=-1.0E-01
            else:
                j =0
                len_DTA1 = len(DTA1)
                while (j < len_DTA1 - 1):
                    if (R > Ratio[j]) and (R < Ratio[j+1]):
                        sig_DTA1 = DTA1[j+1]-((Ratio[j+1]-R)*(DTA1[j+1]-DTA1[j])/(Ratio[j+1]-Ratio[j]))
                        propa_DTA1 = sig_dyn-sig_DTA1
                        sig_DTA2 = DTA2[j+1]-((Ratio[j+1]-R)*(DTA2[j+1]-DTA2[j])/(Ratio[j+1]-Ratio[j]))
                        propa_DTA2 = sig_dyn-sig_DTA2
                        sig_FTA = FTA[j+1]-((Ratio[j+1]-R)*(FTA[j+1]-FTA[j])/(Ratio[j+1]-Ratio[j]))
                        propa_FTA = sig_dyn-sig_FTA
                        break
                    j=j+1
     
            f.write('Instance:\t %s\tElement:\t %6d\tSig_stat:\t %E\tSig_dyn:\t %E\tMax:\t %E\tMin:\t %E\tR:\t %E\tSig_eq:\t %E\tN_cycle:\t %E\tMaxStress:\t %E\tDamage:\t %E\tpropa_DTA1:\t %E\tpropa_DTA2:\t %E\tpropa_FTA:\t %E\n'%(value.instance.name,value.elementLabel,sig_stat,sig_dyn,Max,Min,R,sig_eq,N_cycle,maxStress,Damage,propa_DTA1,propa_DTA2,propa_FTA))
     
     
    #------------------------------------------------Analyse_frequentielle: HCF-------------------------------------------------------
     
    nb_loadcase = 9
    i = 1
    while i <= nb_loadcase:
        #print "HCF%i" %i 
        stressField = odb.steps['Load'].frames[i+1].fieldOutputs['S']
        stressField1 = odb.steps['Load'].frames[i+2].fieldOutputs['S']
        topCenter = odb.rootAssembly.instances['V20110406-1-1'].elementSets['SKIN']
        Stress = stressField.getSubset(region=topCenter, position=CENTROID).values
        Stress1 = stressField1.getSubset(region=topCenter, position=CENTROID).values
        f=open('HCF%i'%i + '.txt','w')
        calcul(i,f)
        i=i+1    
     
     
    #------------------------------------------------Analyse_temporelle: LCF-------------------------------------------------------
     
     
    #-----------------------------------------------------------GAG-----------------------------------------------------------------
     
     
    # determine the stress value at the frame number 2 and 11  of the second step
    # in the "SKIN" element set (GAG)
    stressField = lcf.steps['Load'].frames[2].fieldOutputs['S']
    stressField1 = lcf.steps['Load'].frames[11].fieldOutputs['S']
    topCenter = lcf.rootAssembly.instances['V20110406-1-1'].elementSets['SKIN']
    Stress = stressField.getSubset(region=topCenter, position=CENTROID).values
    Stress1 = stressField1.getSubset(region=topCenter, position=CENTROID).values
    calcul(nb_loadcase+1, f10)
     
     
    #-----------------------------------------------------------LMC-----------------------------------------------------------------
     
     
    # determine the stress value at the frame number 2 and 17 of the second step
    # in the "SKIN" element set (LMC)
    stressField = lcf.steps['Load'].frames[2].fieldOutputs['S']
    stressField1 = lcf.steps['Load'].frames[17].fieldOutputs['S']
    topCenter = lcf.rootAssembly.instances['V20110406-1-1'].elementSets['SKIN']
    Stress = stressField.getSubset(region=topCenter, position=CENTROID).values
    Stress1 = stressField1.getSubset(region=topCenter, position=CENTROID).values
    calcul(nb_loadcase+2, f11)
     
     
    #-----------------------------------------------------------CC-----------------------------------------------------------------
     
     
    # determine the stress value at the third and forth frame of the second step
    # in the "SKIN" element set (CC)
    stressField = lcf.steps['Load'].frames[3].fieldOutputs['S']
    stressField1 = lcf.steps['Load'].frames[4].fieldOutputs['S']
    topCenter = lcf.rootAssembly.instances['V20110406-1-1'].elementSets['SKIN']
    Stress = stressField.getSubset(region=topCenter, position=CENTROID).values
    Stress1 = stressField1.getSubset(region=topCenter, position=CENTROID).values
    calcul(nb_loadcase+3, f12)
     
     
    #-----------------------------------------------------------OO-----------------------------------------------------------------
     
     
    # determine the stress value at the frame nuber 2 and 13 of the second step
    # in the "SKIN" element set (OO)
    stressField = lcf.steps['Load'].frames[2].fieldOutputs['S']
    stressField1 = lcf.steps['Load'].frames[13].fieldOutputs['S']
    topCenter = lcf.rootAssembly.instances['V20110406-1-1'].elementSets['SKIN']
    Stress = stressField.getSubset(region=topCenter, position=CENTROID).values
    Stress1 = stressField1.getSubset(region=topCenter, position=CENTROID).values
    calcul(nb_loadcase+4, f13)
     
     
    #-----------------------------------------------------------SS-----------------------------------------------------------------
     
     
    # determine the stress value at the frame number 5 and 7 of the second step
    # in the "SKIN" element set (SS)
    stressField = lcf.steps['Load'].frames[5].fieldOutputs['S']
    stressField1 = lcf.steps['Load'].frames[7].fieldOutputs['S']
    topCenter = lcf.rootAssembly.instances['V20110406-1-1'].elementSets['SKIN']
    Stress = stressField.getSubset(region=topCenter, position=CENTROID).values
    Stress1 = stressField1.getSubset(region=topCenter, position=CENTROID).values
    calcul(nb_loadcase+5, f14)

    merci d'avance

    Cordialement

  2. #2
    Membre Expert
    Profil pro
    Développeur en systèmes embarqués retraité
    Inscrit en
    Mars 2006
    Messages
    952
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2006
    Messages : 952
    Par défaut
    Salut,

    C'est '\n'

    A+

    Pfeuh

  3. #3
    Membre Expert Avatar de pacificator
    Profil pro
    Inscrit en
    Août 2006
    Messages
    1 074
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 1 074
    Par défaut
    Bonjour,

    tout est dans la doc.

    Les jointures explicites utilisent un \:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    if 1900 < year < 2100 and 1 <= month <= 12 \
       and 1 <= day <= 31 and 0 <= hour < 24 \
       and 0 <= minute < 60 and 0 <= second < 60:   # Looks like a valid date
            return 1
    les jointures implicites peuvent être utilisées pour les expressions entre (), {}, []:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    month_names = ['Januari', 'Februari', 'Maart',      # These are the
                   'April',   'Mei',      'Juni',       # Dutch names
                   'Juli',    'Augustus', 'September',  # for the months
                   'Oktober', 'November', 'December']   # of the year

  4. #4
    Membre Expert Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Par défaut
    Bonjour,

    J'y rajouterais le PEP8: Limit all lines to a maximum of 79 characters.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    month_names = ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli',
                   'Augustus', 'September','Oktober', 'November', 'December']
    Ou moins si c'est plus lisible bien sur.

    @+

  5. #5
    Membre averti
    Femme Profil pro
    étudiante
    Inscrit en
    Mai 2011
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante

    Informations forums :
    Inscription : Mai 2011
    Messages : 41
    Par défaut
    salut

    j'ai mis \n dans les lignes 121 et 122 après * mais il a généré des erreurs:
    "unexpected character after line continuation charater"

  6. #6
    Membre Expert Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Par défaut
    Lire #3 et #4

  7. #7
    Membre averti
    Femme Profil pro
    étudiante
    Inscrit en
    Mai 2011
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante

    Informations forums :
    Inscription : Mai 2011
    Messages : 41
    Par défaut
    désolée j'ai pas compris; c'est quoi le #3 et #4

  8. #8
    Membre Expert Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Par défaut
    Re,

    Les réponses 3 et 4.

  9. #9
    Membre Expert
    Profil pro
    Développeur en systèmes embarqués retraité
    Inscrit en
    Mars 2006
    Messages
    952
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2006
    Messages : 952
    Par défaut
    Citation Envoyé par PauseKawa Voir le message
    Lire #3 et #4
    Euh oui, j'ai lu la question en diagonale.

  10. #10
    Expert confirmé

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 307
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 307
    Par défaut
    Remarque, si tu as un caractère non visible, donc une espace ou tabulation, après le '\', tu auras aussi droit à:

    SyntaxError: unexpected character after line continuation character

Discussions similaires

  1. Caractère de retour à la ligne.
    Par Pari dans le forum MS SQL Server
    Réponses: 6
    Dernier message: 18/03/2009, 09h59
  2. [FileWriter] retour à la ligne
    Par LoLoSS dans le forum Entrée/Sortie
    Réponses: 5
    Dernier message: 23/06/2004, 10h52
  3. [JTextArea] Fichier et retour à la ligne
    Par eraim dans le forum Composants
    Réponses: 4
    Dernier message: 23/06/2004, 08h21
  4. [MFC] Retour à la ligne dans un CEdit
    Par Kant dans le forum MFC
    Réponses: 7
    Dernier message: 18/02/2004, 08h58
  5. Conserver les retours à la ligne
    Par arwen dans le forum ASP
    Réponses: 2
    Dernier message: 04/12/2003, 12h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo