Gridap.Geometry

DiscreteModels

In Gridap, a DiscreteModel is the main object representing a discretized domain, where the finite element problem is defined adn solved. It has three main components:

  • A GridTopology, which defines the topology of the mesh. That is the polytopes that make up the mesh as well as their connectivity. This object also provides the connectivity between all d-dimensional entities of the mesh, such as vertices, edges, faces, and cells.
  • A Grid, which defines the geometric properties of the mesh. That is, the coordinates of the vertices and the geometric map between the reference space of each polytope and the physical space.
  • A FaceLabeling, which classifies all the d-dimensional entities of the mesh into (non-overlapping) physical entities. These entities are then associated one or multiple tags which can be used to impose boundary conditions or define physical regions on the mesh.

To get a deeper understanding of these three components, we encourage the reader to check the low-level tutorial on geometry. The API for each of these components is documented in the following sections.

GridTopology API

Gridap.Geometry.GridTopologyType
abstract type GridTopology{Dc,Dp}

Abstract type representing the topological information associated with a grid.

The GridTopology interface is defined by overloading the methods:

The GridTopology interface has the following traits

and tested with this function:

source
Gridap.Geometry.OrientationStyleMethod
OrientationStyle(::Type{<:GridTopology})
OrientationStyle(::GridTopology)

Oriented() if has oriented faces, NonOriented() otherwise (default).

source
Gridap.Geometry.get_cell_permutationsMethod
get_cell_permutations(top::GridTopology)
get_cell_permutations(top::GridTopology,d::Integer)

Returns an cell-wise array of permutations. For each cell, the entry contains the permutations of the local d-faces of the cell w.r.t the global d-faces of the mesh.

If no target dimension is specified, all dimensions are returned.

source
Gridap.Geometry.get_isboundary_faceMethod
get_isboundary_face(g::GridTopology)
get_isboundary_face(g::GridTopology,d::Integer)

Returns a vector of booleans indicating if the face is a boundary face. Boundary faces are defined in the following way:

  • If d = D-1, i.e facets, a boundary facet is a facet that is adjacent to only one cell.
  • Otherwise, a face is a boundary face if it belongs to a boundary facet.

If no target dimension is specified, all dimensions are returned.

source
Gridap.Geometry.restrictMethod
restrict(topo::GridTopology, cell_to_parent_cell::AbstractVector{<:Integer})
restrict(topo::GridTopology, parent_cell_to_mask::AbstractVector{Bool})
source

Grid API

Gridap.Geometry.get_cell_reffeMethod
get_cell_reffe(trian::Grid) -> Vector{<:LagrangianRefFE}

It is not desirable to iterate over the resulting array for large number of cells if the underlying reference FEs are of different Julia type.

source

FaceLabeling API

Gridap.Geometry.FaceLabelingType
struct FaceLabeling <: GridapType
  d_to_dface_to_entity::Vector{Vector{Int32}}
  tag_to_entities::Vector{Vector{Int32}}
  tag_to_name::Vector{String}
end
source
Gridap.Geometry.FaceLabelingMethod
FaceLabeling(d_to_num_dfaces::Vector{Int})
FaceLabeling(topo::GridTopology)
FaceLabeling(topo::GridTopology,cell_to_tag::Vector{<:Integer},tag_to_name::Vector{String})
source
Gridap.Geometry.add_tag_from_tag_filter!Method
add_tag_from_tag_filter!(lab::FaceLabeling, name::String, filter::Function)

Adds a new tag name, by including all entities selected by a filter function. The filter function must have signature

filter(entity_tags::Vector{Int}) -> Bool

where entity_tags are the tags of a particular geometrical entity.

source
Gridap.Geometry.add_tag_from_tags!Method
add_tag_from_tags!(lab::FaceLabeling, name::String, tags::Vector{Int})
add_tag_from_tags!(lab::FaceLabeling, name::String, tags::Vector{String})
add_tag_from_tags!(lab::FaceLabeling, name::String, tag::Int)
add_tag_from_tags!(lab::FaceLabeling, name::String, tag::String)

