LifeV
MatrixGraph.cpp
Go to the documentation of this file.
1 #include <lifev/core/fem/MatrixGraph.hpp>
2 #include <chrono>
3 using namespace std::chrono;
4 
5 using namespace std;
6 
7 using namespace LifeV;
8 
9 //=========================================================================
10 // Constructor
11 MatrixGraph::MatrixGraph( const meshPtr_Type& mesh, const commPtr_Type& comm, const ReferenceFE* refFE ) :
12  M_mesh ( mesh ),
13  M_comm ( comm ),
14  M_referenceFE ( refFE )
15 {
16 }
17 //=========================================================================
18 // Destructor //
20 {
21  //---------------------
22 
23  for( int i = 0 ; i < M_numElements ; i++ )
24  {
25  delete [] M_elements[i];
26  }
27  delete [] M_elements;
28 
29  //---------------------
30 
31  for( int i = 0 ; i < M_numElements ; i++ )
32  {
33  delete [] M_rows[i];
34  delete [] M_cols[i];
35  }
36  delete [] M_rows;
37  delete [] M_cols;
38 }
39 //=========================================================================
40 void
41 MatrixGraph::buildGraph ( const int& numElements, CurrentFE* fe, const fespacePtr_Type& fespace, graphPtr_Type& matrix_graph )
42 {
43  M_numElements = numElements;
44 
45  M_numScalarDofs = fespace->dof().numTotalDof();
46 
47  //-------------------------------------------------------------------------------------------------
48  // ALLOCATE MEMORY
49  //-------------------------------------------------------------------------------------------------
50 
51  M_elements = new double* [ M_numElements ];
52 
53  for ( int i = 0; i < M_numElements; i++ )
54  {
55  M_elements[i] = new double [ M_referenceFE->nbDof() ];
56  }
57 
58  for ( int i = 0; i < M_numElements; i++ )
59  {
60  for ( int j = 0; j < M_referenceFE->nbDof(); j++ )
61  {
62  M_elements[i][j] = fespace->dof().localToGlobalMap (i, j);
63  }
64  }
65 
66  M_rows = new int* [M_numElements];
67 
68  for ( int i_elem = 0; i_elem < M_numElements; i_elem++ )
69  {
70  M_rows[i_elem] = new int [ M_referenceFE->nbDof() ];
71  }
72 
73  M_cols = new int* [M_numElements];
74 
75  for ( int i_elem = 0; i_elem < M_numElements; i_elem++ )
76  {
77  M_cols[i_elem] = new int [ M_referenceFE->nbDof() ];
78  }
79 
80  //-------------------------------------------------------------------------------------------------
81  // BUILD GRAPH
82  //-------------------------------------------------------------------------------------------------
83 
84  matrix_graph.reset (new graph_Type (Copy, *(fespace->map().map (Unique) ), 0 ) );
85 
86  int ndof = M_referenceFE->nbDof();
87 
88  for ( int i_elem = 0; i_elem < M_numElements ; i_elem++ )
89  {
90  // DOF - test
91  for ( int i_test = 0; i_test < ndof; i_test++ )
92  {
93  M_rows[i_elem][i_test] = M_elements[i_elem][i_test];
94 
95  // DOF - trial
96  for ( int i_trial = 0; i_trial < ndof; i_trial++ )
97  {
98  M_cols[i_elem][i_trial] = M_elements[i_elem][i_trial];
99  }
100  }
101 
102  matrix_graph->InsertGlobalIndices ( ndof, M_rows[i_elem], ndof, M_cols[i_elem] );
103 
104  for ( UInt d1 = 1; d1 < 3 ; d1++ )
105  {
106  for ( UInt i = 0; i < ndof; i++ )
107  {
108  M_rows[i_elem][i] += M_numScalarDofs;
109  M_cols[i_elem][i] += M_numScalarDofs;
110  }
111  matrix_graph->InsertGlobalIndices ( ndof, M_rows[i_elem], ndof, M_cols[i_elem] );
112  }
113  }
114 
115  matrix_graph->GlobalAssemble();
116 
117 }
void buildGraph(const int &numElements, CurrentFE *fe, const fespacePtr_Type &fespace, graphPtr_Type &matrix_graph)
Build the matrix graph.
Definition: MatrixGraph.cpp:41
const ReferenceFE * M_referenceFE
void updateInverseJacobian(const UInt &iQuadPt)
~MatrixGraph()
Destructor.
Definition: MatrixGraph.cpp:19
boost::shared_ptr< graph_Type > graphPtr_Type
Definition: MatrixGraph.hpp:63
CurrentFE - A primordial class for the assembly of the local matrices/vectors retaining the values on...
Definition: CurrentFE.hpp:243
The class for a reference Lagrangian finite element.
double ** M_elements
Definition: MatrixGraph.hpp:99
boost::shared_ptr< fespace_Type > fespacePtr_Type
Definition: MatrixGraph.hpp:66
MatrixGraph(const meshPtr_Type &mesh, const commPtr_Type &comm, const ReferenceFE *refFE)
Constructor.
Definition: MatrixGraph.cpp:11
boost::shared_ptr< comm_Type > commPtr_Type
Definition: MatrixGraph.hpp:60
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
boost::shared_ptr< mesh_Type > meshPtr_Type
Definition: MatrixGraph.hpp:57