Skip to content

Commit a774839

Browse files
committed
code improvements
1 parent ddb63e4 commit a774839

File tree

6 files changed

+39
-37
lines changed

6 files changed

+39
-37
lines changed

include/aspect/simulator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ namespace aspect
20562056
bool rebuild_sparsity_and_matrices;
20572057
bool rebuild_stokes_matrix;
20582058
bool rebuild_stokes_preconditioner;
2059-
bool assemble_defect_correction_stokes_system;
2059+
bool assemble_newton_stokes_system;
20602060

20612061
/**
20622062
* @}

source/simulator/assembly.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,24 +259,24 @@ namespace aspect
259259

260260
// Set up the set of assemblers depending on the mode of equations
261261
if (!parameters.include_melt_transport
262-
&& !assemble_defect_correction_stokes_system)
262+
&& !assemble_newton_stokes_system)
263263
{
264264
set_advection_assemblers();
265265
set_stokes_assemblers();
266266
}
267267
else if (parameters.include_melt_transport
268-
&& !assemble_defect_correction_stokes_system)
268+
&& !assemble_newton_stokes_system)
269269
{
270270
melt_handler->set_assemblers(*assemblers);
271271
}
272272
else if (!parameters.include_melt_transport
273-
&& assemble_defect_correction_stokes_system)
273+
&& assemble_newton_stokes_system)
274274
{
275275
set_advection_assemblers();
276276
newton_handler->set_assemblers(*assemblers);
277277
}
278278
else if (parameters.include_melt_transport
279-
&& assemble_defect_correction_stokes_system)
279+
&& assemble_newton_stokes_system)
280280
{
281281
AssertThrow (false,
282282
ExcMessage("The melt implementation does not support the Newton solver at the moment."));
@@ -337,7 +337,7 @@ namespace aspect
337337
scratch.material_model_inputs.requested_properties
338338
= MaterialModel::MaterialProperties::equation_of_state_properties |
339339
MaterialModel::MaterialProperties::viscosity |
340-
(parameters.include_melt_transport || assemble_defect_correction_stokes_system
340+
(parameters.include_melt_transport || assemble_newton_stokes_system
341341
?
342342
MaterialModel::MaterialProperties::additional_outputs
343343
:
@@ -621,7 +621,7 @@ namespace aspect
621621

622622
// initialize the material model data on the cell
623623
const bool need_viscosity =
624-
assemble_defect_correction_stokes_system || this->parameters.enable_prescribed_dilation || rebuild_stokes_matrix;
624+
assemble_newton_stokes_system || this->parameters.enable_prescribed_dilation || rebuild_stokes_matrix;
625625

626626
scratch.material_model_inputs.reinit (scratch.finite_element_values,
627627
cell,
@@ -649,7 +649,7 @@ namespace aspect
649649

650650
scratch.finite_element_values[introspection.extractors.velocities].get_function_values(current_linearization_point,
651651
scratch.velocity_values);
652-
if (assemble_defect_correction_stokes_system)
652+
if (assemble_newton_stokes_system)
653653
scratch.finite_element_values[introspection.extractors.velocities].get_function_divergences(current_linearization_point,scratch.velocity_divergence);
654654
if (parameters.formulation_mass_conservation == Parameters<dim>::Formulation::MassConservation::hydrostatic_compression)
655655
scratch.finite_element_values[introspection.extractors.temperature].get_function_gradients(current_linearization_point,
@@ -755,7 +755,7 @@ namespace aspect
755755
{
756756
std::string timer_section_name = "Assemble Stokes system";
757757

758-
if (assemble_defect_correction_stokes_system)
758+
if (assemble_newton_stokes_system)
759759
{
760760
if (!rebuild_stokes_matrix && !stokes_matrix_free)
761761
timer_section_name += " rhs";

source/simulator/core.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,7 @@ namespace aspect
248248

249249
rebuild_stokes_matrix (true),
250250
rebuild_stokes_preconditioner (true),
251-
// note that assemble_defect_correction_stokes_system is
252-
// initialized to false even for defect correction solvers
253-
// because the first nonlinear iteration is always
254-
// solved as the full system
255-
assemble_defect_correction_stokes_system (false)
251+
assemble_newton_stokes_system (false)
256252
{
257253
wall_timer.start();
258254

@@ -438,11 +434,11 @@ namespace aspect
438434
melt_handler->initialize();
439435
}
440436

441-
442437
// Initialize the Newton handler for all defect correction solver schemes
443438
// (defect correction Picard and Newton solvers)
444439
if (Parameters<dim>::is_defect_correction(parameters.nonlinear_solver))
445440
{
441+
assemble_newton_stokes_system = true
446442
newton_handler->initialize_simulator(*this);
447443
newton_handler->parameters.parse_parameters(prm);
448444
}
@@ -647,13 +643,6 @@ namespace aspect
647643
for (auto &particle_manager : particle_managers)
648644
particle_manager.backup_particles();
649645

650-
if (Parameters<dim>::is_defect_correction(parameters.nonlinear_solver))
651-
{
652-
// Ensure we always begin by solving the normal Stokes system
653-
// even for defect correction / Newton solvers
654-
assemble_defect_correction_stokes_system = false;
655-
set_assemblers();
656-
}
657646

658647
// then interpolate the current boundary velocities. copy constraints
659648
// into current_constraints and then add to current_constraints
@@ -1454,7 +1443,7 @@ namespace aspect
14541443
(introspection.n_components,
14551444
[&] (const dealii::Point<dim> &x) -> Tensor<1,dim>
14561445
{
1457-
if (!assemble_defect_correction_stokes_system || (assemble_defect_correction_stokes_system && nonlinear_iteration == 0))
1446+
if (!assemble_newton_stokes_system || (assemble_newton_stokes_system && nonlinear_iteration == 0))
14581447
return boundary_velocity_manager.boundary_velocity(boundary_id, x);
14591448
else
14601449
return Tensor<1,dim>();

source/simulator/helper_functions.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,16 +2611,19 @@ namespace aspect
26112611
temp_velocity_linearization_point
26122612
.swap(current_linearization_point.block(introspection.block_indices.velocities));
26132613

2614-
// Rebuild the whole system to compute the rhs.
2615-
const bool assemble_dc_Stokes_backup = assemble_defect_correction_stokes_system;
2616-
assemble_defect_correction_stokes_system = true;
2617-
rebuild_stokes_preconditioner = false;
2614+
// Ensure we assemble the Newton residual, no matter which system we are solving
2615+
const bool assemble_dc_Stokes_backup = assemble_newton_stokes_system;
2616+
assemble_newton_stokes_system = true;
2617+
// Ensure the assemblers are consistent with the system we are assembling
2618+
if (assemble_dc_Stokes_backup != assemble_newton_stokes_system)
2619+
set_assemblers();
26182620

26192621
// Technically we only need the rhs, but we have asserts in place that check if
26202622
// the system is assembled correctly when boundary conditions are prescribed, so we assemble the whole system.
26212623
// TODO: This is a waste of time in the first nonlinear iteration. Check if we can modify the asserts in the
26222624
// assemble_stokes_system() function to only assemble the RHS.
26232625
rebuild_stokes_matrix = boundary_velocity_manager.get_prescribed_boundary_velocity_indicators().size()!=0;
2626+
rebuild_stokes_preconditioner = false;
26242627

26252628
compute_current_constraints ();
26262629
assemble_stokes_system();
@@ -2633,8 +2636,13 @@ namespace aspect
26332636
current_linearization_point.block(introspection.block_indices.velocities)
26342637
.swap(temp_velocity_linearization_point);
26352638

2636-
// Undo the change to this state variable
2637-
assemble_defect_correction_stokes_system = assemble_dc_Stokes_backup;
2639+
// Undo the change to the state of assembly, assemblers, and constraints
2640+
if (assemble_dc_Stokes_backup != assemble_newton_stokes_system)
2641+
{
2642+
assemble_newton_stokes_system = assemble_dc_Stokes_backup;
2643+
set_assemblers();
2644+
compute_current_constraints ();
2645+
}
26382646

26392647
pcout << " Initial Newton Stokes residual = " << initial_newton_residual << ", v = " << initial_newton_residual_vel << ", p = " << initial_newton_residual_p << std::endl << std::endl;
26402648
return initial_newton_residual;

source/simulator/solver.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,15 +595,15 @@ namespace aspect
595595
{
596596
outputs = stokes_matrix_free->solve(system_matrix,
597597
system_rhs,
598-
assemble_defect_correction_stokes_system,
598+
assemble_newton_stokes_system,
599599
last_pressure_normalization_adjustment,
600600
solution_vector);
601601
}
602602
else if (parameters.use_direct_stokes_solver)
603603
{
604604
outputs = stokes_direct->solve(system_matrix,
605605
system_rhs,
606-
assemble_defect_correction_stokes_system,
606+
assemble_newton_stokes_system,
607607
last_pressure_normalization_adjustment,
608608
solution_vector);
609609
}
@@ -676,7 +676,7 @@ namespace aspect
676676
// linearized_stokes_variables has a different
677677
// layout than current_linearization_point, which also contains all the
678678
// other solution variables.
679-
if (assemble_defect_correction_stokes_system == false)
679+
if (assemble_newton_stokes_system == false)
680680
{
681681
linearized_stokes_initial_guess.block (velocity_block_index) = current_linearization_point.block (velocity_block_index);
682682
linearized_stokes_initial_guess.block (pressure_block_index) = current_linearization_point.block (pressure_block_index);
@@ -702,7 +702,7 @@ namespace aspect
702702
linearized_stokes_initial_guess.block (pressure_block_index) /= pressure_scaling;
703703

704704
double solver_tolerance = 0;
705-
if (assemble_defect_correction_stokes_system == false)
705+
if (assemble_newton_stokes_system == false)
706706
{
707707
// (ab)use the distributed solution vector to temporarily put a residual in
708708
// (we don't care about the residual vector -- all we care about is the
@@ -941,7 +941,7 @@ namespace aspect
941941
// do some cleanup now that we have the solution
942942
remove_nullspace(solution_vector, distributed_stokes_solution);
943943

944-
if (assemble_defect_correction_stokes_system == false)
944+
if (assemble_newton_stokes_system == false)
945945
outputs.pressure_normalization_adjustment = normalize_pressure(solution_vector);
946946
}
947947

source/simulator/solver_schemes.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,18 @@ namespace aspect
611611
dcr.switch_initial_residual = dcr.initial_residual;
612612
dcr.residual_old = dcr.initial_residual;
613613
dcr.residual = dcr.initial_residual;
614+
615+
// Ensure we always begin by solving the normal Stokes system
616+
// even for defect correction / Newton solvers
617+
assemble_newton_stokes_system = false;
618+
set_assemblers();
619+
compute_current_constraints ();
614620
}
615621
else if (nonlinear_iteration == 1)
616622
{
617623
// Switch to solving the defect correction system
618-
assemble_defect_correction_stokes_system = true;
619-
620-
// Replace the assemblers and constraints
624+
// and use the correct assemblers and constraints
625+
assemble_newton_stokes_system = true;
621626
set_assemblers();
622627
compute_current_constraints ();
623628
}

0 commit comments

Comments
 (0)