mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
Merge branch 'master' into boundarylayers
This commit is contained in:
commit
0d339a7443
@ -402,6 +402,12 @@ bool IsInsideTrig( const array<Point<2>,3> & t, Point<2> r )
|
||||
return ( (w % 2) != 0 );
|
||||
}
|
||||
|
||||
bool IsCloseToTrig( const array<Point<2>,3> & t, Point<2> r, double eps=1e-4 )
|
||||
{
|
||||
r += eps * (Center(t[0], t[1], t[2])-r); // move point a bit to center of trig
|
||||
return IsInsideTrig( t, r );
|
||||
}
|
||||
|
||||
|
||||
IntersectionType IntersectTrig( Point<2> p0, Point<2> p1, const array<Point<2>,3> & trig)
|
||||
{
|
||||
@ -1612,7 +1618,7 @@ bool Loop :: IsInside( Point<2> r ) const
|
||||
auto s0 = s.StartPI();
|
||||
auto s1 = s.TangentPoint();
|
||||
auto s2 = s.EndPI();
|
||||
if(!IsInsideTrig( {s0, s1, s2} , r ))
|
||||
if(!IsCloseToTrig( {s0, s1, s2} , r ))
|
||||
w += w_simple;
|
||||
else
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
from .libngpy._geom2d import SplineGeometry, Solid2d, CSG2d, Rectangle, Circle, EdgeInfo, PointInfo
|
||||
from .meshing import meshsize
|
||||
import math as math
|
||||
|
||||
unit_square = SplineGeometry()
|
||||
_pnts = [ (0,0), (1,0), (1,1), (0,1) ]
|
||||
@ -144,3 +145,34 @@ def cp(p_or_px, py_or_none = None):
|
||||
return EdgeInfo(control_point=p)
|
||||
else:
|
||||
return EdgeInfo(control_point=(p_or_px,py_or_none))
|
||||
|
||||
|
||||
def Ellipse(center, a, b, bc="ellipse", mat="ellipse"):
|
||||
"""Creates ellipse centered at point center with principle axis a and b.
|
||||
|
||||
Parameters
|
||||
---------
|
||||
center : Vec2
|
||||
center of ellipse
|
||||
a : Vec2
|
||||
first principle axis, needs to be perpendicular to b
|
||||
b : Vec2
|
||||
second principle axis, needs to be perpendicular to a
|
||||
bc : string
|
||||
boundary name
|
||||
mat : string
|
||||
material name
|
||||
"""
|
||||
if abs(a[0]*b[0] + a[1]*b[1]) > 1e-12:
|
||||
raise Exception("In Ellipse: principle axis a and b are not perpendicular")
|
||||
|
||||
ellipse = Circle( center=(0,0), radius=1.0, mat=mat, bc=bc )
|
||||
|
||||
alpha = math.pi/2-math.atan2(a[0],a[1])
|
||||
r_a = math.sqrt(a[0]**2+a[1]**2)
|
||||
r_b = math.sqrt(b[0]**2+b[1]**2)
|
||||
ellipse.Scale( (r_a,r_b) )
|
||||
ellipse.Rotate( alpha/math.pi*180, center=(0,0) )
|
||||
ellipse.Move( center )
|
||||
|
||||
return ellipse
|
||||
|
@ -54,6 +54,35 @@ def test_trig_and_circle():
|
||||
ngs.Draw(mesh)
|
||||
|
||||
|
||||
def test_circle_plus_rect():
|
||||
circle = Circle( center=(0,0), radius=1 )
|
||||
rect = Rectangle( pmin=(-0.5,0.0), pmax=(0.5,0.5) )
|
||||
|
||||
geo = CSG2d()
|
||||
geo.Add(circle+rect)
|
||||
m = geo.GenerateMesh(maxh=0.2)
|
||||
|
||||
|
||||
ngs = pytest.importorskip("ngsolve")
|
||||
mesh = ngs.Mesh(m)
|
||||
mesh.Curve(5)
|
||||
assert ngs.Integrate(1.0, mesh) == approx(math.pi)
|
||||
|
||||
def test_circle_plus_rect1():
|
||||
circle = Circle( center=(0,0), radius=1 )
|
||||
rect = Rectangle( pmin=(-0.5,-0.5), pmax=(0.5,0.5) )
|
||||
|
||||
geo = CSG2d()
|
||||
geo.Add(circle+rect)
|
||||
m = geo.GenerateMesh(maxh=0.2)
|
||||
|
||||
|
||||
ngs = pytest.importorskip("ngsolve")
|
||||
mesh = ngs.Mesh(m)
|
||||
mesh.Curve(5)
|
||||
assert ngs.Integrate(1.0, mesh) == approx(math.pi)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_two_circles()
|
||||
test_two_edge()
|
||||
|
Loading…
Reference in New Issue
Block a user