PRISMS-PF  v2.1
reinit.cc
Go to the documentation of this file.
1 // reinit() method for MatrixFreePDE class
2 
3 #include "../../include/matrixFreePDE.h"
4 
5  //populate with fields and setup matrix free system
6 template <int dim, int degree>
8 
9  computing_timer.enter_section("matrixFreePDE: reinitialization");
10 
11  //setup system
12  pcout << "Reinitializing matrix free object\n";
13  totalDOFs=0;
14  for(typename std::vector<Field<dim> >::iterator it = fields.begin(); it != fields.end(); ++it){
15  currentFieldIndex=it->index;
16 
17  char buffer[100];
18 
19  //create FESystem
20  FESystem<dim>* fe;
21  fe=FESet.at(it->index);
22 
23  //distribute DOFs
24  DoFHandler<dim>* dof_handler;
25  dof_handler=dofHandlersSet_nonconst.at(it->index);
26 
27  dof_handler->distribute_dofs (*fe);
28  totalDOFs+=dof_handler->n_dofs();
29 
30  //extract locally_relevant_dofs
31  IndexSet* locally_relevant_dofs;
32  locally_relevant_dofs=locally_relevant_dofsSet_nonconst.at(it->index);
33 
34  locally_relevant_dofs->clear();
35  DoFTools::extract_locally_relevant_dofs (*dof_handler, *locally_relevant_dofs);
36 
37  //create constraints
38  ConstraintMatrix *constraintsDirichlet, *constraintsOther;
39 
40  constraintsDirichlet=constraintsDirichletSet_nonconst.at(it->index);
41  constraintsOther=constraintsOtherSet_nonconst.at(it->index);
42 
43  constraintsDirichlet->clear(); constraintsDirichlet->reinit(*locally_relevant_dofs);
44  constraintsOther->clear(); constraintsOther->reinit(*locally_relevant_dofs);
45 
46  // Get hanging node constraints
47  DoFTools::make_hanging_node_constraints (*dof_handler, *constraintsOther);
48 
49  // Add a constraint to fix the value at the origin to zero if all BCs are zero-derivative or periodic
50  std::vector<int> rigidBodyModeComponents;
51  getComponentsWithRigidBodyModes(rigidBodyModeComponents);
52  setRigidBodyModeConstraints(rigidBodyModeComponents,constraintsOther,dof_handler);
53 
54  // Get constraints for periodic BCs
55  setPeriodicityConstraints(constraintsOther,dof_handler);
56 
57  // Get constraints for Dirichlet BCs
58  applyDirichletBCs();
59 
60  constraintsDirichlet->close();
61  constraintsOther->close();
62 
63  // Store Dirichlet BC DOF's
64  valuesDirichletSet[it->index]->clear();
65  for (types::global_dof_index i=0; i<dof_handler->n_dofs(); i++){
66  if (locally_relevant_dofs->is_element(i)){
67  if (constraintsDirichlet->is_constrained(i)){
68  (*valuesDirichletSet[it->index])[i] = constraintsDirichlet->get_inhomogeneity(i);
69  }
70  }
71  }
72 
73  sprintf(buffer, "field '%2s' DOF : %u (Constraint DOF : %u)\n", \
74  it->name.c_str(), dof_handler->n_dofs(), constraintsDirichlet->n_constraints());
75  pcout << buffer;
76  }
77  pcout << "total DOF : " << totalDOFs << std::endl;
78 
79  // Setup the matrix free object
80  typename MatrixFree<dim,double>::AdditionalData additional_data;
81  // The member "mpi_communicator" was removed in deal.II version 8.5 but is required before it
82  #if (DEAL_II_VERSION_MAJOR < 9 && DEAL_II_VERSION_MINOR < 5)
83  additional_data.mpi_communicator = MPI_COMM_WORLD;
84  #endif
85  additional_data.tasks_parallel_scheme = MatrixFree<dim,double>::AdditionalData::partition_partition;
86  //additional_data.tasks_parallel_scheme = MatrixFree<dim,double>::AdditionalData::none;
87  //additional_data.tasks_block_size = 1; // This improves performance for small runs, not sure about larger runs
88  additional_data.mapping_update_flags = (update_values | update_gradients | update_JxW_values | update_quadrature_points);
89  QGaussLobatto<1> quadrature (degree+1);
90  matrixFreeObject.clear();
91  matrixFreeObject.reinit (dofHandlersSet, constraintsOtherSet, quadrature, additional_data);
92 
93  bool dU_scalar_init = false;
94  bool dU_vector_init = false;
95 
96  // Setup solution vectors
97  pcout << "initializing parallel::distributed residual and solution vectors\n";
98  for(unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
99  vectorType *U;
100 
101  U=solutionSet.at(fieldIndex);
102 
103  matrixFreeObject.initialize_dof_vector(*U, fieldIndex); *U=0;
104 
105  // Initializing temporary dU vector required for implicit solves of the elliptic equation.
106  if (fields[fieldIndex].pdetype==TIME_INDEPENDENT || fields[fieldIndex].pdetype==IMPLICIT_TIME_DEPENDENT || (fields[fieldIndex].pdetype==AUXILIARY && userInputs.var_nonlinear[fieldIndex])){
107  if (fields[fieldIndex].type == SCALAR){
108  if (dU_scalar_init == false){
109  matrixFreeObject.initialize_dof_vector(dU_scalar, fieldIndex);
110  dU_scalar_init = true;
111  }
112  }
113  else {
114  if (dU_vector_init == false){
115  matrixFreeObject.initialize_dof_vector(dU_vector, fieldIndex);
116  dU_vector_init = true;
117  }
118  }
119  }
120  }
121 
122  // Compute invM in PDE is a time-dependent BVP
123  if (isTimeDependentBVP){
124  computeInvM();
125  }
126 
127  // Transfer solution from previous mesh
128  for(unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
129 
130  //interpolate and clear used solution transfer sets
131  soltransSet[fieldIndex]->interpolate(*solutionSet[fieldIndex]);
132  delete soltransSet[fieldIndex];
133 
134  //reset residual vector
135  vectorType *R=residualSet.at(fieldIndex);
136  matrixFreeObject.initialize_dof_vector(*R, fieldIndex); *R=0;
137  }
138 
139  // Create new solution transfer sets
140  soltransSet.clear();
141  for(unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
142  soltransSet.push_back(new parallel::distributed::SolutionTransfer<dim, vectorType>(*dofHandlersSet_nonconst[fieldIndex]));
143  }
144 
145  // If remeshing at the zeroth time step, re-apply initial conditions so the starting values are correct on the refined mesh
146  if (currentIncrement == 0 && !userInputs.load_grain_structure){
147  applyInitialConditions();
148  }
149 
150  // Ghost the solution vectors. Also apply the Dirichet BC's (if any) on the solution vectors
151  for(unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
152  constraintsDirichletSet[fieldIndex]->distribute(*solutionSet[fieldIndex]);
153  constraintsOtherSet[fieldIndex]->distribute(*solutionSet[fieldIndex]);
154  solutionSet[fieldIndex]->update_ghost_values();
155  }
156 
157  computing_timer.exit_section("matrixFreePDE: reinitialization");
158 }
159 
160 #include "../../include/matrixFreePDE_template_instantiations.h"
Definition: fields.h:9
void reinit()
Definition: reinit.cc:7
dealii::parallel::distributed::Vector< double > vectorType
Definition: FloodFiller.h:15