# Output of the solution of a assigned point

**URL:** <https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012>\
**Category:** General Discussion\
**Created:** [September 18, 2022, 3:50am UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012 "2022-09-18T03:50:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 18, 2022, 3:50am UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/1 "2022-09-18T03:50:06Z")

</div>

Dear all,

How can i output the solution of a assigned point in a 3D mesh at the parallel computing by loading “PETSc”?  
Give me some advice,please.  
Thank you in advance.

Best,  
Liu

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 18, 2022, 6:35am UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/2 "2022-09-18T06:35:53Z")

</div>

You need to find which process is in charge of the point, for example using the function `chi`, and then output the solution on that process.

```auto
load "msh3"
mesh3 Th = cube(20, 20, 20);
cout << chi(Th)(-1, 0, 0) << " " << chi(Th)(0.5, 0.5, 0.5) << endl;

```

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 18, 2022, 1:09pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/3 "2022-09-18T13:09:57Z")

</div>

Dear Professor,

Many thanks for your answer.  
I have another question.  
For the elasticity problems, I want to obtain the propagation process of elastic wave in 3D mesh with time. This need the transfer of displacement of adjacent particle in the 3D mesh with varying time. I have solved this problem based on the serial computation code, which is as follows:  
"…  
…  
…  
solve Lame([u1,u2,u3],[v1,v2,v3],solver=CG,master=-1)=  
int3d(Th1)(density_idt2_u1_v1)-int3d(Th1)(density_2_idt2_u1f_v1)+int3d(Th1)(density_idt2_u1b_v1)+  
int3d(Th1)(density_idt2_u2_v2)-int3d(Th1)(density_2_idt2_u2f_v2)+int3d(Th1)(density_idt2_u2b_v2)+  
int3d(Th1)(density_idt2_u3_v3)-int3d(Th1)(density_2_idt2_u3f_v3)+int3d(Th1)(density_idt2_u3b_v3)+  
int3d(Th1)(lambda_div(u1,u2,u3)div(v1,v2,v3)+2.mu( epsilon(u1,u2,u3)'epsilon(v1,v2,v3)))  
+on(2001,u1=0.,u3=0.,u2=amplitude(1.-2.(pi_f\*(t-tt))^2)_exp(-(pi_f\*(t-tt))^2))  
+on(1001,2002,2003,2004,2005,2006,2007,u1=0.,u2=0.,u3=0.);

u1b=0;  
u1f= u1b;  
u1=u1f;

u2b=0;  
u2f=u2b;  
u2=u2f;

u3b=0;  
u3f=u3b;  
u3=u3f;

for(int i=0;i\<300;++i)  
{  
t=t+dt;  
Lame;  
u1b=u1f;  
u1f=u1;  
u2b=u2f;  
u2f=u2;  
u3b=u3f;  
u3f=u3;  
plot (u1);  
}.  
However, correspondingly, the solution using the parallel computing by loading “PETSc” is wrong. The parallel computing code is as following:  
"…  
…  
…  
varf Lame([u1,u2,u3],[v1,v2,v3])  
=int3d(Th1)(density1_idt2_u1_v1)-int3d(T1h)(density1_2_idt2_u1f_v1)+int3d(Th1)(density1_idt2_u1b_v1)+  
int3d(Th1)(density1_idt2_u2_v2)-int3d(Th1)(density1_2_idt2_u2f_v2)+int3d(Th1)(density1_idt2_u2b_v2)+  
int3d(Th1)(density1_idt2_u3_v3)-int3d(Th1)(density1_2_idt2_u3f_v3)+int3d(Th1)(density1_idt2_u3b_v3)+  
int3d(Th1)(lambda1_div(u1,u2,u3)div(v1,v2,v3)+2.mu1( epsilon(u1,u2,u3)'epsilon(v1,v2,v3)))  
+ on(2002,u1=0.,u3=0.,u2=0.001(1.-2.(pi_f\*(t-tt))^2)_exp(-(pi_f\*(t-tt))^2));

[u1b,u2b,u3b]=[0.,0.,0.];  
[u1f,u2f,u3f]=[u1b,u2b,u3b];  
[u1,u2,u3]=[u1f,u2f,u3f];

Mat A;  
createMat(Th, A, Pk)

for(int i=0;i\<300;++i) {  
t=t+dt;  
matrix Loc = Lame(Vh, Vh,tgv=-1);  
real[int] rhs = Lame(0, Vh,tgv=-1);  
set(A, sparams = “-ksp\_view -ksp\_max\_it 100”);  
Vh def(u);  
A = Loc;  
u = A^-1 \* rhs;  
[u1b,u2b,u3b]=[u1f,u2f,u3f];  
[u1f,u2f,u3f]=[u,uB,uC];  
macro def1(u)// EOM  
plotMPI (u1);  
}.  
I do not find the reason for the wrong solution. I have searched all the examples, but I haven’t found any relevant ones. Of course, I may have missed them.  
Please give me some advice.  
Thank you very much.

Best,  
Liu

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 18, 2022, 7:31pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/4 "2022-09-18T19:31:54Z")

</div>

You should add `-pc_type lu` to your set of `sparams`.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 20, 2022, 12:56pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/5 "2022-09-20T12:56:49Z")

</div>

Dear Professor,

According to your suggestion, I have added “-pc\_type lu” in the set of sparams. However, the solutions with time iteration is still wrong.  
The parallel computing code is as follows,  
"…  
…  
fespace Vh(Th,Pk);  
Vh [u,uB,uC], [v,vB,vC],[u1f,u2f,u3f]=[.0,.0,.0],[u1b,u2b,u3b]=[.0,.0,.0];  
…  
varf Lame([u,uB,uC],[v,vB,vC])  
=int3d(Th)(density_idt2_u_v)-int3d(Th)(density_2_idt2_u1f_v)+int3d(Th)(density_idt2_u1b_v)+  
int3d(Th)(density_idt2_uB_vB)-int3d(Th)(density_2_idt2_u2f_vB)+int3d(Th)(density_idt2_u2b_vB)+  
int3d(Th)(density_idt2_uC_vC)-int3d(Th)(density_2_idt2_u3f_vC)+int3d(Th)(density_idt2_u3b_vC)+  
int3d(Th)(lambda_div(u,uB,uC)div(v,vB,vC)+2.mu( epsilon(u,uB,uC)'epsilon(v,vB,vC)))  
+ on(1001,u=0.,uB=0.,uC=0.00001(1.-2.(pi_f\*(t-tt))^2)_exp(-(pi_f\*(t-tt))^2))  
+on(2001,2002,2003,2004,2005,2006,2007,u=0.,uB=0.,uC=0.);

[u1b,u2b,u3b]=[0.,0.,0.];  
[u1f,u2f,u3f]=[u1b,u2b,u3b];  
[u,uB,uC]=[u1f,u2f,u3f];

Mat A;  
createMat(Th, A, Pk)

for(int i=0;i\<100;++i) {   
t=t+dt;

matrix Loc = Lame(Vh, Vh,tgv=-1); //solve the problem  
real[int] rhs = Lame(0, Vh,tgv=-1);  
set(A, sparams = “-ksp\_view -ksp\_max\_it 100 -pc\_type lu”);  
Vh def(u); // local solution  
A = Loc;  
u = A^-1 \* rhs;

macro def1(u)u// EOM

//Time iteration of displacement  
[u1b,u2b,u3b]=[u1f,u2f,u3f];  
[u1f,u2f,u3f]=[u,uB,uC];

macro params()cmm = “Global solution time=”+t, fill = 1// EOM  
plotMPI(Th, def1(u), P1, def1, real, params)

int[int] Order=[1,1];  
savevtk(“uhydrate6\_y.vtu”, Th,[u,uB,uC], dataname=“[u,uB,uC]”, order=Order,append = true);  
}."  
The obtained solution significantly monotonically increases with number of iterations from (negative solution)^20 to (positive solution)^20. Such solution is apparently wrong. Because the solution should be fluctuating around 0, the solution has been obtained from serial calculation code using FreeFem++.

Please give me some advice. Thank you very much.

Best regards,  
Liu

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 24, 2022, 9:29am UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/6 "2022-09-24T09:29:13Z")

</div>

Dear Professor,

Could you give me some advice about the below problem?

> [@Output of the solution of a assigned point](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/5):
>
> Dear Professor, According to your suggestion, I have added “-pc\_type lu” in the set of sparams. However, the solutions with time iteration is still wrong. The parallel computing code is as follows, "… … fespace Vh(Th,Pk); Vh [u,uB,uC], [v,vB,vC],[u1f,u2f,u3f]=[.0,.0,.0],[u1b,u2b,u3b]=[.0,.0,.0]; … varf Lame([u,uB,uC],[v,vB,vC]) =int3d(Th)(densityidt2uv)-int3d(Th)(density2idt2u1fv)+int3d(Th)(densityidt2u1bv)+ int3d(Th)(densityidt2uBvB)-int3d(Th)(density2idt2u2fvB)+int3d(Th)(densityidt2u…

Thank you very much.

Best,  
Liu

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 24, 2022, 10:49am UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/7 "2022-09-24T10:49:27Z")

</div>

I cannot run the code, so I cannot help.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 24, 2022, 11:14am UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/8 "2022-09-24T11:14:52Z")

</div>

Dear Professor,

Thank you very much for your reply.  
The files of code and of .msh (the second file) are attached to this reply.  
[Parallel\_11.edp](https://community.freefem.org/uploads/short-url/qtchN1CQuUOtExUybi9VophOKwO.edp) (4.8 KB)  
[Quartz\_water\_calcite6.edp](https://community.freefem.org/uploads/short-url/onBBe7W8aYd7jz348Uj8MR4DiWT.edp) (2.2 MB)

In addition, my computer has 32 processors. However, the code cannot provide the solution but without any error remind, when I run the code based on the number of processors bigger than 8.  
Please give me some advice.  
Give you my best withes.

Liu

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 24, 2022, 1:38pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/9 "2022-09-24T13:38:06Z")

</div>

You did not attach ` Background_fracture_hydrate6.msh` (or ` Background_fracture_hydrate6.edp` that I then rename). I don’t understand what the problem is, your code is working on 8 or less processes, but not on more?

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 24, 2022, 1:57pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/10 "2022-09-24T13:57:20Z")

</div>

Dear Professor,

Thank you so much for your reply.  
You are exactly right that the second file “Quartz\_water\_calcite6.edp” is the file of .msh. You can rename it as "Background\_fracture\_hdyrate6.msh.  
I have two questions. You mentioned “my code is working on 8 or less processes, but not on more” is the first one. The second problem that is the most important one, is that the obtained solution using the parallel computing code significantly monotonically increases from (negative solution)^20 to (positive solution)^20 with number of iterations. Such solution is apparently wrong. Because the solution should be fluctuating around 0 and at the region between (negative solution)^-4 to (positive solution)^-4 , and has been obtained from serial calculation code using FreeFem++, as shown in the below figure,  
 ![The solution of a point with number of iterations](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/1/11fce81da8439ddc95bf38f14cccde40e1a954ed.png).  
So, could you help me find the problem in the parallel computing code, please?  
Thank you very much.

Best,  
Liu

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 24, 2022, 2:24pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/11 "2022-09-24T14:24:57Z")

