Peano
Loading...
Searching...
No Matches
matrices.py
Go to the documentation of this file.
1import numpy as np
2from numpy.polynomial.legendre import leggauss
3from scipy.interpolate import lagrange
4import peano4, petsc
5from petsc.matrixgenerators import MatrixGeneratorBase
6
7
8class DgGenerator(MatrixGeneratorBase):
9 '''
10 use this class to pre-generate matrices to be used
11 in Peano as far as possible.
12 '''
13 def __init__(self,
14 dimensions,
15 poly_degree,
16 unknowns_per_cell_dof):
17
18 #set unknowns per face dof to be the same for now
19
20 super( DgGenerator, self ).__init__(dimensions,
21 poly_degree,
22 unknowns_per_cell_dof,
23 unknowns_per_cell_dof)
24
26 '''
27 needs to be scaled by h**2
28 '''
29 dim = self.celldofs * self.unknowns_per_cell_dof
30 output = np.eye(dim,dim)
31 return output
32 # for i in range( self.celldofs ):
33 # for j in range( self.celldofs ):
34 # output[3*i+1, 3*j+1] += self.evaluateIntegral2d(functions2d=[ self.getPoly2d(i), self.getPoly2d(j) ]) # phi_x-phi_x coupling
35 # output[3*i+2, 3*j+2] += self.evaluateIntegral2d(functions2d=[ self.getPoly2d(i), self.getPoly2d(j) ]) # phi_y-phi_y coupling
36 # return output
37
39 '''
40 needs to be scaled 0.5*h, that is why we use factor=2.0 as evaluateIntegral2d() has coeff. 0.25 as default,
41 so normalise by h
42 '''
43 dim = self.celldofs * self.unknowns_per_cell_dof
44 output = np.eye(dim,dim)
45 return output
46 # for i in range( self.celldofs ):
47 # for j in range( self.celldofs ):
48 # # They are all the same, but they don't have to be!
49 # # We should have different getDeriv2d, getPoly2d for different fields: u, phi_x, phi_y
50 # output[3*i+1, 3*j] += self.evaluateIntegral2d(factor=2.0, functions2d=[ self.getDeriv2d(i,0), self.getPoly2d(j) ]) # phi_x-u coupling
51 # output[3*i+2, 3*j] += self.evaluateIntegral2d(factor=2.0, functions2d=[ self.getDeriv2d(i,1), self.getPoly2d(j) ]) # phi_y-u coupling
52 # output[3*i, 3*j+1] += self.evaluateIntegral2d(factor=2.0, functions2d=[ self.getDeriv2d(i,0), self.getPoly2d(j) ]) # u-phi_x coupling
53 # output[3*i, 3*j+2] += self.evaluateIntegral2d(factor=2.0, functions2d=[ self.getDeriv2d(i,1), self.getPoly2d(j) ]) # u-phi_y coupling
54 # return output
55
57 faceDim = self.facedofs * self.unknowns_per_face_dof * 2 * self.dimensions * 2 # * 2 at the end since we are glueing together 2 faces
58 cellDim = self.celldofs * self.unknowns_per_cell_dof
59 return np.eye(faceDim,cellDim)
60
62 dim = self.facedofs * self.unknowns_per_face_dof * 2 # * 2 at the end since we are glueing together 2 faces
63 return np.eye(dim,dim)
64
use this class to pre-generate matrices to be used in Peano as far as possible.
Definition matrices.py:8
getCellCellMassMatrix(self)
needs to be scaled by h**2
Definition matrices.py:25
getCellCellSystemMatrix(self)
needs to be scaled 0.5*h, that is why we use factor=2.0 as evaluateIntegral2d() has coeff.
Definition matrices.py:38
getCellToFaceMatrix(self)
Definition matrices.py:56
__init__(self, dimensions, poly_degree, unknowns_per_cell_dof)
Definition matrices.py:16