geom

package
v0.0.0-...-b5d641a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 4 Imported by: 12

Documentation

Overview

package geom provides routines and types for dealing with an array of geometry-related tasks.

package geom contains routines for computing geometrical quantities in a box with periodic boundary conditions.

Index

Constants

View Source
const (

	// TetraDirCount is the number of orientations that a tetrahedron can have
	// within a cube. Should be iterated over when calling TetraIdxs.Init().
	TetraDirCount      = 6
	TetraCenteredCount = 8
)

Variables

View Source
var DerivOptionsDefault = &DerivOptions{false, None, 4}
View Source
var (
	// Yeah, this one was super fun to figure out.
	Dirs = [TetraDirCount][2][3]int64{
		{{1, 0, 0}, {1, 1, 0}},
		{{1, 0, 0}, {1, 0, 1}},
		{{0, 1, 0}, {1, 1, 0}},
		{{0, 0, 1}, {1, 0, 1}},
		{{0, 1, 0}, {0, 1, 1}},
		{{0, 0, 1}, {0, 1, 1}},
	}
)

Functions

func DistributeUnit

func DistributeUnit(vecBuf []Vec)

DistributeUnit distributes a set of points in a unit cube across a unit tetrahedron and stores the results to vecBuf.

Types

type CellBounds

type CellBounds struct {
	Origin, Width [3]int
}

CellBounds represents a bounding box aligned to grid cells.

func (*CellBounds) Intersect

func (cb1 *CellBounds) Intersect(cb2 *CellBounds, width int) bool

Intersect retursn true if the two bounding boxes overlap and false otherwise.

func (*CellBounds) IntersectUnbounded

func (cb1 *CellBounds) IntersectUnbounded(cb2 *CellBounds) bool

func (*CellBounds) ScaleVecsDomain

func (vcb *CellBounds) ScaleVecsDomain(
	cb *CellBounds, vs []Vec, cells int, boxWidth float64,
)

func (*CellBounds) ScaleVecsSegment

func (vcb *CellBounds) ScaleVecsSegment(
	vs []Vec, cells int, boxWidth float64,
)

type DerivOp

type DerivOp int
const (
	Add DerivOp = iota
	Subtract
	None
)

type DerivOptions

type DerivOptions struct {
	Periodic bool
	Op       DerivOp
	Order    int
}

type Grid

type Grid struct {
	CellBounds
	Length, Area, Volume int
	// contains filtered or unexported fields
}

Grid provides an interface for reasoning over a 1D slice as if it were a 3D grid.

func NewGrid

func NewGrid(origin, width [3]int) *Grid

NewGrid returns a new Grid instance.

func (*Grid) BoundsCheck

func (g *Grid) BoundsCheck(x, y, z int) bool

BoundsCheck returns true if the given coordinates are within the Grid and false otherwise.

func (*Grid) Coords

func (g *Grid) Coords(idx int) (x, y, z int)

Coords returns the x, y, z coordinates of a point from its grid index.

func (*Grid) Idx

func (g *Grid) Idx(x, y, z int) int

Idx returns the grid index corresponding to a set of coordinates.

func (*Grid) IdxCheck

func (g *Grid) IdxCheck(x, y, z int) (idx int, ok bool)

IdxCheck returns an index and true if the given coordinate are valid and false otherwise.

func (*Grid) Init

func (g *Grid) Init(origin, width [3]int)

Init initializes a Grid instance.

type GridLocation

type GridLocation struct {
	Grid
	Cells    int
	BoxWidth float64
}

GridLocation is a Grid which also specifies a physical location within a periodic super-grid.

func NewGridLocation

func NewGridLocation(
	origin, width [3]int, boxWidth float64, cells int,
) *GridLocation

func (*GridLocation) Curl

func (g *GridLocation) Curl(
	vecs, out [3][]float32,
	op *DerivOptions,
)

func (*GridLocation) Deriv

func (g *GridLocation) Deriv(
	vals, out []float32, axis int,
	opt *DerivOptions,
)

func (*GridLocation) Divergence

func (g *GridLocation) Divergence(
	vecs [3][]float32, out []float32,
	op *DerivOptions,
)

func (*GridLocation) Gradient

func (g *GridLocation) Gradient(
	vals []float32, out [3][]float32,
	op *DerivOptions,
)

func (*GridLocation) Init

func (g *GridLocation) Init(
	origin, width [3]int, boxWidth float64, cells int,
)

type Tetra

type Tetra struct {
	Corners [4]Vec
	// contains filtered or unexported fields
}

Tetra is a tetrahedron with points inside a box with periodic boundary conditions.

NOTE: To speed up computations, Tetra contains a number of non-trivial private fields. If there is a need to store a large number of tetrahedra, it is advised to construct a slice of [4]Points instead and switch to Tetra instances only for calculations.

func NewTetra

func NewTetra(c0, c1, c2, c3 *Vec) *Tetra

NewTetra creates a new tetrahedron with corners at the specified positions within a periodic box of the given width.

func (*Tetra) Barycenter

func (t *Tetra) Barycenter() *Vec

Barycenter computes the barycenter of a tetrahedron.

func (*Tetra) CellBounds

func (t *Tetra) CellBounds(cellWidth float64) *CellBounds

