Hi, I’m trying to apply a time-dependent boundary condition. I found the following solution, How to apply time varying boundary conditions coming from a function?.
def complicated_func(t):
return np.sin(2*np.pi*t/10)
# init:
u_D = Expression('c', c=complicated_func(0), degree = 2) # why degree=2 if this is just constant?
# time loop:
u_D.c = complicated_func(t)
but I got problems with Expression.
File "/home/shared/fenics.py", line 36, in <module>
inlet = Expression('c', c=complicated_func(0), degree=2)
TypeError: Expression.__init__() got an unexpected keyword argument 'c'
dokken
2
Expression is not used in the same way in DOLFINx and legacy dolfin.
You probably want to use a constant, and change the value over time:
u_D = Constant(mesh, ScalarType(complicated_func(t)))
t+=10
u_D.value = complicated_func(t)
1 Like
Thank you, it works! Just out of curiosity, what would be the proper way to use Expression, if the boundary is also spatially dependent?
dokken
4
Simply use a lambda function to interpolate into a suitable function (this is what happened under the hood in legacy dolfin, with generated code).
See
https://jsdokken.com/dolfinx-tutorial/chapter2/ns_code2.html#boundary-conditions