</div>

Do you get the proper solution when running your code with a single MPI process?

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 24, 2022, 2:29pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/12 "2022-09-24T14:29:05Z")

</div>

Sorry, I did not running my code with a single MPI process. But I obtain the proper solution using the serial calculation code (one process).

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 24, 2022, 2:29pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/13 "2022-09-24T14:29:52Z")

</div>

One process with PETSc? The exact same code with a single process is running OK?

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 24, 2022, 2:31pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/14 "2022-09-24T14:31:38Z")

</div>

Sorry, professor. I did not running my code with a single MPI process with PETSc.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 24, 2022, 2:36pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/15 "2022-09-24T14:36:11Z")

</div>

OK, then you need to first check that you get the same result with 1 process with PETSc. If not, then the problem is likely not coming from PETSc, but the fact that you are in practice running two scripts that are different, and thus you should not expect the same results.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 24, 2022, 2:42pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/16 "2022-09-24T14:42:41Z")

</div>

OK, professor, now, I’m running my program with a single MPI process with PETSc. I will tell you the result later.  
So, you temporarily think that my parallel computing code is OK to solve the problem, right?  
And, why the code can not run when the number of processes is bigger than 8?

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 24, 2022, 3:03pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/17 "2022-09-24T15:03:15Z")

</div>

