Dear, I want to solve the Poisson equation involving h for different values of h given in Pram (in the following code). Then, I used a loop to pick each value from Pram as a value for h and then solve the problem. I want to compute AvgNu at different values of h. Kindly see my code and guide me to achieve the required results.
real Mesh=60;
real ra=0.1;
border C(t=0,1){x=0.5+racos(2pit);y=0.2sqrt(3)+rasin(2pit);}
mesh Th=buildmesh(C(Mesh));
plot(Th,wait=1);
real Pram=[1,2,3];
for(int i;i<=3;i++)
{
real h=Pram[i];
fespace Vh(Th,P2);
func f= xy;
Vh U,V;
problem Poisson(U,V,solver=LU)=
int2d(Th)(dx(U)*dx(V) + dy(U)*dy(V))
Dear Professor @frederichecht thanks for your response. I think you don’t understand my point. I want to solve the Poisson equation for different values of h using the loop. For example,
for i=1, the code should solve the Poisson problem for h = 1 and compute the value for AvgNu,
for i=2, the code should solve the Poisson problem for h = 2 and compute the value for AvgNu, and
for i=3, the code should solve the Poisson problem for h = 3 and compute the value for AvgNu.
Thank you, dear Professor @frederichecht . For nonlinear PDEs, I got the same value for AvgNu. Maybe I did something wrong in the following code. Kindly have a look and guide me to overcome this error.
real Mesh=60;
real ra=0.1;
border C(t=0,1){x=0.5+racos(2pit);y=0.2sqrt(3)+rasin(2pit);}
mesh Th=buildmesh(C(Mesh));
plot(Th,wait=1);
real a=1;
real err=1;
real[int] Pram=[1,2,3],AvgNu(3);
real b;
fespace Vh(Th,P2);
func f= xy;
Vh U,U0,V;
U0=0;
int i=0;
problem Poisson(U,V,solver=LU,init=i)=
int2d(Th)(dx(U)dx(V) + dy(U)dy(V))
-int2d(Th)(abfU0UV)
+on(C,U=1) ;
verbosity=0;
for( i=0;i<3;i++)
{
b=Pram[i];
for(int ij=0; (ij)<=10; ij++)
while (err>1e-4)
{
Poisson;
err=int2d(Th)(U-U0)^2;
U0 = U;
endl;
}
macro grad(u) [dx(u),dy(u)]//
AvgNu[i]=-int1d(Th,C)((grad(U))'[N.x,N.y]);
cout<<i << "Avg = "<<AvgNu[i]<<endl;
}
I solved the nonlinear problem as: for(int ij=0; (ij)<=10; ij++)
while (err>1e-4)
{
Poisson;
err=int2d(Th)(U-U0)^2;
U0 = U;
endl;
}
and then put it in the loop to compute the solution for various values of b. The got the solution successfully but the solution is same for each value of b.
Dear Professor @frederichecht , I also defined err=1 just after the value b and before starting the second loop. But, I got the same values for AvgNu. Where I have to define the value err so that I get the correct results for AvgNu. I am waiting for your positive response.