Line integrals and resulting reduced dimensionality projection

Dear Netgen / NGSolve developers,

first of all, thanks for the great computational package and service that you provide. I was wondering if a more elegant way exists to the following problem.

I want to implement two models in the field of fluid mechanics. A two-dimensional model, defined on the physical domain (x,y) \in [0,L] x [0,B], and a one-dimensional model defined for x \in [0,L]. The one-dimensional model is the result of integrating the equations of the two-dimensional model over y.

In pseudocode (if it is preferred, I could also provide some actual code)

mesh2D = Rectangle([0,L], [0,B])
mesh1D = Line([0,L]);

fes2D = H1(mesh2D)
fes1D = H1(mesh1D)

sol2D = GridFunction(fes2D) %This is the solution of a nonlinear 2D problem

Having obtained a solution to the 2D model in the form of a GridFunction sol2D, I need to use this solution as an input for the 1D model. Let’s call this input f. To do this, I integrate the 2D solution over y to obtain a 1D function.

Right now, this is done in an (in my view) ‘ugly’ way using numpy.trapz integration:

sol2D_numpy = numpy.array([sol2D(mesh2D(*p)) for p in np.nditer([X, Y])]).reshape(X.shape) % Evaluate sol2D on a regular meshgrid [X,Y]

f_numpy = np.trapz(sol2D_numpy, Y, axis = 0)

Importantly, the points contained in X exactly coincide with the one-dimensional mesh nodes, otherwise I would use interpolation in the following step.

f = Gridfunction(fes1D)

(( Set GridFunction values of f using the NumPy array f_numpy ))

Finally, we have our desired GridFunction, which I then convert to a 1D CoefficientFunction.

My questions:

  • Is there a way to avoid using numpy to do the step between double brackets?
  • Is there a way to avoid using numpy or scipy altogether and just rely on NGSolve functions?
    The above approach can be very slow and relies on trapz, which I think is far less accurate than some integration methods NGSolve implements.

In other words, does NGSolve implement a projection from the 2D space into the 1D space in some sense? I couldn’t find it in the documentation or the forum. I would have no problem in solving another minimization problem, as this is probably much faster than the method I use now.

Many thanks in advance.

Best,
Henk

1 Like

I have similar needs. Would be great to see this feature in ngsolve.