Adds a new tag name, given by the union of the tags tags.

source
Gridap.Geometry.add_tag_from_tags_complementary!Method
add_tag_from_tags_complementary!(lab::FaceLabeling, name::String, tags::Vector{Int})
add_tag_from_tags_complementary!(lab::FaceLabeling, name::String, tags::Vector{String})
add_tag_from_tags_complementary!(lab::FaceLabeling, name::String, tag::Int)
add_tag_from_tags_complementary!(lab::FaceLabeling, name::String, tag::String)

Adds a new tag name, given by the complementary of the tags tags.

source
Gridap.Geometry.add_tag_from_tags_intersection!Method
add_tag_from_tags_intersection!(labels::FaceLabeling, name::String, tags::Vector{Int})
add_tag_from_tags_intersection!(labels::FaceLabeling, name::String, tags::Vector{String})

Adds a new tag name, given by the intersection of the tags tags.

source
Gridap.Geometry.add_tag_from_tags_setdiff!Method
add_tag_from_tags_setdiff!(lab::FaceLabeling, name::String, tags_include::Vector{Int}, tags_exclude::Vector{Int})
add_tag_from_tags_setdiff!(lab::FaceLabeling, name::String, tags_include::Vector{String}, tags_exclude::Vector{String})

Adds a new tag name, given by the set difference between tags_include and tags_exclude.

source
Gridap.Geometry.face_labeling_from_cell_tagsMethod
face_labeling_from_cell_tags(topo::GridTopology,cell_to_tag::Vector{<:Integer},tag_to_name::Vector{String})

Creates a FaceLabeling object from a GridTopology and a vector containing a tag for each cell.

You can use this function to add custom cell-defined tags to a pre-existing FaceLabeling, by calling merge! on the two FaceLabeling objects, i.e

  labels = FaceLabeling(topo)
  additional_labels = face_labeling_from_cell_tags(topo,cell_to_tag,tag_to_name)
  merge!(labels,additional_labels)
source
Gridap.Geometry.face_labeling_from_vertex_filterMethod
face_labeling_from_vertex_filter(topo::GridTopology, name::String, filter::Function)

Creates a FaceLabeling object from a GridTopology and a coordinate-based filter function. The filter function takes in vertex coordinates and returns a boolean values. A geometrical entity is tagged if all its vertices pass the filter.

You can use this function to add custom vertex-defined tags to a pre-existing FaceLabeling, by calling merge! on the two FaceLabeling objects, i.e

  labels = FaceLabeling(topo)
  additional_labels = face_labeling_from_vertex_filter(topo,name,filter)
  merge!(labels,additional_labels)
source
Gridap.Geometry.get_face_maskMethod
get_face_mask(labeling::FaceLabeling,tags::Vector{Int},d::Integer)
get_face_mask(labeling::FaceLabeling,tags::Vector{String},d::Integer)
get_face_mask(labeling::FaceLabeling,tag::Int,d::Integer)
get_face_mask(labeling::FaceLabeling,tag::String,d::Integer)
source
Gridap.Geometry.get_face_tagMethod
get_face_tag(labeling::FaceLabeling,tags::Vector{Int},d::Integer)
get_face_tag(labeling::FaceLabeling,tags::Vector{String},d::Integer)
get_face_tag(labeling::FaceLabeling,tag::Int,d::Integer)
get_face_tag(labeling::FaceLabeling,tag::String,d::Integer)
get_face_tag(labeling::FaceLabeling,d::Integer)

The first of the given tags appearing in the face is taken. If there is no tag on a face, this face will have a value equal to UNSET. If not tag or tags are provided, all the tags in the model are considered

source
Gridap.Geometry.get_face_tag_indexMethod
get_face_tag_index(labeling::FaceLabeling,tags::Vector{Int},d::Integer)
get_face_tag_index(labeling::FaceLabeling,tags::Vector{String},d::Integer)
get_face_tag_index(labeling::FaceLabeling,tag::Int,d::Integer)
get_face_tag_index(labeling::FaceLabeling,tag::String,d::Integer)

