# Assign a force to boundary node depending on node displacement

**URL:** https://community.freefem.org/t/assign-a-force-to-boundary-node-depending-on-node-displacement/1254
**Category:** General Discussion
**Created:** [October 14, 2021, 9:50am UTC](https://community.freefem.org/t/assign-a-force-to-boundary-node-depending-on-node-displacement/1254 "2021-10-14T09:50:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)
#### Post date: [October 14, 2021, 9:50am UTC](https://community.freefem.org/t/assign-a-force-to-boundary-node-depending-on-node-displacement/1254/1 "2021-10-14T09:50:58Z")

</div>

So instead of fixing the left edge by saying

```auto
on(4, u = 0, v =0)

```

I want to assign a force that depends on the displacement. That is a simple string force with a high stiffness coefficient.

This was my attempt:

```auto
// Parameters
real E = 2230e6;
real nu = 0.4;
 
real f = 10e4;
real k = 1e6;
  
// Mesh
mesh Th = square(5, 2, [x,y * 0.5]);
// Fespace
fespace Vh(Th, P2);
Vh u, v, vold, uold;
Vh uu, vv;
Vh sxx, syy, sxy;
Vh rx, ry;

// Macro
real sqrt2=sqrt(2.);
macro epsilon(u1,u2) [dx(u1),dy(u2),(dy(u1)+dx(u2))/sqrt2] //
// The sqrt2 is because we want: epsilon(u1,u2)'* epsilon(v1,v2) = epsilon(u): epsilon(v)
macro div(u,v) ( dx(u)+dy(v) ) //

for (int i = 0; i < Th.nv; i++){
    uold[](i) = Th(i).x;
    vold[](i) = Th(i).y;
}

// Problem
real mu= E/(2*(1+nu));
real lambda = E*nu/((1+nu)*(1-2*nu));

solve lame([u, v, uold, vold], [uu, vv])
   = int2d(Th)(
        lambda * div(u, v) * div(uu, vv)
      + 2.*mu * ( epsilon(u,v)' * epsilon(uu,vv) )
   )
   - int1d(Th, 2)(
        f*uu
   )
   - int1d(Th, 4)([k * 1000 * (u - uold), k * (v - vold)]' * [uu, vv])
// + on(4, u=0)
// + on(4, u=0)
// + on(1, v=0)
;

```

But it does not seem to work, for some reason. Is there any other way to do this? I don’t seem to be able to figure it out. 😕

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [October 15, 2021, 1:57am UTC](https://community.freefem.org/t/assign-a-force-to-boundary-node-depending-on-node-displacement/1254/2 "2021-10-15T01:57:52Z")

</div>

Just a few grammatical problems in `solve lame(...) ...`:

```auto
solve lame([u, v], [uu, vv]) // the variables to solved are u and v 
   = int2d(Th)(
        lambda * div(u, v) * div(uu, vv)
      + 2.*mu * ( epsilon(u,v)' * epsilon(uu,vv) )
   )
   - int1d(Th, 2)(
        f*uu
   )
   - int1d(Th, 4)([k * 1000 * u, k * v]' * [uu, vv]) // to assemble into coefficient matrix
  + int1d(Th, 4) ([k * 1000 * uold, k * vold]' * [uu, vv]) // to assemble into right-hand side
// + on(4, u=0)
// + on(4, u=0)
// + on(1, v=0)
;

```
