# The answer doesn't converge by refining the mesh

**URL:** <https://community.freefem.org/t/the-answer-doesnt-converge-by-refining-the-mesh/2883>\
**Category:** General Discussion\
**Created:** [January 15, 2024, 8:49pm UTC](https://community.freefem.org/t/the-answer-doesnt-converge-by-refining-the-mesh/2883 "2024-01-15T20:49:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.javad98](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@m.javad98](https://community.freefem.org/u/m.javad98)\
**Post date:** [January 15, 2024, 8:49pm UTC](https://community.freefem.org/t/the-answer-doesnt-converge-by-refining-the-mesh/2883/1 "2024-01-15T20:49:39Z")

</div>

Hi, I am trying to solve a BVP to obtain the micropolar strain localization tensor in a 2D chiral geometry with some periodic boundary conditions. I have 2 unknowns h111 and h211.  
The boundary conditions are:  
h111(-0.5,y)= h111(0.5,y)  
h211(-0.5,y)= h211(0.5,y)  
h111(x,-0.5)= h111(x,0.5)  
h211(x,-0.5)= h211(x,0.5)  
Below is the code I’ve been using:

```auto
> load "gmsh"
> mesh Th=gmshload("Chiral.msh");
> plot(Th,wait=1);
> fespace Vh(Th,P1,periodic=[[18,x],[20,x],[19,y],[21,y]]);
> Vh h211,w2,h111,w1,b=24500/13,c=10500/13,d=14000/13;
> solve diffuse([h111,h211],[w1,w2])= 
> int2d(Th)(dx(w2)*(d*dx(h211))
> + dx(w1)*(b*dx(h111) + c*dy(h211))
> + dy(w1)*(d*dx(h211))
> + dy(w2)*(c*dx(h111) + b*dy(h211)))
> + int2d(Th) (b*dx(w1))+int2d(Th) (c*dy(w2));
> real sigma11=int2d(Th)(((24500*dx(h111))/13 + 24500/13)*(dx(h111) + 1) 
> + (10500*dy(h211)*(dx(h111) + 1))/13 + (28000*dx(h211)^2)/13 + (24500*dy(h211)^2)/13 + dy(h211)*((10500*dx(h111))/13 + 10500/13));
> 
> cout << "sigma11 " << sigma11 << endl;

```

However, sigma11, calculated using h111 and h211, does not converge by refining the mesh. Sometimes it decreases and sometimes it increases. What should I do?  
Thank you in advance for your answers.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [January 16, 2024, 4:24pm UTC](https://community.freefem.org/t/the-answer-doesnt-converge-by-refining-the-mesh/2883/2 "2024-01-16T16:24:13Z")

</div>

Can you post the code as an attachment as my browser makes copy paste  
screw ups. I don’t know if I’ll look at it but curious. Do you have a link to areference  
or the eqn you are trying to solve? Probably it does not matter a lot on the mesh  
for diagnosis although if you have specific features of the mesh it may help to post it.  
Thanks.

---

<div class="post-metadata">

**Author:** ![m.javad98](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@m.javad98](https://community.freefem.org/u/m.javad98)\
**Post date:** [January 17, 2024, 2:34pm UTC](https://community.freefem.org/t/the-answer-doesnt-converge-by-refining-the-mesh/2883/3 "2024-01-17T14:34:29Z")

</div>

Thank you for your answer.  
The code and the geometry are attached to the post.  
In my equation, dx(h211) equals dy(h111) because the micropolar strain localization tensor is symmetric. Before I considered that this tensor is symmetric, my equation was:

```auto
 int2d(Th)(dx(w2)*(a*dx(h211) + a*dy(h111))
+ dx(w1)*(b*dx(h111) + c*dy(h211))
+ dy(w1)*(a*dx(h211) + a*dy(h111))
+ dy(w2)*(c*dx(h111) + b*dy(h211)))
+ int2d(Th) (b*dx(w1))+int2d(Th) (c*dy(w2))

```

and the sigma11 had converged.  
thanks again.  
[FreeFem++.rar](https://community.freefem.org/uploads/short-url/97xQZ6zwoa74ZlvOHc9Vv1kMKdh.rar) (208.5 KB)

---

<div class="post-metadata">

**Author:** ![m.javad98](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@m.javad98](https://community.freefem.org/u/m.javad98)\
**Post date:** [January 17, 2024, 3:24pm UTC](https://community.freefem.org/t/the-answer-doesnt-converge-by-refining-the-mesh/2883/4 "2024-01-17T15:24:47Z")

</div>

The geometry.geo is attached to this post.  
[Chiralgeo.rar](https://community.freefem.org/uploads/short-url/2GuM1gQ77cqr71GgFluOQ9AirW3.rar) (729 Bytes)

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [January 17, 2024, 6:31pm UTC](https://community.freefem.org/t/the-answer-doesnt-converge-by-refining-the-mesh/2883/5 "2024-01-17T18:31:06Z")

</div>

I don’t have time to sort it out as there are a lot of constants in the signal expression  
and you didn’t post the equation. I get a constant signal over a range of mesh values  
using a simple square mesh,  
See if the attached code can help you sort it out. Also did you intend to have a  
cross product in there- could be a sign mistake.

```auto
//load "gmsh"
//mesh Th=gmshload("Chiral.msh");
int nn=5;
mesh Th = square(nn,nn,[100*x,100*y]);
//fespace Vh(Th, P1); //scalar FE
fespace Vh(Th,P2,periodic=[[2, y],[4, y],[1, x],[3, x]]); //bi-periodic FE
//fespace Vh(Th,P2,periodic=[[18,x],[20,x],[19,y],[21,y]]);
Vh h211,w2,h111,w1,a=7000/13,b=24500/13,c=10500/13,d=14000/13;
solve diffuse([h111,h211],[w1,w2])= 
int2d(Th)(dx(w2)*(d*dx(h211))
+ dx(w1)*(b*dx(h111) + c*dy(h211))
+ dy(w1)*(d*dx(h211))
+ dy(w2)*(c*dx(h111) + b*dy(h211)))
+ int2d(Th) (b*dx(w1))+int2d(Th) (c*dy(w2));
real sigma11=int2d(Th)(((24500*dx(h111))/13 + 24500/13)*(dx(h111) + 1) 
+ (10500*dy(h211)*(dx(h111) + 1))/13 + (28000*dx(h211)^2)/13 + (24500*dy(h211)^2)/13 + dy(h211)*((10500*dx(h111))/13 + 10500/13));

plot(h111,wait=1,fill=1);
plot(h211,wait=1,fill=1);
cout << "sigma11 " << sigma11 << endl;

```

[test4.edp](https://community.freefem.org/uploads/short-url/2pAzTAvk0omJ2C01g00tM6m30uh.edp) (853 Bytes)

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [January 17, 2024, 6:35pm UTC](https://community.freefem.org/t/the-answer-doesnt-converge-by-refining-the-mesh/2883/6 "2024-01-17T18:35:48Z")

</div>

Also I would get in the habit of writing expressions with decimal points  
as the consts may be evaluated as int/int but probably that is just a small  
issue. You can check with this though,

```auto
cout<<"c="<<c<<endl;

```