CellBounds returns the smallest enclosing set of cell bounds around a tetrahedron.

func (*Tetra) CellBoundsAt

func (t *Tetra) CellBoundsAt(cellWidth float64, cb *CellBounds)

CellBoundsAt is the same as CellBounds, but is done in-place.

func (*Tetra) Contains

func (t *Tetra) Contains(v *Vec) bool

Contains returns true if a tetrahedron contains the given point and false otherwise.

func (*Tetra) Distribute

func (tet *Tetra) Distribute(xs, ys, zs []float64, vecBuf []Vec)

Distribute converts a sequences of points generated uniformly within a unit cube to be distributed uniformly within the base tetrahedron. The results are placed in vecBuf.

func (*Tetra) DistributeTetra

func (tet *Tetra) DistributeTetra(pts []Vec, out []Vec)

DistributeTetra takes a set of points distributed across a unit tetrahedron and distributes them across the given tetrahedron through barycentric coordinate transformations.

func (*Tetra) DistributeTetra64

func (tet *Tetra) DistributeTetra64(pts []Vec, out [][3]float64)

I hate that this function exists. Go, you make my life so hard sometimes.

func (*Tetra) Init

func (t *Tetra) Init(c0, c1, c2, c3 *Vec) *Tetra

Init initializes a tetrahedron to correspond to the given corners.

func (*Tetra) RandomSample

func (tet *Tetra) RandomSample(gen *rand.Generator, randBuf []float64, vecBuf []Vec)

RandomSample fills a buffer of vecotrs with points generated uniformly at random from within a tetrahedron. The length of randBuf must be three times the length of vecBuf.

func (*Tetra) Volume

func (t *Tetra) Volume() float64

Volume computes the volume of a tetrahedron.

type TetraIdxs

type TetraIdxs [4]int64

TetraIdxs are the indices of particles whichare the corners of a tetrahedron.

func NewTetraIdxs

func NewTetraIdxs(idx, countWidth, skip int64, dir int) *TetraIdxs

NewTetraIdxs creates a collection of indices corresponding to a tetrhedron with an anchor point at the given index. The parameter dir selects a particular tetrahedron configuration and must line in the range [0, TetraDirCount).

func (*TetraIdxs) Init

func (idxs *TetraIdxs) Init(idx, countWidth, skip int64, dir int) *TetraIdxs

Init initializes a TetraIdxs collection using the same rules as NewTetraIdxs.

func (*TetraIdxs) InitCartesian

func (idxs *TetraIdxs) InitCartesian(
	x, y, z, countWidth int64, dir int,
) *TetraIdxs

InitCartesian works the same as Init, but doesn't take periodic boundaries into account for some reason.

func (*TetraIdxs) InitCentered

func (idxs *TetraIdxs) InitCentered(
	idx, countWidth, skip int64, dir int,
) (ti *TetraIdxs, ok bool)

I have no idea what this function does.

type Vec

type Vec [3]float32

Vec represents a 3D vector. All vector methods which return vectors will also contain *Self() and *At() variants which compute the operation in-place and at the specified location, respectively. All output vectors are valid unless they overlap with an input vector but are not equal to that vector.

func (*Vec) Add

func (v1 *Vec) Add(v2 *Vec) *Vec

Add adds two vectors together.

func (*Vec) AddAt

func (v1 *Vec) AddAt(v2, out *Vec) *Vec

func (*Vec) AddSelf

func (v1 *Vec) AddSelf(v2 *Vec) *Vec

func (*Vec) Cross

func (v1 *Vec) Cross(v2 *Vec) *Vec

Cross computes the cross product of two vectors.

func (*Vec) CrossAt

func (v2 *Vec) CrossAt(v1, out *Vec) *Vec

func (*Vec) CrossSelf

func (v1 *Vec) CrossSelf(v2 *Vec) *Vec

func (*Vec) Dot

func (v1 *Vec) Dot(v2 *Vec) float64

Dot computes the dot product of two vectors.

func (*Vec) Mod

func (v *Vec) Mod(width float64) *Vec

Mod calculates the value of a vector within the fundamental domain of a box with period boundary condiitions of the given width.

func (*Vec) ModAt

func (v *Vec) ModAt(width float64, out *Vec) *Vec

func (*Vec) ModSelf

func (v *Vec) ModSelf(width float64) *Vec

func (*Vec) Norm

func (v *Vec) Norm() float64

Norm computes the norm of a vector.

func (*Vec) Scale

func (v *Vec) Scale(k float64) *Vec

Scale multiplies all components of a vector by a constant.

func (*Vec) ScaleAt

func (v *Vec) ScaleAt(k float64, out *Vec) *Vec

func (*Vec) ScaleSelf

func (v *Vec) ScaleSelf(k float64) *Vec

func (*Vec) Sub

func (v1 *Vec) Sub(v2 *Vec, width float64) *Vec

Sub caluculates the dispacement vector between two vectors, assuming a box of the given width with periodic boundary conditions.

func (*Vec) SubAt

func (v1 *Vec) SubAt(v2 *Vec, width float64, out *Vec) *Vec

func (*Vec) SubSelf

func (v1 *Vec) SubSelf(v2 *Vec, width float64) *Vec

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL