Example #1
0
def pebi_fill(domain, constr=[], pts=[]):
    """Builds perpendicular bisector cells in given domain.

    :param domain: single or list of closed contours
        representing bounding domain

    :param constr: single or list of contours representing
        meshing constraints

    :param pts: set of points in ``[len0, [x0, y0], ...]``
        format where ``x, y`` are coordinates of internal vertices
        which should be embedded into the resulting grid,
        ``len`` - size of adjacent cells

    :return: grid identifier

    A contour tree will be built using all closed contours
    passed as **domain** parameter. Only the interior parts
    of this tree will be meshed. Contours passed by **domain**
    should not intersect each other, but could intersect **constr**
    contours.

    Routine can produce concave cells (as a result of bad size
    control or near the concave domain boundary vertices).
    Use :func:`heal_grid` routine with ``convex_cells`` option to fix this.

    See details in :ref:`unstructured-meshing`.
    """
    icheck(0, UListOr1(ACont2D()))
    icheck(1, UListOr1(ACont2D()))
    icheck(2, CompoundList(Float(grthan=0.0), Point2D()))
    return _triquad(domain, constr, pts, 'pebi')
Example #2
0
def export3d_grid_msh(gid, fname, periodic_pairs=[]):
    """Exports 3D grid to fluent msh ascii format.

    :param gid: 3D grid file identifier or list of identifiers

    :param str grid: filename for output

    :param list periodic_pairs:
       ``[periodic-0, shadow-0, periodic-point-0, shadow-point-0,
       periodic-1, shadow-1, periodic-point-1, ...]``

       Each periodic pair is defined by four values:

       * ``periodic`` - boundary identifier for periodic surface
       * ``shadow`` - boundary identifier for shadow surface
       * ``periodic-point`` - point in [x, y, z] format on periodic contour
       * ``shadow-point`` - point in [x, y, z] format on shadow contour

       Given points will be projected to closest vertex on the boundaries
       of respective subsurfaces.

       Periodic and shadow subsurfaces should be singly connected and
       topologically equivalent with respect to given points.
       For surface 2D topology definition periodic/shadow surfaces are taken
       with outside/inside normals respectively.

    """
    icheck(0, UListOr1(Grid3D()))
    icheck(1, String())
    icheck(2, CompoundList(ZType(), ZType(), Point3D(), Point3D()))

    cb = flow.interface.ask_for_callback()
    grid = _grid3_from_id(gid)
    bt = flow.receiver.get_zone_types()
    fluent_export.grid3(fname, grid, bt, periodic_pairs, cb)
Example #3
0
def export_contour_hmc(cid, fname, fmt="ascii"):
    """Exports contours to native format.

      :param cid: contour identifier or list of identifiers,

      :param str fname: output filename

      :param str fmt: output data format:

         * ``'ascii'`` - all fields will be saved as text fields,
         * ``'bin'`` - all fields will be saved in binary section,
         * ``'fbin'`` - only floating point fields will be saved
           in binary section.

      :returns: None

      See :ref:`contour2d-file` for format description.
    """
    if fmt == "binary":
        fmt = "bin"
    elif fmt == "fbinary":
        fmt = "fbin"
    icheck(0, UListOr1(ACont2D()))
    icheck(1, String())
    icheck(2, OneOf('ascii', 'bin', 'fbin'))

    names = cid if isinstance(cid, list) else [cid]
    conts = [_cont2_from_id(n) for n in names]
    cb = flow.interface.ask_for_callback()
    native_export.cont2_tofile(fname, conts, names, fmt, cb)
Example #4
0
def export3d_surface_hmc(sid, fname, fmt="ascii"):
    """Exports 3d surface to hybmesh native format.

      :param sid: single or list of surface identifiers

      :param str fname: output filename

      :param str fmt: output data format:

         * ``'ascii'`` - all fields will be saved as text fields,
         * ``'bin'`` - all fields will be saved in binary section,
         * ``'fbin'`` - only floating point fields will be saved
           in binary section.

      See :ref:`surface3d-file` for format description.
    """
    if fmt == "binary":
        fmt = "bin"
    elif fmt == "fbinary":
        fmt = "fbin"
    icheck(0, UListOr1(ASurf3D()))
    icheck(1, String())
    icheck(2, OneOf('ascii', 'bin', 'fbin'))

    names = sid if isinstance(sid, list) else [sid]
    surfs = [_surf3_from_id(n) for n in names]
    cb = flow.interface.ask_for_callback()
    native_export.surf3_tofile(fname, surfs, names, fmt, cb)
