diff --git a/src/systems/frequency_system.C b/src/systems/frequency_system.C index 68bac5507c..8a4f2e65bc 100644 --- a/src/systems/frequency_system.C +++ b/src/systems/frequency_system.C @@ -343,12 +343,7 @@ void FrequencySystem::solve (const unsigned int n_start, // Get the user-specified linear solver tolerance, // the user-specified maximum # of linear solver iterations, // the user-specified wave speed - const Real tol = parameters.have_parameter("linear solver tolerance") ? - double(parameters.get("linear solver tolerance")) : - es.parameters.get("linear solver tolerance"); - const unsigned int maxits = parameters.have_parameter("linear solver maximum iterations") ? - parameters.get("linear solver maximum iterations") : - es.parameters.get("linear solver maximum iterations"); + const auto [maxits, tol] = this->get_linear_solve_parameters(); // start solver loop for (unsigned int n=n_start; n<= n_stop; n++) diff --git a/src/systems/implicit_system.C b/src/systems/implicit_system.C index 39feef0f87..87e4bc0b74 100644 --- a/src/systems/implicit_system.C +++ b/src/systems/implicit_system.C @@ -1222,16 +1222,14 @@ LinearSolver * ImplicitSystem::get_linear_solver() const std::pair ImplicitSystem::get_linear_solve_parameters() const { - if (parameters.have_parameter("linear solver maximum iterations") && - parameters.have_parameter("linear solver tolerance")) - return std::make_pair(parameters.get("linear solver maximum iterations"), - parameters.get("linear solver tolerance")); - else if (!parameters.have_parameter("linear solver maximum iterations") && - !parameters.have_parameter("linear solver tolerance")) - return std::make_pair(this->get_equation_systems().parameters.get("linear solver maximum iterations"), - this->get_equation_systems().parameters.get("linear solver tolerance")); - else - libmesh_error_msg("ERROR: Insufficient linear solver parameters"); + return std::make_pair( + parameters.have_parameter("linear solver maximum iterations") + ? parameters.get("linear solver maximum iterations") + : this->get_equation_systems().parameters.get( + "linear solver maximum iterations"), + parameters.have_parameter("linear solver tolerance") + ? parameters.get("linear solver tolerance") + : this->get_equation_systems().parameters.get("linear solver tolerance")); } diff --git a/src/systems/linear_implicit_system.C b/src/systems/linear_implicit_system.C index 4ad537c4c9..23fcc55ad8 100644 --- a/src/systems/linear_implicit_system.C +++ b/src/systems/linear_implicit_system.C @@ -118,10 +118,6 @@ void LinearImplicitSystem::solve () // Assemble the linear system this->assemble (); - // Get a reference to the EquationSystems - const EquationSystems & es = - this->get_equation_systems(); - // If the linear solver hasn't been initialized, we do so here. if (libMesh::on_command_line("--solver-system-names")) linear_solver->init((this->name()+"_").c_str()); @@ -131,14 +127,7 @@ void LinearImplicitSystem::solve () linear_solver->init_names(*this); // Get the user-specified linear solver tolerance - const double tol = parameters.have_parameter("linear solver tolerance") ? - double(parameters.get("linear solver tolerance")) : - double(es.parameters.get("linear solver tolerance")); - - // Get the user-specified maximum # of linear solver iterations - const unsigned int maxits = parameters.have_parameter("linear solver maximum iterations") ? - parameters.get("linear solver maximum iterations") : - es.parameters.get("linear solver maximum iterations"); + const auto [maxits, tol] = this->get_linear_solve_parameters(); if (_subset != nullptr) linear_solver->restrict_solve_to(&_subset->dof_ids(),_subset_solve_mode); diff --git a/src/systems/nonlinear_implicit_system.C b/src/systems/nonlinear_implicit_system.C index 53237c7515..79434e4019 100644 --- a/src/systems/nonlinear_implicit_system.C +++ b/src/systems/nonlinear_implicit_system.C @@ -147,13 +147,7 @@ void NonlinearImplicitSystem::set_solver_parameters () double(es.parameters.get("nonlinear solver relative step tolerance")); // Get the user-specified linear solver tolerances - const unsigned int maxlinearits = parameters.have_parameter("linear solver maximum iterations") ? - parameters.get("linear solver maximum iterations") : - es.parameters.get("linear solver maximum iterations"); - - const double linear_tol = parameters.have_parameter("linear solver tolerance") ? - double(parameters.get("linear solver tolerance")) : - double(es.parameters.get("linear solver tolerance")); + const auto [maxlinearits, linear_tol] = this->get_linear_solve_parameters(); const double linear_min_tol = parameters.have_parameter("linear solver minimum tolerance") ? double(parameters.get("linear solver minimum tolerance")) : diff --git a/tests/systems/systems_test.C b/tests/systems/systems_test.C index 8d30b6b49f..efe511f87e 100644 --- a/tests/systems/systems_test.C +++ b/tests/systems/systems_test.C @@ -472,6 +472,7 @@ public: CPPUNIT_TEST( test3DProjectVectorFEHex20 ); CPPUNIT_TEST( test3DProjectVectorFEHex27 ); #ifdef LIBMESH_HAVE_SOLVER + CPPUNIT_TEST( testSetSystemParameterOverEquationSystem); CPPUNIT_TEST( testAssemblyWithDgFemContext ); #endif #endif // LIBMESH_DIM > 2 @@ -1289,8 +1290,9 @@ public: // Create an equation systems object. EquationSystems equation_systems (mesh); - // Set some parameters to the equation system that would cause a failed solve + // Set some parameters to the equation system that would cause a failed test equation_systems.parameters.set("linear solver maximum iterations") = 0; + equation_systems.parameters.set("nonlinear solver absolute residual tolerance") = 1e8; // Setup Linear Implicit system LinearImplicitSystem & li_system = @@ -1313,21 +1315,21 @@ public: nli_system.get_linear_solver()->set_preconditioner_type(IDENTITY_PRECOND); // Set some parameters to the system that work for the solve - li_system.parameters.set("linear solver maximum iterations") = 100; - nli_system.parameters.set("linear solver maximum iterations") = 100; + li_system.parameters.set("linear solver maximum iterations") = 5; + nli_system.parameters.set("nonlinear solver absolute residual tolerance") = 1e-10; // See the solve pass, indicating system parameters are used over equation system parameters equation_systems.init (); li_system.solve(); nli_system.solve(); - // We set the solution to be 1 everywhere, so the final l1 norm of the - // solution is the product of the number of variables and number of nodes. - Real ref_l1_norm = static_cast(mesh.n_nodes() * li_system.n_vars()); + // Check that the number of iterations from the systems got obeyed + CPPUNIT_ASSERT_EQUAL(li_system.n_linear_iterations(), 5u); - LIBMESH_ASSERT_FP_EQUAL(li_system.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE); - LIBMESH_ASSERT_FP_EQUAL(nli_system.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE); - } + // Check that the solution for the nonlinear system is converged + Real ref_l1_norm = static_cast(mesh.n_nodes() * li_system.n_vars()); + LIBMESH_ASSERT_FP_EQUAL(nli_system.solution->l1_norm(), ref_l1_norm, TOLERANCE); +} void testAssemblyWithDgFemContext() {