Utilities

Backend

Bramble.BackendType
struct Backend{VT<:AbstractVector,MT<:AbstractMatrix}

A structure containing types and configuration for backend linear algebra objects. This structure has no fields, only types.

This allows specifying the desired concrete types for vectors and matrices (e.g., dense Vector, sparse SparseVector, different element types like Float32 or Float64).

source
Base.eltypeMethod
eltype(backend::Backend)

Returns the element type of the vector type (VT) used in the given Backend type or instance. This function allows querying the underlying element type stored in the backend's vector representation.

source
Bramble.backendMethod
backend(; vector_type, matrix_type)

Create a linear algebra Backend using keyword arguments.

Defaults to standard dense Float64 vectors and SparseMatrixCSC matrices, ensuring the provided vector_type and matrix_type are constructible with the intended dimensions via standard patterns like T(undef, dims...) or T(dims...).

Examples

julia> dense_sparse = backend() # Default backend (Dense-Sparse Float64)

julia> using SparseArrays;
	   SVec{T} = SparseVector{T,Int};
	   SMat{T} = SparseMatrixCSC{T,Int};
	   T64 = Float64

julia> sparse_sparse = backend(vector_type = SVec{T64}, matrix_type = SMat{T64}) # Sparse-Sparse Float64 backend

julia> T32 = Float32;
	   dense32 = backend(vector_type = Vector{T32}, matrix_type = SMat{T32}) # Dense-Sparse Float32 backend
source
Bramble.backend_eyeMethod
backend_eye(backend::Backend, n)

Constructs a square n x n sparse identity matrix associated with the given Backend instance.

source
Bramble.backend_typesMethod
backend_types(backend::Backend)

Returns a tuple with the backend associated types:

  • the element type of VT,
  • the type VT,
  • the type MT,
  • the concrete backend type Backend{VT,MT}.

This is useful for extracting type information from either a Backend type or instance.

source
Bramble.matrixMethod
matrix(backend::Backend, n::Integer, m::Integer)

Create a matrix of the type MT associated with the given Backend instance with dimensions n x m.

source
Bramble.matrix_typeMethod
matrix_type(backend::Backend)

Returns the matrix type (MT) associated with the given Backend instance or type. This function is useful for extracting the underlying matrix type used by a specific backend.

source
Bramble.vector_typeMethod
vector_type(backend::Backend)

Returns the vector type (VT) associated with the given Backend instance or type. This function is useful for extracting the underlying vector type used by a specific backend.

source

Linear Algebra

Bramble._dotMethod
_dot(u, v, w)

Computes the element-wise product of three vectors u, v, and w and sums the results. This is equivalent to the mathematical operation ∑ᵢ uᵢ * vᵢ * wᵢ. It is used as an optimized implementation for the weighted inner product of vectors.

The @fastmath macro allows for aggressive floating-point optimizations, and @simd instructs the compiler to vectorize the loop if possible.

source
Bramble._parallel_for!Method
_parallel_for!(v, idxs, f)

Parallel implementation of a for loop that modifies array v in-place.

Arguments

  • v: Array to be modified in-place
  • idxs: Iterable of indices to process
  • f: Function that takes an index and returns the value to be stored at that index
source
Bramble._serial_for!Method
_serial_for!(v, idxs, f)

Performs a serial (non-parallel) iteration over the specified indices, applying a function f to modify vector v in-place.

Arguments

  • v: Vector to be modified in-place
  • idxs: Indices to iterate over
  • f: Function to be applied at each index
source

Bramble Function

Bramble.BrambleFunctionType
struct BrambleFunction{ArgsType, hastime, CoType, DType}

Internal structure to wrap around functions to make them more type agnostic. It uses FunctionWrappers.jl wrap functions.

Fields

  • wrapped: a FunctionWrapper wrapper for the function

  • domain: domain of the function; the standard is a CartesianProduct

to provide functions calculated on ArgsType. The type arguments are hastime to indicate if the function is time-dependent and CoType, the time of the codomain of the function. It also stores the type of domain of the space part of the function (CartesianProduct)

source
Bramble._embed_withtimeMethod
_embed_withtime(space_domain, time_domain, f; FinalCoType)

Internal implementation for embedding a time-dependent function f(x, t). When this function is called with a specific time t_val, it returns another space-only BrambleFunction, which represents the spatial function f(x, t_val) at that fixed time.

source
Bramble._get_args_typeMethod
_get_args_type(X)

Internal helper to determine the expected argument type for a function based on a domain X.

  • If the domain is 1D (e.g., a line), the argument type is a scalar T.
  • If the domain is D-dimensional, the argument type is an NTuple{D,T}.
  • T is the element type of the domain X.
source
Bramble._get_domainsMethod
_get_domains(domain_spec)

Parses a domain specification, which can be:

  • A Symbol representing a spatial domain (e.g., :Ω).
  • An Expr representing the product of space and time domains (e.g., :(Ω × I)).

Returns a tuple (space_domain_expr, time_domain_expr), where time_domain_expr is nothing if no time domain is specified.

source
Bramble.argstypeMethod
argstype(f::FunctionWrapper{CoType,Tuple{ArgsType}})

Extracts the argument type ArgsType from a FunctionWrapper instance or type.

source
Bramble.bramble_function_with_domainMethod
bramble_function_with_domain(f, X, hastime, CoType; domain)

A low-level constructor for creating a BrambleFunction. It wraps a given Julia function f into a FunctionWrapper and bundles it with its domain.

Arguments

  • f: The function to wrap.
  • X: The spatial domain used to infer the argument type of f.
  • hastime: A boolean indicating if the function is time-dependent.
  • CoType: The codomain (return) type of the function f.
  • domain: The actual domain object to store in the struct (typically X).
source
Bramble.codomaintypeMethod
codomaintype(f::FunctionWrapper{CoType})

Extracts the codomain type CoType from a FunctionWrapper instance or type.

source
Bramble.embed_functionMethod
embed_function(space_domain, [time_domain], func)

Creates a BrambleFunction for a function func defined over space_domain. If time_domain is provided, it creates a BrambleFunction for a time-dependent function func(x, t) defined over space_domain × time_domain.

source
Bramble.has_timeMethod
has_time(f::BrambleFunction)

Checks if a BrambleFunction is time-dependent by inspecting its hastime type parameter. Returns true if the function is time-dependent, false otherwise.

source