From 1051d5337a2c4a2a734b27d7b336e77b9ccdbdab Mon Sep 17 00:00:00 2001 From: hepap Date: Fri, 5 Apr 2024 15:14:15 -0400 Subject: [PATCH] Correct bug --- source/solvers/cahn_hilliard.cc | 121 ++++++++++++------------- source/solvers/navier_stokes_base.cc | 4 +- tests/core/non_linear_test_system_01.h | 8 +- tests/core/vector_problem.cc | 8 +- 4 files changed, 66 insertions(+), 75 deletions(-) diff --git a/source/solvers/cahn_hilliard.cc b/source/solvers/cahn_hilliard.cc index 8c849df67d..d7e492bfdb 100644 --- a/source/solvers/cahn_hilliard.cc +++ b/source/solvers/cahn_hilliard.cc @@ -1327,78 +1327,71 @@ void CahnHilliard::output_newton_update_norms( const unsigned int display_precision) { - auto mpi_communicator = triangulation->get_communicator(); - - FEValuesExtractors::Scalar phase_order(0); - FEValuesExtractors::Scalar chemical_potential(1); - - ComponentMask phase_order_mask = fe->component_mask(phase_order); - ComponentMask chemical_potential_mask = fe->component_mask(chemical_potential); - - const std::vector index_set_phase_order = - DoFTools::locally_owned_dofs_per_component(dof_handler, phase_order_mask); - const std::vector index_set_chemical_potential = - DoFTools::locally_owned_dofs_per_component(dof_handler, chemical_potential_mask); - - double local_sum = 0.0; - double local_max = std::numeric_limits::lowest(); - - - for (auto j = index_set_phase_order[0].begin(); - j != index_set_phase_order[0].end(); - j++) - { - double dof_newton_update = newton_update[*j]; + auto mpi_communicator = triangulation->get_communicator(); - local_sum += dof_newton_update * dof_newton_update; + FEValuesExtractors::Scalar phase_order(0); + FEValuesExtractors::Scalar chemical_potential(1); - local_max = std::max(local_max, dof_newton_update); - } - + ComponentMask phase_order_mask = fe->component_mask(phase_order); + ComponentMask chemical_potential_mask = + fe->component_mask(chemical_potential); - double global_phase_order_l2_norm = - std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator)); - double global_phase_order_linfty_norm = - Utilities::MPI::max(local_max, mpi_communicator); + const std::vector index_set_phase_order = + DoFTools::locally_owned_dofs_per_component(dof_handler, phase_order_mask); + const std::vector index_set_chemical_potential = + DoFTools::locally_owned_dofs_per_component(dof_handler, + chemical_potential_mask); - local_sum = 0.0; - local_max = std::numeric_limits::lowest(); + double local_sum = 0.0; + double local_max = std::numeric_limits::lowest(); - for (auto j = index_set_chemical_potential[1].begin(); - j != index_set_chemical_potential[1].end(); - j++) - { - double dof_newton_update = newton_update[*j]; - local_sum += dof_newton_update * dof_newton_update; + for (auto j = index_set_phase_order[0].begin(); + j != index_set_phase_order[0].end(); + j++) + { + double dof_newton_update = newton_update[*j]; + + local_sum += dof_newton_update * dof_newton_update; - local_max = std::max(local_max, dof_newton_update); - } + local_max = std::max(local_max, std::abs(dof_newton_update)); + } + + + double global_phase_order_l2_norm = + std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator)); + double global_phase_order_linfty_norm = + Utilities::MPI::max(local_max, mpi_communicator); + + local_sum = 0.0; + local_max = std::numeric_limits::lowest(); + + for (auto j = index_set_chemical_potential[1].begin(); + j != index_set_chemical_potential[1].end(); + j++) + { + double dof_newton_update = newton_update[*j]; + + local_sum += dof_newton_update * dof_newton_update; + + local_max = std::max(local_max, std::abs(dof_newton_update)); + } - double global_chemical_potential_l2_norm = - std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator)); - double global_chemical_potential_linfty_norm = - Utilities::MPI::max(local_max, mpi_communicator); - - this->pcout << std::setprecision(display_precision) - << "\n\t||du||_L2 = " << std::setw(6) - << newton_update.l2_norm() << std::setw(6) - << "\t||du||_Linfty = " - << std::setprecision(display_precision) - << newton_update.linfty_norm() << std::endl; - - this->pcout << std::setprecision(display_precision) - << "\n\t||dphi||_L2 = " << std::setw(6) - << global_phase_order_l2_norm << std::setw(6) - << "\t||dphi||_Linfty = " - << std::setprecision(display_precision) - << global_phase_order_linfty_norm << std::endl; - this->pcout << std::setprecision(display_precision) - << "\t||deta||_L2 = " << std::setw(6) << global_chemical_potential_l2_norm - << std::setw(6) << "\t||deta||_Linfty = " - << std::setprecision(display_precision) - << global_chemical_potential_linfty_norm << std::endl; - + double global_chemical_potential_l2_norm = + std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator)); + double global_chemical_potential_linfty_norm = + Utilities::MPI::max(local_max, mpi_communicator); + + this->pcout << std::setprecision(display_precision) + << "\n\t||dphi||_L2 = " << std::setw(6) + << global_phase_order_l2_norm << std::setw(6) + << "\t||dphi||_Linfty = " << std::setprecision(display_precision) + << global_phase_order_linfty_norm << std::endl; + this->pcout << std::setprecision(display_precision) + << "\t||deta||_L2 = " << std::setw(6) + << global_chemical_potential_l2_norm << std::setw(6) + << "\t||deta||_Linfty = " << std::setprecision(display_precision) + << global_chemical_potential_linfty_norm << std::endl; } template std::pair, Tensor<1, 2>> diff --git a/source/solvers/navier_stokes_base.cc b/source/solvers/navier_stokes_base.cc index 4e4b781230..2c41a40b90 100644 --- a/source/solvers/navier_stokes_base.cc +++ b/source/solvers/navier_stokes_base.cc @@ -2516,7 +2516,7 @@ NavierStokesBase::output_newton_update_norms( local_sum += dof_newton_update * dof_newton_update; - local_max = std::max(local_max, dof_newton_update); + local_max = std::max(local_max, std::abs(dof_newton_update)); } } @@ -2536,7 +2536,7 @@ NavierStokesBase::output_newton_update_norms( local_sum += dof_newton_update * dof_newton_update; - local_max = std::max(local_max, dof_newton_update); + local_max = std::max(local_max, std::abs(dof_newton_update)); } double global_pressure_l2_norm = diff --git a/tests/core/non_linear_test_system_01.h b/tests/core/non_linear_test_system_01.h index d654709f00..5d5599cb2b 100644 --- a/tests/core/non_linear_test_system_01.h +++ b/tests/core/non_linear_test_system_01.h @@ -130,10 +130,10 @@ class NonLinearProblemTestClass : public PhysicsSolver> output_newton_update_norms(const unsigned int display_precision) override { deallog << std::setprecision(display_precision) - << "\t||dx||_L2 = " << std::setw(6) << newton_update.l2_norm() - << std::setw(6) - << "\t||dx||_Linfty = " << std::setprecision(display_precision) - << newton_update.linfty_norm() << std::endl; + << "\t||dx||_L2 = " << std::setw(6) << newton_update.l2_norm() + << std::setw(6) + << "\t||dx||_Linfty = " << std::setprecision(display_precision) + << newton_update.linfty_norm() << std::endl; }; virtual Vector & get_present_solution() override diff --git a/tests/core/vector_problem.cc b/tests/core/vector_problem.cc index 356e34ceb5..bcaedee2e3 100644 --- a/tests/core/vector_problem.cc +++ b/tests/core/vector_problem.cc @@ -105,7 +105,8 @@ test() { correction_norm += dummy_solution[*j] * dummy_solution[*j]; - max_correction = std::max(max_correction, dummy_solution[*j]); + max_correction = + std::max(max_correction, std::abs(dummy_solution[*j])); } } @@ -120,10 +121,7 @@ test() { correction_norm += dummy_solution[*j] * dummy_solution[*j]; - if (dummy_solution[*j] > max_correction) - { - max_correction = dummy_solution[*j]; - } + max_correction = std::max(max_correction, std::abs(dummy_solution[*j])); } deallog << "||p||_L2 : " << std::sqrt(correction_norm) << std::endl;