- Thank you received: 0
IfPos() too slow? Faster solution searched
5 years 4 months ago #1715
by mischl
IfPos() too slow? Faster solution searched was created by mischl
Dear all,
First of all, I am pretty new to Python/NGSolve/Netgen so please apologise any newbie-error I do.
I have a Mesh, let's say the points
(0,0),E1=(0.25,0), E2=(0.75,0), (1,0), (1,1), and (0,1), I ordered them counterclockwise
I wanted to solve the Laplace-Equation on it with the following Dirichlet-boundary conditions:
d=disctance to the section E1E2
With some linear algebra I could write the code down with two IfPos. But it took ages to solve, very often it didn't work at all. Since I never had similar problems with solving the Laplace Equation or others, I assume it was the IfPos(IfPos())
First of all, I am pretty new to Python/NGSolve/Netgen so please apologise any newbie-error I do.
I have a Mesh, let's say the points
(0,0),E1=(0.25,0), E2=(0.75,0), (1,0), (1,1), and (0,1), I ordered them counterclockwise
I wanted to solve the Laplace-Equation on it with the following Dirichlet-boundary conditions:
d=disctance to the section E1E2
With some linear algebra I could write the code down with two IfPos. But it took ages to solve, very often it didn't work at all. Since I never had similar problems with solving the Laplace Equation or others, I assume it was the IfPos(IfPos())
Code:
d=IfPos((e2-e1)*(y-e1), IfPos((e1-e2)*(y-e2), (x*(-(e2-e1))+y*0)/(e2**2+e1**2)**0.5, (x**2-(y-e2)**2)**0.5), (x**2-(y-e1)**2)**0.5)
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
5 years 4 months ago - 5 years 4 months ago #1716
by christopher
Replied by christopher on topic IfPos() too slow? Faster solution searched
Hi, could you attach the example so we can have a look at it.
My first attempt would be to compile the CoefficientFunction, this is described in the new i-tutorials (yet only available in the nightly part of the docu)
ngsolve.org/docu/nightly/i-tutorials/uni...-CoefficientFunction
Another speedup could be to use x*x and sqrt(x) instead of x**2 and x**0.5.
My first attempt would be to compile the CoefficientFunction, this is described in the new i-tutorials (yet only available in the nightly part of the docu)
ngsolve.org/docu/nightly/i-tutorials/uni...-CoefficientFunction
Another speedup could be to use x*x and sqrt(x) instead of x**2 and x**0.5.
Last edit: 5 years 4 months ago by christopher.
5 years 4 months ago #1717
by mischl
Replied by mischl on topic IfPos() too slow? Faster solution searched
Dear christopher,
thanks for the fast reply. I was writing a minimal example, which was surprisingly solved very fast and I didn't had the issues I had before. I have to recheck my old example (it contains out of multiple files, thus I didn't upload them)
Afterwards I added your * and sqrt() tipps!
Thanks for that
However, my solution isn't drawn. That happens regularly in different examples. Can you see the reason why it is not working here?
thanks for the fast reply. I was writing a minimal example, which was surprisingly solved very fast and I didn't had the issues I had before. I have to recheck my old example (it contains out of multiple files, thus I didn't upload them)
Afterwards I added your * and sqrt() tipps!
Thanks for that
However, my solution isn't drawn. That happens regularly in different examples. Can you see the reason why it is not working here?
Attachments:
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
5 years 4 months ago #1722
by christopher
Replied by christopher on topic IfPos() too slow? Faster solution searched
Whitespaces are not allowed in the name of the function. It messes up the gui calls.
Use underlines instead of whitespaces. It seems, that you function is singular at some edges (although I haven't checked your boundary condition - are you sure that you set it correctly?)
Use underlines instead of whitespaces. It seems, that you function is singular at some edges (although I haven't checked your boundary condition - are you sure that you set it correctly?)
5 years 3 months ago #1739
by mischl
Replied by mischl on topic IfPos() too slow? Faster solution searched
Thx! didn't know that with the whitespace!
And yes, somehow it seems I did an error when copypasting the minimal example together
Will check again the whole example
Thx for the help!
And yes, somehow it seems I did an error when copypasting the minimal example together
Will check again the whole example
Thx for the help!
Time to create page: 0.116 seconds