gm

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2017 License: BSD-3-Clause Imports: 9 Imported by: 0

README

Gosl. gm. Geometry algorithms and structures

GoDoc

More information is available in the documentation of this package.

This package provides some functions to help with the solution of geometry problems. It also includes some routines loosely related with geometry.

Bezier curve

Source code: ../examples/gm_bezier01.go

B-spline curve and control net

Source code: ../examples/gm_bspline01.go

NURBS curve: quarter of Circle

Source code: ../examples/gm_nurbs01.go

NURBS curve: circle

Source code: ../examples/gm_nurbs02.go

Documentation

Overview

Package gm (geometry and meshes) implements auxiliary functions for handling geometry and mesh structures

Index

Constants

This section is empty.

Variables

View Source
var FactoryNurbs = facNurbsT{}

FactoryNurbs generates NURBS'

View Source
var FactoryTfinite = facTfinite{}

FactoryTfinite generates transfinite mappings

View Source
var (
	XDELZERO = 1e-10 // minimum distance between coordinates; i.e. xmax[i]-xmin[i] mininum
)

consts

Functions

func DistPointBoxN

func DistPointBoxN(p *PointN, b *BoxN) (dist float64)

DistPointBoxN returns the distance of a point to the box

NOTE: If point p lies outside box b, the distance to the nearest point on b is returned.
      If p is inside b or on its surface, zero is returned.

func DistPointLine

func DistPointLine(p, a, b *Point, tol float64, verbose bool) float64

DistPointLine computes the distance from p to line passing through a -> b

func DistPointPoint

func DistPointPoint(a, b *Point) float64

DistPointPoint computes the unsigned distance from a to b

func DistPointPointN

func DistPointPointN(p *PointN, q *PointN) (dist float64)

DistPointPointN returns the distance between two PointN

func DrawArrow2d

func DrawArrow2d(c, v la.Vector, normalize bool, sf float64, args *plt.A)

DrawArrow2d draws 2d arrow @ c with direction v

func DrawArrow2dM

func DrawArrow2dM(c la.Vector, vm *la.Matrix, col int, normalize bool, sf float64, args *plt.A)

DrawArrow2dM draws 2d arrow @ c with direction v (matrix version)

func DrawArrow3d

func DrawArrow3d(c, v la.Vector, normalize bool, sf float64, args *plt.A)

DrawArrow3d draws 3d arrow @ c with direction v

func DrawArrow3dM

func DrawArrow3dM(c la.Vector, vm *la.Matrix, col int, normalize bool, sf float64, args *plt.A)

DrawArrow3dM draws 3d arrow @ c with direction v (matrix version)

func GetVec2d

func GetVec2d(M *la.Matrix, col int, normalize bool) la.Vector

GetVec2d returns column of matrix as 2D vector

func GetVec3d

func GetVec3d(M *la.Matrix, col int, normalize bool) la.Vector

GetVec3d returns column of matrix as 3D vector

func IsPointIn

func IsPointIn(p *Point, cMin, cMax []float64, tol float64) bool

IsPointIn returns whether p is inside box with cMin and cMax

func IsPointInLine

func IsPointInLine(p, a, b *Point, zero, told, tolin float64) bool

IsPointInLine returns whether p is inside line passing through a and b

func PlotNurbs

func PlotNurbs(dirout, fnkey string, b *Nurbs, ndim, npts int, withIds, withCtrl bool, argsElems, argsCtrl, argsIds *plt.A, extra func())

PlotNurbs plots a NURBS

ndim -- 2 or 3 => to plot in a 2D or 3D space

func PlotNurbsBasis2d

func PlotNurbsBasis2d(dirout, fnkey string, b *Nurbs, la, lb int, withElems, withCtrl bool, argsElems, argsCtrl *plt.A, extra func(idxSubplot int))

PlotNurbsBasis2d plots basis functions la and lb

First row == CalcBasis
Second row == CalcBasisAndDerivs
Third row == RecursiveBasis

func PlotNurbsDerivs2d

func PlotNurbsDerivs2d(dirout, fnkey string, b *Nurbs, la, lb int, withElems, withCtrl bool, argsElems, argsCtrl *plt.A, extra func(idxSubplot int))

PlotNurbsDerivs2d plots derivatives of basis functions la and lb in 2D space

Left column == Analytical
Right column == Numerical

func PointsLims

func PointsLims(pp []*Point) (cmin, cmax []float64)

PointsLims returns the limits of a set of points

func VecDot

func VecDot(u, v []float64) float64

VecDot returns the dot product between two vectors

func VecNew

func VecNew(m float64, u []float64) []float64

VecNew returns a new vector scaled by m

func VecNewAdd

func VecNewAdd(α float64, u []float64, β float64, v []float64) []float64

VecNewAdd returns a new vector by adding two other vectors

w := α*u + β*v

func VecNorm

func VecNorm(u []float64) float64

VecNorm returns the length (Euclidean norm) of a vector

Types

type BezierQuad

type BezierQuad struct {

	// input
	Q [][]float64 // control points; can be set outside

	// auxiliary
	P []float64 // a point on curve
}

BezierQuad implements a quadratic Bezier curve