Example #5
0
def export3d_grid_vtk(gid, fname_grid=None, fname_surface=None):
    """Exports 3D grid and its surface to vtk ascii format.

    :param gid: 3D grid file identifier or list of identifiers

    :param str-or-None fname_grid: filename for grid output.

    :param str-or-None fname_surface: filename for surface output.

    Only hexahedron, prism, wedge and tetrahedron cells could be exported
    as a grid. Surface export takes arbitrary grid.

    If a filename is *None* then respective export will be omitted.

    Boundary types are exported as a field called ``boundary_types`` to
    surface output file.
    """
    icheck(0, UListOr1(Grid3D()))
    icheck(1, NoneOr(String()))
    icheck(2, NoneOr(String()))
    if not fname_grid:
        fname_grid = None
    if not fname_surface:
        fname_surface = None

    cb = flow.interface.ask_for_callback()
    grid = _grid3_from_id(gid)
    if fname_grid is not None:
        vtk_export.grid3(fname_grid, grid, cb)
    if fname_surface is not None:
        vtk_export.grid3_surface(fname_surface, grid, cb)
Example #6
0
def export_grid_msh(gid, fname, periodic_pairs=[]):
    """Exports grid to fluent msh format.

    :param gid: 2d grid file identifier or list of identifiers.

    :param str fname: output filename

    :param list periodic_pairs:
      ``[b-periodic0, b-shadow0, is_reversed0, b-periodic1,
      b-shadow1, is_reversed1, ...]`` list defining periodic boundaries.

      Each periodic condition is defined by three values:

      * ``b-periodic`` - boundary identifier for periodic contour segment
      * ``b-shadow`` - boundary identifier for shadow contour segment
      * ``is_reversed`` - boolean which defines whether shadow contour segment
        should be reversed so that first point of periodic segment be
        equivalent to last point of shadow segment

      Periodic and shadow boundary segments should be singly connected and
      topologically equivalent.

    :returns: None

    Only grids with triangle/quadrangle cells could be exported.
    """
    icheck(0, UListOr1(Grid2D()))
    icheck(1, String())
    icheck(2, CompoundList(ZType(), ZType(), Bool()))

    cb = flow.interface.ask_for_callback()
    grid = _grid2_from_id(gid)
    bt = flow.receiver.get_zone_types()
    fluent_export.grid2(fname, grid, bt, periodic_pairs, cb)
Example #7
0
def tetrahedral_fill(domain):
    """ Fills 3D domain with tetrahedral mesh

    :param domain: surface/3d grid identifier (or list of identifiers)

    :returns: 3d grid identifier

    Domain is defined by any number of closed surfaces passed in **domain**
    argument. Internal nesting procedure
    will be executed to built target domain out of given surfaces.
    Boundary surface could possibly contain faces built
    by any number of vertices.
    However if boundary face is not a triangle than a n-side pyramid
    will be built at its site. Hence resulting grid will not be strictly
    tetrahedral.

    .. note::

        By now program uses simplified bounding box based nesting
        algorithm. It could give improper results for complicated
        surface structures. Be sure that passed surface list nesting equals
        nesting of respective surface bounding boxes.
    """
    icheck(0, UListOr1(ASurf3D()))

    if not isinstance(domain, list):
        domain = [domain]

    c = com.grid3dcom.TetrahedralFill({"source": domain})
    flow.exec_command(c)
    return c.added_grids3()[0]
Example #8
0
def remove_geom(objs):
    """ Completely removes object or list of objects

    :param objs: identifier or list of identifiers of removing objects

    :returns: None
    """
    icheck(0, UListOr1(AObject()))
    ob = objs if isinstance(objs, list) else [objs]
    c = com.objcom.RemoveGeom({"names": ob})
    flow.exec_command(c)
