Internals
This section documents functions and structures that are not part of Muscades or Muscade.Toolbox's public API. These are neither intended to be used by developers of Muscade-based applications nor by users such of applications. Interface changes can occur at any time.
Muscade
Muscade.IdVec — Type
An "identity vector"
id = IdVec i = 9834987 id[i] == i # true for any i
See also Julia's identity function.
Muscade.OffsetVector — Type
A simple offset vector that only implements "setindex!" and "getindex". Based on Memory, so cannot be extended.
Muscade.addin! — Method
Muscade.addin!(asm,global,block,ibr,ibc,factor=1.)Add a sparse block into a large out sparse matrix, at block-row and -column ibr and ibc. Use prepare to allocate memory for global and build the assembler asm.
Muscade.addin! — Method
addin!(asm,outvec,blockvec,ibr)Add a full block vector into a large outvec full vector. at block-row ibr. Use prepare to create asm.
See also: prepare
Muscade.geneig — Type
λ,v,ncv = Muscade.geneig{ALGO}(A,B,neig=5)Solves (A-λ*B)*v=0, finding the neig lowest eigenvalues λ (in absolute value) and the corresponding eigenvectors v (a Vector{Vector})
Input
ALGO can be
- :SDP if
Ais symmetric definite positive andBis symmetric. Will return realλandv. - :Hermitian if
Ais symmetric indefinite andBis symmetric. Will return realλandv. - :Complex otherwise, will return complex
λandv.
Optional keyword arguments:
maxiter = 300verbosity = 0 ∈ {0,1,2,3}krylovdim = 2neig+6
Uses KrylovKit.jl. Freely based on VibrationGEPHelpers.jl and input from PetrKryslUCSD and stevengj. See GIThub-blame for bug-credits.
Muscade.to_order — Type
to_order{P,N}(V)Decrease (lossy) or increase (pad partials with zeros) the order of differentiation of V. V is a nested structure of NamedTuple, Tuple, SArray, and the components of V must be of type ∂ℝ or 𝕣.
IMPORTANT:
- assumes all the nested differentiations are with respect to the same variable.
- to_order{P,N}(V::𝕣) = V
Muscade.variate_ — Method
X = variate_{P,N}(x)where typeof(x)<:SVector{N}, create a SVector of automatic differentiation objects of precedence P.
X = variate_{P}(x)where typeof(x)<:Real, create an object of precedence P.
!!! Warning Improper use may cause perturbation confusion. Assumes, without testing, that precedence(x)=P-1
Muscade.δ_ — Method
X = δ_{P,N,R}()create a SVector of automatic differentiation objects of precedence P and value zero.
X = δ_{P}()Create automatic differentiation object of precedence P and value zero.
!!! Warning Improper use may cause perturbation confusion
See also: precedence, Muscade.variate_, value, ∂, VALUE, value_∂
Base.copy — Method
s2 = copy(s1::State)Copy a state so that s1 and s2 do not share memory.
(Actualy the States will stil share the same Model, but no operations are provided to mutate it).
s2 = copy(s1;[time=t])create a copied State with time t.
See also: initialize!, setdof!
Muscade.colnormalize — Method
colnormalize(a)Euclidian-normalize the columns of an SMatrix
Muscade.columnmatrix — Method
columnmatrix(v)Reshape a vector into a matrix of size (length(v),1)
Muscade.eletyp — Method
et = eletyp(model)Return a vector of the concrete types of elements in the model.
Muscade.indent — Method
str = indent(str,n)Add n spaces at the begining of every line in str.
Muscade.isapprox_dbg — Method
Muscade.isapprox_dbg(a,b;kwargs...)Compare two ∂ℝ of the same type (or two conformant AbstractArrays of same eltype). The comparison applies to the value and the partial derivatives.
This differs from
isapprox(a,b;kwargs...)which only compares values, in keeping with the principle that ∂ℝ must behave as ℝ.
Muscade.prepare — Method
bigmat,bigmatasm,bigvecasm,bigvecdis = Muscade.prepare(pattern)Prepare for the assembly of sparse blocks into a large sparse matrix. bigmat is allocated, with the correct sparsity structure, but its nzval undef'ed. Where some blocks share the same sparsity structure, blocks in pattern can have === elements.
pattern is a SparseMatrixCSC{<:SparseMatrixCSC}, where empty blocks are structuraly zero
See also: addin!
Muscade.rowmatrix — Method
rowmatrix(v)Reshape a vector into a matrix of size (1,length(v))
Muscade.sinc1 — Method
Muscade.sinc1(x)sinc1(x) = sin(x)/x - but sinc1(0.) = 1.. The function can be differentiated to the fourth order.
This differs from Julia's sinc(x) = sin(π*x)/(π*x).
Muscade.sparser! — Method
sparser!(S::SparseMatrixCSC,keep::Function)Eliminate terms that do not satisfy a criteria from the storage of a sparse matrix. S will be mutated, and the size of its internal storage modified. keep is a Function which to an index into S.nzval associate true if storage is to be kept for this term and false otherwise. Alternatively, keep can be a Vector{Bool}
Examples
sparser!([T],S,i->abs(S.nzval[i])>tol)
sparser!([T],S,keep::Vector{Boolean})If T is provided (initialised as T = copy(S)), then result is set in T, S is unchanged, other wise S is mutated in place. The input keep::Vector{Boolean} must be of length nnz(S).
sparser!([S1,S2,...],rtol=1e-9)Operates in place, reducing the sparses S1, S2 etc... to a common sparsity pattern.
In the first example, the keep function accesses S.nzval[i], and the term is then mutated by sparser!. Any criteria requiring multiple access to nzval must build a Vector before calling sparser!.
Note that assemble! computes the nzval of a sparse, assumning that its sparsity structure colptr and rowval is unchanged since sparse storage was allocated by asmmat in prepare. In other words, if applying sparser! directly to a sparse returned by assemble!, assemble! can no longer be called for this matrix.
Muscade.symmetric! — Method
sA = symmetric!(A)Compute the symmetric part of a square Matrix. Mutates the input argument.
Muscade.variate_indices — Method
iV = variate_indices(V)For use in conjunction with
TV = variate(V)iV has the same structure as V and TV but contains integers: the indices into the partials of TV
See also: revariate
Muscade.zero! — Method
zero!(a)Set to zero all elements of an arrays. If a is sparse, the vector nzval of values is set to zero and the sparsity structure is unchanged.
Muscade.𝕫log2 — Method
𝕫log2(i::𝕫)Compute the integer log2 of an integer, fast. Fails if i is not a power of two.
Muscade.Toolbox
Muscade.Toolbox.trace — Method
trace(v::SMatrix{3,3})Computes the trace of a matrix.
Muscade.Toolbox.vec3 — Method
vec3(v, ind)Create a 3-element static vector from selected elements of vector v.
Arguments
v: The input vector from which elements are selected.ind: A collection of 3 indices specifying which elements ofvto include.
Returns
- An
SVector{3}containing the elementsv[ind[1]],v[ind[2]],v[ind[3]].
Muscade.allocate_drawing — Method
Drawing a Bar3D.
draw!(axis,state)Optional arguments (and their default values) are
line_color = :blackcolor of the lineUdof(trueiff element has Udofs) wether to draw U-forces.Uscale = 1.How many meter is a Newton per meter?
Muscade.allocate_drawing — Method
Drawing a EulerBeam3D.
draw!(axis,state)
draw!(axis,state;EulerBeam3D=(;style=:shape))
α = 2π*(0:19)/20
circle = 0.1*[cos.(α) sin.(α)]'
draw!(axis,state;EulerBeam3D=(;style=:solid,section = circle))style=:shape shows the deformed neutral axis of the element. It has optional arguments frame=true (draws the element's corotated frame of reference) and nseg=10 (number of points to show the deflected shape of each element).
style=:solid shows the deformed shape of the element. It requires the input section=... to be given a matrix of size (2,nsec) describing nsec points around the cross section of the element (no need to close the circumference by repeating the first point at the end). It has optional arguments nseg=10 as above, marking=true to draw a longitudinal marking and solid_color=:yellow.
Other optional arguments (and their default values) are
Udof(trueiff element has Udofs) wether to draw U-forces.draw_frame = falsewether to draw the local reference frame of each elementdraw_marking = truewether to draw "longitudinal marking" along the element. Will only draw if style=:solid.nseg = 1number of segments to display the shape of a deformed elementsolid_color = :yellowcolor of the surface ifstyle=:solidline_color = :blackcolor of the line ifstyle=:sshapeUscale = 1.How many meter is a Newton per meter?