C(t) = (1-t)² Q0  +  2 t (1-t) Q1  +  t² Q2
     = t² A  +  2 t B  +  Q0
A = Q2 - 2 Q1 + Q0
B = Q1 - Q0

func (*BezierQuad) DistPoint

func (o *BezierQuad) DistPoint(X []float64, doplot bool) float64

DistPoint returns the distance from a point to this Bezier curve It finds the closest projection which is stored in P

func (*BezierQuad) GetControlCoords

func (o *BezierQuad) GetControlCoords() (X, Y, Z []float64)

GetControlCoords returns the coordinates of control points as 1D arrays (e.g. for plotting)

func (*BezierQuad) GetPoints

func (o *BezierQuad) GetPoints(T []float64) (X, Y, Z []float64)

GetPoints returns points along the curve for given parameter values

func (*BezierQuad) Point

func (o *BezierQuad) Point(C []float64, t float64)

Point returns the x-y-z coordinates of a point on Bezier curve

type Bin

type Bin struct {
	Index   int         // index of bin
	Entries []*BinEntry // entries
}

Bin defines one bin in Bins (holds entries for search)

func (Bin) String

func (o Bin) String() string

String returns the string representation of one Bin

type BinEntry

type BinEntry struct {
	ID    int         // object Id
	X     []float64   // entry coordinate (read only)
	Extra interface{} // any entity attached to this entry
}

BinEntry holds data of an entry to bin

type Bins

type Bins struct {
	Ndim int       // space dimension
	Xmin []float64 // [ndim] left/lower-most point
	Xmax []float64 // [ndim] right/upper-most point
	Xdel []float64 // [ndim] the lengths along each direction (whole box)
	Size []float64 // size of bins
	Npts []int     // [ndim] number of points along each direction; i.e. ndiv + 1
	All  []*Bin    // [nbins] all bins (there will be an extra "ghost" bin along each dimension)
	// contains filtered or unexported fields
}

Bins implements a set of bins holding entries and is used to fast search entries by given coordinates.

func (*Bins) Append

func (o *Bins) Append(x []float64, id int, extra interface{})

Append adds a new entry {x, id, something} into the Bins structure

func (Bins) CalcIndex

func (o Bins) CalcIndex(x []float64) int

CalcIndex calculates the bin index where the point x is returns -1 if out-of-range

func (*Bins) Clear

func (o *Bins) Clear()

Clear clears all bins

func (*Bins) Draw

func (o *Bins) Draw(withEntry, withGrid, withEntryTxt, withGridTxt bool, argsEntry, argsGrid, argsTxtEntry, argsTxtGrid *plt.A, selBins map[int]bool)

Draw draws bins; i.e. grid

func (Bins) FindAlongSegment

func (o Bins) FindAlongSegment(xi, xf []float64, tol float64) []int

FindAlongSegment gets the ids of entries that lie close to a segment

Note: the initial (xi) and final (xf) points on segment define a bounding box to filter points

func (Bins) FindBinByIndex

func (o Bins) FindBinByIndex(idx int) *Bin

FindBinByIndex finds or allocate new bin corresponding to index idx

func (Bins) FindClosest

func (o Bins) FindClosest(x []float64) (idClosest int, sqDistMin float64)

FindClosest returns the id of the entry whose coordinates are closest to x

idClosest -- the id of the closest entity. return -1 if out-of-range or not found
sqDistMin -- the minimum distance (squared) between x and the closest entity in the same bin

func (*Bins) FindClosestAndAppend

func (o *Bins) FindClosestAndAppend(nextID *int, x []float64, extra interface{}, radTol float64, diff func(idOld int, xNew []float64) bool) (id int, existent bool)

FindClosestAndAppend finds closest point and, if not found, append to bins with a new Id

Input:
  nextId -- is the Id of the next point. Will be incremented if x is a new point to be added.
  x      -- is the point to be added
  extra  -- extra information attached to point
  radTol -- is the tolerance for the radial distance (i.e. NOT squared) to decide
            whether a new point will be appended or not.
  diff   -- [optional] a function for further check that the new and an eventual existent
            points are really different, even after finding that they coincide (within tol)
Output:
  id       -- the id attached to x
  existent -- flag telling if x was found, based on given tolerance

func (*Bins) Init

func (o *Bins) Init(xmin, xmax []float64, ndiv []int)

Init initialise Bins structure

xmin -- [ndim] min/initial coordinates of the whole space (box/cube)
xmax -- [ndim] max/final coordinates of the whole space (box/cube)
ndiv -- [ndim] number of divisions for xmax-xmin

func (*Bins) Nactive

func (o *Bins) Nactive() (nactive int)

Nactive returns the number of active bins; i.e. non-nil bins

func (*Bins) Nentries

func (o *Bins) Nentries() (nentries int)

Nentries returns the total number of entries (in active bins)

func (Bins) String

func (o Bins) String() string

String returns the string representation of a set of Bins

func (*Bins) Summary

func (o *Bins) Summary() (l string)

Summary returns the summary of this Bins' data

type BoxN

type BoxN struct {
	// essential
	Lo *PointN // lower point
	Hi *PointN // higher point

	// auxiliary
	ID int // an auxiliary identification number
}

