Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Convergence flags in linear solvers #204

Merged
merged 1 commit into from

3 participants

@danac
Collaborator

This implements a getter in the linear solver classes (LinearSolver::get_converged_reason()) which returns a flag indicating the convergence status of the solver.

The flags are inspired by PETSc's, and gathered in an enum which aims at being generic in the future, defined in include/enums/enum_convergence_flags.h

The LinearSolver::print_converged_reason() method is updated to make use of this new enum in conjunction with Utility::enum_to_string().

PETSc is the only backend for which the getter is currently implemented (in the other solvers libmesh_not_implemented() is called).

@dknez
Collaborator

This looks good to me. It'll be nice to be able to check linear solver convergence programmatically (having to use -ksp_converged_reason and read through stdout isn't very convenient...)

Dana, one comment: I suggest you move print_converged_reason() up to LinearSolver as well.

@danac
Collaborator

I moved print_converged_reason() to the base class and squashed/rebased the branch.

@friedmud
Owner

Were you planning on doing the same for the Nonlienar solver? If we're going to do one - we should do both so they are consistent...

Other than that - this is looking good.

@dknez
Collaborator

There's already an enum in DiffSolver for the nonlinear case, so I don't think Dana wanted to mess with that.

Perhaps it'd best if one of the FEMSystem experts refactors the code for the nonlinear case (e.g. move the DiffSolver enum into enum_convergence_flags.h)? I'd suggest we merge this pull request first and then deal with the nonlinear case.

@dknez
Collaborator

I'll go ahead and merge this now, unless there are any objections? (I agree about updating the nonlinear flags, but I think that can be done in a separate PR, since it'll involve changing some existing DiffSolver code)

@dknez dknez merged commit 44f346e into libMesh:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 17, 2014
  1. @danac
