2016-11-04 16:14:52 +05:00
|
|
|
from libngpy._geom2d import *
|
|
|
|
from libngpy._meshing import *
|
2015-08-08 15:58:41 +05:00
|
|
|
|
2015-08-08 22:10:48 +05:00
|
|
|
tmp_generate_mesh = SplineGeometry.GenerateMesh
|
|
|
|
|
|
|
|
def geom2d_meshing_func (geom, **args):
|
|
|
|
if "mp" in args:
|
|
|
|
return tmp_generate_mesh (geom, args["mp"])
|
|
|
|
else:
|
|
|
|
return tmp_generate_mesh (geom, MeshingParameters (**args))
|
|
|
|
|
|
|
|
|
|
|
|
SplineGeometry.GenerateMesh = geom2d_meshing_func
|
2015-08-08 15:58:41 +05:00
|
|
|
|
|
|
|
|
2015-08-08 22:10:48 +05:00
|
|
|
unit_square = SplineGeometry()
|
|
|
|
pnts = [ (0,0), (1,0), (1,1), (0,1) ]
|
2016-03-13 23:05:36 +05:00
|
|
|
lines = [ (0,1,1,"bottom"), (1,2,2,"right"), (2,3,3,"top"), (3,0,4,"left") ]
|
2015-08-08 22:10:48 +05:00
|
|
|
pnums = [unit_square.AppendPoint(*p) for p in pnts]
|
2016-03-13 23:05:36 +05:00
|
|
|
for l1,l2,bc,bcname in lines:
|
|
|
|
unit_square.Append( ["line", pnums[l1], pnums[l2]], bc=bcname)
|
2015-08-08 22:10:48 +05:00
|
|
|
|
2015-11-01 16:07:26 +05:00
|
|
|
|
2015-11-11 22:44:05 +05:00
|
|
|
def MakeRectangle (geo, p1, p2, bc=None, bcs=None, **args):
|
2015-11-01 16:07:26 +05:00
|
|
|
p1x, p1y = p1
|
|
|
|
p2x, p2y = p2
|
|
|
|
p1x,p2x = min(p1x,p2x), max(p1x, p2x)
|
|
|
|
p1y,p2y = min(p1y,p2y), max(p1y, p2y)
|
2015-11-11 22:44:05 +05:00
|
|
|
if not bcs: bcs=4*[bc]
|
|
|
|
print ("bcs = ", bcs)
|
2015-11-01 16:07:26 +05:00
|
|
|
pts = [geo.AppendPoint(*p) for p in [(p1x,p1y), (p2x, p1y), (p2x, p2y), (p1x, p2y)]]
|
2015-11-11 22:44:05 +05:00
|
|
|
for p1,p2,bc in [(0,1,bcs[0]), (1, 2, bcs[1]), (2, 3, bcs[2]), (3, 0, bcs[3])]:
|
|
|
|
geo.Append( ["line", pts[p1], pts[p2]], bc=bc, **args)
|
2015-11-01 16:07:26 +05:00
|
|
|
|
|
|
|
def MakeCircle (geo, c, r, **args):
|
|
|
|
cx,cy = c
|
|
|
|
pts = [geo.AppendPoint(*p) for p in [(cx,cy-r), (cx+r,cy-r), (cx+r,cy), (cx+r,cy+r), \
|
|
|
|
(cx,cy+r), (cx-r,cy+r), (cx-r,cy), (cx-r,cy-r)]]
|
|
|
|
for p1,p2,p3 in [(0,1,2), (2,3,4), (4, 5, 6), (6, 7, 0)]:
|
|
|
|
geo.Append( ["spline3", pts[p1], pts[p2], pts[p3]], **args)
|
|
|
|
|
|
|
|
|
|
|
|
SplineGeometry.AddCircle = lambda geo, c, r, **args : MakeCircle(geo, c, r, **args)
|
|
|
|
SplineGeometry.AddRectangle = lambda geo, p1, p2, **args : MakeRectangle(geo, p1, p2, **args)
|
|
|
|
SplineGeometry.AddSegment = SplineGeometry.Append
|
|
|
|
SplineGeometry.AddPoint = SplineGeometry.AppendPoint
|
|
|
|
|
|
|
|
|
2015-10-30 23:50:40 +05:00
|
|
|
__all__ = ['SplineGeometry', 'unit_square']
|
2015-08-08 15:58:41 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|