This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

assembleFEMatrices

Assemble finite element matrices

Syntax

FEM = assembleFEMatrices(model)
FEM = assembleFEMatrices(model,bcmethod)

Description

example

FEM = assembleFEMatrices(model) returns a structure containing finite element matrices for the PDE problem in model.

example

FEM = assembleFEMatrices(model,bcmethod) assembles finite element matrices and imposes boundary conditions using the method specified by bcmethod.

Examples

collapse all

Create a PDEModel for the Poisson equation on the L-shaped membrane with zero Dirichlet boundary conditions.

model = createpde(1);
geometryFromEdges(model,@lshapeg);
specifyCoefficients(model,'m',0,'d',0,'c',1,'a',0,'f',1);
applyBoundaryCondition(model,'edge',1:model.Geometry.NumEdges,'u',0);

Generate a mesh and obtain the default finite element matrices for the problem and mesh.

generateMesh(model,'Hmax',0.2);
FEM = assembleFEMatrices(model)
FEM = struct with fields:
    K: [401x401 double]
    A: [401x401 double]
    F: [401x1 double]
    Q: [401x401 double]
    G: [401x1 double]
    H: [80x401 double]
    R: [80x1 double]
    M: [401x401 double]

Create a PDEModel for the Poisson equation on the L-shaped membrane with zero Dirichlet boundary conditions.

model = createpde(1);
geometryFromEdges(model,@lshapeg);
specifyCoefficients(model,'m',0,'d',0,'c',1,'a',0,'f',1);
applyBoundaryCondition(model,'edge',1:model.Geometry.NumEdges,'u',0);

Generate a mesh and obtain the nullspace finite element matrices for the problem and mesh.

generateMesh(model,'Hmax',0.2);
FEM = assembleFEMatrices(model,'nullspace')
FEM = struct with fields:
    Kc: [321x321 double]
    Fc: [321x1 double]
     B: [401x321 double]
    ud: [401x1 double]
     M: [321x321 double]

Obtain the solution to the PDE.

u = FEM.B*(FEM.Kc\FEM.Fc) + FEM.ud;

Compare to the solution using solvepde. The two solutions are identical.

u1 = solvepde(model);
norm(u - u1.NodalSolution)
ans = 0

Input Arguments

collapse all

PDE model, specified as a PDEModel object.

Example: model = createpde

Method for including boundary conditions, specified as 'none', 'nullspace', or 'stiff-spring'. For the meaning and use of bcmethod, see Algorithms.

Example: FEM = assembleFEMatrices(model,'nullspace')

Data Types: char | string

Output Arguments

collapse all

Finite element matrices, returned as a structure. The fields in the structure depend on bcmethod. (These fields correspond to the legacy assempde outputs with the same names, except that there are now both A and M matrices.)

  • 'none' or no bcmethod given — The fields are K, A, F, Q, G, H, R, M.

  • 'nullspace' — The fields are Kc, Fc, B, ud, M.

  • 'stiff-spring' — The fields are Ks, Fs, M.

For the meaning and use of FEM, see Algorithms.

Tips

Algorithms

The full finite element matrices and vectors are the following:

  • K is the stiffness matrix, the integral of the c coefficient against the basis functions.

  • M is the mass matrix, the integral of the m or d coefficient against the basis functions.

  • A is the integral of the a coefficient against the basis functions.

  • F is the integral of the f coefficient against the basis functions.

  • Q is the integral of the q boundary condition against the basis functions.

  • G is the integral of the g boundary condition against the basis functions.

  • The H and R matrices come directly from the Dirichlet conditions and the mesh.

Given these matrices, the 'nullspace' technique generates the combined finite element matrices [Kc,Fc,B,ud] as follows. The combined stiffness matrix is for the reduced linear system, Kc = K + M + Q. The corresponding combined load vector is Fc = F + G. The B matrix spans the null space of the columns of H (the Dirichlet condition matrix representing hu = r). The R vector represents the Dirichlet conditions in Hu = R. The ud vector represents boundary condition solutions for the Dirichlet conditions.

From the 'nullspace' matrices, you can compute the solution u as

u = B*(Kc\Fc) + ud.

Note

Internally, for time-independent problems, solvepde uses the 'nullspace' technique, and calculates solutions using u = B*(Kc\Fc) + ud.

Alternatively, the 'stiff-spring' technique returns a matrix Ks and a vector Fs that together represent a different type of combined finite element matrices. The approximate solution u is u = Ks\Fs.

The 'stiff-spring' technique generates matrices more quickly than the 'nullspace' technique, but the 'stiff-spring' technique generally gives less accurate solutions.

Introduced in R2016a