Solver
Solving a problem requires both spatial and stochastic discretization. These are combined into a specialized vector structure, which is then passed to a solver function that executes an iterative algorithm tailored to each model problem.
SGFEVector
The spatial discretization is defined by a single finite element space from ExtendableFEM.jl, while the stochastic discretization uses a tensorized basis for the parameter space of the stochastic coefficient. Both components must be set up in advance.
Currently, it is not possible to use different finite element spaces for different multi-indices. This feature may be added in the future.
ExtendableASGFEM.SGFEVector — Type
struct SGFEVector{T, Tv, Ti, ONBType<:ONBasis, MIType}A structure that extends ExtendableFEMBase.FEVector to include information about the stochastic discretization, specifically the associated TensorizedBasis.
Fields
FES_space: Array of finite element spaces for all stochastic modes.TB: The tensorized basis used for the stochastic discretization.active_modes: Indices of the active stochastic modes (with respect toTB.multi_indices).length4modes: Offsets for each mode in the global vector.FEVectorBlocks: Vector block mask for each multi-index (stochastic mode).entries: The full coefficient vector containing all degrees of freedom.last_sample: The last sample used for evaluation (for efficient repeated evaluation).FEV: AnFEVectorused for evaluating the SGFEVector at a given sample.
This structure enables efficient storage, evaluation, and manipulation of solutions in stochastic Galerkin finite element methods.
ExtendableASGFEM.SGFEVector — Method
SGFEVector(
FES::Array{<:ExtendableFEMBase.FESpace{Tv, Ti}, 1},
TB::TensorizedBasis{Tv, ONBType, MIType};
active_modes,
T,
unames
) -> SGFEVector
Constructs an SGFEVector for the given spatial finite element spaces FES and the tensorized basis TB representing the stochastic discretization.
Arguments
FES: Array of finite element spaces (one for each unknown).TB: The tensorized basis for the stochastic discretization.active_modes: Indices of the active stochastic modes to include (default: all modes inTB).T: The floating-point type for the coefficient vector (default:Tv).unames: Names or identifiers for the unknowns (default:1:length(FES)).
Returns
An SGFEVector object that stores the spatial and stochastic discretization, the coefficient vector, and all necessary metadata for efficient evaluation and manipulation in stochastic Galerkin FEM.
Base.getindex — Method
getindex(
SGFEV::SGFEVector,
u::Int64,
i::Int64
) -> ExtendableFEMBase.FEVectorBlock
returns the FEVectorBlock for the i-th stochastic mode of the u-th unknown
Base.getindex — Method
getindex(
SGFEV::SGFEVector,
i::Int64
) -> ExtendableFEMBase.FEVectorBlock
returns the i-th stochastic mode
Base.length — Method
length(SGFEV::SGFEVector) -> Int64
returns the length of the full vector, i.e., the total number of degrees of freedom
ExtendableASGFEM.fetypes — Method
fetypes(SGFEV::SGFEVector) -> Vector
returns the finite element types of the (spatial) FE spaces
ExtendableASGFEM.num_multiindices — Method
num_multiindices(SGFEV::SGFEVector) -> Int64
returns the number of active modes (that are used from the stored tensorized basis)
ExtendableASGFEM.set_sample! — Method
set_sample!(SGFEV::SGFEVector, S::AbstractVector)
Evaluates the SGFEVector at the given sample S and stores the result in SGFEV.FEV.
Arguments
SGFEV: The stochastic Galerkin finite element vector to evaluate.S: A vector representing the sample (values for the stochastic variables).
Details
- The sample
Sis stored inSGFEV.last_sample(truncated or padded as needed). - The tensorized basis is evaluated at
S, and the resulting coefficients are used to assemble the spatial solution inSGFEV.FEV. - This enables efficient evaluation of the SGFEM solution at arbitrary points in the stochastic parameter space.
Solve Dispatchers
ExtendableASGFEM.solve! — Method
solve!(
::Type{ExtendableASGFEM.AbstractModelProblem},
sol::SGFEVector,
C::AbstractStochasticCoefficient;
rhs,
use_iterative_solver,
bonus_quadorder_f,
bonus_quadorder_a,
kwargs...
)
Solves the specified model problem using the provided stochastic coefficient C and right-hand side rhs, writing the solution into sol.
The sol vector communicates both the spatial and stochastic discretization, as well as any initial data required for the iterative solver.
- If
use_iterative_solver(default:true) is set, an iterative solver is used. Otherwise, the full system matrix is assembled and solved directly (note: this is very slow for large systems). - The parameters
bonus_quadorder_f(default:0) andbonus_quadorder_a(default:2) allow you to increase the quadrature order for terms involving the right-hand side or the stochastic coefficient, respectively. - Additional keyword arguments can be passed via
kwargs.
If no solver is implemented for the given model problem, an error is thrown.
Poisson Primal Solvers
The primal stochastic Poisson problem can be solved both iteratively (matrix-free) and directly (full assembly). See Iterative Solution of the Primal Poisson Problem for a detailed explanation of the iterative algorithm.
ExtendableASGFEM.MyPreconditionerPrimal — Type
MyPreconditionerPrimal{Tv, FAC}Block-diagonal LU preconditioner for the primal SG Poisson system.
Each diagonal block is the inverse of the mean stiffness matrix $A_0$, obtained via LU factorisation. Boundary dofs are handled by stiffening those diagonal entries in the pre-factored $A_0$ so that forward/backward substitution implicitly enforces zero Dirichlet conditions.
Fields
LUA::FAC: LU factorisation of $A_0$ with stiffened boundary dofs.DA::Vector{Tv}: Diagonal of $A_0$ (kept for compatibility, not used in current path).bdofs::Vector{Int}: Boundary dofs.nmodes::Int: Number of stochastic modes.
ExtendableASGFEM.MyPreconditionerPrimal — Method
MyPreconditionerPrimal(A::ExtendableSparseMatrix, bdofs, nmodes)Construct a block-diagonal LU preconditioner from the mean matrix $A_0$.
Stiffens boundary diagonal entries to $1e60$ and precomputes the LU factorisation of the modified matrix. The factorisation is reused for every preconditioner-vector product in the GMRES iteration.
ExtendableASGFEM.MySystemPrimal — Type
MySystemPrimal{Tv, MT, VT, GT}Matrix-free block system evaluator for the primal stochastic Poisson problem.
Represents the block-structured linear operator arising from the stochastic Galerkin discretisation with a Karhunen-Loeve expanded diffusion coefficient. The operator acts on vectors partitioned by stochastic mode and implements mul! for matrix-vector products without assembling the full block matrix.
Fields
A0::MT: Mean diffusion block.Am::Vector{MT}: KL perturbation blocks (one per random dimension).G::GT: Coupling tensor with entriesG[e, mu, nu]mapping KL indiceseto mode pairs.bdofs::Vector{Int}: Boundary dofs for homogeneous Dirichlet conditions.nmodes::Int: Number of stochastic modes.
ExtendableASGFEM.solve_full_primal! — Method
solve_full_primal!(SolutionSGFEM::SGFEVector, A0, A, b, G, nmodes, rhsfac)Build the full block SG Poisson matrix and solve it with a direct backslash.
Assembles the complete block system into a $FEMatrix$ with $nmodes * nmodes$ blocks: the diagonal receives contributions from the mean operator $A_0$, and off-diagonal and diagonal blocks are filled by the KL perturbations $A_e$ weighted by the coupling tensor $G$. Boundary dofs are stiffened and RHS entries set to zero. The system is solved in a single line via Julia's $\$ operator.
This function is primarily useful for verification against the matrix-free solver $solve_primal!$ since it scales as $O((nmodes * ndofs)^3)$.
Arguments
SolutionSGFEM: Output $SGFEVector$ (modified in-place).A0: Mean stiffness block.A: Vector of KL-perturbation blocks.b: Right-hand side blocks.G: Coupling tensor.nmodes: Number of stochastic modes.rhsfac: Not used.
ExtendableASGFEM.solve_primal! — Method
solve_primal!(SolutionSGFEM::SGFEVector, A0, Am, b0, G, nmodes, bfac; atol, rtol)Solve the primal SG Poisson system iteratively using matrix-free preconditioned GMRES.
Builds a MySystemPrimal operator and a MyPreconditionerPrimal from the mean matrix $A_0$, KL perturbation blocks $A_m$, coupling tensor $G$, and boundary info extracted from the $SGFEVector$. The right-hand side is assembled by copying the solution vector, adding the deterministic force block $b_0$ to mode 1, and zeroing boundary entries on all modes.
Krylov.jl's $Krylov.gmres$ is used as the solver. Default tolerances are 1e-14.
Arguments
SolutionSGFEM: Output $SGFEVector$ (modified in-place).A0: Mean stiffness block.Am: Vector of KL-perturbation stiffness blocks.b0: Deterministic right-hand side block (applied to mode 1 only).G: Coupling tensor $G[e, mu, nu]$.nmodes: Number of stochastic modes.bfac: Not used.
Keywords
atol: Absolute GMRES tolerance (default 1.0e-14).rtol: Relative GMRES tolerance (default 1.0e-14).
LinearAlgebra.mul! — Method
LinearAlgebra.mul!(Ax, S::MySystemPrimal, x)Matrix-free matmul for the block-structured SG Poisson operator.
Computes the product $Ax$ in-place without assembling the full block matrix. For each stochastic mode $\mu$, the deterministic diffusion $A_0$ is applied to mode $\mu$ of $x$, and every KL perturbation $A_e$ is applied to mode $\nu$ of $x$ weighted by the coupling coefficient $G_{e,\mu,\nu}$. Boundary rows are zeroed out after accumulation.