This page is out of date. Refresh to see the latest.
View
1  include/Makefile.in
@@ -533,6 +533,7 @@ include_HEADERS = \
base/sparsity_pattern.h \
base/variable.h \
base/variant_filter_iterator.h \
+ enums/enum_convergence_flags.h \
enums/enum_eigen_solver_type.h \
enums/enum_elem_quality.h \
enums/enum_elem_type.h \
View
65 include/enums/enum_convergence_flags.h
@@ -0,0 +1,65 @@
+// The libMesh Finite Element Library.
+// Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
+
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+
+#ifndef LIBMESH_ENUM_CONVERGENCE_FLAGS
+#define LIBMESH_ENUM_CONVERGENCE_FLAGS
+
+/*
+ * The \p libMeshEnums namespace is the namespace all \p enum definitions
+ * should be put into.
+ */
+
+// ------------------------------------------------------------
+// enum ConvergenceFlags definition
+namespace libMeshEnums {
+
+ /**
+ * Linear solver convergence flags (taken from the PETSc flags)
+ */
+ enum LinearConvergenceReason{
+ /* converged */
+ CONVERGED_RTOL_NORMAL = 1,
+ CONVERGED_ATOL_NORMAL = 9,
+ CONVERGED_RTOL = 2,
+ CONVERGED_ATOL = 3,
+ CONVERGED_ITS = 4,
+ CONVERGED_CG_NEG_CURVE = 5,
+ CONVERGED_CG_CONSTRAINED = 6,
+ CONVERGED_STEP_LENGTH = 7,
+ CONVERGED_HAPPY_BREAKDOWN = 8,
+ /* diverged */
+ DIVERGED_NULL = -2,
+ DIVERGED_ITS = -3,
+ DIVERGED_DTOL = -4,
+ DIVERGED_BREAKDOWN = -5,
+ DIVERGED_BREAKDOWN_BICG = -6,
+ DIVERGED_NONSYMMETRIC = -7,
+ DIVERGED_INDEFINITE_PC = -8,
+ DIVERGED_NAN = -9,
+ DIVERGED_INDEFINITE_MAT = -10,
+
+ CONVERGED_ITERATING = 0,
+
+ UNKNOWN_FLAG = -128};
+
+}
+
+using namespace libMeshEnums;
+
+#endif // LIBMESH_ENUM_CONVERGENCE_FLAGS
View
1  include/include_HEADERS
@@ -44,6 +44,7 @@ include_HEADERS = \
base/sparsity_pattern.h \
base/variable.h \
base/variant_filter_iterator.h \
+ enums/enum_convergence_flags.h \
enums/enum_eigen_solver_type.h \
enums/enum_elem_quality.h \
enums/enum_elem_type.h \
View
5 include/libmesh/Makefile.am
@@ -5,7 +5,7 @@
# include the magic script!
EXTRA_DIST = rebuild_makefile.sh
-BUILT_SOURCES = auto_ptr.h dirichlet_boundaries.h dof_map.h dof_object.h factory.h getpot.h id_types.h libmesh.h libmesh_C_isnan.h libmesh_augment_std_namespace.h libmesh_base.h libmesh_common.h libmesh_documentation.h libmesh_exceptions.h libmesh_logging.h libmesh_singleton.h libmesh_version.h multi_predicates.h periodic_boundaries.h periodic_boundary.h periodic_boundary_base.h print_trace.h reference_counted_object.h reference_counter.h single_predicates.h sparsity_pattern.h variable.h variant_filter_iterator.h enum_eigen_solver_type.h enum_elem_quality.h enum_elem_type.h enum_fe_family.h enum_inf_map_type.h enum_io_package.h enum_norm_type.h enum_order.h enum_parallel_type.h enum_point_locator_type.h enum_preconditioner_type.h enum_quadrature_type.h enum_solver_package.h enum_solver_type.h enum_subset_solve_mode.h enum_xdr_mode.h adjoint_refinement_estimator.h adjoint_residual_error_estimator.h discontinuity_measure.h error_estimator.h exact_error_estimator.h exact_solution.h fourth_error_estimators.h hp_coarsentest.h hp_selector.h hp_singular.h jump_error_estimator.h kelly_error_estimator.h patch_recovery_error_estimator.h uniform_refinement_estimator.h weighted_patch_recovery_error_estimator.h fe.h fe_abstract.h fe_base.h fe_compute_data.h fe_interface.h fe_macro.h fe_map.h fe_transformation_base.h fe_type.h fe_xyz_map.h h1_fe_transformation.h hcurl_fe_transformation.h inf_fe.h inf_fe_instantiate_1D.h inf_fe_instantiate_2D.h inf_fe_instantiate_3D.h inf_fe_macro.h cell.h cell_hex.h cell_hex20.h cell_hex27.h cell_hex8.h cell_inf.h cell_inf_hex.h cell_inf_hex16.h cell_inf_hex18.h cell_inf_hex8.h cell_inf_prism.h cell_inf_prism12.h cell_inf_prism6.h cell_prism.h cell_prism15.h cell_prism18.h cell_prism6.h cell_pyramid.h cell_pyramid14.h cell_pyramid5.h cell_tet.h cell_tet10.h cell_tet4.h edge.h edge_edge2.h edge_edge3.h edge_edge4.h edge_inf_edge2.h elem.h elem_quality.h elem_range.h elem_type.h face.h face_inf_quad.h face_inf_quad4.h face_inf_quad6.h face_quad.h face_quad4.h face_quad8.h face_quad9.h face_tri.h face_tri3.h face_tri6.h node.h node_elem.h node_range.h plane.h point.h reference_elem.h remote_elem.h side.h sphere.h stored_range.h surface.h abaqus_io.h boundary_info.h boundary_mesh.h checkpoint_io.h diva_io.h ensight_io.h exodusII_io.h exodusII_io_helper.h fro_io.h gmsh_io.h gmv_io.h gnuplot_io.h inf_elem_builder.h legacy_xdr_io.h matlab_io.h medit_io.h mesh.h mesh_base.h mesh_communication.h mesh_data.h mesh_function.h mesh_generation.h mesh_input.h mesh_inserter_iterator.h mesh_modification.h mesh_output.h mesh_refinement.h mesh_serializer.h mesh_smoother.h mesh_smoother_laplace.h mesh_smoother_vsmoother.h mesh_tetgen_interface.h mesh_tetgen_wrapper.h mesh_tools.h mesh_triangle_holes.h mesh_triangle_interface.h mesh_triangle_wrapper.h nemesis_io.h nemesis_io_helper.h off_io.h parallel_mesh.h patch.h postscript_io.h serial_mesh.h tecplot_io.h tetgen_io.h ucd_io.h unstructured_mesh.h unv_io.h vtk_io.h xdr_head.h xdr_io.h xdr_mesh.h xdr_mgf.h xdr_mhead.h xdr_shead.h xdr_soln.h analytic_function.h const_fem_function.h const_function.h coupling_matrix.h dense_matrix.h dense_matrix_base.h dense_submatrix.h dense_subvector.h dense_vector.h dense_vector_base.h distributed_vector.h eigen_core_support.h eigen_preconditioner.h eigen_sparse_matrix.h eigen_sparse_vector.h fem_function_base.h function_base.h laspack_matrix.h laspack_vector.h numeric_vector.h parsed_function.h petsc_macro.h petsc_matrix.h petsc_preconditioner.h petsc_vector.h preconditioner.h raw_accessor.h refinement_selector.h shell_matrix.h sparse_matrix.h sparse_shell_matrix.h sum_shell_matrix.h tensor_shell_matrix.h tensor_tools.h tensor_value.h trilinos_epetra_matrix.h trilinos_epetra_vector.h trilinos_preconditioner.h type_n_tensor.h type_tensor.h type_vector.h vector_value.h wrapped_function.h zero_function.h parallel.h parallel_algebra.h parallel_bin_sorter.h parallel_conversion_utils.h parallel_elem.h parallel_ghost_sync.h parallel_hilbert.h parallel_histogram.h parallel_implementation.h parallel_node.h parallel_object.h parallel_sort.h threads.h threads_allocators.h centroid_partitioner.h hilbert_sfc_partitioner.h linear_partitioner.h metis_csr_graph.h metis_partitioner.h morton_sfc_partitioner.h parmetis_partitioner.h partitioner.h sfc_partitioner.h diff_physics.h diff_qoi.h fem_physics.h quadrature.h quadrature_clough.h quadrature_conical.h quadrature_gauss.h quadrature_gm.h quadrature_grid.h quadrature_jacobi.h quadrature_monomial.h quadrature_rules.h quadrature_simpson.h quadrature_trap.h derived_rb_construction.h derived_rb_evaluation.h rb_assembly_expansion.h rb_construction.h rb_construction_base.h rb_eim_assembly.h rb_eim_construction.h rb_eim_evaluation.h rb_eim_theta.h rb_evaluation.h rb_parameters.h rb_parametrized.h rb_parametrized_function.h rb_scm_construction.h rb_scm_evaluation.h rb_temporal_discretization.h rb_theta.h rb_theta_expansion.h transient_rb_assembly_expansion.h transient_rb_construction.h transient_rb_evaluation.h transient_rb_theta_expansion.h direct_solution_transfer.h dtk_adapter.h dtk_evaluator.h dtk_solution_transfer.h meshfree_interpolation.h meshfree_solution_transfer.h meshfunction_solution_transfer.h radial_basis_functions.h radial_basis_interpolation.h solution_transfer.h adaptive_time_solver.h diff_solver.h eigen_solver.h eigen_sparse_linear_solver.h eigen_time_solver.h euler2_solver.h euler_solver.h laspack_linear_solver.h linear.h linear_solver.h memory_solution_history.h newton_solver.h no_solution_history.h nonlinear_solver.h petsc_diff_solver.h petsc_dm_nonlinear_solver.h petsc_linear_solver.h petsc_nonlinear_solver.h petscdmlibmesh.h slepc_eigen_solver.h slepc_macro.h solution_history.h solver.h steady_solver.h time_solver.h trilinos_aztec_linear_solver.h trilinos_nox_nonlinear_solver.h twostep_time_solver.h unsteady_solver.h condensed_eigen_system.h continuation_system.h dg_fem_context.h diff_context.h diff_system.h eigen_system.h elem_assembly.h equation_systems.h explicit_system.h fem_context.h fem_system.h frequency_system.h implicit_system.h linear_implicit_system.h newmark_system.h nonlinear_implicit_system.h parameter_vector.h qoi_set.h sensitivity_data.h steady_system.h system.h system_norm.h system_subset.h system_subset_by_subdomain.h transient_system.h compare_types.h error_vector.h hashword.h ignore_warnings.h location_maps.h mapvector.h null_output_iterator.h number_lookups.h ostream_proxy.h parameters.h perf_log.h perfmon.h plt_loader.h point_locator_base.h point_locator_list.h point_locator_tree.h pool_allocator.h restore_warnings.h statistics.h string_to_enum.h timestamp.h tree.h tree_base.h tree_node.h utility.h vectormap.h xdr_cxx.h parallel_communicator_specializations
+BUILT_SOURCES = auto_ptr.h dirichlet_boundaries.h dof_map.h dof_object.h factory.h getpot.h id_types.h libmesh.h libmesh_C_isnan.h libmesh_augment_std_namespace.h libmesh_base.h libmesh_common.h libmesh_documentation.h libmesh_exceptions.h libmesh_logging.h libmesh_singleton.h libmesh_version.h multi_predicates.h periodic_boundaries.h periodic_boundary.h periodic_boundary_base.h print_trace.h reference_counted_object.h reference_counter.h single_predicates.h sparsity_pattern.h variable.h variant_filter_iterator.h enum_convergence_flags.h enum_eigen_solver_type.h enum_elem_quality.h enum_elem_type.h enum_fe_family.h enum_inf_map_type.h enum_io_package.h enum_norm_type.h enum_order.h enum_parallel_type.h enum_point_locator_type.h enum_preconditioner_type.h enum_quadrature_type.h enum_solver_package.h enum_solver_type.h enum_subset_solve_mode.h enum_xdr_mode.h adjoint_refinement_estimator.h adjoint_residual_error_estimator.h discontinuity_measure.h error_estimator.h exact_error_estimator.h exact_solution.h fourth_error_estimators.h hp_coarsentest.h hp_selector.h hp_singular.h jump_error_estimator.h kelly_error_estimator.h patch_recovery_error_estimator.h uniform_refinement_estimator.h weighted_patch_recovery_error_estimator.h fe.h fe_abstract.h fe_base.h fe_compute_data.h fe_interface.h fe_macro.h fe_map.h fe_transformation_base.h fe_type.h fe_xyz_map.h h1_fe_transformation.h hcurl_fe_transformation.h inf_fe.h inf_fe_instantiate_1D.h inf_fe_instantiate_2D.h inf_fe_instantiate_3D.h inf_fe_macro.h cell.h cell_hex.h cell_hex20.h cell_hex27.h cell_hex8.h cell_inf.h cell_inf_hex.h cell_inf_hex16.h cell_inf_hex18.h cell_inf_hex8.h cell_inf_prism.h cell_inf_prism12.h cell_inf_prism6.h cell_prism.h cell_prism15.h cell_prism18.h cell_prism6.h cell_pyramid.h cell_pyramid14.h cell_pyramid5.h cell_tet.h cell_tet10.h cell_tet4.h edge.h edge_edge2.h edge_edge3.h edge_edge4.h edge_inf_edge2.h elem.h elem_quality.h elem_range.h elem_type.h face.h face_inf_quad.h face_inf_quad4.h face_inf_quad6.h face_quad.h face_quad4.h face_quad8.h face_quad9.h face_tri.h face_tri3.h face_tri6.h node.h node_elem.h node_range.h plane.h point.h reference_elem.h remote_elem.h side.h sphere.h stored_range.h surface.h abaqus_io.h boundary_info.h boundary_mesh.h checkpoint_io.h diva_io.h ensight_io.h exodusII_io.h exodusII_io_helper.h fro_io.h gmsh_io.h gmv_io.h gnuplot_io.h inf_elem_builder.h legacy_xdr_io.h matlab_io.h medit_io.h mesh.h mesh_base.h mesh_communication.h mesh_data.h mesh_function.h mesh_generation.h mesh_input.h mesh_inserter_iterator.h mesh_modification.h mesh_output.h mesh_refinement.h mesh_serializer.h mesh_smoother.h mesh_smoother_laplace.h mesh_smoother_vsmoother.h mesh_tetgen_interface.h mesh_tetgen_wrapper.h mesh_tools.h mesh_triangle_holes.h mesh_triangle_interface.h mesh_triangle_wrapper.h nemesis_io.h nemesis_io_helper.h off_io.h parallel_mesh.h patch.h postscript_io.h serial_mesh.h tecplot_io.h tetgen_io.h ucd_io.h unstructured_mesh.h unv_io.h vtk_io.h xdr_head.h xdr_io.h xdr_mesh.h xdr_mgf.h xdr_mhead.h xdr_shead.h xdr_soln.h analytic_function.h const_fem_function.h const_function.h coupling_matrix.h dense_matrix.h dense_matrix_base.h dense_submatrix.h dense_subvector.h dense_vector.h dense_vector_base.h distributed_vector.h eigen_core_support.h eigen_preconditioner.h eigen_sparse_matrix.h eigen_sparse_vector.h fem_function_base.h function_base.h laspack_matrix.h laspack_vector.h numeric_vector.h parsed_function.h petsc_macro.h petsc_matrix.h petsc_preconditioner.h petsc_vector.h preconditioner.h raw_accessor.h refinement_selector.h shell_matrix.h sparse_matrix.h sparse_shell_matrix.h sum_shell_matrix.h tensor_shell_matrix.h tensor_tools.h tensor_value.h trilinos_epetra_matrix.h trilinos_epetra_vector.h trilinos_preconditioner.h type_n_tensor.h type_tensor.h type_vector.h vector_value.h wrapped_function.h zero_function.h parallel.h parallel_algebra.h parallel_bin_sorter.h parallel_conversion_utils.h parallel_elem.h parallel_ghost_sync.h parallel_hilbert.h parallel_histogram.h parallel_implementation.h parallel_node.h parallel_object.h parallel_sort.h threads.h threads_allocators.h centroid_partitioner.h hilbert_sfc_partitioner.h linear_partitioner.h metis_csr_graph.h metis_partitioner.h morton_sfc_partitioner.h parmetis_partitioner.h partitioner.h sfc_partitioner.h diff_physics.h diff_qoi.h fem_physics.h quadrature.h quadrature_clough.h quadrature_conical.h quadrature_gauss.h quadrature_gm.h quadrature_grid.h quadrature_jacobi.h quadrature_monomial.h quadrature_rules.h quadrature_simpson.h quadrature_trap.h derived_rb_construction.h derived_rb_evaluation.h rb_assembly_expansion.h rb_construction.h rb_construction_base.h rb_eim_assembly.h rb_eim_construction.h rb_eim_evaluation.h rb_eim_theta.h rb_evaluation.h rb_parameters.h rb_parametrized.h rb_parametrized_function.h rb_scm_construction.h rb_scm_evaluation.h rb_temporal_discretization.h rb_theta.h rb_theta_expansion.h transient_rb_assembly_expansion.h transient_rb_construction.h transient_rb_evaluation.h transient_rb_theta_expansion.h direct_solution_transfer.h dtk_adapter.h dtk_evaluator.h dtk_solution_transfer.h meshfree_interpolation.h meshfree_solution_transfer.h meshfunction_solution_transfer.h radial_basis_functions.h radial_basis_interpolation.h solution_transfer.h adaptive_time_solver.h diff_solver.h eigen_solver.h eigen_sparse_linear_solver.h eigen_time_solver.h euler2_solver.h euler_solver.h laspack_linear_solver.h linear.h linear_solver.h memory_solution_history.h newton_solver.h no_solution_history.h nonlinear_solver.h petsc_diff_solver.h petsc_dm_nonlinear_solver.h petsc_linear_solver.h petsc_nonlinear_solver.h petscdmlibmesh.h slepc_eigen_solver.h slepc_macro.h solution_history.h solver.h steady_solver.h time_solver.h trilinos_aztec_linear_solver.h trilinos_nox_nonlinear_solver.h twostep_time_solver.h unsteady_solver.h condensed_eigen_system.h continuation_system.h dg_fem_context.h diff_context.h diff_system.h eigen_system.h elem_assembly.h equation_systems.h explicit_system.h fem_context.h fem_system.h frequency_system.h implicit_system.h linear_implicit_system.h newmark_system.h nonlinear_implicit_system.h parameter_vector.h qoi_set.h sensitivity_data.h steady_system.h system.h system_norm.h system_subset.h system_subset_by_subdomain.h transient_system.h compare_types.h error_vector.h hashword.h ignore_warnings.h location_maps.h mapvector.h null_output_iterator.h number_lookups.h ostream_proxy.h parameters.h perf_log.h perfmon.h plt_loader.h point_locator_base.h point_locator_list.h point_locator_tree.h pool_allocator.h restore_warnings.h statistics.h string_to_enum.h timestamp.h tree.h tree_base.h tree_node.h utility.h vectormap.h xdr_cxx.h parallel_communicator_specializations
DISTCLEANFILES = $(BUILT_SOURCES)
@@ -171,6 +171,9 @@ variable.h: $(top_srcdir)/include/base/variable.h
variant_filter_iterator.h: $(top_srcdir)/include/base/variant_filter_iterator.h
$(AM_V_GEN)rm -f $@ && $(LN_S) $< $@
+enum_convergence_flags.h: $(top_srcdir)/include/enums/enum_convergence_flags.h
+ $(AM_V_GEN)rm -f $@ && $(LN_S) $< $@
+
enum_eigen_solver_type.h: $(top_srcdir)/include/enums/enum_eigen_solver_type.h
$(AM_V_GEN)rm -f $@ && $(LN_S) $< $@
View
17 include/libmesh/Makefile.in
@@ -432,13 +432,13 @@ BUILT_SOURCES = auto_ptr.h dirichlet_boundaries.h dof_map.h \
periodic_boundary.h periodic_boundary_base.h print_trace.h \
reference_counted_object.h reference_counter.h \
single_predicates.h sparsity_pattern.h variable.h \
- variant_filter_iterator.h enum_eigen_solver_type.h \
- enum_elem_quality.h enum_elem_type.h enum_fe_family.h \
- enum_inf_map_type.h enum_io_package.h enum_norm_type.h \
- enum_order.h enum_parallel_type.h enum_point_locator_type.h \
- enum_preconditioner_type.h enum_quadrature_type.h \
- enum_solver_package.h enum_solver_type.h \
- enum_subset_solve_mode.h enum_xdr_mode.h \
+ variant_filter_iterator.h enum_convergence_flags.h \
+ enum_eigen_solver_type.h enum_elem_quality.h enum_elem_type.h \
+ enum_fe_family.h enum_inf_map_type.h enum_io_package.h \
+ enum_norm_type.h enum_order.h enum_parallel_type.h \
+ enum_point_locator_type.h enum_preconditioner_type.h \
+ enum_quadrature_type.h enum_solver_package.h \
+ enum_solver_type.h enum_subset_solve_mode.h enum_xdr_mode.h \
adjoint_refinement_estimator.h \
adjoint_residual_error_estimator.h discontinuity_measure.h \
error_estimator.h exact_error_estimator.h exact_solution.h \
@@ -867,6 +867,9 @@ variable.h: $(top_srcdir)/include/base/variable.h
variant_filter_iterator.h: $(top_srcdir)/include/base/variant_filter_iterator.h
$(AM_V_GEN)rm -f $@ && $(LN_S) $< $@
+enum_convergence_flags.h: $(top_srcdir)/include/enums/enum_convergence_flags.h
+ $(AM_V_GEN)rm -f $@ && $(LN_S) $< $@
+
enum_eigen_solver_type.h: $(top_srcdir)/include/enums/enum_eigen_solver_type.h
$(AM_V_GEN)rm -f $@ && $(LN_S) $< $@
View
7 include/solvers/eigen_sparse_linear_solver.h
@@ -128,7 +128,12 @@ class EigenSparseLinearSolver : public LinearSolver<T>
* Prints a useful message about why the latest linear solve
* con(di)verged.
*/
- virtual void print_converged_reason();
+ virtual void print_converged_reason() const;
+
+ /**
+ * Returns the solver's convergence flag
+ */
+ virtual LinearConvergenceReason get_converged_reason() const;
private:
View
7 include/solvers/laspack_linear_solver.h
@@ -132,7 +132,12 @@ class LaspackLinearSolver : public LinearSolver<T>
* Prints a useful message about why the latest linear solve
* con(di)verged.
*/
- virtual void print_converged_reason();
+ virtual void print_converged_reason() const;
+
+ /**
+ * Returns the solver's convergence flag
+ */
+ virtual LinearConvergenceReason get_converged_reason() const;
private:
View
10 include/solvers/linear_solver.h
@@ -22,6 +22,7 @@
// Local includes
#include "libmesh/libmesh_common.h"
+#include "libmesh/enum_convergence_flags.h"
#include "libmesh/enum_solver_package.h"
#include "libmesh/enum_solver_type.h"
#include "libmesh/enum_preconditioner_type.h"
@@ -44,7 +45,6 @@ template <typename T> class NumericVector;
template <typename T> class ShellMatrix;
template <typename T> class Preconditioner;
-
/**
* This class provides a uniform interface for linear solvers. This base
* class is overloaded to provide linear solvers from different packages
@@ -224,8 +224,12 @@ class LinearSolver : public ReferenceCountedObject<LinearSolver<T> >,
* Prints a useful message about why the latest linear solve
* con(di)verged.
*/
- virtual void print_converged_reason() = 0;
-
+ virtual void print_converged_reason() const;
+
+ /**
+ * Returns the solver's convergence flag
+ */
+ virtual LinearConvergenceReason get_converged_reason() const = 0;
protected:
View
5 include/solvers/petsc_linear_solver.h
@@ -236,10 +236,9 @@ class PetscLinearSolver : public LinearSolver<T>
Real get_initial_residual();
/**
- * Prints a useful message about why the latest linear solve
- * con(di)verged.
+ * Returns the solver's convergence flag
*/
- virtual void print_converged_reason();
+ virtual LinearConvergenceReason get_converged_reason() const;
private:
View
10 src/solvers/eigen_sparse_linear_solver.C
@@ -233,7 +233,7 @@ void EigenSparseLinearSolver<T>::set_eigen_preconditioner_type ()
template <typename T>
-void EigenSparseLinearSolver<T>::print_converged_reason()
+void EigenSparseLinearSolver<T>::print_converged_reason() const
{
libMesh::out << "print_converged_reason() is currently only supported"
<< "with Petsc 2.3.1 and later." << std::endl;
@@ -241,6 +241,14 @@ void EigenSparseLinearSolver<T>::print_converged_reason()
+template <typename T>
+LinearConvergenceReason EigenSparseLinearSolver<T>::get_converged_reason() const
+{
+ libmesh_not_implemented();
+}
+
+
+
//------------------------------------------------------------------
// Explicit instantiations
template class EigenSparseLinearSolver<Number>;
View
10 src/solvers/laspack_linear_solver.C
@@ -516,7 +516,7 @@ void LaspackLinearSolver<T>::set_laspack_preconditioner_type ()
template <typename T>
-void LaspackLinearSolver<T>::print_converged_reason()
+void LaspackLinearSolver<T>::print_converged_reason() const
{
libMesh::out << "print_converged_reason() is currently only supported"
<< "with Petsc 2.3.1 and later." << std::endl;
@@ -524,6 +524,14 @@ void LaspackLinearSolver<T>::print_converged_reason()
+template <typename T>
+LinearConvergenceReason LaspackLinearSolver<T>::get_converged_reason() const
+{
+ libmesh_not_implemented();
+}
+
+
+
//------------------------------------------------------------------
// Explicit instantiations
template class LaspackLinearSolver<Number>;
View
7 src/solvers/linear_solver.C
@@ -29,6 +29,7 @@
#include "libmesh/trilinos_aztec_linear_solver.h"
#include "libmesh/preconditioner.h"
#include "libmesh/sparse_matrix.h"
+#include "libmesh/string_to_enum.h"
namespace libMesh
{
@@ -173,6 +174,12 @@ LinearSolver<T>::restrict_solve_to(const std::vector<unsigned int>* const dofs,
}
+template <typename T>
+void LinearSolver<T>::print_converged_reason() const
+{
+ LinearConvergenceReason reason = this->get_converged_reason();
+ libMesh::out << "Linear solver convergence/divergence reason: " << Utility::enum_to_string(reason) << std::endl;
+}
//------------------------------------------------------------------
// Explicit instantiations
View
32 src/solvers/petsc_linear_solver.C
@@ -1804,14 +1804,40 @@ void PetscLinearSolver<T>::set_petsc_solver_type()
}
}
+
+
template <typename T>
-void PetscLinearSolver<T>::print_converged_reason()
+LinearConvergenceReason PetscLinearSolver<T>::get_converged_reason() const
{
KSPConvergedReason reason;
KSPGetConvergedReason(_ksp, &reason);
- libMesh::out << "Linear solver convergence/divergence reason: " << KSPConvergedReasons[reason] << std::endl;
-}
+ switch(reason)
+ {
+ case KSP_CONVERGED_RTOL_NORMAL : return CONVERGED_RTOL_NORMAL;
+ case KSP_CONVERGED_ATOL_NORMAL : return CONVERGED_ATOL_NORMAL;
+ case KSP_CONVERGED_RTOL : return CONVERGED_RTOL;
+ case KSP_CONVERGED_ATOL : return CONVERGED_ATOL;
+ case KSP_CONVERGED_ITS : return CONVERGED_ITS;
+ case KSP_CONVERGED_CG_NEG_CURVE : return CONVERGED_CG_NEG_CURVE;
+ case KSP_CONVERGED_CG_CONSTRAINED : return CONVERGED_CG_CONSTRAINED;
+ case KSP_CONVERGED_STEP_LENGTH : return CONVERGED_STEP_LENGTH;
+ case KSP_CONVERGED_HAPPY_BREAKDOWN : return CONVERGED_HAPPY_BREAKDOWN;
+ case KSP_DIVERGED_NULL : return DIVERGED_NULL;
+ case KSP_DIVERGED_ITS : return DIVERGED_ITS;
+ case KSP_DIVERGED_DTOL : return DIVERGED_DTOL;
+ case KSP_DIVERGED_BREAKDOWN : return DIVERGED_BREAKDOWN;
+ case KSP_DIVERGED_BREAKDOWN_BICG : return DIVERGED_BREAKDOWN_BICG;
+ case KSP_DIVERGED_NONSYMMETRIC : return DIVERGED_NONSYMMETRIC;
+ case KSP_DIVERGED_INDEFINITE_PC : return DIVERGED_INDEFINITE_PC;
+ case KSP_DIVERGED_NAN : return DIVERGED_NAN;
+ case KSP_DIVERGED_INDEFINITE_MAT : return DIVERGED_INDEFINITE_MAT;
+ case KSP_CONVERGED_ITERATING : return CONVERGED_ITERATING;
+ default :
+ libMesh::err << "Unknown convergence flag!" << std::endl;
+ return UNKNOWN_FLAG;
+ }
+}
template <typename T>
View
30 src/utils/string_to_enum.C
@@ -24,6 +24,7 @@
// Local includes
#include "libmesh/libmesh_common.h"
#include "libmesh/string_to_enum.h"
+#include "libmesh/enum_convergence_flags.h"
#include "libmesh/enum_elem_quality.h"
#include "libmesh/enum_elem_type.h"
#include "libmesh/enum_eigen_solver_type.h"
@@ -552,7 +553,35 @@ INSTANTIATE_ENUM_MAPS(XdrMODE, xdr_mode)
}
+INSTANTIATE_ENUM_MAPS(LinearConvergenceReason, linear_convergence_reason)
+ // Initialize xdr_mode_to_enum on first call
+ void init_linear_convergence_reason_to_enum ()
+ {
+ if (linear_convergence_reason_to_enum.empty())
+ {
+ linear_convergence_reason_to_enum["CONVERGED_RTOL_NORMAL"] = CONVERGED_RTOL_NORMAL;
+ linear_convergence_reason_to_enum["CONVERGED_ATOL_NORMAL"] = CONVERGED_ATOL_NORMAL;
+ linear_convergence_reason_to_enum["CONVERGED_RTOL"] = CONVERGED_RTOL;
+ linear_convergence_reason_to_enum["CONVERGED_ATOL"] = CONVERGED_ATOL;
+ linear_convergence_reason_to_enum["CONVERGED_ITS"] = CONVERGED_ITS;
+ linear_convergence_reason_to_enum["CONVERGED_CG_NEG_CURVE"] = CONVERGED_CG_NEG_CURVE;
+ linear_convergence_reason_to_enum["CONVERGED_CG_CONSTRAINED"] = CONVERGED_CG_CONSTRAINED;
+ linear_convergence_reason_to_enum["CONVERGED_STEP_LENGTH"] = CONVERGED_STEP_LENGTH;
+ linear_convergence_reason_to_enum["CONVERGED_HAPPY_BREAKDOWN"] = CONVERGED_HAPPY_BREAKDOWN;
+ linear_convergence_reason_to_enum["DIVERGED_NULL"] = DIVERGED_NULL;
+ linear_convergence_reason_to_enum["DIVERGED_ITS"] = DIVERGED_ITS;
+ linear_convergence_reason_to_enum["DIVERGED_DTOL"] = DIVERGED_DTOL;
+ linear_convergence_reason_to_enum["DIVERGED_BREAKDOWN"] = DIVERGED_BREAKDOWN;
+ linear_convergence_reason_to_enum["DIVERGED_BREAKDOWN_BICG"] = DIVERGED_BREAKDOWN_BICG;
+ linear_convergence_reason_to_enum["DIVERGED_NONSYMMETRIC"] = DIVERGED_NONSYMMETRIC;
+ linear_convergence_reason_to_enum["DIVERGED_INDEFINITE_PC"] = DIVERGED_INDEFINITE_PC;
+ linear_convergence_reason_to_enum["DIVERGED_NAN"] = DIVERGED_NAN;
+ linear_convergence_reason_to_enum["DIVERGED_INDEFINITE_MAT"] = DIVERGED_INDEFINITE_MAT;
+ linear_convergence_reason_to_enum["CONVERGED_ITERATING"] = CONVERGED_ITERATING;
+ linear_convergence_reason_to_enum["UNKNOWN_FLAG"] = UNKNOWN_FLAG;
+ }
+ }
#undef INSTANTIATE_ENUM_MAPS
@@ -616,6 +645,7 @@ INSTANTIATE_STRING_TO_ENUM(PointLocatorType, point_locator_type)
INSTANTIATE_STRING_TO_ENUM(SolverPackage,solverpackage_type)
INSTANTIATE_STRING_TO_ENUM(SubsetSolveMode,subset_solve_mode)
INSTANTIATE_STRING_TO_ENUM(XdrMODE,xdr_mode)
+INSTANTIATE_STRING_TO_ENUM(LinearConvergenceReason, linear_convergence_reason)
#undef INSTANTIATE_STRING_TO_ENUM
Something went wrong with that request. Please try again.