BoxN implements a box int he N-dimensional space

func NewBoxN

func NewBoxN(L ...float64) *BoxN

NewBoxN creates a new box with given limiting coordinates

L -- limits [4] or [6]: xmin,xmax, ymin,ymax, {zmin,zmax} optional

func (BoxN) Draw

func (o BoxN) Draw(withTxt bool, args, argsTxt *plt.A)

Draw draws box

func (*BoxN) GetMid

func (o *BoxN) GetMid() (mid []float64)

GetMid gets the centre coordinates of box

func (*BoxN) GetSize

func (o *BoxN) GetSize() (delta []float64)

GetSize returns the size of box (deltas)

func (BoxN) IsInside

func (o BoxN) IsInside(p *PointN) bool

IsInside tells whether a PointN is inside box or not

type Bspline

type Bspline struct {

	// essential
	T []float64 // array of knots: e.g: T = [t_0, t_1, ..., t_{m-1}]

	// optional
	Q [][]float64 // control points (has to call SetControl to change this)
	// contains filtered or unexported fields
}

Bspline holds B-spline data

Reference:
 [1] Piegl L and Tiller W (1995) The NURBS book, Springer, 646p

func NewBspline

func NewBspline(T []float64, p int) (o *Bspline)

NewBspline returns a new B-spline

func (*Bspline) CalcBasis

func (o *Bspline) CalcBasis(t float64)

CalcBasis computes all non-zero basis functions N[i] @ t Note: use GetBasis to get a particular basis function value

func (*Bspline) CalcBasisAndDerivs

func (o *Bspline) CalcBasisAndDerivs(t float64)

CalcBasisAndDerivs computes all non-zero basis functions N[i] and corresponding first order derivatives of basis functions w.r.t t => dR[i]dt @ t Note: use GetBasis to get a particular basis function value

use GetDeriv to get a particular derivative

func (*Bspline) Draw2d

func (o *Bspline) Draw2d(npts, option int, withCtrl bool, argsCurve, argsCtrl *plt.A)

Draw2d draws curve and control points option = 0 : use CalcBasis

1 : use RecursiveBasis

func (*Bspline) Draw3d

func (o *Bspline) Draw3d(npts int)

Draw3d draws bspline in 3D

func (*Bspline) Elements

func (o *Bspline) Elements() (spans [][]int)

Elements returns the indices of nonzero spans

func (*Bspline) GetBasis

func (o *Bspline) GetBasis(i int) float64

GetBasis returns the basis function N[i] just computed by CalcBasis or CalcBasisAndDerivs

func (*Bspline) GetDeriv

func (o *Bspline) GetDeriv(i int) float64

GetDeriv returns the derivative dN[i]dt just computed by CalcBasisAndDerivs

func (*Bspline) NumBasis

func (o *Bspline) NumBasis() int

NumBasis returns the number (n) of basis functions == number of control points

func (*Bspline) PlotBasis

func (o *Bspline) PlotBasis(npts, option int)

PlotBasis plots basis functions in I option = 0 : use CalcBasis

1 : use CalcBasisAndDerivs
2 : use RecursiveBasis

func (*Bspline) PlotDerivs

func (o *Bspline) PlotDerivs(npts int)

PlotDerivs plots derivatives of basis functions in I

func (*Bspline) Point

func (o *Bspline) Point(t float64, option int) (C []float64)

Point returns the x-y-z coordinates of a point on B-spline option = 0 : use CalcBasis

1 : use RecursiveBasis

func (*Bspline) RecursiveBasis

func (o *Bspline) RecursiveBasis(t float64, i int) float64

RecursiveBasis computes one particular basis function N[i] recursively (not efficient)

func (*Bspline) SetControl

func (o *Bspline) SetControl(Q [][]float64)

SetControl sets B-spline control points

func (*Bspline) SetOrder

func (o *Bspline) SetOrder(p int)

SetOrder sets B-spline order (p)

type CurvGrid

type CurvGrid struct {
	Ndim int            // space dimension
	N0   int            // number of points along 0-direction
	N1   int            // number of points along 1-direction
	N2   int            // number of points along 2-direction [default = 1]
	M2d  [][]*Metrics   // [n1][n0] metrics in 2D
	M3d  [][][]*Metrics // [n2][n1][n0] metrics in 3D
}

CurvGrid holds metrics data for 2d or 3d grids represented by curvilinear coordinates

func (*CurvGrid) DrawBases

func (o *CurvGrid) DrawBases(scale float64, argsG0, argsG1, argsG2 *plt.A)

DrawBases draw basis vectors

func (*CurvGrid) SetTransfinite2d

func (o *CurvGrid) SetTransfinite2d(trf *Transfinite, R, S []float64)

SetTransfinite2d sets grid from 2D transfinite mapping

trf -- 2D transfinite structure
R   -- [n1] reference coordinates along r-direction
S   -- [n2] reference coordinates along s-direction

func (*CurvGrid) SetTransfinite3d

func (o *CurvGrid) SetTransfinite3d(B, Bd, Bdd []fun.Vss, R, S, T []float64)

SetTransfinite3d sets grid from 3D transfinite mapping

