- Thank you received: 0
CoefficientFunction from interpolation list
4 years 8 months ago #2473
by NilsHM
CoefficientFunction from interpolation list was created by NilsHM
Hello Everyone,
I want to define a CoefficientFunction from another CoefficientFunction using an interpolation list for values.
Here is a short example:
Here I tried to define the CoefficientFunction as follows:
But this does not work.
Is there a way of making the CoefficientFunction make use of the np.interp() function or is there another way?
Thanks
Nils
I want to define a CoefficientFunction from another CoefficientFunction using an interpolation list for values.
Here is a short example:
Code:
import numpy as np
from ngsolve import *
B_list = [0.0, 0.211862, 0.265665, 0.332377]
mu_list = [2.66233640, 2.62172474, 2.59376841, 2.54489696]
B_cf = x
Code:
mu_cf = CoefficientFunction( [ np.interp(B, B_list, mu_list) for B in B_cf ] )
Is there a way of making the CoefficientFunction make use of the np.interp() function or is there another way?
Thanks
Nils
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
4 years 8 months ago #2474
by christopher
Replied by christopher on topic CoefficientFunction from interpolation list
You can use the BSpline coefficient function for this. It gets an order, a list of nodes and a list of values.
Best
Christopher
Best
Christopher
The following user(s) said Thank You: NilsHM
4 years 8 months ago #2486
by NilsHM
Replied by NilsHM on topic CoefficientFunction from interpolation list
Thanks! The BSpline CF probably what I was looking for.
The value of that CF however follows the data not very closely.
I'm setting up the CF like this:
I put the output value of that CF for different orders compared to the interpolation data in the attachments. Order 1 is mapping the the data in a acceptable way but since I need to differentiate this cf order 1 is out of question.
Is there a way of making the CF just interpolate the data or something else to make this work?
Best regards
Nils
Data: blue dots
BSpline result: red dashed line
Order n=1
Order n=2
Order n=3
The value of that CF however follows the data not very closely.
I'm setting up the CF like this:
Code:
spline = BSpline(n, B_list, mu_list)
mu_cf = spline(B_cf)
Is there a way of making the CF just interpolate the data or something else to make this work?
Best regards
Nils
Data: blue dots
BSpline result: red dashed line
Order n=1
Order n=2
Order n=3
Attachments:
4 years 8 months ago #2487
by joachim
Replied by joachim on topic CoefficientFunction from interpolation list
you have to duplicate the first control point (value of B_list)
then the n=2 B-spline will be linear interpolation.
Joachim
then the n=2 B-spline will be linear interpolation.
Joachim
The following user(s) said Thank You: NilsHM
4 years 8 months ago #2490
by NilsHM
Replied by NilsHM on topic CoefficientFunction from interpolation list
Thanks!
Now I have a different problem:
I'm using this CF in a nonlinear BilinearForm:
When assembling a linearized matrix of the system the matrix has a lot of nan entries.
This should not happen since the values of spline() are always nonzero positive.
Do you know why there are nan entries in the matrix and how to avoid it?
Best regards
Nils
Now I have a different problem:
I'm using this CF in a nonlinear BilinearForm:
Code:
u,v = fes.TnT()
a = BilinearForm(fes)
a += SymbolicBFI(1.0/spline(Norm(grad(u))) * grad(u) * grad(v))
This should not happen since the values of spline() are always nonzero positive.
Do you know why there are nan entries in the matrix and how to avoid it?
Best regards
Nils
4 years 8 months ago #2491
by joachim
Replied by joachim on topic CoefficientFunction from interpolation list
difficult to say without testing, but maybe you try to differentiate Norm at grad(u) = 0 ?
Replace Norm(grad(u)) by
sqrt( InnerProduct(grad(u),grad(u)) + 1e-15 )
Joachim
Replace Norm(grad(u)) by
sqrt( InnerProduct(grad(u),grad(u)) + 1e-15 )
Joachim
The following user(s) said Thank You: NilsHM
Time to create page: 0.101 seconds