Example #9
0
def export3d_grid_hmg(gid, fname, fmt="ascii", afields=[]):
    """Exports 3d grid to hybmesh native format.

      :param gid: single or list of grid identifiers

      :param str fname: output filename

      :param str fmt: output data format:

         * ``'ascii'`` - all fields will be saved as text fields,
         * ``'bin'`` - all fields will be saved in binary section,
         * ``'fbin'`` - only floating point fields will be saved
           in binary section.

      :param list-of-str afields: additional data which should be placed
          to output file.

      To save additional data into grid file
      :ref:`user defined fields <udef-fields>`
      place any of these strings into **afields** list:

      * ``'face-vertices'`` - face vertex ordered connectivity,
      * ``'cell-faces'`` - cell face connectivity,
      * ``'cell-vertices'`` - cell vertex connectivity,
      * ``'linfem'`` - tries to write cells-vertex connectivity
        for cell types most widely used in linear fem solvers.
        Supported cell types are: tetrahedron (4 nodes), hexahedron (8),
        prism(6), pyramid(5).
        Record for each of those cells contains points in order prescribed
        by vtk file format. If a cell is not of one of those types
        then a zero length connectivity list will be written for it.

        .. figure:: vtk_cells3d.png
           :width: 500 px

      See :ref:`grid3d-file` for format description.
    """
    if fmt == "binary":
        fmt = "bin"
    if fmt == "fbinary":
        fmt = "fbin"
    icheck(0, UListOr1(Grid3D()))
    icheck(1, String())
    icheck(2, OneOf('ascii', 'bin', 'fbin'))
    icheck(
        3,
        UList(OneOf('face-vertices', 'cell-faces', 'cell-vertices', 'linfem')))
    names = gid if isinstance(gid, list) else [gid]
    grids = map(flow.receiver.get_grid3, names)
    cb = flow.interface.ask_for_callback()
    native_export.grid3_tofile(fname, grids, names, fmt, afields, cb)
Example #10
0
def export_contour_vtk(cid, fname):
    """Exports contour to vtk format.

    :param cid: contour identifier or list of identifiers,

    :param str fname: output filename.

    :return: None
    """
    icheck(0, UListOr1(ACont2D()))
    icheck(1, String())

    cont = _cont2_from_id(cid)
    cb = flow.interface.ask_for_callback()
    vtk_export.cont2(fname, cont, cb)
Example #11
0
def triangulate_domain(domain, constr=[], pts=[], fill='3'):
    """Builds constrained triangulation within given domain

    :param domain: single or list of closed contours
        representing bounding domain

    :param constr: single or list of contours representing
        triangulation constraints

    :param pts: set of points in ``[len0, [x0, y0], ...]``
        format where ``x, y`` are coordinates of internal vertices
        which should be embedded into the resulting grid,
        ``len`` - size of adjacent cells
    :param str fill: if '3' then triangulates area; '4' runs
        recombination algorithm to make mostly quadrangular mesh

    :return: grid identifier

    A contour tree will be built using all closed contours
    passed as **domain** parameter. Only the interior parts
    of this tree will be meshed. Contours passed by **domain**
    should not intersect each other, but could intersect **constr**
    contours.
    **constr** could contain any set of closed and open contours.

    See details in :ref:`unstructured-meshing`.
    """
    icheck(0, UListOr1(ACont2D()))
    icheck(1, UListOr1(ACont2D()))
    icheck(2, CompoundList(Float(grthan=0.0), Point2D()))
    icheck(3, OneOf('3', '4'))

    if fill == '3':
        return _triquad(domain, constr, pts, '3')
    elif fill == '4':
        return _triquad(domain, constr, pts, '4')
Example #12
0
def export_grid_vtk(gid, fname):
    """ Exports 2d grid to vtk format

       :param gid: single or list of 2d grid identifiers

       :param str fname: output filename

       :returns: None
    """
    icheck(0, UListOr1(Grid2D()))
    icheck(1, String())

    grid = _grid2_from_id(gid)
    cb = flow.interface.ask_for_callback()
    vtk_export.grid2(fname, grid, cb)
