General Helpers
General utility functions that are used throughout Mantis.
All docstrings from Mantis.GeneralHelpers
Mantis.GeneralHelpers.cache_dict Method
cache_dict(::Type{K}, ::Type{V}, id=Val{1}()) where {K, V}Return a Dict{K,V} dictionary stored at compile time. An optional id can be given to force the compilation of a new cache. This is useful to avoid clashes of dictionaries using the same types.
Warning
As per Julia's documentation, it is not guaranteed that the dictionary is not wiped during runtime. Read this for more information.
Examples
julia> using Mantis
julia> dict = Mantis.GeneralHelpers.cache_dict(Int, String)
Dict{Int64, String}()
julia> dict[42] = "Answer"
"Answer"
julia> Mantis.GeneralHelpers.cache_dict(Int, String)
Dict{Int64, String} with 1 entry:
42 => "Answer"
julia> not_new_dict = Mantis.GeneralHelpers.cache_dict(Int, String)
Dict{Int64, String} with 1 entry:
42 => "Answer"
julia> new_dict = Mantis.GeneralHelpers.cache_dict(Int, String, Val(2))
Dict{Int64, String}()Mantis.GeneralHelpers.export_path Method
export_path(output_directory_tree::Vector, filename)Create a directory (if needed) and return the path to the output file.
Arguments
output_directory_tree::Vector: A vector representing the directory tree.filename: The name of the output file.
Example
output_file = export_path(["examples", "data", "output"], "output.vtu")Mantis.GeneralHelpers.get_derivative_idx Method
get_derivative_idx(der_key::NTuple{manifold_dim, Int}, id=Val{1}()) where {manifold_dim}Convert the given derivative key to a linear index corresponding to its storage location.
If local_basis corresponds to basis evaluations for some manifold_dim-variate function space, then its k-th derivatives will all be stored in the location local_basis[k+1]. Moreover, the k-th derivative corresponding to the key [i₁,i₂,...,iₙ] in the location local_basis[k+1][m] where:
m = 1wheniⱼ = 0for allj, i.e., for basis function values;m = 1+rwheniⱼ = 0for alljexcept forj = randiⱼ = 1, i.e., for the first derivative w.r.t. thej-th canonical coordinate;in all other cases (i.e., when
k>1), the value ofmis equal tolif[i₁,i₂,...,iₙ]is thel-th key returned by the functioninteger_sums(k, Val(manifold_dim)).
As an example, consider the first derivative with respect to x₁ (∂/∂x₁) in 2D, which has key [1, 0]. In 3D, this same derivative has key [1, 0, 0]. In 3D, the derivative ∂³/∂x₁²∂x₂ thus has key [2, 1, 0].
An optional id can be given choose the used cache. This is useful to avoid clashes of dictionaries using the same types. See also cache_dict.
Arguments
der_key::NTuple{manifold_dim, Int}: A key for the desired derivative order.
Returns
::Int: The linear index corresponding to the derivative's storage location in basis evaluations.
Mantis.GeneralHelpers.get_from_cache Method
get_from_cache(::Type{K}, ::Type{V}, key, f, id=Val{1}()) where {K, V}Call cache_dict on the types K and V with id to retrieve a cached dictionary. Then, call get! on the dictionary with key and f(key).
An optional id can be given choose the used cache. This is useful to avoid clashes of dictionaries using the same types.
See also cache_dict and get!.
Mantis.GeneralHelpers.integer_sums Function
integer_sums(init_sum::Int, final_sum::Int, num_indices::Val, id=Val{1}())Generates all possible combinations of non-negative integers that sum up to init_sum until final_sum, where each combination has num_indices length.
An optional id can be given choose the used cache. This is useful to avoid clashes of dictionaries using the same types. See also cache_dict.
Examples
julia> using Mantis;
julia> Mantis.GeneralHelpers.integer_sums(0, 2, Val(2))
6-element Vector{Tuple{Int64, Int64}}:
(0, 0)
(0, 1)
(1, 0)
(0, 2)
(1, 1)
(2, 0)Mantis.GeneralHelpers.integer_sums Method
integer_sums(sum_indices::Int, num_indices::Val{N}, id=Val{1}()) where {N}Generates all possible combinations of non-negative integers that sum up to a given value, where each combination has a specified number of elements.
An optional id can be given choose the used cache. This is useful to avoid clashes of dictionaries using the same types. See also cache_dict.
Arguments
sum_indices::Int: The target sum of the integers in each combination.num_indices::Val{N}: The number of integers in each combination, given byN.
Returns
::Vector{NTuple{N, Int}}: Each inner vector represents a combination of integers that sum up tosum_indices. If no valid combinations exist, the vectors are empty.
Mantis.GeneralHelpers.num_der_indices Method
num_der_indices(n, d)Return the number of distinct partial derivatives of order d in an n-variate space, assuming equality of mixed partial derivatives.
Examples
using Mantis
julia> Mantis.GeneralHelpers.num_der_indices(1, 2)
1
julia> Mantis.GeneralHelpers.num_der_indices(3, 2)
6