Ut0 = [20.0, 0.0, 0.0] NB = np.size(Ut0) Itf = 0 # Nb iterations Uold, U = our_mesh.init_cond(coeff_d, dt, Ut0) ''' Initial situation ''' our_mesh.maj_matrices() print("\n Matrice A1 : ", our_mesh.A) Z1 = np.array(range(1, 6)) for it in range(Itf): if (it % 100 == 0): print("\nIteration :", it) Uold = np.array(our_mesh.Uold) U = np.array(our_mesh.vector_U(Rf=100)) our_mesh.t += dt 'NB particles + save paraview' Utot = [sum(col) for col in zip(*U)] # Utot2=np.dot(Z1,U) # write_file(our_mesh,Utot2,int(it)) #MASS write_file(our_mesh, Utot, int(it)) if our_mesh.equilibrium(U, Uold, prec=1e-4): print("U:\n", U) print('---Equilibrium reached---- : Iteration {} and t={}\n'.format( it, our_mesh.t)) break
) erase_files() '''parameters''' dt = 1 coeff_d = 2 U0 = 10.0 Itf = 10000 # Nb iterations our_mesh.init_cond(coeff_d, dt, U0) ''' Initial situation ''' our_mesh.maj_matrices() ''' Time loop ''' for it in range(Itf): if ((it % 10 == 0)): '''Write solution in paraview format''' write_file(our_mesh, int(it / 10)) Uold = our_mesh.Uold U = our_mesh.vector_U() our_mesh.t += dt if equilibrium(Uold, U, prec=1e-3): print('---Equilibrium reached---- : Iteration {} and t={}\n'.format( it, our_mesh.t)) break '''Write Final in paraview format''' write_file(our_mesh, int(Itf / 10)) '''Print Uold''' for it in range(0, np.size(our_mesh.Uold)): print('Uold({})={}'.format(it, our_mesh.Uold[it])) '''Save animation ''' #plot_animation(our_mesh,Uit)
Itf = int(Tf / dt) # Nb iterations UM = [] Uold, U = solve.init_cond(coeff_d, dt, Ut0) ''' Initial situation ''' solve.maj_matrices() cl = 0 for it in range(Itf): #print("\n Iteration :",it) Uold = np.array(solve.Uold) Utot_old = [sum(col) for col in zip(*Uold)] for it in range(0, np.size(U[cl, :])): print('Uold{}({})={}'.format(cl + 1, it, Uold[cl, it])) if ((it % 10 == 0)): '''Write solution in paraview format''' write_file(our_mesh, Uold[cl, :], int(it / 10)) # write_file(our_mesh,Uold[NB-1,:],int(it)) U = np.array(solve.vector_U()) # Utot=[sum(col) for col in zip(*U)] solve.t += solve.dt write_file(our_mesh, Uold[cl, :], int(Itf)) print("Itf", Itf) for it in range(0, np.size(U[cl, :])): # print('Uold({})={}, Uexacte={}'.format(it, solve.U[it],sol_exacte(our_mesh.Nodes[it].x,solve.t,coeff_d))) # print('Uold({})={}'.format(it, solve.Uold[it])) print('U_{}({})={}'.format(cl + 1, it, U[cl, it]))
# Mesh creation from msh file: our_mesh = read_file("../maillage/square_simple_h50.msh") #parameters our_mesh.init_cond(coeff_d,dt,U0) our_mesh.maj_matrices() Uit=np.array([]) it=0 for it in range(Itf): print('Iteration : %d'%it) b=our_mesh.vector_b() U=our_mesh.vector_U() Uit=np.concatenate((Uit,U)) our_mesh.t+=dt it+=1 Uit=Uit.reshape((Itf,our_mesh.Ns)) #Write solution in paraview format write_file(our_mesh) #save matrices in files #check_mat(our_mesh) #print matrices #check_print(our_mesh)
Uold, U = our_mesh.init_cond(coeff_d, dt, Ut0) ''' Initial situation ''' our_mesh.maj_matrices() #Utotal2=Utot(our_mesh.U) #printU(Uold[0,:],our_mesh.Ns) ''' Time loop ''' for it in range(Itf): #print("Iteration : ",it) # if((it%10==0)): # #Utotal1=Utotal2 # '''Write solution in paraview format''' # write_file(our_mesh,U[0,:],int(it/10)) #print(U[0,:]) write_file(our_mesh, our_mesh.U, "INIT") #print(U[0,:]) Uold = np.array(our_mesh.Uold) U = np.array(our_mesh.vector_U()) our_mesh.t += dt if equilibrium(Uold[0, :], U[0, :], prec=1e-5): print('---Equilibrium reached---- : Iteration {} and t={}\n'.format( it, our_mesh.t)) break #Utotal=Utot(our_mesh.U) '''Write Final in paraview format''' #write_file(our_mesh,our_mesh.U[0,:],int(Itf/10))
'''parameters''' L = 1000 dt = 1 Itf = 300 # Nb iterations coeff_d = 1 #U0=U_init(5,15,our_mesh.Nodes) t = 200 X = vecteurX(our_mesh.Nodes) U0 = sol_exacte(X, t, coeff_d) print(U0) our_mesh.init_cond(coeff_d, dt, U0) our_mesh.t = t ''' Initial situation ''' our_mesh.maj_matrices() write_file(our_mesh, "init") ''' Time loop ''' for it in range(Itf): # if((it%10==0)): # '''Write solution in paraview format''' # write_file(our_mesh,int(it/10)) Uold = our_mesh.Uold U = our_mesh.vector_U() our_mesh.t += dt # if equilibrium(Uold,U,prec=1e-5) : # print('---Equilibrium reached---- : Iteration {} and t={}\n'.format(it,our_mesh.t)) # break; # #'''Write Final in paraview format'''
for it in range(Itf): if (it % 100 == 0): print("\nIteration :", it) Uold = np.array(our_mesh.Uold) Q = our_mesh.Qcalc(Uold)[0] print("\n t: ", our_mesh.t) print("\nUold:", Uold[:, 0]) print("f_0 = {}, f_1 = {},f_2 = {} ".format(func_f(our_mesh.t, 1), func_f(our_mesh.t, 2), func_f(our_mesh.t, 3))) #print("\nQ =",Q[:,0]) #print("df_0 = {}, df_1 = {},df_2 = {} ".format(d_f(our_mesh.t,1),d_f(our_mesh.t,2),d_f(our_mesh.t,3))) U = np.array(our_mesh.vector_U()) #print("U:\n",U) our_mesh.t += our_mesh.dt 'Save paraview' Utot = [sum(col) for col in zip(*U)] # Utot2=np.dot(Z1,U) # write_file(our_mesh,Utot2,int(it)) #MASS write_file(our_mesh, Uold[0, :], int(it)) # if equilibrium(Uold[:,0],U[:,0],prec=1e-4): # print("U:\n",U) # print('---Equilibrium reached---- : Iteration {} and t={}\n'.format(it,our_mesh.t)) # break;
UM = [] Uold, U = our_mesh.init_cond(coeff_d, dt, Ut0) ''' Initial situation ''' our_mesh.maj_matrices() for it in range(Itf): #print("\n Iteration :",it) Uold = np.array(our_mesh.Uold) Utot_old = [sum(col) for col in zip(*Uold)] # if((it%100==0)): # '''Write solution in paraview format''' # write_file(our_mesh,Uold[NB-1,:],int(it/100)) write_file(our_mesh, Uold[NB - 1, :], int(it)) U = np.array(our_mesh.vector_U()) Utot = [sum(col) for col in zip(*U)] our_mesh.t += our_mesh.dt #print('UM({})= {}\n'.format(it,sum(U[NB-1,:]))) UM.append(sum(U[NB - 1, :])) # if our_mesh.equilibrium(np.array(U[0,:]),np.array(Uold[0,:]),prec=1e-11): # print("U:\n",U[NB-1,:]) # print('---Equilibrium reached---- : Iteration {} and t={}\n'.format(it,our_mesh.t)) ## break; # for it in range(0,np.size(U[0,:])): # print('Q_{}({})={},'.format(1,it,our_mesh.Q,)) #write_file(our_mesh,Uold[NB-1,:],int(NB))