/usr/share/doc/freefem++/examples/examples++/parareal.edp is in freefem++-doc 3.19.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | //int Nh=20;
// d u /dt = cos(t), u= sin(t) + u0
// avec de methode para reel.
// schema euler explicite
// (u,v)' = (v,-u)
// u_n+1 - u_n = v_n*dt, u_n+1 = u_n + v_n*dt
// v_n+1 - v_n = -u_n*dt,
// u=cos(t) u' = - sin(t) = v
// v=sin(t), v' = cos(t) = u
// ----------------------------
real DT=0.4;
int nbT=50; // nb de big time step
int ksub=50; // nb of small time step
int Nbig=20; // max number of Big iteration
real T0=0; // initial time
real tol=1e-5; // tolerance
// ----------------------------------------------------
int nbt=ksub*nbT;
real dt=DT/ksub;
// array for plotting
real[int] pt(nbt+1),pT(nbT+1),pu(nbt+1),pU(nbT+1);
// gros maillage
mesh TH=square(3,3);
// maillage fin
mesh Th=trunc(TH,1,split=1);
fespace VH(TH,P1);
fespace Vh(Th,P1);
int n=2;
int N=2;
func real Norm(real[int] & U)
{
return sqrt(square(U[10])+square(U[11]));
}
// restriction
func bool h2H(real[int] & u,real[int] & U)
{
U=0;
U[10+0]=u[0];
U[10+1]=u[1];
return true;
}
// prolongement
func bool H2h(real[int] & U,real[int] & u)
{
u=0;
u[0]=U[10+0];
u[1]=U[10+1];
return true;
}
func bool initG(real[int] & U)
{
U=0;
U[10+0]=1;// cos(0)
U[10+1]=0;// sin(0)
}
// un pas de temps FIN
func bool F(real[int] & u,real[int] & up)
{
u[0] = up[0] + up[1]*dt;
u[1] = up[1] - up[0]*dt;
// cout << up[0] << " " << up[1] << endl;
return true;
}
// pas de temps grossier
func bool G(real[int] & U,real[int] & Up)
{
U[0+10] = Up[0+10] + Up[1+10]*DT;
U[1+10] = Up[1+10] - Up[0+10]*DT;
// cout << Up[10] << " " << Up[11] << endl;
return true;
}
func bool AddGp(real[int] & U,int I)
{
pT[I]= T0+I*DT;
pU[I]=U[10];
return true;
}
func bool AddFp(real[int] & u,int I,int i)
{
pt[I*ksub+i]= T0+I*DT+i*dt;
pu[I*ksub+i]= u[0];
return true;
}
Vh ustart[nbT+1],uend[nbT]; // start
VH Uend[nbT];
VH U0,U1;
real t=T0,T=T0; // temps courant
int it=0,iT=0;
pt[it]=t;
pT[iT]=T;
initG(U0[]);
AddGp(U0[],iT);
H2h(U0[], ustart[iT][]);
// initial
for (int I=0;I<nbT;I++)
{
G(U1[],U0[]);
U0[]=U1[];
Uend[I][]=U1[];
H2h(U0[],ustart[I+1][]);
AddGp(U1[],I+1);
}
cout << pT.max << " " << pU.min << " " << pU.max << endl;
real[int] exact(nbt+1),fu(nbt+1);
{
Vh u0,u1;
u0[]=ustart[0][];
for (int i=0;i<=nbt;i++)
{
pt[i]=T0+i*dt;
exact[i]=cos(pt[i]);
F(u1[],u0[]);
u0[]=u1[];
AddFp(u0[],0,i);
}
}
fu=pu;
plot([pT,pU],[pt,exact],[pt,fu],wait=1);
// big loop
for (int K=0;K< Nbig;K++)
{
// para real loop --
for (int I=0;I<nbT;I++)
{
Vh u0,u1;
u0[]=ustart[I][];
AddFp(u0[],I,0);
for (int i=0;i<ksub;i++)
{
F(u1[],u0[]);
u0[]=u1[];
AddFp(u0[],I,i+1);
}
uend[I][]=u0[];
}
plot([pT,pU],[pt,pu],[pt,exact],cmm="iteration "+K);
// update loop
ustart[K+1]=uend[K];
real err=0;
for (int I=K+1;I<nbT;I++)
{
// Attention pb fin grossier
VH U0,U1;
h2H(ustart[I][],U0[]);
AddGp(U0[],I);
G(U1[],U0[]);
AddGp(U1[],I+1);
U0[]=U1[];
U1[] -=Uend[I][]; // U1=U1-U1(old)
err += Norm(U1[]);
Uend[I][]=U0[]; // save U1
Vh u1;
H2h(U1[],u1[]);
ustart[I+1][] = u1[]+ uend[I][] ;
}
cout << "\n\n big iteration " << K << " err= " << err << endl;
if (err < tol) break;
//plot([pT,pU],wait=1,clean=0);
}
plot([pt,pu],[pt,exact],[pt,fu],wait=1,cmm=" final fin");
plot([pT,pU],[pt,exact],[pt,fu],wait=1,cmm=" final grossier");
|