Discrétisation d'un barreau élastique et passage au continu

FondamentalDiaporama du micro-contenu (rafraichir la page si redimensionnée)

SimulationProgramme Python

1
# -*- coding: utf-8 -*-
2
"""
3
Chaine continue
4
O. Thual, 21/08/2021
5
"""
6
7
#  clear all
8
for iglob in list(globals().keys()):
9
    if(iglob[0] != '_'):
10
        exec('del {}'.format(iglob))
11
# import libraries
12
import numpy as np
13
import matplotlib.pyplot as plt
14
import os
15
16
17
def inifig(xaxe=0,yaxe=0,xlab='x',ylab='y'):
18
    plt.figure(2)
19
    plt.axvline(xaxe)
20
    plt.axhline(yaxe)
21
    plt.xticks(fontsize=12)
22
    plt.yticks(fontsize=12)
23
    plt.xlabel(xlab,fontsize=16 )
24
    plt.ylabel(ylab,fontsize=16)
25
    
26
def zfi(x,le=2):
27
    miss=le-len(str(x))
28
    a='0'*miss+str(x)
29
    return a
30
31
def animation(name):
32
    a=np.linspace(0,L,N+1);
33
    acont=np.linspace(0,L,501);
34
    t=0; 
35
    dt=T/Nt
36
    for i in range(0,Nt+1):
37
        title=name+" i="+zfi(i)
38
        titlefig=name
39
        print(title)
40
        fig=plt.figure(N,figsize=(7,4))
41
        plt.xlabel('a',fontsize=16 )
42
        plt.ylabel(r'Déplacement $\xi$',fontsize=16)
43
        plt.title(titlefig,fontsize=16)
44
        # signal
45
        t=dt*i;
46
        xi=signal(a,t)
47
        xicont=signal(acont,t)
48
        for dup in duprange:
49
            plt.scatter(a+sc*xi,dup+0*xi,marker='o',color='blue',s=40)
50
            plt.scatter(a,dup+0*xi,marker='o',color='red',s=20)
51
        plt.plot(acont,xicont,color='black',linewidth=3)
52
        #plt.scatter(a,xi,marker='o',color='black',s=40)
53
        plt.xlim(0,L)
54
        plt.ylim(ymin,ymax)
55
        namei=name+zfi(i)+'.png';
56
        plt.grid(color='black', axis='y', linestyle='-', linewidth=1)        
57
        plt.grid(color='black', axis='x', linestyle='-', linewidth=1)        
58
        plt.savefig(namei)
59
        #plt.show()
60
        plt.close()
61
    gifanim="Anim"+name+".gif"
62
    os.system('/opt/local/bin/convert -set delay '+delay+' '+name+'* '+gifanim);
63
    os.system('rm '+name+'*');   
64
65
# Main 
66
F=False; T=True
67
68
def pulse(a,d):
69
    al=0*a[a<-d]; ac=a[np.abs(a)<=d]; ar=0*a[a>d];
70
    k=np.pi/d; fc=.5*(1+np.cos(k*ac));
71
    f=np.concatenate((al,fc,ar))
72
    return f
73
74
def statio(a,d):
75
    k=np.pi/d; fc=.5*(1+np.cos(k*ac));
76
    f=np.cos
77
    return f
78
79
# Pulse
80
if T: 
81
    N=20; L=10; d=4; c=1; 
82
    T=(L+2*d)/c; Nt=20; sc=.9*L/N # scaling 
83
    k=np.pi/d;
84
    ymin=-.2; ymax=1;
85
    duprange=np.linspace(-.2,1,7)
86
    delay="80"
87
    # signal 
88
    def signal(a,t):
89
        xi=pulse(a-c*t+d,d)
90
        return xi
91
    animation("Pulse") 
92
93
 # Progressive-cos
94
if F: 
95
    N=20; L=10; c=1; 
96
    Nt=20; sc=.9*L/N # scaling 
97
    k=np.pi/L; omega=k*c;
98
    ymin=-1; ymax=1;
99
    duprange=np.linspace(-1,1,9)
100
    delay="20"
101
    # signal 
102
    def signal(a,t):
103
        xi=np.cos(n*k*(a-c*t))
104
        return xi
105
    for m in range(10,30,10):
106
        n=m/10; T=2*L/(n*c); dt=T/Nt; T=T-dt;
107
        print("Progressive-cos-10xn="+zfi(m))
108
        animation("Progressive-cos-10xn="+zfi(m)) 
109
110
 
111
 # Stationnaire-cos
112
if F: 
113
    N=20; L=10; c=1; 
114
    T=2*L/c; Nt=20; sc=.9*L/N # scaling 
115
    k=np.pi/L; omega=k*c;
116
    ymin=-1; ymax=1;
117
    duprange=np.linspace(-1,1,9)
118
    delay="20"
119
    # signal 
120
    def signal(a,t):
121
        xi=np.cos(n*k*a)*np.cos(omega*t+np.pi/2)
122
        return xi
123
    for m in range(5,55,5):
124
        print("Stationaire-sin-10xn="+zfi(m))
125
        n=m/10; animation("Stationaire-cos-10xn="+zfi(m)) 
126
127
 
128
 # Stationnaire-sin
129
if F: 
130
    N=20; L=10; c=1; 
131
    T=2*L/c; Nt=20; sc=.9*L/N # scaling 
132
    k=np.pi/L; omega=k*c;
133
    ymin=-1; ymax=1;
134
    duprange=np.linspace(-1,1,9)
135
    delay="20"
136
    # signal 
137
    def signal(a,t):
138
        xi=np.sin(n*k*a)*np.cos(omega*t+np.pi/2)
139
        return xi
140
    #for m in np.linspace(5,50,11):
141
    for m in range(5,55,5):
142
        print("Stationaire-sin-10xn="+zfi(m))
143
        n=m/10; animation("Stationaire-sin-10xn="+zfi(m)) 
144