Like get_face_tag by provides the index into the array tags instead of the tag stored in tags.

source

DiscreteModel API

Gridap.Geometry.DiscreteModelType
abstract type DiscreteModel{Dc,Dp} <: Grid

Abstract type holding information about a physical grid, the underlying grid topology, and a labeling of the grid faces. This is the information that typically provides a mesh generator, and it is what one needs to perform a simulation.

The DiscreteModel interface is defined by overloading the methods:

The interface is tested with this function:

source

Types of models

UnstructuredDiscreteModels

These are the main types of models used for unstructured meshes. They have their own type of topology and grid.

Gridap.Geometry.UnstructuredDiscreteModelType
struct UnstructuredDiscreteModel{Dc,Dp,Tp,B} <: DiscreteModel{Dc,Dp}
  grid::UnstructuredGrid{Dc,Dp,Tp,B}
  grid_topology::UnstructuredGridTopology{Dc,Dp,Tp,B}
  face_labeling::FaceLabeling
end
source
Gridap.Geometry.UnstructuredGridType
struct UnstructuredGrid{Dc,Dp,Tp,Ti,O} <: Grid{Dc,Dp}
  node_coordinates::Vector{Point{Dp,Tp}}
  cell_node_ids::Table{Ti,Int32}
  reffes::Vector{<:LagrangianRefFE{Dc}}
  cell_types::Vector{Int8}
end
source
Gridap.Geometry.UnstructuredGridMethod
function UnstructuredGrid(
  node_coordinates::Vector{Point{Dp,Tp}},
  cell_node_ids::Table{Ti},
  reffes::Vector{<:LagrangianRefFE{Dc}},
  cell_types::Vector,
  orientation_style::OrientationStyle=NonOriented()) where {Dc,Dp,Tp,Ti}
end

Low-level inner constructor.

source
Gridap.Geometry.UnstructuredGridTopologyType
UnstructuredGridTopology(
  vertex_coordinates::Vector{<:Point},
  cell_vertices::Table,
  cell_type::Vector{<:Integer},
  polytopes::Vector{<:Polytope},
  orientation_style::OrientationStyle=NonOriented())
source
Gridap.Geometry.UnstructuredGridTopologyType
UnstructuredGridTopology(
  vertex_coordinates::Vector{<:Point},
  d_to_dface_vertices::Vector{<:Table},
  cell_type::Vector{<:Integer},
  polytopes::Vector{<:Polytope},
  orientation_style::OrientationStyle=NonOriented())
source

CartesianDiscreteModels

Cartesian models are specific structures to represent cartesian domains, possibly mapped by a prescribed function. They offer optimizations with respect to the unstructured models and are quite lighweight memory-wise. They implement their own type of grid and can be converted to unstructured models if needed.

Gridap.Geometry.CartesianDiscreteModelMethod

CartesianDiscreteModel(desc::CartesianDescriptor{D,T,F}, cmin::CartesianIndex, cmax::CartesianIndex)

Builds a CartesianDiscreteModel object which represents a subgrid of a (larger) grid represented by desc. This subgrid is described by its D-dimensional minimum (cmin) and maximum (cmax) CartesianIndex identifiers.

source
Gridap.Geometry._find_ncube_face_neighbor_deltasMethod

findncubefaceneighbor_deltas(p::ExtrusionPolytope{D}) -> Vector{CartesianIndex}

Given an n-cube type ExtrusionPolytope{D}, returns V=Vector{CartesianIndex} with as many entries as the number of faces in the boundary of the Polytope. For an entry facelid in this vector, V[facelid] returns what has to be added to the CartesianIndex of a cell in order to obtain the CartesianIndex of the cell neighbour of K across the face F with local ID face_lid.

source
Gridap.Geometry.CartesianDescriptorType
struct CartesianDescriptor{D,T,F<:Function}
  origin::Point{D,T}
  sizes::NTuple{D,T}
  partition::NTuple{D,Int}
  map::F
end

Struct that stores the data defining a Cartesian grid.