type Entity

type Entity interface {
}

Entity defines the geometric (or not) entity/element to be stored in the Octree

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

Grid implements a generic (uniform or nonuniform) grid of points in 2D or 3D

NOTE: use methods GenUniform, Set2d, or Set3d to generate coordinates

func (*Grid) Boundary

func (o *Grid) Boundary(tag int) []int

Boundary returns list of edge or face nodes on boundary

NOTE: will return empty list if tag is not available

func (*Grid) Draw

func (o *Grid) Draw(withTxt bool, argsGrid, argsTxt *plt.A) (coordsGenerated bool)

Draw draws grid

coordsGenerate -- tells whether the meshgrid coordinates are generated or not.
                  if the size of the current arrays are the same, no new coordinates
                  will be generated. Thus, make sure to call the "set" commands with the
                  genMeshCoordinates flag equal to true if when updating the grid.

func (*Grid) Edge

func (o *Grid) Edge(iEdge int) []int

Edge returns the ids of points on edges: [edge0, edge1, edge2, edge3]

       2
 +-----------+
 |           |
 |           |
3|           |1
 |           |
 |           |
 +-----------+
       0

func (*Grid) EdgeT

func (o *Grid) EdgeT(tag int) []int

EdgeT returns a list of nodes marked with given tag

        21
   +-----------+
   |           |
   |           |
 10|           |11
   |           |
   |           |
   +-----------+
        20

NOTE: will return empty list if tag is not available

func (*Grid) Face

func (o *Grid) Face(iFace int) []int

Face returns the ids of points on faces: [face0, face1, face2, face3, face4, face5]

          +----------------+
        ,'|              ,'|
      ,'  |  ___       ,'  |
    ,'    |,'5,' [0] ,'    |
  ,'      |~~~     ,'  ,   |
+'===============+'  ,'|   |
|   ,'|   |      |   |3|   |
|   |2|   |      |   |,'   |
|   |,'   +- - - | +- - - -+
|   '   ,'       |       ,'
|     ,' [1]  ___|     ,'
|   ,'      ,'4,'|   ,'
| ,'        ~~~  | ,'
+----------------+'

func (*Grid) FaceT

func (o *Grid) FaceT(tag int) []int

FaceT returns a list of nodes marked with given tag

            +----------------+
          ,'|              ,'|
        ,'  |  ___       ,'  |
      ,'    |,'31'  10 ,'    |
    ,'      |~~~     ,'  ,,  |
  +'===============+'  ,' |  |
  |   ,'|   |      |   |21|  |
  |  |20|   |      |   |,'   |
  |  | ,'   +- - - | +- - - -+
  |   '   ,'       |       ,'
  |     ,' 11   ___|     ,'
  |   ,'      ,'30'|   ,'
  | ,'        ~~~  | ,'
  +----------------+'

NOTE: will return empty list if tag is not available

func (*Grid) GenUniform

func (o *Grid) GenUniform(min, max []float64, ndiv []int, genMeshCoords bool)

GenUniform generates uniform grid

min  -- min x-y-z values, len==ndim: [xmin, ymin, zmin]
max  -- max x-y-z values, len==ndim: [xmax, ymax, zmax]
ndiv -- number of divisions along each direction len==ndim: [ndivx, ndivy, ndivz]
genMeshCoords -- generate "meshgrid" coordinates. Accessed with Mesh2d or Mesh3d

func (*Grid) GetNode

func (o *Grid) GetNode(n int) (x la.Vector)

GetNode returns coordinates of node 'n'

func (*Grid) Length

func (o *Grid) Length(dim int) float64

Length returns the lengths along each direction (whole box)

dim -- direction in [0, ndim-1]

func (*Grid) Max

func (o *Grid) Max(dim int) float64

Max returns maximum x-y-z value

dim -- direction in [0, ndim-1]

func (*Grid) Mesh2d

func (o *Grid) Mesh2d() (X, Y [][]float64)

Mesh2d returns 2D "meshgrid"

func (*Grid) Mesh3d

func (o *Grid) Mesh3d() (X, Y, Z [][][]float64)

Mesh3d returns 3D "meshgrid"

func (*Grid) Min

func (o *Grid) Min(dim int) float64

Min returns mininum x-y-z value

dim -- direction in [0, ndim-1]

func (*Grid) Ndim

func (o *Grid) Ndim() int

Ndim returns the space dimension

func (*Grid) Node

func (o *Grid) Node(x la.Vector, n int)

Node returns in 'x' the coordinates of a node 'n'

func (*Grid) Npts

func (o *Grid) Npts(dim int) int

Npts returns the number of points along each direction

dim -- direction in [0, ndim-1]

func (*Grid) Set2d

func (o *Grid) Set2d(X, Y []float64, genMeshCoords bool)

Set2d sets coordinates along each direction

genMeshCoords -- generate "meshgrid" coordinates. Accessed with Mesh2d or Mesh3d

func (*Grid) Set3d

func (o *Grid) Set3d(X, Y, Z []float64, genMeshCoords bool)

Set3d sets coordinates along each direction

genMeshCoords -- generate "meshgrid" coordinates. Accessed with Mesh2d or Mesh3d