Example #13
0
def remove_all_but(objs):
    """ Removes all geometry objects except for listed ones

    :param objs: identifier or list of identifiers of objects
       which should NOT be removed

    :returns: None
    """
    icheck(0, UListOr1(AObject()))

    if not isinstance(objs, list):
        objs = [objs]

    all_obj = flow.receiver.get_names()
    all_obj = [x for x in all_obj if x not in objs]
    remove_geom(all_obj)
Example #14
0
def rotate_geom(objs, angle, pc=[0.0, 0.0]):
    """ Rotates group of 2d objects

    :param objs: identifier or list of identifiers of rotating 2d objects

    :param float angle: degree of rotation. Positive angle corresponds to
       counterclockwise rotation

    :param list-of-float pc: center of rotation

    :returns: None
    """
    icheck(0, UListOr1(ACont2D()))
    icheck(1, Float())
    icheck(2, Point2D())
    ob = objs if isinstance(objs, list) else [objs]
    c = com.objcom.RotateGeom({"names": ob, "angle": angle, "p0": pc})
    flow.exec_command(c)
Example #15
0
def export_grid_hmg(gid, fname, fmt='ascii', afields=[]):
    """Exports 2d grid to hybmesh native format.

      :param gid: single or list of grid identifiers

      :param str fname: output filename

      :param str fmt: output data format:

         * ``'ascii'`` - all fields will be saved as text fields,
         * ``'bin'`` - all fields will be saved in binary section,
         * ``'fbin'`` - only floating point fields will be saved
           in binary section.

      :param list-of-str afields: additional data which should be placed
          to output file.

      :returns: None

      To save additional data into grid file
      :ref:`user defined fields <udef-fields>`
      place any of these strings into **afields** list:

      * ``'cell-vertices'`` -- cell vertex connectivity. All vertices will
        be written in counterclockwise direction;
      * ``'cell-edges'`` -- cell edge connectivity. All edges will be written
        in counterclockwise direction.

      See :ref:`grid2d-file` for format description.

    """
    if fmt == "binary":
        fmt = "bin"
    if fmt == "fbinary":
        fmt = "fbin"
    icheck(0, UListOr1(Grid2D()))
    icheck(1, String())
    icheck(2, OneOf('ascii', 'bin', 'fbin'))
    icheck(3, UList(OneOf('cell-vertices', 'cell-edges')))

    names = gid if isinstance(gid, list) else [gid]
    grids = map(flow.receiver.get_grid2, names)
    cb = flow.interface.ask_for_callback()
    native_export.grid2_tofile(fname, grids, names, fmt, afields, cb)
Example #16
0
def reflect_geom(objs, pnt1, pnt2):
    """ Makes a reflection of 2d geometry objects over a  given line

    :param objs: identifier or list of identifiers of 2d objects to reflect

    :param list-of-float pnt1:

    :param list-of-float pnt2: points in [x, y] format which define a line
        to reflect over

    :returns: None
    """
    icheck(0, UListOr1(ACont2D()))
    icheck(1, Point2D())
    icheck(2, Point2D(noteq=[pnt1]))

    ob = objs if isinstance(objs, list) else [objs]
    c = com.objcom.ReflectGeom({"names": ob, "p1": pnt1, "p2": pnt2})
    flow.exec_command(c)
Example #17
0
def export3d_grid_tecplot(gid, fname):
    """Exports 3D grid to tecplot ascii format.

    :param gid: 3D grid file identifier or list of identifiers

    :param str grid: filename for output

    A grid zone and zones for each boundary surface defined by boundary type
    will be created in the output file.

    All 3D cells will be saved as FEPOLYHEDRON elements.
    """
    icheck(0, UListOr1(Grid3D()))
    icheck(1, String())

    cb = flow.interface.ask_for_callback()
    grid = _grid3_from_id(gid)
    bt = flow.receiver.get_zone_types()
    tecplot_export.grid3(fname, grid, bt, cb)
Example #18
0
def export_grid_tecplot(gid, fname):
    """Exports grid to tecplot ascii format.

    :param gid: grid identifier or list of identifiers

    :param fname: output filename

    :returns: None

    All cells will be saved as FEPolygon elements.
    Boundary segments with same boundary type will be converted
    to separate zones.
    """
    icheck(0, UListOr1(Grid2D()))
    icheck(1, String())

    cb = flow.interface.ask_for_callback()
    grid = _grid2_from_id(gid)
    bt = flow.receiver.get_zone_types()
    tecplot_export.grid2(fname, grid, bt, cb)
