Skip to content

General Helpers

General utility functions that are used throughout Mantis.

All docstrings from Mantis.GeneralHelpers

Mantis.GeneralHelpers.cache_dict Method
julia
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
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}()
source
Mantis.GeneralHelpers.export_path Method
julia
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

julia
output_file = export_path(["examples", "data", "output"], "output.vtu")
source
Mantis.GeneralHelpers.get_derivative_idx Method
julia
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 = 1 when iⱼ = 0 for all j, i.e., for basis function values;

  • m = 1+r when iⱼ = 0 for all j except for j = r and iⱼ = 1, i.e., for the first derivative w.r.t. the j-th canonical coordinate;

  • in all other cases (i.e., when k>1), the value of m is equal to l if [i₁,i₂,...,iₙ] is the l-th key returned by the function integer_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.
source
Mantis.GeneralHelpers.get_from_cache Method
julia
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!.

source
Mantis.GeneralHelpers.integer_sums Function
julia
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
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)
source
Mantis.GeneralHelpers.integer_sums Method
julia
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 by N.

Returns

  • ::Vector{NTuple{N, Int}}: Each inner vector represents a combination of integers that sum up to sum_indices. If no valid combinations exist, the vectors are empty.
source
Mantis.GeneralHelpers.num_der_indices Method
julia
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

julia
using Mantis

julia> Mantis.GeneralHelpers.num_der_indices(1, 2)
1

julia> Mantis.GeneralHelpers.num_der_indices(3, 2)
6
source