# How to apply spring boundary condition in FENICS

Hi guys,

I know this is a really basic question, can any tell how to apply spring boundary condition in z-axis at the bottom 4 corners of a 3D plate. Here is the code.

``````# importing libraries for pre-processing

import dolfin as df
import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path
import json
from mshr import Polygon, generate_mesh
from scipy.optimize import root
from math import cos, cosh
import sys
import argparse
from functools import partial
import pandas as pd
import meshio as mio
from stl import mesh as mstl

param = {
"length": 1,
"width": 1,
"thickness": 5e-2,
"E": 1e6,
"nu": 0.3,
"rho":1000,
"bc_stiff":1e6,
}
# Lame's Constants
param["mu"] = 0.5 * param["E"] / (1+param["nu"])
param["lmbda"] = param["E"]*param["nu"] / ((1+param["nu"])*(1-2*param["nu"]))

# Global Constants
GRAVITY = 9.81

corner1 = df.Point(0, 0, 0)

# corner2 is diagonally opposite to the corner1
corner2 = df.Point(param["length"],
param["width"],
-param["thickness"])

# res is the resolution of the mesh
res = 2 * int(1/param["thickness"])
mesh = df.BoxMesh(corner1, corner2,
int(res * param["length"]),
int(res * param["width"]),
int(res * param["thickness"]))
# Strain Function
def strain(disp):

# Stress Function
def stress(disp):
dim = disp.geometric_dimension()
return 2.0*param["mu"]*strain(disp) + param["lmbda"]*df.tr(strain(disp))*df.Identity(dim)

V = df.VectorFunctionSpace(mesh, 'Lagrange', degree=1)
u_ = df.TrialFunction(V)
du = df.TestFunction(V)

def corner_spring_bc(x, on_boundary):
"""Function to apply spring boundary condition at the corners of the plate bottom"""
tol = 1/res
bottom = df.near(x[2],-param["thickness"],tol)

if bottom:
left   = df.near(x[0],0,tol)
right  = df.near(x[0],param["length"],tol)
front  = df.near(x[1],param["width"],tol)
back   = df.near(x[1],0,tol)

corner1 = left  and front
corner2 = left  and back
corner3 = right and front
corner4 = right and back

return corner1 or corner2 or corner3 or corner4

return bottom

# Spring boundary Condition in z axis of stiffness param["bc_stiff"]
#bc = ?

``````

Also, am I defining the corner points correctly?