Conditional with pointwise condition

9 months ago by
How can I define a function like this in FEniCS for a given function  $f\in L^2\left(\Omega\right)$ƒ L2(Ω)  and  $g\in L^{\infty}\left(\Omega\right)$gL(Ω) :

v(x) = \begin{cases}
f(x), \quad \text{if } |f(x)|\leq g(x) \\
\frac{f(x)}{|f(x)|}g(x),\quad \text{if } |f(x)| > g(x)

I don't really think, that you can implement this using "conditional", because of this "pointwise" condition. Btw: I'm using Nedelec's edge elements. Thanks for your help
Community: FEniCS Project
if your function \(f(x)\) represents the unknown of your pde like you describe

you have introduced a non linearity into your pde and as such must solve using a nonlinear method.  There are two ways to accomplish this: make \(f(x)\) a "fenics::Function", use a "fenics::conditional" specified with \(f(x)\) just like the cases you have mathed out above and solve via Newton's method; or, solve via fixed-point iteration and update "point-wise" coefficients each iteration depending on the current value of the "fenics::Function" \(f(x)\) which satisfies your linear pde as Ruben correctly suggested below.  read, thanks to nate:

Thanks, Nate!

also here:

for your convenience.
written 9 months ago by pf4d  

1 Answer

9 months ago by
Hi there,

You could try
import numpy as np
class v_Expression(Expression):
  def eval(self, value, x):
    #your functions here
    f = x[0]**2 + 2*x[0] + 1
    g = -x[0]**3 + x[0] -2
    if np.abs(f)<= g:
       value[0] = f
       value[0] = (f/np.abs(f))*g

#to use the personalized function
v = v_Expression(degree = 3)​

Good luck!!

This is certainly a valid way to do this for non-time dependent problems, but i believe he wants \(f(x)\) to be a "fenics::TrialFunction" as per the previous post

written 9 months ago by pf4d  
Thanks you both for your answers. Ruben answered my question! Regarding my last question, I made a mistake during the calculations and the function  $f\left(x\right)$ƒ (x) only depends on known functions. So it is basically just an other "data"-function and the pde stays linear. But your comment answers even my intended question. Thanks!!
written 9 months ago by FFoDWindow  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »