Skip to content

Commit f533a1f

Browse files
committed
Correct bug
1 parent c186752 commit f533a1f

File tree

4 files changed

+66
-75
lines changed

4 files changed

+66
-75
lines changed

source/solvers/cahn_hilliard.cc

+57-64
Original file line numberDiff line numberDiff line change
@@ -1327,78 +1327,71 @@ void
13271327
CahnHilliard<dim>::output_newton_update_norms(
13281328
const unsigned int display_precision)
13291329
{
1330-
auto mpi_communicator = triangulation->get_communicator();
1331-
1332-
FEValuesExtractors::Scalar phase_order(0);
1333-
FEValuesExtractors::Scalar chemical_potential(1);
1334-
1335-
ComponentMask phase_order_mask = fe->component_mask(phase_order);
1336-
ComponentMask chemical_potential_mask = fe->component_mask(chemical_potential);
1337-
1338-
const std::vector<IndexSet> index_set_phase_order =
1339-
DoFTools::locally_owned_dofs_per_component(dof_handler, phase_order_mask);
1340-
const std::vector<IndexSet> index_set_chemical_potential =
1341-
DoFTools::locally_owned_dofs_per_component(dof_handler, chemical_potential_mask);
1342-
1343-
double local_sum = 0.0;
1344-
double local_max = std::numeric_limits<double>::lowest();
1345-
1346-
1347-
for (auto j = index_set_phase_order[0].begin();
1348-
j != index_set_phase_order[0].end();
1349-
j++)
1350-
{
1351-
double dof_newton_update = newton_update[*j];
1330+
auto mpi_communicator = triangulation->get_communicator();
13521331

1353-
local_sum += dof_newton_update * dof_newton_update;
1332+
FEValuesExtractors::Scalar phase_order(0);
1333+
FEValuesExtractors::Scalar chemical_potential(1);
13541334

1355-
local_max = std::max(local_max, dof_newton_update);
1356-
}
1357-
1335+
ComponentMask phase_order_mask = fe->component_mask(phase_order);
1336+
ComponentMask chemical_potential_mask =
1337+
fe->component_mask(chemical_potential);
13581338

1359-
double global_phase_order_l2_norm =
1360-
std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator));
1361-
double global_phase_order_linfty_norm =
1362-
Utilities::MPI::max(local_max, mpi_communicator);
1339+
const std::vector<IndexSet> index_set_phase_order =
1340+
DoFTools::locally_owned_dofs_per_component(dof_handler, phase_order_mask);
1341+
const std::vector<IndexSet> index_set_chemical_potential =
1342+
DoFTools::locally_owned_dofs_per_component(dof_handler,
1343+
chemical_potential_mask);
13631344

1364-
local_sum = 0.0;
1365-
local_max = std::numeric_limits<double>::lowest();
1345+
double local_sum = 0.0;
1346+
double local_max = std::numeric_limits<double>::lowest();
13661347

1367-
for (auto j = index_set_chemical_potential[1].begin();
1368-
j != index_set_chemical_potential[1].end();
1369-
j++)
1370-
{
1371-
double dof_newton_update = newton_update[*j];
13721348

1373-
local_sum += dof_newton_update * dof_newton_update;
1349+
for (auto j = index_set_phase_order[0].begin();
1350+
j != index_set_phase_order[0].end();
1351+
j++)
1352+
{
1353+
double dof_newton_update = newton_update[*j];
1354+
1355+
local_sum += dof_newton_update * dof_newton_update;
13741356

1375-
local_max = std::max(local_max, dof_newton_update);
1376-
}
1357+
local_max = std::max(local_max, std::abs(dof_newton_update));
1358+
}
1359+
1360+
1361+
double global_phase_order_l2_norm =
1362+
std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator));
1363+
double global_phase_order_linfty_norm =
1364+
Utilities::MPI::max(local_max, mpi_communicator);
1365+
1366+
local_sum = 0.0;
1367+
local_max = std::numeric_limits<double>::lowest();
1368+
1369+
for (auto j = index_set_chemical_potential[1].begin();
1370+
j != index_set_chemical_potential[1].end();
1371+
j++)
1372+
{
1373+
double dof_newton_update = newton_update[*j];
1374+
1375+
local_sum += dof_newton_update * dof_newton_update;
1376+
1377+
local_max = std::max(local_max, std::abs(dof_newton_update));
1378+
}
13771379