func (*Grid) Size

func (o *Grid) Size() int

Size returns the total number of points; e.g. Npts(0) * Npts(1) * Npts(2)

type Metrics

type Metrics struct {
	U          la.Vector     // reference coordinates {r,s,t}
	X          la.Vector     // physical coordinates {x,y,z}
	CovG0      la.Vector     // covariant basis g_0 = d{x}/dr
	CovG1      la.Vector     // covariant basis g_1 = d{x}/ds
	CovG2      la.Vector     // covariant basis g_2 = d{x}/dt
	CovGmat    *la.Matrix    // covariant metrics g_ij = g_i ⋅ g_j
	CntGmat    *la.Matrix    // contravariant metrics g^ij = g^i ⋅ g^j
	DetCovGmat float64       // determinant of covariant g matrix = det(CovGmat)
	GammaS     [][][]float64 // [k][i][j] Christoffel coefficients of second kind
	L          []float64     // [3] L-coefficients = sum(Γ_ij^k ⋅ g^ij)
}

Metrics holds data related to a position in a space represented by curvilinear coordinates

func NewMetrics2d

func NewMetrics2d(u, x, dxdr, dxds, ddxdrr, ddxdss, ddxdrs la.Vector) (o *Metrics)

NewMetrics2d allocate new 2D metrics structure

type Nurbs

type Nurbs struct {
	Q [][][][]float64 // Qw: weighted control points and weights [n[0]][n[1]][n[2]][4] (Piegl p120)
	// contains filtered or unexported fields
}

Nurbs holds NURBS data

NOTE: (1) Control points must be set after a call to Init
      (2) Either SetControl must be called or the Q array must be directly specified

Reference:
 [1] Piegl L and Tiller W (1995) The NURBS book, Springer, 646p

func NewNurbs

func NewNurbs(gnd int, ords []int, knots [][]float64) (o *Nurbs)

NewNurbs returns a new Nurbs object

func (*Nurbs) CalcBasis

func (o *Nurbs) CalcBasis(u []float64)

CalcBasis computes all non-zero basis functions R[i][j][k] @ u. Note: use GetBasisI or GetBasisL to get a particular basis function value

func (*Nurbs) CalcBasisAndDerivs

func (o *Nurbs) CalcBasisAndDerivs(u []float64)

CalcBasisAndDerivs computes all non-zero basis functions R[i][j][k] and corresponding first order derivatives of basis functions w.r.t u => dRdu[i][j][k] @ u Note: use GetBasisI or GetBasisL to get a particular basis function value

use GetDerivI or GetDerivL to get a particular derivative

func (*Nurbs) CloneCtrlsAlongCurve

func (o *Nurbs) CloneCtrlsAlongCurve(iAlong, jAt int) (Qnew [][][][]float64)

CloneCtrlsAlongCurve returns a copy of control points @ 2D boundary

func (*Nurbs) CloneCtrlsAlongSurface

func (o *Nurbs) CloneCtrlsAlongSurface(iAlong, jAlong, kat int) (Qnew [][][][]float64)

CloneCtrlsAlongSurface returns a copy of control points @ 3D boundary

func (*Nurbs) DrawCtrl

func (o *Nurbs) DrawCtrl(ndim int, withIds bool, args, argsIds *plt.A)

DrawCtrl draws control net in 2D or 3D space

ndim -- 2 or 3 => to plot in a 2D or 3D space

func (*Nurbs) DrawEdge

func (o *Nurbs) DrawEdge(ndim int, tmin, tmax, cte float64, along, npts int, args *plt.A)

DrawEdge draws edge from tmin to tmax in 2D or 3D space

ndim -- 2 or 3 => to plot in a 2D or 3D space

func (*Nurbs) DrawElem

func (o *Nurbs) DrawElem(ndim int, span []int, npts int, withIds bool, args, argsIds *plt.A)

DrawElem draws element (non-zero span) in 2D or 3D space

ndim -- 2 or 3 => to plot in a 2D or 3D space

func (*Nurbs) DrawElems

func (o *Nurbs) DrawElems(ndim int, npts int, withIds bool, args, argsIds *plt.A)

DrawElems draws all elements (non-zero spans) in 2D or 3D space

ndim -- 2 or 3 => to plot in a 2D or 3D space

func (*Nurbs) DrawSurface

func (o *Nurbs) DrawSurface(ndim int, nu, nv int, withSurf, withWire bool, argsSurf, argsWire *plt.A)

DrawSurface draws surface

ndim -- 2 or 3 => to plot in a 2D or 3D space

func (*Nurbs) DrawVectors3d

func (o *Nurbs) DrawVectors3d(nu, nv int, sf float64, argsU, argsV *plt.A)

DrawVectors3d draws tangent vectors of 3D surface

func (*Nurbs) ElemBryLocalInds

func (o *Nurbs) ElemBryLocalInds() (I [][]int)

ElemBryLocalInds returns the local (element) indices of control points @ boundaries (if element would have all surfaces @ boundaries)

func (*Nurbs) Elements

func (o *Nurbs) Elements() (spans [][]int)

Elements returns the indices of nonzero spans

func (*Nurbs) ExtractSurfaces

