PRISMS-PF  v2.1
invM.cc
Go to the documentation of this file.
1 //computeInvM() method for MatrixFreePDE class
2 
3 #include "../../include/matrixFreePDE.h"
4 
5 //compute inverse of the diagonal mass matrix and store in vector invM
6 template <int dim, int degree>
8  //initialize invM
9  bool invMInitialized=false;
10  unsigned int parabolicFieldIndex=0;
11  for(unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
12  if (fields[fieldIndex].pdetype==EXPLICIT_TIME_DEPENDENT || fields[fieldIndex].pdetype==AUXILIARY){
13  matrixFreeObject.initialize_dof_vector (invM, fieldIndex);
14  parabolicFieldIndex=fieldIndex;
15  invMInitialized=true;
16  break;
17  }
18  }
19  //check if invM initialized
20  if (!invMInitialized){
21  pcout << "matrixFreePDE.h: no PARABOLIC field... hence setting parabolicFieldIndex to 0 and marching ahead withn invM computation\n";
22  //exit(-1);
23  }
24 
25  //compute invM
26  matrixFreeObject.initialize_dof_vector (invM, parabolicFieldIndex);
27  invM=0.0;
28 
29  //select gauss lobatto quadrature points which are suboptimal but give diagonal M
30  if (fields[parabolicFieldIndex].type==SCALAR){
31  VectorizedArray<double> one = make_vectorized_array (1.0);
32  FEEvaluation<dim,degree> fe_eval(matrixFreeObject, parabolicFieldIndex);
33  const unsigned int n_q_points = fe_eval.n_q_points;
34  for (unsigned int cell=0; cell<matrixFreeObject.n_macro_cells(); ++cell){
35  fe_eval.reinit(cell);
36  for (unsigned int q=0; q<n_q_points; ++q){
37  fe_eval.submit_value(one,q);
38  }
39  fe_eval.integrate (true,false);
40  fe_eval.distribute_local_to_global (invM);
41  }
42  }
43  else {
44  dealii::Tensor<1, dim, dealii::VectorizedArray<double> > oneV;
45  for (unsigned int i=0;i<dim;i++){
46  oneV[i] = 1.0;
47  }
48 
49  FEEvaluation<dim,degree,degree+1,dim> fe_eval(matrixFreeObject, parabolicFieldIndex);
50 
51  const unsigned int n_q_points = fe_eval.n_q_points;
52  for (unsigned int cell=0; cell<matrixFreeObject.n_macro_cells(); ++cell){
53  fe_eval.reinit(cell);
54  for (unsigned int q=0; q<n_q_points; ++q){
55  fe_eval.submit_value(oneV,q);
56  }
57  fe_eval.integrate (true,false);
58  fe_eval.distribute_local_to_global (invM);
59  }
60  }
61 
62 
63  invM.compress(VectorOperation::add);
64  //invert mass matrix diagonal elements
65  for (unsigned int k=0; k<invM.local_size(); ++k){
66  if (std::abs(invM.local_element(k))>1.0e-15){
67  invM.local_element(k) = 1./invM.local_element(k);
68  }
69  else{
70  invM.local_element(k) = 0;
71  }
72  }
73  pcout << "computed mass matrix (using FE space for field: " << parabolicFieldIndex << ")\n";
74 }
75 
76 #include "../../include/matrixFreePDE_template_instantiations.h"
void computeInvM()
Definition: invM.cc:7