1378-
double global_chemical_potential_l2_norm =
1379-
std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator));
1380-
double global_chemical_potential_linfty_norm =
1381-
Utilities::MPI::max(local_max, mpi_communicator);
1382-
1383-
this->pcout << std::setprecision(display_precision)
1384-
<< "\n\t||du||_L2 = " << std::setw(6)
1385-
<< newton_update.l2_norm() << std::setw(6)
1386-
<< "\t||du||_Linfty = "
1387-
<< std::setprecision(display_precision)
1388-
<< newton_update.linfty_norm() << std::endl;
1389-
1390-
this->pcout << std::setprecision(display_precision)
1391-
<< "\n\t||dphi||_L2 = " << std::setw(6)
1392-
<< global_phase_order_l2_norm << std::setw(6)
1393-
<< "\t||dphi||_Linfty = "
1394-
<< std::setprecision(display_precision)
1395-
<< global_phase_order_linfty_norm << std::endl;
1396-
this->pcout << std::setprecision(display_precision)
1397-
<< "\t||deta||_L2 = " << std::setw(6) << global_chemical_potential_l2_norm
1398-
<< std::setw(6) << "\t||deta||_Linfty = "
1399-
<< std::setprecision(display_precision)
1400-
<< global_chemical_potential_linfty_norm << std::endl;
1401-
1380+
double global_chemical_potential_l2_norm =
1381+
std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator));
1382+
double global_chemical_potential_linfty_norm =
1383+
Utilities::MPI::max(local_max, mpi_communicator);
1384+
1385+
this->pcout << std::setprecision(display_precision)
1386+
<< "\n\t||dphi||_L2 = " << std::setw(6)
1387+
<< global_phase_order_l2_norm << std::setw(6)
1388+
<< "\t||dphi||_Linfty = " << std::setprecision(display_precision)
1389+
<< global_phase_order_linfty_norm << std::endl;
1390+
this->pcout << std::setprecision(display_precision)
1391+
<< "\t||deta||_L2 = " << std::setw(6)
1392+
<< global_chemical_potential_l2_norm << std::setw(6)
1393+
<< "\t||deta||_Linfty = " << std::setprecision(display_precision)
1394+
<< global_chemical_potential_linfty_norm << std::endl;
14021395
}
14031396

14041397
template std::pair<Tensor<1, 2>, Tensor<1, 2>>

source/solvers/navier_stokes_base.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ NavierStokesBase<dim, VectorType, DofsType>::output_newton_update_norms(
25162516

25172517
local_sum += dof_newton_update * dof_newton_update;
25182518

2519-
local_max = std::max(local_max, dof_newton_update);
2519+
local_max = std::max(local_max, std::abs(dof_newton_update));
25202520
}
25212521
}
25222522

@@ -2536,7 +2536,7 @@ NavierStokesBase<dim, VectorType, DofsType>::output_newton_update_norms(
25362536

25372537
local_sum += dof_newton_update * dof_newton_update;
25382538

2539-
local_max = std::max(local_max, dof_newton_update);
2539+
local_max = std::max(local_max, std::abs(dof_newton_update));
25402540
}
25412541

25422542
double global_pressure_l2_norm =

tests/core/non_linear_test_system_01.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ class NonLinearProblemTestClass : public PhysicsSolver<Vector<double>>
130130
output_newton_update_norms(const unsigned int display_precision) override
131131
{
132132
deallog << std::setprecision(display_precision)
133-
<< "\t||dx||_L2 = " << std::setw(6) << newton_update.l2_norm()
134-
<< std::setw(6)
135-
<< "\t||dx||_Linfty = " << std::setprecision(display_precision)
136-
<< newton_update.linfty_norm() << std::endl;
133+
<< "\t||dx||_L2 = " << std::setw(6) << newton_update.l2_norm()
134+
<< std::setw(6)
135+
<< "\t||dx||_Linfty = " << std::setprecision(display_precision)
136+
<< newton_update.linfty_norm() << std::endl;
137137
};
138138
virtual Vector<double> &
139139
get_present_solution() override

tests/core/vector_problem.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ test()
105105
{
106106
correction_norm += dummy_solution[*j] * dummy_solution[*j];
107107

108-
max_correction = std::max(max_correction, dummy_solution[*j]);
108+
max_correction =
109+
std::max(max_correction, std::abs(dummy_solution[*j]));
109110
}
110111
}
111112

@@ -120,10 +121,7 @@ test()
120121
{
121122
correction_norm += dummy_solution[*j] * dummy_solution[*j];
122123

123-
if (dummy_solution[*j] > max_correction)
124-
{
125-
max_correction = dummy_solution[*j];
126-
}
124+
max_correction = std::max(max_correction, std::abs(dummy_solution[*j]));
127125
}
128126

129127
deallog << "||p||_L2 : " << std::sqrt(correction_norm) << std::endl;

0 commit comments

Comments
 (0)