Utilities
Backend
Bramble.Backend — Typestruct 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).
Base.eltype — Methodeltype(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.
Bramble.backend — Methodbackend(; 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
Bramble.backend_eye — Methodbackend_eye(backend::Backend, n)Constructs a square n x n sparse identity matrix associated with the given Backend instance.
Bramble.backend_types — Methodbackend_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.
Bramble.backend_zeros — Methodbackend_zeros(backend::Backend, n)Constructs a square n x n sparse matrix of zeros associated with the given Backend instance.
Bramble.matrix — Methodmatrix(backend::Backend, n::Integer, m::Integer)Create a matrix of the type MT associated with the given Backend instance with dimensions n x m.
Bramble.matrix_type — Methodmatrix_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.
Bramble.vector_type — Methodvector_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.
Linear Algebra
Bramble._dot — Method_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.
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-placeidxs: Iterable of indices to processf: Function that takes an index and returns the value to be stored at that index
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-placeidxs: Indices to iterate overf: Function to be applied at each index
Bramble Function
Bramble.BrambleFunction — Typestruct 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: aFunctionWrapperwrapper for the functiondomain: 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)
Bramble._embed_notime — Method_embed_notime(X, f; CoType)
A convenience constructor for creating a time-independent (hastime=false) BrambleFunction. It's a simplified wrapper around bramble_function_with_domain.
Bramble._embed_withtime — Method_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.
Bramble._get_args_type — Method_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}. Tis the element type of the domainX.
Bramble._get_domains — Method_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.
Bramble.argstype — Methodargstype(f::FunctionWrapper{CoType,Tuple{ArgsType}})Extracts the argument type ArgsType from a FunctionWrapper instance or type.
Bramble.bramble_function_with_domain — Methodbramble_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 off.hastime: A boolean indicating if the function is time-dependent.CoType: The codomain (return) type of the functionf.domain: The actual domain object to store in the struct (typicallyX).
Bramble.codomaintype — Methodcodomaintype(f::FunctionWrapper{CoType})Extracts the codomain type CoType from a FunctionWrapper instance or type.
Bramble.embed_function — Methodembed_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.
Bramble.has_time — Methodhas_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.