- Thank you received: 0
error when re-loading mesh from file
- walker_tr9
- Topic Author
- Offline
- Senior Member
Less
More
2 years 5 months ago #4405
by walker_tr9
error when re-loading mesh from file was created by walker_tr9
The error is this. If I create a 3-D mesh from scratch, with some uniform refinements, it has a certain number of faces, facets, and edges. I then save the mesh to a .vol file. When I reload the mesh, the number of faces, facets, and edges is *different*. Why?
I have created a sample code below.
import numpy as np
import netgen.gui
from ngsolve import *
from netgen.csg import unit_cube
from netgen.csg import CSGeometry
from netgen.csg import Pnt
from netgen.csg import OrthoBrick
#load_mesh = True
load_mesh = False
mesh_FN = "test_mesh.vol"
if load_mesh:
print("Load mesh from file.")
mesh = Mesh(mesh_FN)
else:
print("Create mesh from scratch.")
# make the mesh
cube = OrthoBrick( Pnt(0,0,0), Pnt(1,1,1) ).bc("Gamma")
geo = CSGeometry()
geo.Add(cube)
mesh = Mesh(geo.GenerateMesh(maxh=1.0))
for r in range(3):
mesh.Refine()
# save the mesh
mesh.ngmesh.Save(mesh_FN)
print("Some info about the mesh:")
print("Number of Elements: " + str(mesh.ne))
print("Number of Faces: " + str(mesh.nface))
print("Number of Facets: " + str(mesh.nfacet))
print("Number of Edges: " + str(mesh.nedge))
print("Number of Vertices: " + str(mesh.nv))
When you run it the first time, you should get:
>From scratch:
>Number of Elements: 3072
>Number of Faces: 7530
>Number of Facets: 7530
>Number of Edges: 4905
>Number of Vertices: 729
Next, change "load_mesh" to True and rerun. The output will be:
>When loading from file:
>Number of Elements: 3072
>Number of Faces: 6528
>Number of Facets: 6528
>Number of Edges: 4184
>Number of Vertices: 729
Why is it different?
I have created a sample code below.
import numpy as np
import netgen.gui
from ngsolve import *
from netgen.csg import unit_cube
from netgen.csg import CSGeometry
from netgen.csg import Pnt
from netgen.csg import OrthoBrick
#load_mesh = True
load_mesh = False
mesh_FN = "test_mesh.vol"
if load_mesh:
print("Load mesh from file.")
mesh = Mesh(mesh_FN)
else:
print("Create mesh from scratch.")
# make the mesh
cube = OrthoBrick( Pnt(0,0,0), Pnt(1,1,1) ).bc("Gamma")
geo = CSGeometry()
geo.Add(cube)
mesh = Mesh(geo.GenerateMesh(maxh=1.0))
for r in range(3):
mesh.Refine()
# save the mesh
mesh.ngmesh.Save(mesh_FN)
print("Some info about the mesh:")
print("Number of Elements: " + str(mesh.ne))
print("Number of Faces: " + str(mesh.nface))
print("Number of Facets: " + str(mesh.nfacet))
print("Number of Edges: " + str(mesh.nedge))
print("Number of Vertices: " + str(mesh.nv))
When you run it the first time, you should get:
>From scratch:
>Number of Elements: 3072
>Number of Faces: 7530
>Number of Facets: 7530
>Number of Edges: 4905
>Number of Vertices: 729
Next, change "load_mesh" to True and rerun. The output will be:
>When loading from file:
>Number of Elements: 3072
>Number of Faces: 6528
>Number of Facets: 6528
>Number of Edges: 4184
>Number of Vertices: 729
Why is it different?
Time to create page: 0.110 seconds