Assign a force to boundary node depending on node displacement

So instead of fixing the left edge by saying

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:

// 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. :confused:

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

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)
;
1 Like