Spaces:
Sleeping
Sleeping
File size: 7,288 Bytes
66c9c8a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | from typing import Any
import warp as wp
from warp.fem.types import Sample, ElementIndex, Coords
from warp.fem import cache
from .element import Element
class Geometry:
"""
Interface class for discrete geometries
A geometry is composed of cells and sides. Sides may be boundary or interior (between cells).
"""
dimension: int = 0
def cell_count(self):
"""Number of cells in the geometry"""
raise NotImplementedError
def side_count(self):
"""Number of sides in the geometry"""
raise NotImplementedError
def boundary_side_count(self):
"""Number of boundary sides (sides with a single neighbour cell) in the geometry"""
raise NotImplementedError
def reference_cell(self) -> Element:
"""Prototypical element for a cell"""
raise NotImplementedError
def reference_side(self) -> Element:
"""Prototypical element for a side"""
raise NotImplementedError
@property
def name(self) -> str:
return self.__class__.__name__
def __str__(self) -> str:
return self.name
CellArg: wp.codegen.Struct
"""Structure containing arguments to be passed to device functions evaluating cell-related quantities"""
SideArg: wp.codegen.Struct
"""Structure containing arguments to be passed to device functions evaluating side-related quantities"""
SideIndexArg: wp.codegen.Struct
"""Structure containing arguments to be passed to device functions for indexing sides"""
@staticmethod
def cell_arg_value(self, device) -> "Geometry.CellArg":
"""Value of the arguments to be passed to cell-related device functions"""
raise NotImplementedError
@staticmethod
def cell_position(args: "Geometry.CellArg", s: "Sample"):
"""Device function returning the world position of a cell sample point"""
raise NotImplementedError
@staticmethod
def cell_deformation_gradient(args: "Geometry.CellArg", s: "Sample"):
"""Device function returning the transpose of the gradient of world position with respect to reference cell"""
raise NotImplementedError
@staticmethod
def cell_inverse_deformation_gradient(args: "Geometry.CellArg", cell_index: ElementIndex, coords: Coords):
"""Device function returning the matrix right-transforming a gradient w.r.t. cell space to a gradient w.r.t. world space
(i.e. the inverse deformation gradient)
"""
raise NotImplementedError
@staticmethod
def cell_lookup(args: "Geometry.CellArg", pos: Any):
"""Device function returning the cell sample point corresponding to a world position"""
raise NotImplementedError
@staticmethod
def cell_lookup(args: "Geometry.CellArg", pos: Any, guess: "Sample"):
"""Device function returning the cell sample point corresponding to a world position. Can use guess for faster lookup"""
raise NotImplementedError
@staticmethod
def cell_measure(args: "Geometry.CellArg", s: "Sample"):
"""Device function returning the measure determinant (e.g. volume, area) at a given point"""
raise NotImplementedError
@wp.func
def cell_measure_ratio(args: Any, s: Sample):
return 1.0
@staticmethod
def cell_normal(args: "Geometry.CellArg", s: "Sample"):
"""Device function returning the element normal at a sample point.
For elements with the same dimension as the embedding space, this will be zero."""
raise NotImplementedError
@staticmethod
def side_arg_value(self, device) -> "Geometry.SideArg":
"""Value of the arguments to be passed to side-related device functions"""
raise NotImplementedError
@staticmethod
def boundary_side_index(args: "Geometry.SideIndexArg", boundary_side_index: int):
"""Device function returning the side index corresponding to a boundary side"""
raise NotImplementedError
@staticmethod
def side_position(args: "Geometry.SideArg", s: "Sample"):
"""Device function returning the side position at a sample point"""
raise NotImplementedError
@staticmethod
def side_deformation_gradient(args: "Geometry.CellArg", s: "Sample"):
"""Device function returning the gradient of world position with respect to reference cell"""
raise NotImplementedError
@staticmethod
def side_inner_inverse_deformation_gradient(args: "Geometry.CellArg", side_index: ElementIndex, coords: Coords):
"""Device function returning the matrix right-transforming a gradient w.r.t. inner cell space to a gradient w.r.t. world space
(i.e. the inverse deformation gradient)
"""
raise NotImplementedError
@staticmethod
def side_outer_inverse_deformation_gradient(args: "Geometry.CellArg", side_index: ElementIndex, coords: Coords):
"""Device function returning the matrix right-transforming a gradient w.r.t. outer cell space to a gradient w.r.t. world space
(i.e. the inverse deformation gradient)
"""
raise NotImplementedError
@staticmethod
def side_measure(args: "Geometry.SideArg", s: "Sample"):
"""Device function returning the measure determinant (e.g. volume, area) at a given point"""
raise NotImplementedError
@staticmethod
def side_measure_ratio(args: "Geometry.SideArg", s: "Sample"):
"""Device function returning the ratio of the measure of a side to that of its neighbour cells"""
raise NotImplementedError
@staticmethod
def side_normal(args: "Geometry.SideArg", s: "Sample"):
"""Device function returning the element normal at a sample point"""
raise NotImplementedError
@staticmethod
def side_inner_cell_index(args: "Geometry.SideArg", side_index: ElementIndex):
"""Device function returning the inner cell index for a given side"""
raise NotImplementedError
@staticmethod
def side_outer_cell_index(args: "Geometry.SideArg", side_index: ElementIndex):
"""Device function returning the outer cell index for a given side"""
raise NotImplementedError
@staticmethod
def side_inner_cell_coords(args: "Geometry.SideArg", side_index: ElementIndex, side_coords: Coords):
"""Device function returning the coordinates of a point on a side in the inner cell"""
raise NotImplementedError
@staticmethod
def side_outer_cell_coords(args: "Geometry.SideArg", side_index: ElementIndex, side_coords: Coords):
"""Device function returning the coordinates of a point on a side in the outer cell"""
raise NotImplementedError
@staticmethod
def side_from_cell_coords(
args: "Geometry.SideArg",
side_index: ElementIndex,
element_index: ElementIndex,
element_coords: Coords,
):
"""Device function converting coordinates on a cell to coordinates on a side, or ``OUTSIDE``"""
raise NotImplementedError
@staticmethod
def side_to_cell_arg(side_arg: "Geometry.SideArg"):
"""Device function converting a side-related argument value to a cell-related argument value, for promoting trace samples to the full space"""
raise NotImplementedError
|