func (o *Nurbs) ExtractSurfaces() (surfs []*Nurbs)

ExtractSurfaces returns a new NURBS representing a boundary of this NURBS

func (*Nurbs) GetBasisI

func (o *Nurbs) GetBasisI(I []int) float64

GetBasisI returns the basis function R[i][j][k] just computed by CalcBasis or CalcBasisAndDerivs Note: I = [i,j,k]

func (*Nurbs) GetBasisL

func (o *Nurbs) GetBasisL(l int) float64

GetBasisL returns the basis function R[i][j][k] just computed by CalcBasis or CalcBasisAndDerivs Note: l = i + j * n0 + k * n0 * n1

func (*Nurbs) GetDerivI

func (o *Nurbs) GetDerivI(dRdu []float64, I []int)

GetDerivI returns the derivative of basis function dR[i][j][k]du just computed by CalcBasisAndDerivs Note: I = [i,j,k]

func (*Nurbs) GetDerivL

func (o *Nurbs) GetDerivL(dRdu []float64, l int)

GetDerivL returns the derivative of basis function dR[i][j][k]du just computed by CalcBasisAndDerivs Note: l = i + j * n0 + k * n0 * n1

func (*Nurbs) GetElemNumBasis

func (o *Nurbs) GetElemNumBasis() (npts int)

GetElemNumBasis returns the number of control points == basis functions needed for one element

npts := Π_i (p[i] + 1)

func (*Nurbs) GetLimitsQ

func (o *Nurbs) GetLimitsQ() (xmin, xmax []float64)

GetLimitsQ computes the limits of all coordinates of control points in NURBS

func (*Nurbs) GetQ

func (o *Nurbs) GetQ(i, j, k int) (x []float64)

GetQ gets a control point x[i,j,k] (size==4)

func (*Nurbs) GetQl

func (o *Nurbs) GetQl(l int) (x []float64)

GetQl gets a control point x[l] (size==4)

func (*Nurbs) GetU

func (o *Nurbs) GetU(dir int) []float64

GetU returns the knots along direction dir

func (*Nurbs) Gnd

func (o *Nurbs) Gnd() int

Gnd returns the geometry dimension

func (*Nurbs) IndBasis

func (o *Nurbs) IndBasis(span []int) (L []int)

IndBasis returns the indices of basis functions == local indices of control points

func (*Nurbs) IndsAlongCurve

func (o *Nurbs) IndsAlongCurve(iAlong, iSpan0, jAt int) (L []int)

IndsAlongCurve returns the control points indices along curve

func (*Nurbs) IndsAlongSurface

func (o *Nurbs) IndsAlongSurface(iAlong, jAlong, iSpan0, jSpan0, kat int) (L []int)

IndsAlongSurface return the control points indices along surface

func (*Nurbs) Krefine

func (o *Nurbs) Krefine(X [][]float64) (O *Nurbs)

Krefine returns a new Nurbs with knots refined Note: X[gnd][numNewKnots]

func (*Nurbs) KrefineN

func (o *Nurbs) KrefineN(ndiv int, hughesEtAlPaper bool) *Nurbs

KrefineN return a new Nurbs with each span divided into ndiv parts = [2, 3, ...]

func (*Nurbs) NonZeroSpans

func (o *Nurbs) NonZeroSpans(dir int) [][]int

NonZeroSpans returns the 'elements' along direction dir

func (*Nurbs) NumBasis

func (o *Nurbs) NumBasis(dir int) int

NumBasis returns the number of basis (controls) along direction dir

func (*Nurbs) Ord

func (o *Nurbs) Ord(dir int) int

Ord returns the order along direction dir

func (*Nurbs) PlotBasis2d

func (o *Nurbs) PlotBasis2d(l int, npts, option int)

PlotBasis2d plots basis function (2D only) option = 0 : use CalcBasis

1 : use CalcBasisAndDerivs
2 : use RecursiveBasis

func (*Nurbs) PlotDeriv2d

func (o *Nurbs) PlotDeriv2d(l, d int, npts int)

PlotDeriv2d plots derivative dR[i][j][k]du[d] (2D only)

func (*Nurbs) Point

func (o *Nurbs) Point(C, u []float64, ndim int)

Point returns the x-y-z coordinates of a point on curve/surface/volume

Input:
  u    -- [gnd] knot values
  ndim -- the dimension of the point. E.g. allows drawing curves in 3D
Output:
  C -- [ndim] point coordinates
NOTE: Algorithm A4.1 (p124) of [1]

func (*Nurbs) PointDeriv

func (o *Nurbs) PointDeriv(dCdu *la.Matrix, C, u []float64, ndim int)

PointDeriv returns the derivatives of the x-y-z coordinates of a point on curve/surface/volume with respect to the knot values u @ u

Input:
  u    -- [gnd] knot values
  ndim -- the dimension of the point. E.g. allows drawing curves in 3D
Output:
  dCdu -- [ndim][gnd] derivatives dC_i/du_j
  C    -- [ndim] point coordinates

func (*Nurbs) RecursiveBasis

func (o *Nurbs) RecursiveBasis(u []float64, l int) (res float64)

