# Fix/Pin nodes as boundary condition

**URL:** <https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596>\
**Category:** General Discussion\
**Created:** [March 13, 2022, 10:19pm UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596 "2022-03-13T22:19:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yvan](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yvan/32/1055_2.png) [@Yvan](https://community.freefem.org/u/Yvan)\
**Post date:** [March 13, 2022, 10:19pm UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/1 "2022-03-13T22:19:38Z")

</div>

Hello,

I would like to know if it is possible to pin nodes (instead of surfaces) as boundary conditions to solve thermoelasticity problems.  
I want to get the geometric distorsion of the part from the thermal shrinkage. However, I don’t want to pin a surface but just 3 nodes to avoid rigid body translation/rotation.

I looked and try different solution proposed here but it doesn’t work properly.

There is two options :

- Pin different nodes
- Extract an element surface and apply the boundary condition only in this surface.

I can illustrate the exemple if necessary.  
Here some part of my code : (no shrinkage, it is just to try with a pressure)

mesh3 MTPt = cube(1, 1, 1, [x_0.3-0.15, y_0.3-0.15, z\*0.1]);  
fespace TP(MTPt, [P1, P1,P1]);  
TP [ut, vt, wt], [uut, vvt, wwt];

real E1 = 5.5e10;  
real E2 = 30e8;  
real E3 = 10e8;  
real nu12 = 0.33;  
real nu13 = 0.33;  
real nu23 = 0.33;  
real nu21 = 0.33;  
real nu31 = 0.33;  
real nu32 = 0.33;  
real G23 = 5.2e9;  
real G13 = 5.2e9;  
real G12 = 5.2e9;

real Aa = 1 - nu12_nu21 - nu23_nu32 - nu31_nu13 - 2_nu21_nu32_nu13;  
Aa = Aa / ( E1_E2_E3);  
real C11 = (1- nu23_nu32) / (E2_E3_Aa);  
real C12 = (nu21 + nu31_nu23) / (E2_E3_Aa);  
real C13 = (nu31 + nu21_nu32) / (E2_E3_Aa);  
real C22 = (1 - nu13_nu31) / (E1_E3_Aa);  
real C23 = (nu32 - nu12_nu31) / (E1_E3_Aa);  
real C33 = (1- nu12_nu21) / (E1_E2_Aa);  
real C44 = 2_G23;  
real C55 = 2_G13;  
real C66 = 2\*G12;

macro Strain(u,v,w) [dx(u), dy(v), dz(w), sqrt(2)_(dy(w)+dz(v)), sqrt(2)_(dx(w)+dz(u)), sqrt(2)\*(dy(u)+dx(v))]//  
func Cc = [[C11, C12, C13, 0, 0, 0] ,  
[C12, C22, C23, 0, 0, 0] ,  
[C13, C23, C33, 0, 0, 0] ,  
[0, 0, 0, C44, 0, 0] ,  
[0, 0, 0, 0, C55, 0] ,  
[0, 0, 0, 0, 0, C66] ];  
real Pressure = -1;

solve mechanics([ut,vt,wt],[uut,vvt,wwt])=  
int3d(MeshTP)(Strain(uut,vvt,wwt)’_(Cc_Strain(ut,vt,wt)))

- int2d(MeshTP, 6)(Press\*wwt)

- on(5, wt=0)
- on(1, vt=0)
- on(2, ut=0);  
savevtk(“presse.vtu”,dataname=“u v w tot”,MeshTP, u,t vt, wt, [ut,vt,wt], order=Order, bin=false);

I also tried with a varf approach :

varf a ( [ut, vt, wt],[uut, vvt, wwt] ) = int3d ( MTPt ) ( Strain(uut,vvt,wwt)'_Cc_Strain(ut,vt,wt) )  
+ int2d(MTPt, 6)(Pressure\*wwt)  
+ on(5, wt = 0)  
+ on(1, vt = 0)  
+ on(2, ut = 0) ;

matrix A = a ( TP , TP, solver=sparsesolver ) ; // build the matrix  
real[int] b = a(0, TP);  
ut[] = A^-1\*b;

which leads to the same result obviously.

I then tried to reduce the matrix A by removing the row and colum associated to my pinned nodes. Same for b. But I don"t get the result I expected …

Thank you for your help.

DENIS Yvan

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [March 15, 2022, 8:57am UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/2 "2022-03-15T08:57:22Z")

</div>

Remark, in FreeFEM all boundary condition is taken on surface in 3d not on DoF to remove lot of error  
.

If you want to remove only 3 rigid body modes in plan 0xy,

in the variational formution add

```auto
solve mechanics([ut,vt,wt],[uut,vvt,wwt])=
int3d(MeshTP)(Strain(uut,vvt,wwt)’*(CcStrain(ut,vt,wt))  
  + epsilon*( [ut,vt]'*[uut,vvt] + (dx(vt)-dy(ut))*((dx(vvt)-dy(uut)) )

```

where epsilon is small but not too small (1e-6) and the solution do not depend of epsilon if epsilon is small.

The term [ut,vt]’\*[uut,vvt] imposes no translation in x and y and the

(dx(vt)-dy(ut))_((dx(vvt)-dy(uut)) == curl([ut,vt,wt])\_3_curl[uut,vvt,wwt])\_3 impose not rotation around axe z.

---

<div class="post-metadata">

**Author:** ![Yvan](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yvan/32/1055_2.png) [@Yvan](https://community.freefem.org/u/Yvan)\
**Post date:** [July 10, 2023, 12:53pm UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/3 "2023-07-10T12:53:04Z")

</div>

Thank you very much for your answer. I will give it a try and check the result.

May I ask why BC cannot be applied in DoF in FreeFEM ? If we are using the varf approach, we are using an implicit scheme which should allow such method ?

Regards,

Y

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [July 11, 2023, 9:44am UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/4 "2023-07-11T09:44:27Z")

</div>

It is because , lot of person make crazy things and lots of bug.

---

<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:** [July 11, 2023, 10:53am UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/5 "2023-07-11T10:53:07Z")

</div>

You can always zero out the row except for diagonal element and set the rhs.  
I guess by crazy the idea is that an isolated dof depends on the mesh which should  
not be critical for the end result but at least maybe for sensitivity testing  
you want to play some games.

---

<div class="post-metadata">

**Author:** ![Yvan](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yvan/32/1055_2.png) [@Yvan](https://community.freefem.org/u/Yvan)\
**Post date:** [July 11, 2023, 11:48am UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/6 "2023-07-11T11:48:00Z")

</div>

@marchywka Let’s play a game then !

More seriously thanks for your answers. I will make some tries on my side.

---

<div class="post-metadata">

**Author:** ![Yvan](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yvan/32/1055_2.png) [@Yvan](https://community.freefem.org/u/Yvan)\
**Post date:** [February 29, 2024, 1:51pm UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/7 "2024-02-29T13:51:34Z")

</div>

@marchywka FYI, I’ve spent some times on the theory and managed to apply BC on nodes instead of FE faces. After making some tries and comparison it looks like it is working well. I think the method is not numerically optimized but has its merits! Thanks again for your advices.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/d/df99d205fb51854bd2acf206772be9fec9d5db3d.jpeg)

Y.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [March 11, 2024, 8:54pm UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/8 "2024-03-11T20:54:34Z")

</div>

To make this you can follow the script

> <https://github.com/FreeFem/FreeFem-sources/blob/master/examples/3d/Elasticity-simple-support-BC.edp>

---

<div class="post-metadata">

**Author:** ![Shyam](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@Shyam](https://community.freefem.org/u/Shyam)\
**Post date:** [December 9, 2025, 9:38am UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/9 "2025-12-09T09:38:41Z")

</div>

> [@frederichecht](#):
>
> [https://github.com/FreeFem/FreeFem-sources/blob/master/examples/3d/Elasticity-simple-support-BC.edp](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/3d/Elasticity-simple-support-BC.edp) How did you achieve this?

How did you achieve setting BC on boundaty?

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [December 9, 2025, 11:28am UTC](https://community.freefem.org/t/fix-pin-nodes-as-boundary-condition/1596/10 "2025-12-09T11:28:25Z")

</div>

The correct link is

> <https://github.com/FreeFem/FreeFem-sources/blob/master/examples/3d/Elasticity-simple-support-BC.md>

The principle is to define an array over the degrees of freedom of the fespace, that is nonzero at the locations you want to remove the corresponding dof.  
Then the command  
setBC(A,array,tgv) will modify the lines of the matrix A of index i where array(i) is nonzero,  
according to the value of tgv. The rules for tgv are explained in the documentation  
[https://doc.freefem.org/pdf/FreeFEM-documentation.pdf](https://doc.freefem.org/pdf/FreeFEM-documentation.pdf) p.223/224  
This method enables to set Dirichlet boundary conditions on sets which are not lines in 2d (surfaces in 3d), or even to set conditions inside the domain.
