Peano
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
DLinear.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
13 Simple matrix generator for continuous d-linear finite elements
14
15 This factory method is there for convenience, i.e. users can take it to
16 pre-assemble local matrices and then to pipe it into the Peano 4 multigrid
17 classes. Most of the stuff in here in hard-coded, so only well-suited for
18 relatively primitive solvers. You might want to specialise these routines,
19 switch to a more sophisticated matrix generator, or abandon the idea of a
20 matrix generator altogether.
21
22 '''
23 def __init__(self,
24 dimensions,
25 unknowns_per_node,
26 ):
27
28 super( DLinear, self ).__init__(dimensions,
29 poly_degree = 1,
30 unknowns_per_node = unknowns_per_node
31 )
32
33 # Use matrices for DG Interior Penalty for Poisson equation as we only need the cell-cell and mass matrices, which are identical from CG
35
36 @property
37 def _cell_dofs(self):
38 """!
39 @todo should this be 2**D or (p+1)**D? suppose it's not relevant, given this is a linear solver
40 """
41 return 2**(self.dimensionsdimensions)
42
43
45 """!
46
47 Return identity matrix and a 0 as the identity matrix has no intrinsic
48 scaling, i.e. its scaling is @f$ h^0 @f$.
49
50 """
51 dim = self._cell_dofs * self.unknowns_per_vertex_dof
52 # identity matrix.
53 output = np.eye(dim,dim) * 2**(-self.dimensionsdimensions)
54 return output, 0
55
56
58 """!
59
60 Get this working for 2d.
61
62 What about 3d? If we select an index for the first dimension
63 and then sum over the other two (ie call np.sum( massMatrix[i,] ))
64 it will just add up all elements along the 2 other dimensions, as
65 if we flattened it. Is this what we want?
66 """
67 #get mass matrix
69 output = np.zeros_like(massMatrix)
70 for i in range( output.shape[0] ):
71 output[i,i] = np.sum( massMatrix[i,] )
72 return output
73
74
76 '''!
77
78 Create a cell-cell mass matrix
79
80 This matrix does not couple the individual unknowns per degree of freedom.
81 The resulting matrix has to be scaled by @f$ h^d @f$.
82
83 Use the mass matrix generated for DG Interior Penalty for Poisson equation.
84
85 '''
86 output = self.block_matrix._RHS_CC[(1,1)]
87 return [output], [self.dimensionsdimensions]
88
89
91 '''!
92
93 Create a cell-cell mass matrix
94
95 In a finite element context, this matrix has to be
96 scaled with @f$ h^{d-2} @f$. Therefore, we retturn d-2 as second argument.
97
98 Use the cell-cell matrix generated for DG Interior Penalty for Poisson equation.
99
100 '''
101
102 output = self.block_matrix._A_CC[(0,0)][(0,0)]
103 return [output], [self.dimensionsdimensions - 2]
Simple matrix generator for continuous d-linear finite elements.
Definition DLinear.py:10
get_cell_system_matrix_for_laplacian(self)
Create a cell-cell mass matrix.
Definition DLinear.py:90
get_cell_mass_matrix(self)
Create a cell-cell mass matrix.
Definition DLinear.py:75
get_lumped_mass_matrix(self)
Get this working for 2d.
Definition DLinear.py:57
get_cell_identity_matrix(self)
Return identity matrix and a 0 as the identity matrix has no intrinsic scaling, i....
Definition DLinear.py:44
__init__(self, dimensions, unknowns_per_node)
Definition DLinear.py:26
Base class for generating matrices that we pipe into the C++ code.
Classical DG discretisation of 2d classical Poisson formulation with spurious facet function spaces.