1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Authors:
#     Loic Gouarin <loic.gouarin@cmap.polytechnique.fr>
#     Nicole Spillane <nicole.spillane@cmap.polytechnique.fr>
#
# License: BSD 3 clause
from .utils import buildVecWithFunction
from.assembling import buildMassMatrix

def buildRHS(da, h, apply_func):
    """
    Construct the right hand side of the elasticity problem.

    Parameters
    ==========

    da : petsc.DMDA
        The mesh structure.

    h : list
        The space step in each direction.

    apply_func: function
        Function corresponding to the f (rhs, or source term) in the 
        elasticity problem.

    Returns
    =======

    b: petsc.Vec
        The right hand side.

    """
    b = da.createGlobalVec()
    A = buildMassMatrix(da, h)
    A.assemble()
    tmp = buildVecWithFunction(da, apply_func)
    A.mult(tmp, b)
    return b