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.

How to define a CoefficientFunction from a discrete data

More
4 years 8 months ago - 4 years 8 months ago #1755 by P. Sh
Hi,

I'd like to define a CoefficientFunction from a discrete data like an array of numbers {1,2,3,4,5,6,...}. Is it possible in NGSolve? I was wondering if someone could possibly share her/his knowledge with me in this regard. Thanks.

Best,
Danial
Last edit: 4 years 8 months ago by P. Sh.
More
4 years 8 months ago #1756 by joachim
Hi Danial,

where do your values relate to ? If every value corresponds to one element, you can define an L2-gridfunction, and set its coefficients to your values:
Code:
fespace = L2(mesh, order=0) gf = GridFunction(fespace) for i in range(fes.ndof): gf.vec[i| = value[i]

You can plot the GridFunction, and you can use it where you want to use your coefficient. A GridFunction is a CoefficientFunction, too.

The basis-functions of the L2(order=0) space are exactly the characteristic functions of every element.
If your values correspond to vertices, you use an H1-space (with order=1) instead.

Best, Joachim
More
4 years 8 months ago #1758 by P. Sh
Hi Joachim,
Thank you very much for your complete explanation. According to your question, the values were defined over a domain. Take a one dimensional problem, for example. I have 100 values over the domain. Now, I'd like to define a function using these values that I can use it in the variational form to solve an ODE. Note that, there is no relationship between the values and the elements. Would that be possible to apply the same way for all domain? Thanks.

Best,
Danial
Time to create page: 0.141 seconds