Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# From :
#
# > In this last extrusion command we retrieved the volume number
# > programatically by saving the output of the command into a
# > list. This list will contain the "top" of the extruded surface (in
# > out[0]) as well as the newly created volume (in out[1]).
#
top = f"{name}[0]"
extruded = f"{name}[1]"
if isinstance(input_entity, LineBase):
top = LineBase(top)
# A surface extruded from a single line has always 4 edges
extruded = SurfaceBase(extruded, 4)
elif isinstance(input_entity, (SurfaceBase, self.Polygon)):
top = SurfaceBase(top, input_entity.num_edges)
extruded = VolumeBase(extruded)
elif isinstance(input_entity, PointBase):
top = PointBase(top)
extruded = LineBase(extruded)
else:
top = Dummy(top)
extruded = Dummy(extruded)
lat = []
# lateral surfaces can be deduced only if we start from a SurfaceBase
# or a Polygon
if isinstance(input_entity, (SurfaceBase, self.Polygon)):
# out[0]` is the surface, out[1] the top, and everything after that
# the sides, cf.
# . Each
# lateral surface has 4 edges: the one from input_entity, the one
self._GMSH_CODE.append(extrusion_string)
# From :
#
# > In this last extrusion command we retrieved the volume number
# > programatically by saving the output of the command into a
# > list. This list will contain the "top" of the extruded surface (in
# > out[0]) as well as the newly created volume (in out[1]).
#
top = f"{name}[0]"
extruded = f"{name}[1]"
if isinstance(input_entity, LineBase):
top = LineBase(top)
# A surface extruded from a single line has always 4 edges
extruded = SurfaceBase(extruded, 4)
elif isinstance(input_entity, (SurfaceBase, self.Polygon)):
top = SurfaceBase(top, input_entity.num_edges)
extruded = VolumeBase(extruded)
elif isinstance(input_entity, PointBase):
top = PointBase(top)
extruded = LineBase(extruded)
else:
top = Dummy(top)
extruded = Dummy(extruded)
lat = []
# lateral surfaces can be deduced only if we start from a SurfaceBase
# or a Polygon
if isinstance(input_entity, (SurfaceBase, self.Polygon)):
# out[0]` is the surface, out[1] the top, and everything after that
# the sides, cf.
from .surface_base import SurfaceBase
class CompoundSurface(SurfaceBase):
"""
Generates the Compound Surface Gmsh function.
Creates a compound surface from several elementary surfaces.
When meshed, a compound surface will be reparametrized as
a single surface, whose mesh can thus cross internal boundaries.
Compound surfaces are mostly useful for remeshing discrete models.
Parameters
----------
surfaces : array-like[N]
Contains the identification number of the elementary surfaces
that should be reparametrized as a single surface.
"""
def __init__(self, surfaces):
super().__init__()
from .. import built_in
class SurfaceBase(built_in.surface_base.SurfaceBase):
"""
Increments the Surface ID every time a new surface object
is created. Inherits from built_in SurfaceBase.
"""
_ID = 0
dimension = 2
def __init__(self, is_list=False, id0=None):
super().__init__(id0=id0)
self.is_list = is_list
if is_list:
self.id += "[]"
return
if not isinstance(entities, list):
entities = [entities]
d = {0: "Point", 1: "Line", 2: "Surface", 3: "Volume"}
tpe = d[entities[0].dimension]
for e in entities:
assert isinstance(
e,
(
Point,
PointBase,
LineBase,
Surface,
PlaneSurface,
SurfaceBase,
Volume,
VolumeBase,
),
), "Can add physical groups only for Points, Lines, Surfaces, Volumes, not {}.".format(
type(e)
)
assert d[e.dimension] == tpe
label = self._new_physical_group(label)
self._GMSH_CODE.append(
"Physical {}({}) = {{{}}};".format(
tpe, label, ", ".join([e.id for e in entities])
)
)
return
else:
top = Dummy(top)
extruded = Dummy(extruded)
lat = []
# lateral surfaces can be deduced only if we start from a SurfaceBase
# or a Polygon
if isinstance(input_entity, (SurfaceBase, self.Polygon)):
# out[0]` is the surface, out[1] the top, and everything after that
# the sides, cf.
# . Each
# lateral surface has 4 edges: the one from input_entity, the one
# from top, and the two lines (or splines) connecting their extreme
# points.
lat = [
SurfaceBase("{}[{}]".format(name, i + 2), 4)
for i in range(input_entity.num_edges)
]
return top, extruded, lat
def __init__(self, id0=None, num_edges=0):
if id0:
assert isinstance(id0, str)
self.id = id0
else:
self.id = f"s{SurfaceBase._ID}"
SurfaceBase._ID += 1
self.num_edges = num_edges
return