source
Gridap.Geometry.CartesianDescriptorMethod
CartesianDescriptor(
  domain,
  partition;
  map::Function=identity,
  isperiodic::NTuple{D,Bool}=tfill(false,Val{D}))

domain and partition are 1D indexable collections of arbitrary type.

source
Gridap.Geometry.CartesianDescriptorMethod
CartesianDescriptor(
  origin::Point{D},
  sizes::NTuple{D},
  partition;
  map::Function=identity,
  isperiodic::NTuple{D,Bool}=tfill(false,Val{D})) where D

partition is a 1D indexable collection of arbitrary type.

source
Gridap.Geometry.CartesianDescriptorMethod
CartesianDescriptor(
  pmin::Point{D},
  pmax::Point{D},
  partition;
  map::Function=identity,
  isperiodic::NTuple{D,Bool}=tfill(false,Val{D})) where D

partition is a 1D indexable collection of arbitrary type.

source

PolytopalDiscreteModels

Polytopal models are used to represent meshes made of arbitrarily shaped polytopes. They are directly build on the physical domain and therefore do require a geometric map. They can only be used with polytopal methods such as DG, HDG or HHO. More expensive than regular unstructured models, but also more flexible. They implement their own type of grid and topology.

Gridap.Geometry.PolytopalDiscreteModelType
struct PolytopalDiscreteModel{Dc,Dp,Tp,Tn} <: DiscreteModel{Dc,Dp}
  grid::PolytopalGrid{Dc,Dp,Tp,Tn}
  grid_topology::PolytopalGridTopology{Dc,Dp,Tp}
  labels::FaceLabeling
end

Discrete model for polytopal grids.

Constructors:

PolytopalDiscreteModel(model::DiscreteModel)
PolytopalDiscreteModel(grid::PolytopalGrid,grid_topology::PolytopalGridTopology,labels::FaceLabeling)
source
Gridap.Geometry.PolytopalGridType
struct PolytopalGrid{Dc,Dp,Tp,Tn} <: Grid{Dc,Dp}
  node_coordinates::Vector{Point{Dp,Tp}}
  cell_node_ids::Table{Int32,Vector{Int32},Vector{Int32}}
  polytopes::Vector{GeneralPolytope{Dc,Dp,Tp,Nothing}}
  facet_normal::Tn
end

Grid for polytopal meshes.

Constructors:

PolytopalGrid(grid::Grid)
PolytopalGrid(topo::PolytopalGridTopology)
PolytopalGrid(node_coordinates,cell_node_ids,polytopes[,facet_normal=nothing])
source
Gridap.Geometry.PolytopalGridTopologyType
struct PolytopalGridTopology{Dc,Dp,Tp} <: GridTopology{Dc,Dp}
  vertex_coordinates::Vector{Point{Dp,Tp}}
  n_m_to_nface_to_mfaces::Matrix{Table{Int32,Vector{Int32},Vector{Int32}}}
  polytopes::Vector{GeneralPolytope{Dc,Dp,Tp,Nothing}}
end

Grid topology for polytopal grids.

Constructors:

PolytopalGridTopology(topo::UnstructuredGridTopology)
PolytopalGridTopology(vertex_coordinates,cell_vertices,polytopes)
source
Gridap.Geometry.voronoiMethod
voronoi(model::DiscreteModel) -> PolytopalDiscreteModel
voronoi(topo::GridTopology) -> PolytopalGridTopology

Given a mesh, computes it's associated Voronoi mesh. NOTE: Only working in 2D.

source

Other models

Gridap.Geometry.restrictMethod
restrict(model::DiscreteModel, cell_to_parent_cell::AbstractVector{<:Integer})
restrict(model::DiscreteModel, parent_cell_to_mask::AbstractArray{Bool})
source
Gridap.Geometry.GridPortionType
struct GridPortion{Dc,Dp,G} <: Grid{Dc,Dp}
  parent::G
  cell_to_parent_cell::Vector{Int32}
  node_to_parent_node::Vector{Int32}