Dear Professor,

In order to effectively solve the problem, I attached the serial calculating code to this reply.  
[Quartz\_water\_calcite6 (2).edp](https://community.freefem.org/uploads/short-url/9ktVuhIUGTVYM3YTjSu7h5lBPZr.edp) (4.7 KB)

I have carefully compared the two codes. I think that the parallel computing code is right. However, I am afraid there is something I don’t understand. So, please check the two codes to find the potential problems.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 24, 2022, 3:39pm UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/18 "2022-09-24T15:39:12Z")

</div>

Dear Professor,

I have obtained the solution with 1 process with PETSc, which is similar to the result from 8 processes with PETSc and is not same to the results from serial calculating code.  
In addition, I know that I can not obtain the exactly same results between the two codes. However, the trends and order of magnitude of the results from MPI with PETSc are wrong. Therefore, I suspect there’s something wrong with my parallel computing code So, I ask for your help.  
Do you have any other suggestions？

Best,  
Liu

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 26, 2022, 10:55am UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/19 "2022-09-26T10:55:47Z")

</div>

You need to figure out why the “PETSc with a single process” and the sequential codes are giving you different results. This is not expected. For that, I would start with a simplified code instead of using your huge variational formulation.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [September 26, 2022, 11:31am UTC](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012/20 "2022-09-26T11:31:13Z")

</div>

Yes, Professor, I am trying to figure out what the problem is. After I find this problem, I will ask for your help. Thank you very much.

[Next page](https://community.freefem.org/t/output-of-the-solution-of-a-assigned-point/2012.md?page=2)
