LCOV - code coverage report
Current view: top level - ugbase/bridge/algebra_bridges - solver_bridge.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 99.0 % 105 104
Test Date: 2025-09-21 23:31:46 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2012-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Andreas Vogel
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : // extern headers
      34              : #include <iostream>
      35              : #include <sstream>
      36              : #include <string>
      37              : 
      38              : // include bridge
      39              : #include "bridge/bridge.h"
      40              : #include "bridge/util.h"
      41              : #include "bridge/util_algebra_dependent.h"
      42              : 
      43              : // solver
      44              : #include "lib_algebra/lib_algebra.h"
      45              : #include "lib_algebra/operator/damping.h"
      46              : #include "lib_algebra/operator/linear_solver/linear_solver.h"
      47              : #include "lib_algebra/operator/linear_solver/auto_linear_solver.h"
      48              : #include "lib_algebra/operator/linear_solver/analyzing_solver.h"
      49              : #include "lib_algebra/operator/linear_solver/cg.h"
      50              : #include "lib_algebra/operator/linear_solver/bicgstab.h"
      51              : #include "lib_algebra/operator/linear_solver/gmres.h"
      52              : #include "lib_algebra/operator/linear_solver/lu.h"
      53              : #include "lib_algebra/operator/linear_solver/agglomerating_solver.h"
      54              : #include "lib_algebra/operator/linear_solver/debug_iterator.h"
      55              : #include "lib_algebra/operator/linear_solver/external_solvers/external_solvers.h"
      56              : #ifdef UG_PARALLEL
      57              : #include "lib_algebra/operator/linear_solver/feti.h"
      58              : #endif
      59              : #include "../util_overloaded.h"
      60              : 
      61              : 
      62              : using namespace std;
      63              : 
      64              : namespace ug{
      65              : namespace bridge{
      66              : namespace Solver{
      67              : 
      68              : /**
      69              :  * \defgroup solver_bridge Solver Bridge
      70              :  * \ingroup algebra_bridge
      71              :  * \{
      72              :  */
      73              : 
      74              : /**
      75              :  * Class exporting the functionality. All functionality that is to
      76              :  * be used in scripts or visualization must be registered here.
      77              :  */
      78              : struct Functionality
      79              : {
      80              : 
      81              : /**
      82              :  * Function called for the registration of Algebra dependent parts.
      83              :  * All Functions and Classes depending on Algebra
      84              :  * are to be placed here when registering. The method is called for all
      85              :  * available Algebra types, based on the current build options.
      86              :  *
      87              :  * @param reg                           registry
      88              :  * @param parentGroup           group for sorting of functionality
      89              :  */
      90              : template <typename TAlgebra>
      91            3 : static void Algebra(Registry& reg, string grp)
      92              : {
      93            3 :         string suffix = GetAlgebraSuffix<TAlgebra>();
      94            3 :         string tag = GetAlgebraTag<TAlgebra>();
      95              : 
      96              : //      typedefs for this algebra
      97              :         typedef typename TAlgebra::vector_type vector_type;
      98              :         typedef typename TAlgebra::matrix_type matrix_type;
      99              : 
     100              : 
     101              : //      IDamping
     102              :         {
     103              :                 typedef IDamping<vector_type> T;
     104            3 :                 string name = string("IDamping").append(suffix);
     105            9 :                 reg.add_class_<T>(name, grp);
     106            9 :                 reg.add_class_to_group(name, "IDamping", tag);
     107              :         }
     108              : 
     109              : //      MinimalResiduumDamping
     110              :         {
     111              :                 typedef MinimalResiduumDamping<vector_type> T;
     112              :                 typedef IDamping<vector_type> TBase;
     113            3 :                 string name = string("MinimalResiduumDamping").append(suffix);
     114            9 :                 reg.add_class_<T,TBase>(name, grp, "Minimal Residdum Damping (damping computed based on the minimal residuum)")
     115            3 :                         .add_constructor()
     116            3 :                         .set_construct_as_smart_pointer(true);
     117            9 :                 reg.add_class_to_group(name, "MinimalResiduumDamping", tag);
     118              :         }
     119              :         
     120              : //      MinimalEngergyDamping
     121              :         {
     122              :                 typedef MinimalEnergyDamping<vector_type> T;
     123              :                 typedef IDamping<vector_type> TBase;
     124            3 :                 string name = string("MinimalEnergyDamping").append(suffix);
     125            9 :                 reg.add_class_<T,TBase>(name, grp, "Minimal Energy Damping (damping computed based on the minimal energy)")
     126            3 :                         .add_constructor()
     127            3 :                         .set_construct_as_smart_pointer(true);
     128            9 :                 reg.add_class_to_group(name, "MinimalEnergyDamping", tag);
     129              :         }
     130              :         
     131              : //      Pre- and postprocess operations
     132              :         {
     133              :                 typedef IPProcessVector<vector_type> T;
     134            3 :                 string name = string("IPProcessVector").append(suffix);
     135            9 :                 reg.add_class_<T>(name, grp)
     136            6 :                         .add_method("apply", &T::apply, "applies the operation", "vector");
     137            9 :                 reg.add_class_to_group(name, "IPProcessVector", tag);
     138              :         }
     139              : 
     140              : //      LinearSolver
     141              :         {
     142              :                 typedef LinearSolver<vector_type> T;
     143              :                 typedef IPreconditionedLinearOperatorInverse<vector_type> TBase;
     144            3 :                 string name = string("LinearSolver").append(suffix);
     145            9 :                 reg.add_class_<T,TBase>(name, grp, "Linear Solver")
     146            3 :                         .add_constructor()
     147            6 :                         . ADD_CONSTRUCTOR( (SmartPtr<ILinearIterator<vector_type,vector_type> > ) )("precond")
     148            6 :                         . ADD_CONSTRUCTOR( (SmartPtr<ILinearIterator<vector_type,vector_type> >, SmartPtr<IConvergenceCheck<vector_type> >) )("precond#convCheck")
     149            9 :                         .add_method("add_postprocess_corr", &T::add_postprocess_corr, "adds a postprocess of the corrections", "op")
     150            9 :                         .add_method("remove_postprocess_corr", &T::remove_postprocess_corr, "removes a postprocess of the corrections", "op")
     151            3 :                         .set_construct_as_smart_pointer(true);
     152            9 :                 reg.add_class_to_group(name, "LinearSolver", tag);
     153              :         }
     154              : 
     155              : 
     156              : //      AutoLinearSolver
     157              :         {
     158              :                 typedef AutoLinearSolver<vector_type> T;
     159              :                 typedef IPreconditionedLinearOperatorInverse<vector_type> TBase;
     160            3 :                 string name = string("AutoLinearSolver").append(suffix);
     161            9 :                 reg.add_class_<T,TBase>(name, grp, "Auto Linear Solver")
     162            3 :                         .add_constructor()
     163            6 :                         .ADD_CONSTRUCTOR( (double, double) )("reductionAlwaysAccept#worseThenAverage")
     164            9 :                         .add_method("set_reduction_always_accept", &T::set_reduction_always_accept)
     165           12 :                         .add_method("set_reinit_when_worse_then_average", &T::set_reinit_when_worse_then_average)
     166            9 :                         .add_method("print_information", &T::print_information)
     167            3 :                         .set_construct_as_smart_pointer(true);
     168              : 
     169            9 :                 reg.add_class_to_group(name, "AutoLinearSolver", tag);
     170              :         }
     171              : 
     172              : //      AnalyzingSolver
     173              :         {
     174              :                 typedef AnalyzingSolver<matrix_type, vector_type> T;
     175              :                 typedef  ILinearOperatorInverse<vector_type> TBase;
     176            3 :                 string name = string("AnalyzingSolver").append(suffix);
     177            9 :                 reg.add_class_<T,TBase>(name, grp, "AnalyzingSolver")
     178            6 :                         .ADD_CONSTRUCTOR( (SmartPtr<ILinearOperatorInverse<vector_type> >) )("solver")
     179            3 :                         .set_construct_as_smart_pointer(true);
     180            9 :                 reg.add_class_to_group(name, "AnalyzingSolver", tag);
     181              :         }
     182              : 
     183              :         //      Debug iteration
     184              :         {
     185              :                 typedef DebugIterator<TAlgebra> T;
     186              :                 typedef ILinearIterator<typename TAlgebra::vector_type> TBase;
     187              : 
     188              :                 typedef ILinearIterator<typename TAlgebra::vector_type> base_type;
     189              :                 typedef IPreconditionedLinearOperatorInverse<vector_type> solver_type;
     190              : 
     191            3 :                 string name = string("DebugIterator").append(suffix);
     192            9 :                 reg.add_class_<T,TBase>(name, grp, "DebugIterator")
     193            3 :                 .add_constructor()
     194            6 :                 . ADD_CONSTRUCTOR( (SmartPtr<base_type> pprecond, SmartPtr<solver_type> psolver) ) ("precond#solver")
     195            9 :                 .add_method("set_preconditioner", &T::set_preconditioner)
     196           12 :                 .add_method("set_solver", &T::set_solver)
     197           12 :                 .add_method("set_debug", &T::set_debug)
     198           12 :                 .add_method("set_solution", &T::set_solution)
     199            9 :                 .add_method("set_random_bounds", &T::set_random_bounds)
     200            3 :                 .set_construct_as_smart_pointer(true);
     201            9 :                 reg.add_class_to_group(name, "DebugIterator", tag);
     202              :         }
     203              : 
     204              : 
     205              :         //      CG Solver
     206              :         {
     207              :                 typedef CG<vector_type> T;
     208              :                 typedef IPreconditionedLinearOperatorInverse<vector_type> TBase;
     209            3 :                 string name = string("CG").append(suffix);
     210            9 :                 reg.add_class_<T,TBase>(name, grp, "Conjugate Gradient Solver")
     211            3 :                         .add_constructor()
     212            6 :                         . ADD_CONSTRUCTOR( (SmartPtr<ILinearIterator<vector_type,vector_type> > ) )("precond")
     213            6 :                         . ADD_CONSTRUCTOR( (SmartPtr<ILinearIterator<vector_type,vector_type> >, SmartPtr<IConvergenceCheck<vector_type> >) )("precond#convCheck")
     214            9 :                         .add_method("add_postprocess_corr", &T::add_postprocess_corr, "adds a postprocess of the corrections", "op")
     215            9 :                         .add_method("remove_postprocess_corr", &T::remove_postprocess_corr, "removes a postprocess of the corrections", "op")
     216            3 :                         .set_construct_as_smart_pointer(true);
     217            9 :                 reg.add_class_to_group(name, "CG", tag);
     218              :         }
     219              : 
     220              : //      BiCGStab Solver
     221              :         {
     222              :                 typedef BiCGStab<vector_type> T;
     223              :                 typedef IPreconditionedLinearOperatorInverse<vector_type> TBase;
     224            3 :                 string name = string("BiCGStab").append(suffix);
     225            9 :                 reg.add_class_<T,TBase>(name, grp, "BiCGStab Solver")
     226            3 :                         .add_constructor()
     227            6 :                         . ADD_CONSTRUCTOR( (SmartPtr<ILinearIterator<vector_type,vector_type> > ) )("precond")
     228            6 :                         . ADD_CONSTRUCTOR( (SmartPtr<ILinearIterator<vector_type,vector_type> >, SmartPtr<IConvergenceCheck<vector_type> >) )("precond#convCheck")
     229            9 :                         .add_method("set_restart", &T::set_restart)
     230           12 :                         .add_method("set_min_orthogonality", &T::set_min_orthogonality)
     231           12 :                         .add_method("add_postprocess_corr", &T::add_postprocess_corr, "adds a postprocess of the corrections", "op")
     232            9 :                         .add_method("remove_postprocess_corr", &T::remove_postprocess_corr, "removes a postprocess of the corrections", "op")
     233            3 :                         .set_construct_as_smart_pointer(true);
     234            9 :                 reg.add_class_to_group(name, "BiCGStab", tag);
     235              :         }
     236              : 
     237              : //      GMRES Solver
     238              :         {
     239              :                 typedef GMRES<vector_type> T;
     240              :                 typedef IPreconditionedLinearOperatorInverse<vector_type> TBase;
     241            3 :                 string name = string("GMRES").append(suffix);
     242            9 :                 reg.add_class_<T,TBase>(name, grp, "GMRES Solver")
     243            6 :                         .ADD_CONSTRUCTOR( (size_t restar) )("restart")
     244            9 :                         .add_method("add_postprocess_corr", &T::add_postprocess_corr, "adds a postprocess of the corrections", "op")
     245            9 :                         .add_method("remove_postprocess_corr", &T::remove_postprocess_corr, "removes a postprocess of the corrections", "op")
     246            3 :                         .set_construct_as_smart_pointer(true);
     247            9 :                 reg.add_class_to_group(name, "GMRES", tag);
     248              :         }
     249              : 
     250              : //      LU Solver
     251              :         {
     252              :                 typedef LU<TAlgebra> T;
     253              :                 typedef ILinearOperatorInverse<vector_type> TBase;
     254            3 :                 string name = string("LU").append(suffix);
     255            9 :                 reg.add_class_<T,TBase>(name, grp, "LU-Decomposition exact solver")
     256            3 :                         .add_constructor()
     257            9 :                         .add_method("set_minimum_for_sparse", &T::set_minimum_for_sparse, "", "N")
     258           12 :                         .add_method("set_sort_sparse", &T::set_sort_sparse, "", "bSort", "if bSort=true, use a cuthill-mckey sorting to reduce fill-in in sparse LU. default true")
     259           12 :                         .add_method("set_info", &T::set_info, "", "bInfo", "if true, sparse LU prints some fill-in info")
     260            9 :                         .add_method("set_show_progress", &T::set_show_progress, "", "onoff", "switches the progress indicator on/off")
     261            3 :                         .set_construct_as_smart_pointer(true);
     262            9 :                 reg.add_class_to_group(name, "LU", tag);
     263              :         }
     264              : 
     265              : //      AgglomeratingSolver
     266              :         {
     267              :                 typedef AgglomeratingSolver<TAlgebra> T;
     268              :                 typedef ILinearOperatorInverse<vector_type> TBase;
     269            3 :                 string name = string("AgglomeratingSolver").append(suffix);
     270            9 :                 reg.add_class_<T,TBase>(name, grp, "AgglomeratingSolver")
     271            6 :                         .ADD_CONSTRUCTOR( (SmartPtr<ILinearOperatorInverse<vector_type, vector_type> > ) )("pLinOp")
     272            3 :                         .set_construct_as_smart_pointer(true);
     273            9 :                 reg.add_class_to_group(name, "AgglomeratingSolver", tag);
     274              :         }
     275              : 
     276              : 
     277              : #ifdef UG_PARALLEL
     278              : //      LocalSchurComplement
     279              :         {
     280              :                 typedef LocalSchurComplement<TAlgebra> T;
     281              :                 typedef ILinearOperator<vector_type> TBase;
     282              :                 typedef DebugWritingObject<TAlgebra> TBase2;
     283              :                 string name = string("LocalSchurComplement").append(suffix);
     284              :                 reg.add_class_<      T, TBase, TBase2>(name, grp)
     285              :                 .add_constructor()
     286              :                 .add_method("set_matrix", &T::set_matrix,
     287              :                                         "", "Matrix")
     288              :                 .add_method("set_dirichlet_solver", &T::set_dirichlet_solver,
     289              :                                         "", "Dirichlet Solver")
     290              :                 // the following functions would normally not be executed from script
     291              :                 .add_method("init", static_cast<void (T::*)()>(&T::init))
     292              :                 .add_method("apply", &T::apply,
     293              :                                         "Success", "local SC times Vector#Vector")
     294              :                 .set_construct_as_smart_pointer(true);
     295              :                 reg.add_class_to_group(name, "LocalSchurComplement", tag);
     296              :         }
     297              : 
     298              : //      FETISolver
     299              :         {
     300              :                 typedef FETISolver<TAlgebra> T;
     301              :                 typedef IMatrixOperatorInverse<matrix_type, vector_type> BaseT;
     302              :                 typedef DebugWritingObject<TAlgebra> TBase2;
     303              :                 string name = string("FETI").append(suffix);
     304              :                 reg.add_class_<      T, BaseT,TBase2>(name, grp, "FETI Domain Decomposition Solver")
     305              :                 .add_constructor()
     306              :                 .add_method("set_neumann_solver", &T::set_neumann_solver, "", 
     307              :                                         "", "Neumann Solver")
     308              :                 .add_method("set_dirichlet_solver", &T::set_dirichlet_solver, "",
     309              :                                         "", "Dirichlet Solver")
     310              :                 .add_method("set_coarse_problem_solver", &T::set_coarse_problem_solver, "",
     311              :                                         "", "Coarse Problem Solver")
     312              :                 .add_method("set_domain_decomp_info", &T::set_domain_decomp_info)
     313              :                 .add_method("print_statistic_of_inner_solver", &T::print_statistic_of_inner_solver)
     314              :                 .add_method("set_debug", &T::set_debug)
     315              :                 .add_method("test_layouts", &T::test_layouts)
     316              :                 .add_method("set_test_one_to_many_layouts", &T::set_test_one_to_many_layouts)
     317              :                 .set_construct_as_smart_pointer(true);
     318              :                 reg.add_class_to_group(name, "FETI", tag);
     319              :         }
     320              : #endif
     321              : 
     322              :         // ExternalSolver
     323              :         {
     324              :                 typedef IExternalSolver<TAlgebra> T;
     325            3 :                 string name = string("ExternalSolver").append(suffix);
     326            9 :                 reg.add_class_<T>(name, grp)
     327            9 :                         .add_method("set_disable_preprocessing", &T::set_disable_preprocessing, "", "", "")
     328            9 :                         .add_method("enable_consistent_interfaces", &T::enable_consistent_interfaces, "", "", "");
     329              : 
     330              :         }
     331              : 
     332              : 
     333            3 : }
     334              : 
     335              : }; // end Functionality
     336              : 
     337              : // end group solver_bridge
     338              : /// \}
     339              : 
     340              : }// end Solver
     341              : 
     342              : /// \addtogroup solver_bridge
     343            1 : void RegisterBridge_Solver(Registry& reg, string grp)
     344              : {
     345            1 :         grp.append("/Algebra/Solver");
     346              :         typedef Solver::Functionality Functionality;
     347              : 
     348              :         try{
     349            1 :                 RegisterAlgebraDependent<Functionality>(reg,grp);
     350              :         }
     351            0 :         UG_REGISTRY_CATCH_THROW(grp);
     352            1 : }
     353              : 
     354              : } // namespace bridge
     355              : } // namespace ug
        

Generated by: LCOV version 2.0-1