end
source
Gridap.Geometry.restrictMethod
restrict(grid::Grid, cell_to_parent_cell::AbstractVector{<:Integer})
restrict(grid::Grid, parent_cell_to_mask::AbstractArray{Bool})
source

Triangulations

Given a model, which holds information for all dimensions and on the whole domain, we can take d-dimensional slices of it (or part of it) where we will define our finite element spaces and/or integrate our weakforms. These slices are called Triangulations.

Body-Fitted triangulations

The most basic type of triangulation is the BodyFittedTriangulation. It represents a d-dimensional set of faces attached to d-dimensional faces of the model. In particular, it is the type used to represent bulk triangulations (which contain a subset of the cells of the model).

Gridap.Geometry.best_targetMethod
best_target(trian1::Triangulation,trian2::Triangulation)

If possible, returns a Triangulation to which CellDatum objects can be transferred from trian1 and trian2. Can be trian1, trian2 or a new Triangulation.

source

Boundary and Skeleton triangulations

To perform integration of bulk variables on a set of faces (for instance the integration of Neumann terms), we somehow need to link these faces to one of their neighboring cells (otherwise the bulk variables are not uniquely valued on the faces). This is done through the BoundaryTriangulation object. It is generally used for integrals on the physical boundary (where faces have a single neighboring cell), but offer quite a lot more flexibility. Conceptually, a BoundaryTriangulation is given by a BodyFittedTriangulation of faces and a FaceToCellGlue that links each face to the selected neighboring cell. To perform integration on interior faces, which have two neighboring cells, we can use the SkeletonTriangulation object. Each SkeletonTriangulation is a wrapper around two BoundaryTriangulations, one for each side of the face. It provides straighforward ways to performs jumps and means over the interior faces.

Gridap.Geometry.BoundaryTriangulationMethod
BoundaryTriangulation(model::DiscreteModel,labeling::FaceLabeling;tags::Vector{Int})
BoundaryTriangulation(model::DiscreteModel,labeling::FaceLabeling;tags::Vector{String})
BoundaryTriangulation(model::DiscreteModel,labeling::FaceLabeling;tag::Int)
BoundaryTriangulation(model::DiscreteModel,labeling::FaceLabeling;tag::String)
source
Gridap.Geometry.BoundaryTriangulationMethod
BoundaryTriangulation(model::DiscreteModel,tags::Vector{Int})
BoundaryTriangulation(model::DiscreteModel,tags::Vector{String})
BoundaryTriangulation(model::DiscreteModel,tag::Int)
BoundaryTriangulation(model::DiscreteModel,tag::String)
source

Patch triangulations

We provide an API to integrate and solve problems on patches of cells. This API revolves around two objects: The PatchTopology defines the topology of the patches, and holds information on all the d-dimensional entities belonging to each patch. One can then take d-dimensional slices of these patches using PatchTriangulations.

Gridap.Geometry.PatchTopologyType
struct PatchTopology{Dc,Dp} <: GridapType
  topo :: GridTopology{Dc,Dp}
  d_to_patch_to_dfaces :: Vector{Table{Int32,Vector{Int32},Vector{Int32}}}
end

Fields:

  • topo: Underlying grid topology
  • d_to_patch_to_dfaces: For each dimension d, a table mapping each patch to it's d-faces.
source
Gridap.Geometry.PatchTriangulationType
struct PatchTriangulation{Dc,Dp} <: Triangulation{Dc,Dp}
  trian :: Triangulation{Dc,Dp}
  ptopo :: PatchTopology
  glue  :: PatchGlue{Dc}
end

Wrapper around a Triangulation, for patch-based assembly.

Fields:

  • trian: Underlying triangulation. In general, this can be a non-injective triangulation.
  • ptopo: Patch topology, to which the triangulation faces can be mapped
  • glue: Patch glue, mapping triangulation faces to the patches
source
Gridap.Geometry.PatchTriangulationMethod
PatchTriangulation(model::DiscreteModel,ptopo::PatchTopology;tags=nothing)
PatchTriangulation(::Type{ReferenceFE{D}},model::DiscreteModel,ptopo::PatchTopology;tags=nothing)
source

Other triangulations