1248 * (dynamic_sparsity_pattern, dof_handler.n_locally_owned_dofs_per_processor(),
1249 * mpi_communicator, locally_relevant_dofs);
1251 * system_rhs.reinit(locally_owned_dofs, mpi_communicator);
1252 * system_matrix.reinit(locally_owned_dofs, dynamic_sparsity_pattern,
1253 * mpi_communicator);
1255 * CDR::create_system_matrix<dim>
1256 * (dof_handler, quad, convection_function, parameters, time_step, constraints,
1259 * preconditioner.initialize(system_matrix);
1264 *
void CDRProblem<dim>::time_iterate()
1266 *
double current_time = parameters.start_time;
1267 * CDR::WritePVTUOutput pvtu_output(parameters.patch_level);
1268 *
for (
unsigned int time_step_n = 0; time_step_n < parameters.n_time_steps;
1271 * current_time += time_step;
1274 * CDR::create_system_rhs<dim>
1275 * (dof_handler, quad, convection_function, forcing_function, parameters,
1276 * locally_relevant_solution, constraints, current_time, system_rhs);
1280 * 1
e-6*system_rhs.l2_norm(),
1284 * solver.solve(system_matrix, completely_distributed_solution, system_rhs,
1286 * constraints.distribute(completely_distributed_solution);
1287 * locally_relevant_solution = completely_distributed_solution;
1289 *
if (time_step_n % parameters.save_interval == 0)
1291 * pvtu_output.write_output(dof_handler, locally_relevant_solution,
1292 * time_step_n, current_time);
1301 *
void CDRProblem<dim>::refine_mesh()
1304 * std::map<types::boundary_id, const Function<dim> *>;
1309 * locally_relevant_solution, estimated_error_per_cell);
1313 * This solver uses a crude refinement strategy where cells with relatively
1314 * high errors are refined and cells with relatively low errors are
1315 * coarsened. The maximum refinement
level is capped to prevent
run-away
1319 *
for (
const auto &cell :
triangulation.active_cell_iterators())
1321 *
if (std::abs(estimated_error_per_cell[cell->active_cell_index()]) >= 1
e-3)
1323 * cell->set_refine_flag();
1325 *
else if (std::abs(estimated_error_per_cell[cell->active_cell_index()]) <= 1
e-5)
1327 * cell->set_coarsen_flag();
1331 *
if (
triangulation.n_levels() > parameters.max_refinement_level)
1333 *
for (
const auto &cell :
1334 *
triangulation.cell_iterators_on_level(parameters.max_refinement_level))
1336 * cell->clear_refine_flag();
1342 * Transferring the solution between different grids is ultimately just a
1343 * few
function calls but they must be made in exactly the right order.
1347 * solution_transfer(dof_handler);
1350 * solution_transfer.prepare_for_coarsening_and_refinement
1351 * (locally_relevant_solution);
1358 * The <code>solution_transfer</code>
object stores a pointer to
1359 * <code>locally_relevant_solution</code>, so when
1361 * those values to populate <code>temporary</code>.
1365 * (locally_owned_dofs, mpi_communicator);
1366 * solution_transfer.interpolate(temporary);
1369 * After <code>temporary</code> has the correct
value,
this call correctly
1370 * populates <code>completely_distributed_solution</code>, which had its
1371 * index
set updated above with the
call to <code>setup_dofs</code>.
1374 * completely_distributed_solution = temporary;
1377 * Constraints cannot be applied to
1378 * @ref GlossGhostedVector
"vectors with ghost entries" since the ghost
1379 * entries are write only, so
this first goes through the completely
1380 * distributed vector.
1383 * constraints.distribute(completely_distributed_solution);
1384 * locally_relevant_solution = completely_distributed_solution;
1399 * constexpr
int dim {2};
1402 *
int main(
int argc,
char *argv[])
1406 * One of the
new features in
C++11 is the <code>chrono</code> component of
1407 * the standard library. This gives us an easy way to time the output.
1410 *
auto t0 = std::chrono::high_resolution_clock::now();
1413 * CDR::Parameters parameters;
1414 * parameters.read_parameter_file(
"parameters.prm");
1415 * CDRProblem<dim> cdr_problem(parameters);
1416 * cdr_problem.run();
1418 *
auto t1 = std::chrono::high_resolution_clock::now();
1421 * std::cout <<
"time elapsed: "
1422 * << std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count()
1423 * <<
" milliseconds."