Example #19
0
def export_contour_tecplot(cid, fname):
    """Exports contour to tecplot ascii format.

    :param cid: contour identifier or list of identifiers,

    :param str fname: output filename.

    :returns: None

    All contour segments will be saved to a zone called "Contour".
    Additional zones will be created for all segments with same
    boundary type.
    """
    icheck(0, UListOr1(ACont2D()))
    icheck(1, String())

    cb = flow.interface.ask_for_callback()
    cont = _cont2_from_id(cid)
    bt = flow.receiver.get_zone_types()
    tecplot_export.cont2(fname, cont, bt, cb)
Example #20
0
def export3d_grid_gmsh(gid, fname):
    """Exports 3D grid to gmsh ascii format.

    :param gid: grid identifier or list of identifiers

    :param str fname: output filename.

    Only grids with tetrahedral/hexahedral/prism/pyramid cells
    could be exported.

    Boundary edges will be exported as Elements of triangle/quadrangle type.
    All boundary types which present in grid will be exported as
    Physical Groups with an id identical to boundary index and
    respective Physical Name.
    """
    icheck(0, UListOr1(Grid3D()))
    icheck(1, String())
    cb = flow.interface.ask_for_callback()
    grid = _grid3_from_id(gid)
    bt = flow.receiver.get_zone_types()
    gmsh_export.grid3(fname, grid, bt, cb)
Example #21
0
def scale_geom(objs, xpc=100., ypc=100., zpc=100., refp=[0.0, 0.0, 0.0]):
    """ Scales objects

    :param objs: identifier or list of identifiers of scaling objects

    :param float xpc:

    :param float ypc:

    :param float zpc: percentages of scaling in x, y and z directions

    :param list-of-float refp: reference point as ``[x, y, z]`` which stays
       fixed after transformation

    :returns: None

    if **objs** contains only 2d objects **zpc** is ignored and could be
    ommitted, **refp** could by given as ``[x, y]``.
    """
    icheck(0, UListOr1(AObject()))
    icheck(1, Float(grthan=0.))
    icheck(2, Float(grthan=0.))
    icheck(3, Float(grthan=0.))
    icheck(4, APoint())
    # for backward compatibility check if zpc was omitted
    if isinstance(zpc, list):
        refp = zpc
        zpc = 100.
    if len(refp) == 2:
        refp = [refp[0], refp[1], 0.]

    ob = objs if isinstance(objs, list) else [objs]
    c = com.objcom.ScaleGeom({
        "names": ob,
        "xpc": xpc,
        "ypc": ypc,
        "zpc": zpc,
        "p0": refp
    })
    flow.exec_command(c)
Example #22
0
def move_geom(objs, dx, dy, dz=0.):
    """ Moves a list of objects

    :param objs: identifier or list of identifiers of moving objects

    :param float dx:

    :param float dy:

    :param float dz: shifts in x, y and z direction. Z moves take place only
       for 3d objects

    :returns: None
    """
    icheck(0, UListOr1(AObject()))
    icheck(1, Float())
    icheck(2, Float())
    icheck(3, Float())

    ob = objs if isinstance(objs, list) else [objs]
    c = com.objcom.MoveGeom({"names": ob, "dx": dx, "dy": dy, "dz": dz})
    flow.exec_command(c)
Example #23
0
def export_grid_gmsh(gid, fname):
    """ Exports grid to gmsh ascii format.

    :param gid: single or list of grid identifiers

    :param fname: output filename

    :returns: None

    Only grids with triangle/quadrangle cells could be exported.

    Boundary edges will be exported as Elements of "Line" type.
    All boundary types which present in grid will be exported as
    Physical Groups with an id
    identical to boundary index and a respective Physical Name.
    """
    icheck(0, UListOr1(Grid2D()))
    icheck(1, String())

    cb = flow.interface.ask_for_callback()
    grid = _grid2_from_id(gid)
    bt = flow.receiver.get_zone_types()
    gmsh_export.grid2(fname, grid, bt, cb)