RecursiveBasis implements basis functions by means of summing all terms in Bernstein polynomial using recursive Cox-DeBoor formula (very not efficient) Note: l = i + j * n0 + k * n0 * n1

func (*Nurbs) SetControl

func (o *Nurbs) SetControl(verts [][]float64, ctrls []int)

SetControl sets control points from list of global vertices

func (*Nurbs) SetQ

func (o *Nurbs) SetQ(i, j, k int, x []float64)

SetQ sets a control point x[i,j,k] (size==4)

func (*Nurbs) SetQl

func (o *Nurbs) SetQl(l int, x []float64)

SetQl sets a control point x[l] (size==4)

func (*Nurbs) U

func (o *Nurbs) U(dir, idx int) float64

U returns the value of a knot along direction dir

type NurbsExchangeData

type NurbsExchangeData struct {
	ID    int         `json:"i"` // id of Nurbs
	Gnd   int         `json:"g"` // 1: curve, 2:surface, 3:volume (geometry dimension)
	Ords  []int       `json:"o"` // order along each x-y-z direction [gnd]
	Knots [][]float64 `json:"k"` // knots along each x-y-z direction [gnd][m]
	Ctrls []int       `json:"c"` // global ids of control points
}

NurbsExchangeData holds all data required to exchange NURBS; e.g. read/save files

type NurbsExchangeDataSet

type NurbsExchangeDataSet []*NurbsExchangeData

NurbsExchangeDataSet defines a set of nurbs exchange data

type NurbsPatch

type NurbsPatch struct {

	// input/output data
	ControlPoints []*PointExchangeData `json:"points"` // input/output control points
	ExchangeData  NurbsExchangeDataSet `json:"patch"`  // input/output nurbs data

	// Nurbs structures
	Entities []*Nurbs `json:"-"` // pointers to NURBS

	// auxiliary
	Bins Bins `json:"-"` // auxiliary structure to locate points
}

NurbsPatch defines a patch of many NURBS'

func NewNurbsPatch

func NewNurbsPatch(binsNdiv int, tolerance float64, entities ...*Nurbs) (o *NurbsPatch)

NewNurbsPatch returns new patch of NURBS

tolerance -- tolerance to assume that two control points are the same

func NewNurbsPatchFromFile

func NewNurbsPatchFromFile(filename string, binsNdiv int, tolerance float64) (o *NurbsPatch)

NewNurbsPatchFromFile allocates a NurbsPatch with data from file

func (NurbsPatch) LimitsAndNdim

func (o NurbsPatch) LimitsAndNdim() (xmin, xmax []float64, ndim int)

LimitsAndNdim computes the limits of the patch and max dimension by looping over all Entities

func (*NurbsPatch) ResetFromEntities

func (o *NurbsPatch) ResetFromEntities(binsNdiv int, tolerance float64)

ResetFromEntities will reset all exchange data with information from Entities slice

func (*NurbsPatch) ResetFromExchangeData

func (o *NurbsPatch) ResetFromExchangeData(binsNdiv int, tolerance float64)

ResetFromExchangeData will reset all Entities with information from ExchangeData (and ControlPoints)

func (NurbsPatch) Write

func (o NurbsPatch) Write(dirout, fnkey string)

Write writes ExchangeData to json file

type Octree

type Octree struct {

	// constants
	DIM  uint32 // dimension
	PMAX uint32 // roughly how many levels fit in 32 bits
	QO   uint32 // 4 for quadtree, 8 for octree
	QL   uint32 // offset constant to leftmost daughter
	// contains filtered or unexported fields
}

Octree implements a Quad-Tree or an Oct-Tree to assist in fast-searching elements (entities) in the 2D or 3D space

func NewOctree

func NewOctree(L ...float64) (o *Octree)

NewOctree creates a new Octree

L -- limits [4] or [6]: xmin,xmax, ymin,ymax, {zmin,zmax} optional

type Point

type Point struct {
	X, Y, Z float64
}

Point holds the Cartesian coordinates of a point in 3D space

func (*Point) NewCopy

func (o *Point) NewCopy() *Point

NewCopy creates a new copy of Point

func (*Point) NewDisp

func (o *Point) NewDisp(dx, dy, dz float64) *Point

NewDisp creates a new copy of Point displaced by dx, dy, dz

func (*Point) String

func (o *Point) String() string

String outputs Point

type PointExchangeData

type PointExchangeData struct {
	ID  int       `json:"i"` // id
	Tag int       `json:"t"` // tag
	X   []float64 `json:"x"` // coordinates (size==4)
}

PointExchangeData holds data for exchanging control points

type PointN

type PointN struct {

	// esssential
	X []float64 // coordinates

	// optional
	ID int // some identification number
}

PointN implements a point in N-dim space

func NewPointN

func NewPointN(X ...float64) (o *PointN)

NewPointN creats a new PointN with given coordinates; can be any number

func NewPointNdim

func NewPointNdim(ndim uint32) (o *PointN)

NewPointNdim creates a new PointN with given dimension (ndim)

func (PointN) AlmostTheSameX

func (o PointN) AlmostTheSameX(p *PointN, tol float64) bool

AlmostTheSameX returns true if the X slices of two points have almost the same values, for given tolerance

