netgen/tests/pytest/test_savemesh.py
Christopher Lackner 89fe31b550 Squashed commit of the following:
commit fa556baaa222ba349d534027f7203588dcda6ad8
Author: Christopher Lackner <christopher.lackner@tuwien.ac.at>
Date:   Thu Feb 23 15:56:47 2017 +0100

    add python path to docker template

commit 54eb7eedc77ad8c86952c347536e7e1a854b62ed
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Thu Feb 23 14:59:45 2017 +0100

    install pytest in docker images

commit 3c1c755891e8372762130a6ed8c39cf056430264
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Thu Feb 23 14:52:32 2017 +0100

    enable CTest properly, add pytest

commit 4c4cf229ab8e7fd6057f535fb05c3079a9278f80
Author: Christopher Lackner <christopher.lackner@tuwien.ac.at>
Date:   Thu Feb 23 14:02:13 2017 +0100

    fix write splinesurface to savemesh

commit 069fbdbc529c9dd91644663f3f365e08be5af70e
Author: Christopher Lackner <christopher.lackner@tuwien.ac.at>
Date:   Thu Feb 23 09:03:26 2017 +0100

    fix lifetime of SplineSurface
2017-02-23 16:41:27 +01:00

53 lines
1.6 KiB
Python

from netgen.csg import *
from netgen import meshing
import filecmp
import difflib
from math import sqrt, cos, sin
def CreateQuad():
base = Plane(Pnt(0,0,0),Vec(0,0,1))
surface = SplineSurface(base)
pts = [(-0.2,-0.2,0),(-0.2,0.2,0),(0.2,0.2,0),(0.2,-0.2,0)]
geopts = [surface.AddPoint(*p) for p in pts]
for p1,p2,bc in [(0,1,"wire"), (1, 2,"contact"),(2,3,"wire"),(3,0,"wire")]:
surface.AddSegment(geopts[p1],geopts[p2],bc)
return surface
Cross = lambda a,b: [a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-b[0]*a[1]]
def CreateGeo():
geo = CSGeometry()
air = OrthoBrick(Pnt(-1,-1,-1),Pnt(1,1,1))
geo.Add(air.mat("air"))
surface = CreateQuad()
geo.AddSplineSurface(surface)
return geo
def test_BBNDsave():
mesh = CreateGeo().GenerateMesh(maxh=0.4,perfstepsend = meshing.MeshingStep.MESHSURFACE)
for i in range(2):
mesh.GenerateVolumeMesh(mp = MeshingParameters(only3D_domain=i+1,maxh=0.4))
mesh.SetGeometry(None)
mesh.Save("test.vol")
mesh2 = meshing.Mesh()
mesh2.Load("test.vol")
mesh2.Save("test2.vol")
with open("test.vol","r") as f:
first = f.readlines()
with open("test2.vol","r") as f:
second = f.readlines()
# exclude the face colours section (because they aren't in the same order)
for i,line in enumerate(first):
if line[0:12] == "face_colours":
first = first[0:i]
second = second[0:i]
break
diff = difflib.context_diff(first,second)
print("File diff:")
l = list(diff)
print(*l)
assert len(l)==0