LCOV - code coverage report
Current view: top level - ugbase/lib_algebra/operator/interface - matrix_operator_inverse.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 8 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 6 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2013-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              : #ifndef __H__LIB_ALGEBRA__OPERATOR__INTERFACE__MATRIX_OPERATOR_INVERSE__
      34              : #define __H__LIB_ALGEBRA__OPERATOR__INTERFACE__MATRIX_OPERATOR_INVERSE__
      35              : 
      36              : #include "linear_operator_inverse.h"
      37              : #include "matrix_operator.h"
      38              : #include "common/error.h"
      39              : #include "common/util/smart_pointer.h"
      40              : 
      41              : namespace ug{
      42              : 
      43              : ///////////////////////////////////////////////////////////////////////////////
      44              : // Inverse of a Matrix-based Linear Operator
      45              : ///////////////////////////////////////////////////////////////////////////////
      46              : 
      47              : /// describes an inverse linear mapping X->Y based on a matrix
      48              : /**
      49              :  * This class is the base class for the inversion of linear matrix-based operator
      50              :  * given in form of the IMatrixOperator interface class. Given a operator L,
      51              :  * the basic usage of this class is to invert this operator, i.e. to compute
      52              :  * the solution u of
      53              :  *
      54              :  *              L*u = f     i.e. u := L^{-1} f
      55              :  *
      56              :  *
      57              :  * \tparam      X               domain space (i.e. a vector corresponding to the matrix)
      58              :  * \tparam      Y               range space (i.e. a vector corresponding to the matrix)
      59              :  * \tparam      M               matrix type used to represent linear mapping
      60              :  */
      61              : template <typename M, typename X, typename Y = X>
      62              : class IMatrixOperatorInverse
      63              :         : public virtual ILinearOperatorInverse<X,Y>
      64              : {
      65              :         public:
      66              :         ///     Domain space
      67              :                 typedef X domain_function_type;
      68              : 
      69              :         ///     Range space
      70              :                 typedef Y codomain_function_type;
      71              : 
      72              :         ///     Matrix type
      73              :                 typedef M matrix_type;
      74              : 
      75              :         public:
      76              :         ///     initializes this inverse operator for a matrix-based operator
      77              :         /**
      78              :          * This method passes the operator A that is inverted by this operator. In
      79              :          * addition some preparation step can be made.
      80              :          *
      81              :          * \param[in]   A               linear matrix-basewd operator to invert
      82              :          * \returns             bool    success flag
      83              :          */
      84              :                 virtual bool init(SmartPtr<MatrixOperator<M,Y,X> > A) = 0;
      85              : 
      86              :         /// applies the inverse operator, i.e. returns u = A^{-1} * f
      87              :         /**
      88              :          * This method applies the inverse operator.
      89              :          *
      90              :          * \param[out]  u               solution
      91              :          * \param[in]   f               right-hand side
      92              :          * \returns             bool    success flag
      93              :          */
      94              :                 virtual bool apply(Y& u, const X& f) = 0;
      95              : 
      96              :         /// applies the inverse operator and updates the defect
      97              :         /**
      98              :          * This method applies the inverse operator and updates the defect, i.e.
      99              :          * returns u = A^{-1} * f and in f the last defect d:= f - A*u is returned.
     100              :          *
     101              :          * \param[out]  u               solution
     102              :          * \param[in]   f               right-hand side on entry, defect on exit
     103              :          * \returns             bool    success flag
     104              :          */
     105              :                 virtual bool apply_return_defect(Y& u, X& f) = 0;
     106              : 
     107              :         /// virtual destructor
     108            0 :                 virtual ~IMatrixOperatorInverse() {};
     109              : 
     110              :         public:
     111              :         ///     initializes this inverse operator for a linear operator
     112              :         /**
     113              :          * This method implements the ILinearOperatorInverse interface method.
     114              :          * Basically, the request is forwarded to the matrix-based init method,
     115              :          * if the the operator is matrix-based. If the operator is not matrix-based
     116              :          * this inverse can not be used and false is returned
     117              :          *
     118              :          * \param[in]   A               linear matrix-based operator to invert
     119              :          * \param[in]   u               linearization point
     120              :          * \returns             bool    success flag
     121              :          */
     122            0 :                 virtual bool init(SmartPtr<ILinearOperator<Y,X> > A, const Y&u)
     123              :                 {
     124              :                 //      forget about u and forward request.
     125            0 :                         return init(A);
     126              :                 }
     127              : 
     128              :         ///     initializes this inverse operator for a linear operator
     129              :         /**
     130              :          * This method implements the ILinearOperatorInverse interface method.
     131              :          * Basically, the request is forwarded to the matrix-based init method,
     132              :          * if the the operator is matrix-based. If the operator is not matrix-based
     133              :          * this inverse can not be used and false is returned
     134              :          *
     135              :          * \param[in]   A               linear matrix-based operator to invert
     136              :          * \returns             bool    success flag
     137              :          */
     138            0 :                 virtual bool init(SmartPtr<ILinearOperator<Y,X> > A)
     139              :                 {
     140              :                 //      cast operator
     141            0 :                         SmartPtr<MatrixOperator<M,Y,X> > op =
     142              :                                                                         A.template cast_dynamic<MatrixOperator<M,Y,X> >();
     143              : 
     144              :                 //      check if correct types are present
     145            0 :                         if(op.invalid())
     146            0 :                                 UG_THROW("IMatrixOperatorInverse::init:"
     147              :                                                 " Passed operator is not matrix-based.");
     148              : 
     149              :                 //      forward request
     150            0 :                         return init(op);
     151              :                 }
     152              : };
     153              : 
     154              : }
     155              : #endif /* __H__LIB_ALGEBRA__OPERATOR__INTERFACE__MATRIX_OPERATOR_INVERSE__ */
        

Generated by: LCOV version 2.0-1