3 #include "../../include/matrixFreePDE.h" 4 #include "../../include/varBCs.h" 5 #include <deal.II/grid/grid_generator.h> 8 template <
int dim,
int degree>
10 computing_timer.enter_section(
"matrixFreePDE: initialization");
14 pcout <<
"creating problem mesh...\n";
16 makeTriangulation(triangulation);
22 if (userInputs.resume_from_checkpoint){
23 load_checkpoint_triangulation();
27 triangulation.refine_global (userInputs.refine_factor);
33 pcout <<
"problem dimensions: " << userInputs.domain_size[0] <<
"x" << userInputs.domain_size[1] << std::endl;
36 pcout <<
"problem dimensions: " << userInputs.domain_size[0] <<
"x" << userInputs.domain_size[1] <<
"x" << userInputs.domain_size[2] << std::endl;
38 pcout <<
"number of elements: " << triangulation.n_global_active_cells() << std::endl;
42 pcout <<
"initializing matrix free object\n";
44 for(
typename std::vector<
Field<dim> >::iterator it = fields.begin(); it != fields.end(); ++it){
45 currentFieldIndex=it->index;
52 var_type =
"EXPLICIT_TIME_DEPENDENT";
55 var_type =
"IMPLICIT_TIME_DEPENDENT";
58 var_type =
"TIME_INDEPENDENT";
61 var_type =
"AUXILIARY";
64 sprintf(buffer,
"initializing finite element space P^%u for %9s:%6s field '%s'\n", \
67 (it->type==
SCALAR ?
"SCALAR":
"VECTOR"), \
73 isTimeDependentBVP=
true;
74 parabolicFieldIndex=it->index;
75 hasExplicitEquation=
true;
78 isTimeDependentBVP=
true;
79 ellipticFieldIndex=it->index;
80 hasNonExplicitEquation=
true;
81 std::cerr <<
"PRISMS-PF Error: IMPLICIT_TIME_DEPENDENT equation types are not currently supported" << std::endl;
85 parabolicFieldIndex=it->index;
86 ellipticFieldIndex=it->index;
87 hasNonExplicitEquation=
true;
91 ellipticFieldIndex=it->index;
92 hasNonExplicitEquation=
true;
99 fe=
new FESystem<dim>(FE_Q<dim>(QGaussLobatto<1>(degree+1)),1);
101 else if (it->type==
VECTOR){
102 fe=
new FESystem<dim>(FE_Q<dim>(QGaussLobatto<1>(degree+1)),dim);
105 pcout <<
"\nmatrixFreePDE.h: unknown field type\n";
111 DoFHandler<dim>* dof_handler;
113 dof_handler=
new DoFHandler<dim>(triangulation);
114 dofHandlersSet.push_back(dof_handler);
115 dofHandlersSet_nonconst.push_back(dof_handler);
117 dof_handler->distribute_dofs (*fe);
118 totalDOFs+=dof_handler->n_dofs();
121 IndexSet* locally_relevant_dofs;
123 locally_relevant_dofs=
new IndexSet;
124 locally_relevant_dofsSet.push_back(locally_relevant_dofs);
125 locally_relevant_dofsSet_nonconst.push_back(locally_relevant_dofs);
127 locally_relevant_dofs->clear();
128 DoFTools::extract_locally_relevant_dofs (*dof_handler, *locally_relevant_dofs);
131 ConstraintMatrix *constraintsDirichlet, *constraintsOther;
133 constraintsDirichlet=
new ConstraintMatrix; constraintsDirichletSet.push_back(constraintsDirichlet);
134 constraintsDirichletSet_nonconst.push_back(constraintsDirichlet);
135 constraintsOther=
new ConstraintMatrix; constraintsOtherSet.push_back(constraintsOther);
136 constraintsOtherSet_nonconst.push_back(constraintsOther);
137 valuesDirichletSet.push_back(
new std::map<dealii::types::global_dof_index, double>);
139 constraintsDirichlet->clear(); constraintsDirichlet->reinit(*locally_relevant_dofs);
140 constraintsOther->clear(); constraintsOther->reinit(*locally_relevant_dofs);
143 DoFTools::make_hanging_node_constraints (*dof_handler, *constraintsOther);
146 std::vector<int> rigidBodyModeComponents;
151 setPeriodicityConstraints(constraintsOther,dof_handler);
154 has_Dirichlet_BCs =
false;
155 for (
unsigned int i=0; i<fields.size(); i++){
156 for (
unsigned int direction = 0; direction < 2*dim; direction++){
157 if (userInputs.BC_list[i].var_BC_type[direction] ==
DIRICHLET){
158 has_Dirichlet_BCs =
true;
167 constraintsDirichlet->close();
168 constraintsOther->close();
171 valuesDirichletSet[it->index]->clear();
172 for (types::global_dof_index i=0; i<dof_handler->n_dofs(); i++){
173 if (locally_relevant_dofs->is_element(i)){
174 if (constraintsDirichlet->is_constrained(i)){
175 (*valuesDirichletSet[it->index])[i] = constraintsDirichlet->get_inhomogeneity(i);
180 sprintf(buffer,
"field '%2s' DOF : %u (Constraint DOF : %u)\n", \
181 it->name.c_str(), dof_handler->n_dofs(), constraintsDirichlet->n_constraints());
184 pcout <<
"total DOF : " << totalDOFs << std::endl;
187 typename MatrixFree<dim,double>::AdditionalData additional_data;
189 #if (DEAL_II_VERSION_MAJOR < 9 && DEAL_II_VERSION_MINOR < 5) 190 additional_data.mpi_communicator = MPI_COMM_WORLD;
192 additional_data.tasks_parallel_scheme = MatrixFree<dim,double>::AdditionalData::partition_partition;
194 additional_data.mapping_update_flags = (update_values | update_gradients | update_JxW_values | update_quadrature_points);
195 QGaussLobatto<1> quadrature (degree+1);
196 matrixFreeObject.clear();
197 matrixFreeObject.reinit (dofHandlersSet, constraintsOtherSet, quadrature, additional_data);
199 bool dU_scalar_init =
false;
200 bool dU_vector_init =
false;
203 pcout <<
"initializing parallel::distributed residual and solution vectors\n";
204 for(
unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
208 solutionSet.push_back(U); residualSet.push_back(R);
209 matrixFreeObject.initialize_dof_vector(*R, fieldIndex); *R=0;
211 matrixFreeObject.initialize_dof_vector(*U, fieldIndex); *U=0;
215 if (fields[fieldIndex].type ==
SCALAR){
216 if (dU_scalar_init ==
false){
217 matrixFreeObject.initialize_dof_vector(dU_scalar, fieldIndex);
218 dU_scalar_init =
true;
222 if (dU_vector_init ==
false){
223 matrixFreeObject.initialize_dof_vector(dU_vector, fieldIndex);
224 dU_vector_init =
true;
231 if (isTimeDependentBVP){
238 if (userInputs.resume_from_checkpoint){
239 load_checkpoint_fields();
242 applyInitialConditions();
248 for(
unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
249 soltransSet.push_back(
new parallel::distributed::SolutionTransfer<dim, vectorType>(*dofHandlersSet_nonconst[fieldIndex]));
253 for(
unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
254 constraintsDirichletSet[fieldIndex]->distribute(*solutionSet[fieldIndex]);
255 constraintsOtherSet[fieldIndex]->distribute(*solutionSet[fieldIndex]);
256 solutionSet[fieldIndex]->update_ghost_values();
260 if (!userInputs.resume_from_checkpoint){
265 if (userInputs.resume_from_checkpoint){
266 load_checkpoint_time_info();
269 computing_timer.exit_section(
"matrixFreePDE: initialization");
272 template <
int dim,
int degree>
275 GridGenerator::subdivided_hyper_rectangle (tria, userInputs.subdivisions, Point<dim>(), Point<dim>(userInputs.domain_size[0],userInputs.domain_size[1],userInputs.domain_size[2]));
278 GridGenerator::subdivided_hyper_rectangle (tria, userInputs.subdivisions, Point<dim>(), Point<dim>(userInputs.domain_size[0],userInputs.domain_size[1]));
281 GridGenerator::subdivided_hyper_rectangle (tria, userInputs.subdivisions, Point<dim>(), Point<dim>(userInputs.domain_size[0]));
285 markBoundaries(tria);
289 #include "../../include/matrixFreePDE_template_instantiations.h" virtual void makeTriangulation(parallel::distributed::Triangulation< dim > &) const
dealii::parallel::distributed::Vector< double > vectorType