![]() |
IgANet
IgANets - Isogeometric Analysis Networks
|
In this tutorial you will learn how to create and manipulate B-spline function objects and to evaluate them and their derivatives.
Let us start by creating a univariate uniform B-spline function of degree \( p=2 \) with 6 control points in \( \mathbb{R}^1 \)
That is, a function \( C : [0,1] \to \mathbb{R}^1 \) that is defined through its 6 control points \( x_k \in \mathbb{R}^1, k=0, \dots, 5 \), i.e.
\[ C(\xi) = \sum_{i=0}^5 = x_k B_{i,2}(\xi) \]
Here, univariate refers to the single variable \( \xi \) and uniform means that the knot vector \( \Xi = [0, 0, 0, 0.25, 0.5, 0.75, 1, 1, 1] \) is uniform.
By default, the control points are initialized to the so-called Greville abscissae
\[ x_k^* = \frac{1}{p-1}\left(\xi_{i+1} + \cdots + \xi_{i+p-1} \right), \quad k=0, \dots, 5 \]
which can be obtained using the greville()
function
All IgANets object have the member function pretty_print(std::ostream &os)
and an overload of the operator<<
so that the curve \( C \) can be printed as follows
Here
parDim = 1
is for the dimension of the parameter domain \(
[0,1]^1 \),geoDim = 1
is the dimension of the geometric domain \( C \subset
\mathbb{R}^1 \),degrees = 2
is the degree of the B-spline function,knots = 9
is the number of knots in the knot vector \( \Xi \), andcoeffs = 6
is the number of control points \( c_k \).The general relation for an open knot vector is knots = coeffs + degrees + 1
.
A more verbose output that also prints the knot and control point vectors can be produced by
Here, [ owns/cont ]
indicates that the underlying data is owned by the tensor container and stored contiguously in memory. This output is determined by Torch's is_view()
and is_contiguous()
function.
All properties of the B-spline function object can also be addressed individually, e.g.
Note that IgANets has overload of the operator<<
for the standard containers std::array
and std::vector
. If you want to address individual properties restricted to a single parametric or geometric dimension type
The following properties of the B-spline function object can be access individually
coeffs()
returns the array of control points for all dimensions as flat tensorcoeffs(i)
returns the control points of the i
-th dimension as flat tensorcoeffs_view()
returns the array of control points for all dimensions as multidimensional tensor viewcoeffs_view(i)
returns the control points of the i
-th dimension as multidimensional tensor viewdegree(i)
returns the degree of the i
-th dimensiondegrees()
returns the array of degrees for all dimensionsgeoDim()
returns the geometric dimensionknots()
returns the array of knot vectors for all dimensionsknots(i)
returns the knot vector of the i
-th dimensionncoeffs()
returns the numer of control points for all dimensionsncoeffs(i)
returns the number of control points of the i
-th dimensionncumcoeffs()
returns the total number of control pointsnknots()
returns the number of knots for all dimensionnknots(i)
returns the number of knots of the i
-th dimensionparDim()
returns the parametric dimensionLike in the univariate case, a multivariate uniform B-spline function object is created by specifying the geometric dimension in the first template parameter followed by a sequence of integers specifying the individual degrees from which the parametric dimension is deduced.
As an example, the following code snipped creates
All functionality available for univariate uniform B-spline function objects are also available for multivariate ones.
During creation of the B-spline function object, the values of the control points can be specified either by defining one of the following initialization schemes
init::greville
(default) sets the control points to the Greville pointsinit::linear
sets the control points linearly per direction between zero and oneinit::linspace
sets the control points to a special linspace patterninit::none
leaves the control points uninitializedinit::ones
sets all control points to oneinit::random
sets all control points to a random valueinit::zeros
sets all control points to zeroWhile init::linear
initializes the coordinates of the control points linearly along the respective parametric dimension (e.g., comparable to the meshgrid
function in Matlab) and sets all control point coordinates for which geoDim > parDim
to one, init::linspace
initializes all coordinates with an increasing sequence of integers. The latter is mostly useful for debugging purposes to identify control point coordinates unambiguously. The following code snippet illustrates the difference between init::linear
and init::linspace
Instead of providing an initialization stratey for the control points, it is also also possible to provide the coordinates of the control points as an array of tensors, whereby the size of the array must be equal to geoDim
and the size of the tensor must be equal to ncumcoeffs
, e.g.
By default, the B-spline function constructor makes a soft copy of the control points meaning that the coeffs
object and the control point coefficients of the B-spline function object share the same data. Hence, changing the value of an entry in coeffs
will lead to a change in the coordinates of the control points, e.g.,
This behavior can be changed by providing a third argument (clone=true
) to the constructor so that a deep copy of the control point coordinates is made
As shown in the above code snippet, the coeffs_view()
function returns the control point coordinates as a tensor view that is reshaped according to the values given by ncoeffs()
.
It is moreover possible to construct B-spline function objects from existing ones. To ensure conformity with Torch, the copy constructor makes only soft copies of the internal data. A deep copy can be made by using the clone()
function on the existing B-spline function object and thereby passing it to the move constructor, e.g.,
Query attributes
device() device_index() dtype() layout() requires_griad() pinned_memory() is_sparse()
is_uniform() is_nonuniform()
set_requires_grad()
options()
Constructors (ncoeff, init, options) Constructors (ncoeff, coeffs, options) Constructor(other, options)
as_tensor() from_tensor() as_tensor_size()
eval_from_precomputed(basfunc, coeff_indices, numeval, sizes) eval(xi) eval(xi, knot_indices) eval(xi, knot_indices, coeff_indices)
find_knot_indices(xi) find_coeff_indices(indices)
eval_basfunc(xi) eval_basfunc(xi, knot_indices)
transform()
to_json() knots_to_json() coeffs_to_json()
from_json()
to_xml() from_xml()
load() save()
read() write()
!=
uniform_refine() init_knots() init_coeffs()
to_gismo() from_gismo()
clone() to() diff() abs_diff() scale() translate() rotate() boundingBox()
curl() icurl() div() idiv() grad() igrad() hess() ihess() ja() ijac() lapl() ilapl()
plot()