- Thank you received: 0
How to define a CoefficientFunction from a discrete data
5 years 3 months ago - 5 years 3 months ago #1755
by P. Sh
How to define a CoefficientFunction from a discrete data was created 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
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: 5 years 3 months ago by P. Sh.
5 years 3 months ago #1756
by joachim
Replied by joachim on topic How to define a CoefficientFunction from a discrete data
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:
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
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
5 years 3 months ago #1758
by P. Sh
Replied by P. Sh on topic How to define a CoefficientFunction from a discrete data
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
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.094 seconds