# Geometry

## Contents

# Geometry

Engineering geometries must facilitate:

- accurate representation (to resolve physics)
- element discretization and parallel computation
- region discretization for conditions & couplings
- spatial transformations and instancing

## Introduction

### Structured vs Unstructured

End-users usually interact with unstructured mesh types, but it can be useful to understand:

- Unstructured geometries include traditional declarative meshes: underlying nodal positions and corresponding topology are stored and retrieved as an element.
- Structured geometries include procedural grids and trees: underlying nodal positions and topology are computed upon each element query. Structured geometries are often used for SDF and other background geometry computations.

### Implicit Shape

It can be desirable to express a shape without a discrete topology using “level sets”. Often used for 2D and 3D shapes, fields map coordinates x to a scalar value ϕ(x).

- The implicit boundary is defined where the field cross some constant value C. By default, C=0. Usually the field is monotonic as a function of distance-to-boundary.

#### Signed Distance Field (SDF)

When an implicit shape ϕ(x) has the property that the magnitude of the gradient throughout is equal to one \|∇(x)\|=1, then the implicit field is said to be a distance field.

- If the boundary is defined at C=0, the interior of the object has negative field values and the outside will have positive field values, meeting the criteria for a SDF.
- Generally, ϕ<C is interior and ϕ>C is exterior, while ϕ=C is on the boundary.

##### Analytic vs Sampled Approaches

- **Analytic**: It is possible to describe shapes using functions, combining primitive SDFs into complex implicits with effectively unlimited resolution. However, most implicit operators introduce gradient error into the shape field and therefore require special handling. While re-evaluating the implicit/operators is computationally expensive, implicit shape definition will be exposed to users in future releases.
- **Sampled**: Mesh generation and heavy spatial processing tasks rely on discrete SDF to achieve constant-time parallel sampling of SDF on background grids. A workhorse for spatially-aware physics and contacts, a typical SDF background grid may contain 1M to 1B nodes (at ~64 bytes per node). Starting from imported faces, exact distances are solved for the narrow-band shell; winding numbers are integrated at each node point to robustly determine the sign.

## Computable Topology

Solving physics in a finite computing machine (aka digital computer) requires that the shape be discretized (broken down) into small computable elements.

- Nodes are points in space-time, connected by elements to facilitate information flow. A numerical method then approximates the continuous PDE by transforming the problem into a discrete ODE.

### Elements

Underlying intrinsic attributes of each element:

- `type` (`NODE1`, `LINE2`, `TRI3`, `QUAD4`, `TET4`, `HEX8`, …)
- `id` (`0` is default, positive are for users)
- `indices` (of nodes defining vertices)

Several extrinsic functions exist, including:

- `center` (barycenter)
- `domain` (`XYZ` extrema)
- `distance` (to position)
- `contains` (position)
- `decompose` (to sub-elements)
- `quality` \[0:1\]
- `neighbors`

#### Nodes

Nodes are elements with `0D` topological dimensionality, defining data and position at that particular point. Supported nodes: `NODE1`

Specialized extrinsic functions:

- `volume` (scalar, based on median dual fragment)

#### Edges

Edges are elements with `1D` topological dimensionality, connecting two nodal points. Supported edges: `LINE2`, `DUAL2`

Specialized extrinsic functions:

- `length` (vector)
- `area` (interface vector, only for `DUAL2`)

#### Faces

Faces are elements with `2D` topological dimensionality, connecting three or more nodal points. Supported faces: `TR3`, `QUAD4`

Specialized extrinsic functions:

- `area` (normal vector)

#### Cells

Cells are elements with `3D` topological dimensionality, connecting four or more nodal points. Supported cells: `TET4`, `HEX8`

Specialized extrinsic functions:

- `volume` (scalar)

#### Median Duals

The mesh that you see and save is the primary mesh, described classically from nodes and elements. However, downstream numerics may utilize a different interpretation.

- FEM is formulated to utilize the primary mesh directly. Integration is performed at Gauss-Legendre quadrature points using analytic shape functions.
- FVM is formulated to interpret the primary mesh as its Voronoi inverse, yielding median-dual control volumes for highest flux integration accuracy.

### Regions of Interest

It is useful to assign regions IDs to a subset of elements for boundary conditions and/or coupling.

Intrinsic attributes of a region:

- dimensionality (0, 1, 2, 3)
- id (`0` is default, positive are assignable by users)
- name (useful identifier)

Elements and regions are complementary:

- each element has an integer `id`
- region `id` correspond to the elements with matching `id`

#### Groups

A group is a region of nodes (dimensionality=0).

- In the xcompute-client `interface.cfg`, group visibility is disabled by default, but can be enabled by setting `groups=true`.

#### Loops

A loop is a region of edges (dimensionality=1).

- In the xcompute-client `interface.cfg`, loop visibility is disabled by default, but can be enabled by setting `loops=true`.

#### Surfaces

A surface is a region of faces (dimensionality=2).

- In the xcompute-client `interface.cfg`, surface visibility is enabled by default.

#### Volumes

A volume is a region of cells (dimensionality=3).

- In the xcompute-client `interface.cfg`, volume visibility is enabled by default.
