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

Multiply DG0-function with CG1-function; what's the best way?

+1 vote

Hi!

I have these two functions, one in DG0 and one in CG1, e.g.

DG0 = FunctionSpace(mesh, "DG", 0)
CG1 = FunctionSpace(mesh, "CG", 1)

f1 = Function(DG0)
f2 = Function(CG1)

# Assign some values to f1 and f2
...

# Multiply f1 and f2
...

Now my question is, what would be the best and most natural way to manually multiply these functions (without solving a linear system)? As of now I have interpolated the DG0-funcion to CG1 as this

ll = LagrangeInterpolator()
f3 = Function(CG1)
ll.interpolate(f3, f1)

# Do multiplication
f2.vector()[:] = f2.vector()*f3.vector()

This works ok, but instead of using this piecewise "smooth" DG0 field the interpolated field may be be oscillating a lot. This is not critical since the oscillations are controlled, that is they are in the range of the DG0-function, however a better solution would absolutely be preferred! The multiplication should be more "element wise".

Any tips?

Thanks!

asked Dec 3, 2014 by joakibo FEniCS User (1,140 points)
edited Dec 3, 2014 by joakibo

1 Answer

0 votes

You could interpolate both of them to DG1 or does the output have to be continuous?

answered Dec 5, 2014 by KristianE FEniCS Expert (12,900 points)

Unfortunately the total output has to be continous. This DG0 function is to multiplied with several CG1 functions, hence it is more convenient to interpolate it to CG1 than the other way around (something which also would result in unwanted information loss)

...