Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Creating CoefficientFunctions or GridFunctions Using Integration

More
4 years 11 months ago #1583 by kelley
Hello!

I am new to NGSolve and would like to follow up on a similar question .

I am solving a three dimensional problem and as part of my weak form, I need to implement a vector valued quantity that arises through integration of a coefficient function defined on the bottom of my domain. The integration is wrt z and the result should be a CoefficientFunction or a GridFunction defined on the whole domain.

To do this, I am trying to implement numerical integration myself and essentially create a CoefficientFunction holding the result (though I am not certain this is the most convenient way to do this either). Therefore I would need to create a CoefficientFunction or a GridFunction from a vector or array holding the values from the numerical integration.

My questions are:
  1. Is there a better way to do this numerical integration?
  2. How could I go about setting a GridFunction or CoefficientFunction containing the results if there is no better way?

Thanks in advance,
Josie
More
4 years 11 months ago - 4 years 11 months ago #1587 by christopher
Could you provide a short mathematical description of what you want to do? Maybe with a sketch or something? From what I would understand you can do something like:
Code:
integration_val = Parameter(0) # use this integration val in some SymbolicBFI or so... a +=SymbolicBFI(integration_val * u * v) # then in some loop, etc... integration_val.Set(Integrate(cf, mesh, definedon=mesh.Boundaries("bottom")) # use the new val in the bf,... a.Assemble()

Best
Christopher
Last edit: 4 years 11 months ago by christopher.
More
4 years 11 months ago #1606 by kelley
Hello Christopher,

sorry for being unclear. A rough explanation of my problem is that my bilinear form is a convection operator and I was having trouble implementing the vector that acts as the wind.
Code:
wind = ??? a = SymbolicBFI( InnerProduct( grad(u) * wind, v ) )
This is because each component of the wind arises through integration of a function (that we will call phi), i.e.
Code:
wind_i(x,y,z) = \int_0^z \phi_i (x,y,\tilde{z}) d\tilde{z}, i = 1,...,3
The expression for the wind is actually more complicated, but my question is about evaluating this type of integral: Is there a nicer way to evaluate this integral using NGSolve than by writing a numerical integration scheme myself?
Thanks,
Josie
More
4 years 11 months ago #1607 by christopher
Hi Josie,
you could use another Python package, for example scipy.integrate for that.
Best Christopher
Time to create page: 0.139 seconds