Peano
Loading...
Searching...
No Matches
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 )
31
32 self.unknowns_per_nodeunknowns_per_node = unknowns_per_node
33
34 # Use matrices for DG Interior Penalty for Poisson equation as we only need the cell-cell and mass matrices, which are identical from CG
36
37 @property
38 def _cell_dofs(self):
39 """!
40 @todo should this be 2**D or (p+1)**D? suppose it's not relevant, given this is a linear solver
41 """
42 return 2**(self.dimensionsdimensions)
43
44
46 """!
47
48 Return identity matrix and a 0 as the identity matrix has no intrinsic
49 scaling, i.e. its scaling is @f$ h^0 @f$.
50
51 """
52 dim = self._cell_dofs * self.unknowns_per_vertex_dof
53 # identity matrix.
54 output = np.eye(dim,dim) * 2**(-self.dimensionsdimensions)
55 return output, 0
56
57
59 """!
60
61 Get this working for 2d.
62
63 What about 3d? If we select an index for the first dimension
64 and then sum over the other two (ie call np.sum( massMatrix[i,] ))
65 it will just add up all elements along the 2 other dimensions, as
66 if we flattened it. Is this what we want?
67 """
68 #get mass matrix
70 output = np.zeros_like(massMatrix)
71 for i in range( output.shape[0] ):
72 output[i,i] = np.sum( massMatrix[i,] )
73 return output
74
75
77 '''!
78
79 Create a cell-cell mass matrix
80
81 This matrix does not couple the individual unknowns per degree of freedom.
82 The resulting matrix has to be scaled by @f$ h^d @f$.
83
84 Use the mass matrix generated for DG Interior Penalty for Poisson equation.
85
86 '''
87 output = self.block_matrix._RHS_CC[(1,1)]
88 return [output], [self.dimensionsdimensions]
89
90
92 '''!
93
94 Create a cell-cell mass matrix
95
96 In a finite element context, this matrix has to be
97 scaled with @f$ h^{d-2} @f$. Therefore, we retturn d-2 as second argument.
98
99 Use the cell-cell matrix generated for DG Interior Penalty for Poisson equation.
100
101 '''
102
103 output = self.block_matrix._A_CC[(0,0)][(0,0)]
104 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:91
get_cell_mass_matrix(self)
Create a cell-cell mass matrix.
Definition DLinear.py:76
get_lumped_mass_matrix(self)
Get this working for 2d.
Definition DLinear.py:58
get_cell_identity_matrix(self)
Return identity matrix and a 0 as the identity matrix has no intrinsic scaling, i....
Definition DLinear.py:45
__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.