This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Using Min/Max In A Variational Form

0 votes

Hello,

I would like to use a solution dependent, conditional, penalty term within the variational form of a monolithic Navier Stokes solver (as found in the flow around a cylinder demo code on launchpad). The form of the penalty that I wish to use (written in terms of Dolfin-UFL syntax) is as follows:

p = 1000.0
h = CellSize(mesh)
penalty = p*Max(RhoF*sqrt(dot(v,v))/h), Mu/(h*h))

where RhoF and Mu are constant parameters, and v is a Vector Function based on a function space defined on the mesh (as defined in the demo).

I was wondering how I can go about adding such a conditional term in my form. When I try the above form, it gives me an error message In instant.recompile: The module did not compile with command 'make VERBOSE=1',, and this problem persists even after I run instant-clean - making me think I am not programming the conditional part correctly. (Note, when I remove the conditional penalty term, and just assign a fixed penalty, the code works fine).

I am looking for tips and suggestions to get around this issue.

asked May 27, 2016 by debmukh FEniCS Novice (880 points)

1 Answer

+1 vote

Hi, you can define Max and Min functions with UFL. Below is an example which is easily modified for your case

from dolfin import *

def Max(a, b): return (a+b+abs(a-b))/Constant(2)
def Min(a, b): return (a+b-abs(a-b))/Constant(2)

mesh = RectangleMesh(Point(-1, -1), Point(1, 1), 10, 10, 'crossed')
V = VectorFunctionSpace(mesh, 'CG', 1)
v = interpolate(Expression(('x[0]', '-x[1]'), degree=1), V)

tval = sqrt(dot(v, v))
fval = Constant(0.5)

P = FunctionSpace(mesh, 'DG', 0)
pmax = project(Max(tval, fval), P)
pmin = project(Min(tval, fval), P)

plot(pmax, title='max')
plot(pmin, title='min') 
interactive()
answered May 27, 2016 by MiroK FEniCS Expert (80,920 points)
...