예제 #1
0
def mesh_Cube(n=10):
    dom = mshr.Box(Point(0., 0., 0.), Point(1., 1., 1.))
    gen = mshr.CSGCGALMeshGenerator3D()
    #gen.parameters["facet_angle"] = 30.0
    #gen.parameters["facet_size"] = 0.5
    #gen.parameters["edge_size"] = 0.5
    gen.parameters["mesh_resolution"] = 0.01
    gen.parameters["odt_optimize"] = True
    mesh = gen.generate(mshr.CSGCGALDomain3D(dom))
    return mesh
예제 #2
0
imp = implicitModeller(
    mergeActors(tf, bx),
    distance=0.04,
    outer=True,
    #                       res=[50,20,10],
    res=[110, 40, 20],
    bounds=[-1.0, 10.0, -1.0, 2.0, -.5, .5],
    maxdist=0.25,
)

imp.write(mytext + '.stl', binary=False)
show(imp)

#### tetralize
import mshr
import dolfin

surface = mshr.Surface3D(mytext + '.stl')
polyhedral_domain = mshr.CSGCGALDomain3D(surface)
dolfin.info(polyhedral_domain, True)

generator = mshr.CSGCGALMeshGenerator3D()
generator.parameters["mesh_resolution"] = 40.0
mesh = generator.generate(polyhedral_domain)

dolfin.File(mytext + ".xml") << mesh
printc('saved', mytext + ".xml")

#from vtkplotter.dolfin import plot
#plot(mesh)
예제 #3
0
> vtkplotter shuttle.xml
"""
import mshr
import dolfin
from vtkplotter.dolfin import datadir, plot

fname = "shuttle.stl"

surface = mshr.Surface3D(datadir + fname)

# add a cylinder
cyl = mshr.Cylinder(dolfin.Point(-1.4, 0, 0), dolfin.Point(-1.0, 0, 0), 0.5,
                    0.7)
totdomain = surface + cyl

polyhedral_domain = mshr.CSGCGALDomain3D(totdomain)
dolfin.info(polyhedral_domain, True)

generator = mshr.CSGCGALMeshGenerator3D()

#### Try automatic
generator.parameters["mesh_resolution"] = 35.0
mesh = generator.generate(polyhedral_domain)

xmlname = fname.split(".")[0] + ".xml"
dolfin.File(xmlname) << mesh
print(mesh, "saved to " + xmlname)

##################################
plot(mesh, text=__doc__)
##################################
예제 #4
0
from __future__ import print_function
import mshr
import dolfin

TOLERANCE = 1e-10

# This geometry generates a lot of degenerate facets
cone = mshr.Cylinder(dolfin.Point(-1.0, 1.0, 1.0), dolfin.Point(1.0, -1.0, -1.0), .5, .5)
cyl = mshr.Cone(dolfin.Point(1.0, -1.0, 1.0), dolfin.Point(-1.0, 1.0, -1.0), .5)
geometry = cone + cyl;

polyhedral_domain = mshr.CSGCGALDomain3D(geometry)

print("Degenerate facets after boolean operation: {0}".format(polyhedral_domain.num_degenerate_facets(TOLERANCE)))
polyhedral_domain.remove_degenerate_facets(TOLERANCE)

dolfin.info(polyhedral_domain, True)

#     print('Dim V: {}'.format(V.dim()))
#     if k < K:
#         m = refine(m)

dom = mshr.Box(Point(0., 0., 0.), Point(1., 1., 1.))
# m_orig = mshr.generate_mesh(dom,0.01)

gen = mshr.CSGCGALMeshGenerator3D()

#gen.parameters["facet_angle"] = 30.0
#gen.parameters["facet_size"] = 0.5
#gen.parameters["edge_size"] = 0.5
gen.parameters["mesh_resolution"] = 0.01
gen.parameters["exude_optimize"] = True

m_orig = gen.generate(mshr.CSGCGALDomain3D(dom))

xf = File('mesh_orig.pvd')
xf << m_orig

V = FunctionSpace(m_orig, 'DG', 0)
w = TestFunction(V)
s = assemble(w * dx)
print(s.get_local())

# m = refine(m_orig)
#
# V = FunctionSpace(m, 'Lagrange', 2)
# u = TrialFunction(V)
# v = TestFunction(V)
#
예제 #6
0
  vertex 0 1 0
  vertex 0 1 1
endloop
endfacet
facet normal 0 0 0
outer loop
  vertex 0 0 1
  vertex 0 0 0
  vertex 1 0 1
endloop
endfacet
facet normal 0 0 0
outer loop
  vertex 0 0 0
  vertex 1 0 0
  vertex 1 0 1
endloop
endfacet
endsolid
"""

fd, filename = tempfile.mkstemp(suffix=".stl")
os.write(fd, cube)

s = mshr.Surface3D(filename)
d = mshr.CSGCGALDomain3D(s)
os.close(fd)
os.remove(filename)

assert d.num_holes() == 0
from dolfin import *
import mshr

# Parameters for geometry
a = 0.04
b = a + 0.004
c = a + 0.01
L = 0.5

# Define cylinders
inner = mshr.CSGCGALDomain3D(
    mshr.Cylinder(Point(0, 0, 0), Point(0, 0, L), a, a))
mid = mshr.CSGCGALDomain3D(mshr.Cylinder(Point(0, 0, 0), Point(0, 0, L), b, b))
outer = mshr.CSGCGALDomain3D(
    mshr.Cylinder(Point(0, 0, 0), Point(0, 0, L), c, c))

generator = mshr.TetgenMeshGenerator3D()
generator.parameters["preserve_surface"] = True
generator.parameters["mesh_resolution"] = 16.

# Mesh inner cylinder
inner_mesh = generator.generate(inner)

# Mesh mid part
mid_mesh = generator.generate(mshr.CSGCGALDomain3D(mid - inner))

# Mesh outer part
outer_mesh = generator.generate(mshr.CSGCGALDomain3D(outer - mid))

# Glue together inner and mid mesh
inner_mid_mesh = mshr.DolfinMeshUtils.merge_meshes(inner_mesh, mid_mesh)