Documentation

assema

Assemble area integral contributions

Syntax

  • [K,M,F] = assema(model,c,a,f)
    example
  • [K,M,F] = assema(p,t,c,a,f)
    example

Description

example

[K,M,F] = assema(model,c,a,f) assembles the stiffness matrix K, the mass matrix M, and the load vector F using the mesh contained in model, and the PDE coefficients c, a, and f.

example

[K,M,F] = assema(p,t,c,a,f) assembles the matrices from the mesh data in p and t.

Examples

collapse all

Assemble Finite Element Matrices

Assemble finite element matrices for an elliptic problem on complicated geometry.

The PDE is Poisson's equation,

$$ -\nabla\cdot\nabla u = 1.$$

Partial Differential Equation Toolbox™ solves equations of the form

$$ -\nabla\cdot (c\nabla u) + au = f.$$

So, represent Poisson's equation in toolbox syntax by setting c = 1, a = 0, and f = 1.

c = 1;
a = 0;
f = 1;

Create a PDE model container. Import the ForearmLink.stl file into the model and examine the geometry.

model = createpde;
importGeometry(model,'ForearmLink.stl');
h = pdegplot(model);
h(1).FaceAlpha = 0.5;

Create a mesh for the model.

generateMesh(model);

Create the finite element matrics from the mesh and the coefficients.

[K,M,F] = assema(model,c,a,f);

The returned matrix K is quite sparse. M has no nonzero entries.

disp(['Fraction of nonzero entries in K is ',num2str(nnz(K)/numel(K))])
disp(['Number of nonzero entries in M is ',num2str(nnz(M))])
Fraction of nonzero entries in K is 0.0007101
Number of nonzero entries in M is 0

Assemble Finite Element Matrices Using Legacy Syntax

Assemble finite element matrices for the 2-D L-shaped region, using the legacy syntax.

Define the geometry using the lshapeg function included your software.

g = @lshapeg;

Use coefficients c = 1, a = 0, and f = 1.

c = 1;
a = 0;
f = 1;

Create a mesh and assemble the finite element matrices.

[p,e,t] = initmesh(g);
[K,M,F] = assema(p,t,c,a,f);

The returned matrix M has all zeros. The K matrix is quite sparse.

disp(['Fraction of nonzero entries in K is ',num2str(nnz(K)/numel(K))])
disp(['Number of nonzero entries in M is ',num2str(nnz(M))])
Fraction of nonzero entries in K is 0.042844
Number of nonzero entries in M is 0

Input Arguments

collapse all

model — PDE modelPDEModel object

PDE model, specified as a PDEModel object.

Example: model = createpde(1)

c — PDE coefficientscalar or matrix | character array | coefficient function

PDE coefficient, specified as a scalar or matrix, as a character array, or as a coefficient function. c represents the c coefficient in the scalar PDE

(cu)+au=f,

or in the system of PDEs

(cu)+au=f.

You can specifyc in various ways, detailed in c Coefficient for Systems. See also Scalar PDE Coefficients, Specify Scalar PDE Coefficients in String Form, Specify 2-D Scalar Coefficients in Function Form, Specify 3-D PDE Coefficients in Function Form, and Coefficients for Systems of PDEs.

Example: 'cosh(x+y.^2)'

Data Types: double | char | function_handle
Complex Number Support: Yes

a — PDE coefficientscalar or matrix | character array | coefficient function

PDE coefficient, specified as a scalar or matrix, as a character array, or as a coefficient function. a represents the a coefficient in the scalar PDE

(cu)+au=f,

or in the system of PDEs

(cu)+au=f.

You can specifya in various ways, detailed in a or d Coefficient for Systems. See also Scalar PDE Coefficients, Specify Scalar PDE Coefficients in String Form, Specify 2-D Scalar Coefficients in Function Form, Specify 3-D PDE Coefficients in Function Form, and Coefficients for Systems of PDEs.

Example: 2*eye(3)

Data Types: double | char | function_handle
Complex Number Support: Yes

f — PDE coefficientscalar or matrix | character array | coefficient function

PDE coefficient, specified as a scalar or matrix, as a character array, or as a coefficient function. f represents the f coefficient in the scalar PDE

(cu)+au=f,

or in the system of PDEs

(cu)+au=f.

You can specifyf in various ways, detailed in f Coefficient for Systems. See also Scalar PDE Coefficients, Specify Scalar PDE Coefficients in String Form, Specify 2-D Scalar Coefficients in Function Form, Specify 3-D PDE Coefficients in Function Form, and Coefficients for Systems of PDEs.

Example: char('sin(x)';'cos(y)';'tan(z)')

Data Types: double | char | function_handle
Complex Number Support: Yes

p — Mesh nodesoutput of initmesh | output of meshToPet

Mesh nodes, specified as the output of initmesh or meshToPet. For the structure of a p matrix, see Mesh Data for [p,e,t] Triples: 2-D and Mesh Data for [p,e,t] Triples: 3-D.

Example: [p,e,t] = initmesh(g)

Data Types: double

t — Mesh elementsoutput of initmesh | output of meshToPet

Mesh elements, specified as the output of initmesh or meshToPet. Mesh elements are the triangles or tetrahedra that form the finite element mesh. For the structure of a t matrix, see Mesh Data for [p,e,t] Triples: 2-D and Mesh Data for [p,e,t] Triples: 3-D.

Example: [p,e,t] = initmesh(g)

Data Types: double

Output Arguments

collapse all

K — Stiffness matrixsparse matrix

Stiffness matrix, returned as a sparse matrix. See Elliptic Equations.

Typically, you use K in a subsequent call to assempde.

M — Mass matrixsparse matrix

Mass matrix. returned as a sparse matrix. See Elliptic Equations.

Typically, you use M in a subsequent call to a solver such as assempde or hyperbolic.

F — Load vectorvector

Load vector, returned as a vector. See Elliptic Equations.

Typically, you use F in a subsequent call to assempde.

See Also

|

Introduced before R2006a

Was this topic helpful?