func (PointN) ExactlyTheSameX

func (o PointN) ExactlyTheSameX(p *PointN) bool

ExactlyTheSameX returns true if the X slices of two points have exactly the same values

func (PointN) GetCloneX

func (o PointN) GetCloneX() (p *PointN)

GetCloneX returns a new point with X cloned, but not the other data

type Segment

type Segment struct {
	A, B *Point
}

Segment represents a directed segment from A to B

func NewSegment

func NewSegment(a, b *Point) *Segment

NewSegment creates a new segment from a to b

func (*Segment) Len

func (o *Segment) Len() float64

Len computes the length of Segment == Euclidean norm

func (*Segment) New

func (o *Segment) New(m float64) *Segment

New creates a new Segment scaled by m and starting from A

func (*Segment) String

func (o *Segment) String() string

String outputs Segment

func (*Segment) Vector

func (o *Segment) Vector(m float64) []float64

Vector returns the vector representing Segment from A to B (scaled by m)

type Transfinite

type Transfinite struct {
	// contains filtered or unexported fields
}

Transfinite maps a reference square [-1,+1]×[-1,+1] into a curve-bounded quadrilateral

                                           B[3](r(x,y)) _,'\
            B[3](r)                                  _,'    \ B[1](s(x,y))
           ┌───────┐                              _,'        \
           │       │                             \            \
    B[0](s)│       │B[1](s)     ⇒                 \         _,'
 s         │       │                  B[0](s(x,y)) \     _,'
 │         └───────┘               y                \ _,'  B[2](r(x,y))
 └──r       B[2](r)                │                 '
                                   └──x

                                  +----------------+
                                ,'|              ,'|
     t or z                   ,'  |  ___       ,'  |     B[0](s,t)
        ↑                   ,'    |,'5,'  [0],'    |     B[1](s,t)
        |                 ,'      |~~~     ,'      |     B[2](r,t)
        |               +'===============+'  ,'|   |     B[3](r,t)
        |               |   ,'|   |      |   |3|   |     B[4](r,s)
        |     s or y    |   |2|   |      |   |,'   |     B[5](r,s)
        +-------->      |   |,'   +- - - | +- - - -+
      ,'                |       ,'       |       ,'
    ,'                  |     ,' [1]  ___|     ,'
r or x                  |   ,'      ,'4,'|   ,'
                        | ,'        ~~~  | ,'
                        +----------------+'

func NewTransfinite2d

func NewTransfinite2d(B, Bd, Bdd []fun.Vs) (o *Transfinite)

NewTransfinite2d allocates a new structure

Input:
  B   -- [4] boundary functions
  Bd  -- [4] 1st derivative of boundary functions
  Bdd -- [4 or nil] 2nd derivative of boundary functions [may be nil]

func NewTransfinite3d

func NewTransfinite3d(B []fun.Vss, Bd []fun.Vvss, Bdd []fun.Vvvss) (o *Transfinite)

NewTransfinite3d allocates a new structure

Input:
  B   -- [6] boundary functions
  Bd  -- [6] 1st derivative of boundary functions
  Bdd -- [6 or nil] 2nd derivative of boundary functions [may be nil]

func (*Transfinite) Draw

func (o *Transfinite) Draw(npts []int, onlyBry bool, args, argsBry *plt.A)

Draw draws figure formed by B

func (*Transfinite) Point

func (o *Transfinite) Point(x, u la.Vector)

Point computes "real" position x(r,s,t)

Input:
  u -- the "reference" coordinates {r,s,t} ϵ [-1,+1]×[-1,+1]×[-1,+1]
Output:
  x -- the "real" coordinates {x,y,z}

func (*Transfinite) PointAndDerivs

func (o *Transfinite) PointAndDerivs(x, dxDr, dxDs, dxDt,
	ddxDrr, ddxDss, ddxDtt, ddxDrs, ddxDrt, ddxDst, u la.Vector)

PointAndDerivs computes position and the first and second order derivatives

Input:
  u -- reference coordinates {r,s,t}
Output:
  x      -- position {x,y,z}
  dxDr   -- ∂{x}/∂r
  dxDs   -- ∂{x}/∂s
  dxDt   -- ∂{x}/∂t
  ddxDrr -- ∂²{x}/∂r²  [may be nil]
  ddxDss -- ∂²{x}/∂s²  [may be nil]
  ddxDtt -- ∂²{x}/∂t²  [may be nil]
  ddxDrs -- ∂²{x}/∂r∂s [may be nil]
  ddxDrt -- ∂²{x}/∂r∂t [may be nil]
  ddxDst -- ∂²{x}/∂s∂t [may be nil]

Directories

Path Synopsis
Package msh defines mesh data structures and implements interpolation functions for finite element analyses (FEA)
Package msh defines mesh data structures and implements interpolation functions for finite element analyses (FEA)
Package rw implements reader and writers for geometry files such as the STEP file format
Package rw implements reader and writers for geometry files such as the STEP file format
Package tri wraps Triangle to perform mesh generation a Delaunay triangulation
Package tri wraps Triangle to perform mesh generation a Delaunay triangulation

Jump to

Keyboard shortcuts

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