Skip to content

Commit

Permalink
Merge pull request #16750 from kronbichler/fix_uninitialized_variable
Browse files Browse the repository at this point in the history
Fix uninitialized variable
  • Loading branch information
kronbichler committed Mar 16, 2024
2 parents 5117a55 + 157cdc1 commit b9f7503
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
19 changes: 18 additions & 1 deletion include/deal.II/lac/precondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,8 @@ PreconditionRelaxation<MatrixType, PreconditionerType>::initialize(
const MatrixType &rA,
const AdditionalData &parameters)
{
A = &rA;
A = &rA;
eigenvalues_are_initialized = false;

Assert(parameters.preconditioner, ExcNotInitialized());

Expand Down Expand Up @@ -2880,6 +2881,10 @@ PreconditionJacobi<MatrixType>::initialize(const MatrixType &A,
const AdditionalData &parameters_in)
{
Assert(parameters_in.preconditioner == nullptr, ExcInternalError());
Assert(
parameters_in.relaxation != 0.0,
ExcMessage(
"Relaxation cannot automatically be determined by PreconditionJacobi."));

AdditionalData parameters;
parameters.relaxation = 1.0;
Expand All @@ -2898,6 +2903,10 @@ PreconditionSOR<MatrixType>::initialize(const MatrixType &A,
const AdditionalData &parameters_in)
{
Assert(parameters_in.preconditioner == nullptr, ExcInternalError());
Assert(
parameters_in.relaxation != 0.0,
ExcMessage(
"Relaxation cannot automatically be determined by PreconditionSOR."));

AdditionalData parameters;
parameters.relaxation = 1.0;
Expand All @@ -2916,6 +2925,10 @@ PreconditionSSOR<MatrixType>::initialize(const MatrixType &A,
const AdditionalData &parameters_in)
{
Assert(parameters_in.preconditioner == nullptr, ExcInternalError());
Assert(
parameters_in.relaxation != 0.0,
ExcMessage(
"Relaxation cannot automatically be determined by PreconditionSSOR."));

AdditionalData parameters;
parameters.relaxation = 1.0;
Expand All @@ -2939,6 +2952,10 @@ PreconditionPSOR<MatrixType>::initialize(
const typename BaseClass::AdditionalData &parameters_in)
{
Assert(parameters_in.preconditioner == nullptr, ExcInternalError());
Assert(
parameters_in.relaxation != 0.0,
ExcMessage(
"Relaxation cannot automatically be determined by PreconditionPSOR."));

typename BaseClass::AdditionalData parameters;
parameters.relaxation = 1.0;
Expand Down
24 changes: 14 additions & 10 deletions tests/lac/precondition_relaxation_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ int
main()
{
initlog();
deallog << std::setprecision(10);

using Number = double;
using VectorType = Vector<Number>;
Expand Down Expand Up @@ -225,18 +226,19 @@ main()
{
std::vector<std::tuple<double, double, double, double>> results;

{
// 0) Test PreconditionJacobi
PreconditionJacobi<MatrixType> preconditioner;
if (relaxation != 0.0)
{
// 0) Test PreconditionJacobi
PreconditionJacobi<MatrixType> preconditioner;

PreconditionJacobi<MatrixType>::AdditionalData ad;
ad.relaxation = relaxation;
ad.n_iterations = n_iterations;
PreconditionJacobi<MatrixType>::AdditionalData ad;
ad.relaxation = relaxation;
ad.n_iterations = n_iterations;

preconditioner.initialize(system_matrix, ad);
preconditioner.initialize(system_matrix, ad);

results.emplace_back(test(preconditioner, src));
}
results.emplace_back(test(preconditioner, src));
}

{
// 1) Test PreconditionRelaxation + DiagonalMatrix and matrix with
Expand Down Expand Up @@ -358,7 +360,9 @@ main()

return true;
}))
deallog << "OK!" << std::endl;
deallog << "OK! " << std::get<0>(results[0]) << " "
<< std::get<1>(results[0]) << " " << std::get<2>(results[0])
<< " " << std::get<3>(results[0]) << " " << std::endl;
else
deallog << "ERROR!" << std::endl;
}
Expand Down
24 changes: 12 additions & 12 deletions tests/lac/precondition_relaxation_01.output
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK!
DEAL::OK! 6.061760152 14.68132600 6.061760152 14.68132600
DEAL::OK! 10.52207391 19.32280974 10.52207391 19.32280974
DEAL::OK! 15.36803210 24.20027263 15.36803210 24.20027263
DEAL::OK! 5.625000000 14.26150851 5.625000000 14.26150851
DEAL::OK! 9.854904395 18.64454721 9.854904395 18.64454721
DEAL::OK! 14.32120432 23.14836697 14.32120432 23.14836697
DEAL::OK! 5.062500000 13.72238705 5.062500000 13.72238705
DEAL::OK! 8.978554626 17.75512442 8.978554626 17.75512442
DEAL::OK! 12.97998905 21.79877556 12.97998905 21.79877556
DEAL::OK! 6.187500000 14.80236995 6.187500000 14.80236995
DEAL::OK! 10.71211155 19.51613009 10.71211155 19.51613009
DEAL::OK! 15.67077836 24.50421993 15.67077836 24.50421993

0 comments on commit b9f7503

Please sign in to comment.