Peano
Loading...
Searching...
No Matches
DLinearMassIdentity.py
Go to the documentation of this file.
1# This file is part of the Peano multigrid project. For conditions of
2# distribution and use, please see the copyright notice at www.peano-framework.org
3import numpy as np
4import peano4
5import mghype
6
7from .MatrixGenerator import MatrixGenerator
8
9
11 '''!
12 Using normalised identity matrix instead of the mass matrix.
13 This is necessary when the residual is computed as b-A*u instead of
14 M*b-A*u, for example, when using CG solver for the coarse-grid correction
15 in multigrid.
16
17 ---
18
19 Simple matrix generator for continuous d-linear finite elements
20
21 This factory method is there for convenience, i.e. users can take it to
22 pre-assemble local matrices and then to pipe it into the Peano 4 multigrid
23 classes. Most of the stuff in here in hard-coded, so only well-suited for
24 relatively primitive solvers. You might want to specialise these routines,
25 switch to a more sophisticated matrix generator, or abandon the idea of a
26 matrix generator altogether.
27
28 '''
29 def __init__(self,
30 dimensions,
31 poly_degree,
32 unknowns_per_node,
33 ):
34
35 super( DLinearMassIdentity, self ).__init__(dimensions,
36 poly_degree,
37 )
38 self.unknowns_per_nodeunknowns_per_node = unknowns_per_node
39
40 # Use matrices for DG Interior Penalty for Poisson equation as we only need the cell-cell and mass matrices, which are identical fro CG
42
43 @property
44 def _cell_dofs(self):
45 """!
46 @todo should this be 2**D or (p+1)**D? suppose it's not relevant, given this is a linear solver
47 """
48 return 2**(self.dimensionsdimensions)
49
50
52 """!
53
54 Return identity matrix and a 0 as the identity matrix has no intrinsic
55 scaling, i.e. its scaling is @f$ h^0 @f$.
56
57 """
59 # identity matrix.
60 output = np.eye(dim,dim) * 2**(-self.dimensionsdimensions)
61 return output, 0
62
63
65 """!
66
67 Get this working for 2d.
68
69 What about 3d? If we select an index for the first dimension
70 and then sum over the other two (ie call np.sum( massMatrix[i,] ))
71 it will just add up all elements along the 2 other dimensions, as
72 if we flattened it. Is this what we want?
73 """
74 #get mass matrix
76 output = np.zeros_like(massMatrix)
77 for i in range( output.shape[0] ):
78 output[i,i] = np.sum( massMatrix[i,] )
79 return output
80
81
83 '''!
84 Here we use a normalised identity matrix instead of the mass matrix.
85 To achieve the result (Id_global * b_global), the local matrix should be
86 divided by 2^dimensions, see get_cell_identity_matrix().
87 For example, in 2D, it is 0.25*Id, which, when summed
88 for 4 cells sharing each interior vertex, will result in the global identity.
89 Note that this does not differentiate between interior and boundary vertices.
90
91 ---
92
93 Create a cell-cell mass matrix
94
95 This matrix does not couple the individual unknowns per degree of freedom.
96 The resulting matrix has to be scaled by @f$ h^d @f$.
97
98 Use the mass matrix generated for DG Interior Penalty for Poisson equation.
99
100 '''
102
103 return [output], [0]
104
105
107 '''!
108
109 Create a cell-cell mass matrix
110
111 In a finite element context, this matrix has to be
112 scaled with @f$ h^{d-2} @f$. Therefore, we retturn d-2 as second argument.
113
114 Use the cell-cell matrix generated for DG Interior Penalty for Poisson equation.
115
116 '''
117
118 output = self.block_matrix._A_CC[(0,0)][(0,0)]
119 return [output], [self.dimensionsdimensions - 2]
Using normalised identity matrix instead of the mass matrix.
get_cell_mass_matrix(self)
Here we use a normalised identity matrix instead of the mass matrix.
__init__(self, dimensions, poly_degree, unknowns_per_node)
get_cell_identity_matrix(self)
Return identity matrix and a 0 as the identity matrix has no intrinsic scaling, i....
Base class for generating matrices that we pipe into the C++ code.
get_cell_identity_matrix(self)
Construct identity for this particular equation system.
Classical DG discretisation of 2d classical Poisson formulation with spurious facet function spaces.