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

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2010-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__UG__LIB_DISC__SPATIAL_DISC__DOMAIN_DISC_INTERFACE__
      34              : #define __H__UG__LIB_DISC__SPATIAL_DISC__DOMAIN_DISC_INTERFACE__
      35              : 
      36              : #include "lib_algebra/cpu_algebra_types.h"
      37              : #include "lib_disc/assemble_interface.h"
      38              : #include "lib_disc/time_disc/solution_time_series.h"
      39              : #include "lib_disc/spatial_disc/constraints/constraint_interface.h"
      40              : #include "lib_grid/refinement/refiner_interface.h"
      41              : #include "lib_disc/function_spaces/error_elem_marking_strategy.h"
      42              : 
      43              : namespace ug {
      44              : 
      45              : /// \ingroup lib_disc_domain_assemble
      46              : /// @{
      47              : 
      48              : /// Interface for an object that can estimate the (global) error
      49              : template <typename TAlgebra>
      50              : class IDomainErrorIndicator
      51              : {
      52              : public:
      53              :         /// Type of algebra vector
      54              :         typedef typename TAlgebra::vector_type vector_type;
      55              : 
      56              :         /// Type of error vector
      57              :         typedef typename CPUAlgebra::vector_type error_vector_type;
      58              : 
      59              :         // (virtual) destructor
      60              :         virtual ~IDomainErrorIndicator() {};
      61              : 
      62              :                 /**
      63              :                  * Computes the error estimator.
      64              :                  *
      65              :                  * \param[in]  u                        vector of the solution to estimate the error for
      66              :                  * \param[in]  dd                       DoF Distribution
      67              :                  */
      68              :                         virtual void calc_error
      69              :                         (       const vector_type& u,
      70              :                                 const GridLevel& gl,
      71              :                                 error_vector_type* u_vtk = NULL
      72              :                         ) = 0;
      73              :                         virtual void calc_error
      74              :                         (       const vector_type& u,
      75              :                                 ConstSmartPtr<DoFDistribution> dd,
      76              :                                 error_vector_type* u_vtk = NULL
      77              :                         ) = 0;
      78              : 
      79              :                         //! Transient version
      80              :                         virtual void calc_error
      81              :                         (       ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
      82              :                                 ConstSmartPtr<DoFDistribution> dd,
      83              :                                 const std::vector<number>& vScaleMass,
      84              :                                 const std::vector<number>& vScaleStiff,
      85              :                                 error_vector_type* u_vtk
      86              :                         ) = 0;
      87              : 
      88              :                         //! Transient version
      89              :                         virtual void calc_error
      90              :                         (       ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
      91              :                                 const std::vector<number>& vScaleMass,
      92              :                                 const std::vector<number>& vScaleStiff,
      93              :                                 const GridLevel& gl,
      94              :                                 error_vector_type* u_vtk
      95              :                         ) = 0;
      96              : 
      97              :         /// marks error indicators as invalid
      98              :         virtual void invalidate_error() = 0;
      99              : 
     100              :         /// returns whether current error values are valid
     101              :         virtual bool is_error_valid() = 0;
     102              : };
     103              : 
     104              : /// Interface for an object that can mark elements based on a strategy
     105              : template <typename TDomain>
     106              : class IDomainMarker
     107              : {
     108              : public:
     109              :         /// Type of algebra vector
     110              :         typedef IElementMarkingStrategy<TDomain> element_marking_strategy_type;
     111              : 
     112              :         // (virtual) destructor
     113              :         virtual ~IDomainMarker() {};
     114              : 
     115              :         virtual void mark_with_strategy
     116              :         (       IRefiner& refiner,
     117              :                 SmartPtr<element_marking_strategy_type> spMarkingStrategy
     118              :         ) = 0 ;
     119              : };
     120              : 
     121              : /// Interface for domain discretization
     122              : /**
     123              :  * This class is the interface for spatial discretizations. It can be used
     124              :  * in the stationary case as well as for the domain dependent part of an
     125              :  * instationary problem (i.e. inside ITimeDiscretization).
     126              :  *
     127              :  * By its structure it is convenient to implement element-wise Mass-Matrix and
     128              :  * Stiffness-Matrix. Then the time-independent member functions can call only
     129              :  * the Stiffness-Matrix assembling, while the time-dependent part can call Mass-
     130              :  * and Stiffness-Matrix assembling.
     131              :  *
     132              :  * \tparam              TAlgebra                        Algebra Type
     133              :  */
     134              : template <typename TAlgebra>
     135              : class IDomainDiscretization : public IAssemble<TAlgebra>, public IDomainErrorIndicator<TAlgebra>
     136              : {
     137              :         using IAssemble<TAlgebra>::assemble_rhs;
     138              :         
     139              :         public:
     140              :         /// Algebra type
     141              :                 typedef TAlgebra algebra_type;
     142              : 
     143              :         /// Type of algebra matrix
     144              :                 typedef typename algebra_type::matrix_type matrix_type;
     145              : 
     146              :         /// Type of algebra vector
     147              :                 typedef typename algebra_type::vector_type vector_type;
     148              :                 virtual ~IDomainDiscretization() {};
     149              : 
     150              :         public:
     151              :                 /// assembles Jacobian (or Approximation of Jacobian)
     152              :                 /**
     153              :                  * Assembles Jacobian at a given iterate u.
     154              :                  *
     155              :                  * \param[out]  J       Jacobian J(u) matrix to be filled
     156              :                  * \param[in]   u       Current iterate
     157              :                  * \param[in]   dd      DoF Distribution
     158              :                  */
     159              :                 virtual void assemble_jacobian(matrix_type& J, const vector_type& u, const GridLevel& gl) = 0;
     160              :                 virtual void assemble_jacobian(matrix_type& J, const vector_type& u, ConstSmartPtr<DoFDistribution> dd) = 0;
     161              : 
     162              :                 /// assembles Defect
     163              :                 /**
     164              :                  * Assembles Defect at a given Solution u.
     165              :                  *
     166              :                  * \param[out]  d       Defect d(u) to be filled
     167              :                  * \param[in]   u       Current iterate
     168              :                  * \param[in]   dd      DoF Distribution
     169              :                  */
     170              :                 virtual void assemble_defect(vector_type& d, const vector_type& u, const GridLevel& gl) = 0;
     171              :                 virtual void assemble_defect(vector_type& d, const vector_type& u, ConstSmartPtr<DoFDistribution> dd) = 0;
     172              : 
     173              :                 /// Assembles Matrix and Right-Hand-Side for a linear problem
     174              :                 /**
     175              :                  * Assembles matrix_type and Right-Hand-Side for a linear problem
     176              :                  *
     177              :                  * \param[out]  A       Mass-/Stiffness- Matrix
     178              :                  * \param[out]  b       Right-Hand-Side
     179              :                  * \param[in]   dd      DoF Distribution
     180              :                  */
     181              :                 virtual void assemble_linear(matrix_type& A, vector_type& b, const GridLevel& gl) = 0;
     182              :                 virtual void assemble_linear(matrix_type& A, vector_type& b, ConstSmartPtr<DoFDistribution> dd) = 0;
     183              : 
     184              :                 /// assembles the rhs
     185              :                 virtual void assemble_rhs(vector_type& rhs, const vector_type& u, const GridLevel& gl) = 0;
     186              :                 virtual void assemble_rhs(vector_type& rhs, const vector_type& u, ConstSmartPtr<DoFDistribution> dd) = 0;
     187              : 
     188              :                 /// assembles the rhs
     189              :                 virtual void assemble_rhs(vector_type& b, const GridLevel& gl) = 0;
     190              :                 virtual void assemble_rhs(vector_type& b, ConstSmartPtr<DoFDistribution> dd) = 0;
     191              : 
     192              :                 /// sets dirichlet values in solution vector
     193              :                 /**
     194              :                  * Sets dirichlet values of the NumericalSolution u when components
     195              :                  * are dirichlet
     196              :                  *
     197              :                  * \param[out]  u       Numerical Solution
     198              :                  * \param[in]   dd      DoF Distribution
     199              :                  */
     200              :                 virtual void adjust_solution(vector_type& u, const GridLevel& gl) = 0;
     201              :                 virtual void adjust_solution(vector_type& u, ConstSmartPtr<DoFDistribution> dd) = 0;
     202              : 
     203              :                 /// assembles the mass matrix
     204              :                 virtual void assemble_mass_matrix(matrix_type& M, const vector_type& u, const GridLevel& gl) = 0;
     205              :                 virtual void assemble_mass_matrix(matrix_type& M, const vector_type& u, ConstSmartPtr<DoFDistribution> dd) = 0;
     206              : 
     207              :                 /// assembles the stiffness matrix
     208              :                 virtual void assemble_stiffness_matrix(matrix_type& A, const vector_type& u, const GridLevel& gl) = 0;
     209              :                 virtual void assemble_stiffness_matrix(matrix_type& A, const vector_type& u, ConstSmartPtr<DoFDistribution> dd) = 0;
     210              : 
     211              : 
     212              :         public:
     213              :         /// prepares time step
     214              :         /**
     215              :          * Prepares time step at a given solution u.
     216              :          * This method is called only once before any time step.
     217              :          *
     218              :          * \param[in]  vSol                     vector of previous and current (iterated) solution
     219              :          * \param[in]  dd                       DoF distribution
     220              :          */
     221              :                 virtual void prepare_timestep(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, number future_time, ConstSmartPtr<DoFDistribution> dd) = 0;
     222              :                 virtual void prepare_timestep(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, number future_time, const GridLevel& gl) = 0;
     223            0 :                 virtual void prepare_timestep(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, number future_time)
     224            0 :                 {prepare_timestep(vSol, future_time, GridLevel());}
     225              : 
     226              :         /// prepares time step element-wise
     227              :         /**
     228              :          * prepares time step element-wise at a given solution u.
     229              :          *
     230              :          * \param[in]  vSol                     vector of previous and current (iterated) solution
     231              :          * \param[in]  dd                       DoF Distribution
     232              :          */
     233              :                 virtual void prepare_timestep_elem(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, ConstSmartPtr<DoFDistribution> dd) = 0;
     234              :                 virtual void prepare_timestep_elem(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, const GridLevel& gl) = 0;
     235              : 
     236              :         ///     prepares timestep on surface level
     237              :                 void prepare_timestep_elem(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol)
     238              :                 {prepare_timestep_elem(vSol, GridLevel());}
     239              : 
     240              :         /// assembles Jacobian (or Approximation of Jacobian)
     241              :         /**
     242              :          * Assembles Jacobian at a given Solution u.
     243              :          *
     244              :          * \param[out] J                        Jacobian J(u) Matrix to be filled
     245              :          * \param[in]  vSol                     vector of previous and current (iterated) solution
     246              :          * \param[in]  s_a                      scaling factors for mass matrix
     247              :          * \param[in]  dd                       DoF Distribution
     248              :          */
     249              :                 virtual void assemble_jacobian(matrix_type& J,
     250              :                                                ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     251              :                                                const number s_a, const GridLevel& gl) = 0;
     252              :                 virtual void assemble_jacobian(matrix_type& J,
     253              :                                                ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     254              :                                                const number s_a0,
     255              :                                                ConstSmartPtr<DoFDistribution> dd) = 0;
     256              : 
     257              :         ///     assembles jacobian on surface level
     258            0 :                 void assemble_jacobian(matrix_type& J,
     259              :                                        ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     260              :                                        const number s_a)
     261            0 :                 {assemble_jacobian(J, vSol, s_a, GridLevel());}
     262              : 
     263              : 
     264              :         /// assembles Defect
     265              :         /**
     266              :          * Assembles Defect at a given Solution u.
     267              :          *
     268              :          * \param[out] d                        Defect d(u) to be filled
     269              :          * \param[in]  vSol                     vector of previous and current (iterated) solution
     270              :          * \param[in]  vScaleMass       scaling factors for mass matrix
     271              :          * \param[in]  vScaleStiff      scaling factors for stiffness matrix
     272              :          * \param[in]  dd                       DoF Distribution
     273              :          */
     274              :                 virtual void assemble_defect(vector_type& d,
     275              :                                              ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     276              :                                              const std::vector<number>& vScaleMass,
     277              :                                              const std::vector<number>& vScaleStiff,
     278              :                                              const GridLevel& gl) = 0;
     279              :                 virtual void assemble_defect(vector_type& d,
     280              :                                              ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     281              :                                              const std::vector<number>& vScaleMass,
     282              :                                              const std::vector<number>& vScaleStiff,
     283              :                                              ConstSmartPtr<DoFDistribution> dd) = 0;
     284              : 
     285              :         ///     assembles defect on surface level
     286              :                 void assemble_defect(vector_type& d,
     287              :                                      ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     288              :                                      const std::vector<number>& vScaleMass,
     289              :                                      const std::vector<number>& vScaleStiff)
     290              :                 {assemble_defect(d, vSol, vScaleMass, vScaleStiff, GridLevel());}
     291              : 
     292              :         /// Assembles matrix_type and Right-Hand-Side for a linear problem
     293              :         /**
     294              :          * Assembles matrix_type and Right-Hand-Side for a linear problem
     295              :          *
     296              :          * \param[out] A                        Mass-/Stiffness- matrix_type of the discretization
     297              :          * \param[out] b                        Right-Hand-Side of the discretization
     298              :          * \param[in]  vSol                     vector of previous and current (iterated) solution
     299              :          * \param[in]  vScaleMass       scaling factors for mass matrix
     300              :          * \param[in]  vScaleStiff      scaling factors for stiffness matrix
     301              :          * \param[in]  dd                       DoF Distribution
     302              :          */
     303              :                 virtual void assemble_linear(matrix_type& A, vector_type& b,
     304              :                                              ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     305              :                                              const std::vector<number>& vScaleMass,
     306              :                                              const std::vector<number>& vScaleStiff,
     307              :                                              const GridLevel& gl) = 0;
     308              :                 virtual void assemble_linear(matrix_type& A, vector_type& b,
     309              :                                                                          ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     310              :                                                                          const std::vector<number>& vScaleMass,
     311              :                                                                          const std::vector<number>& vScaleStiff,
     312              :                                                                          ConstSmartPtr<DoFDistribution> dd) = 0;
     313              : 
     314              :         ///     assembles linear on surface level
     315              :                 void assemble_linear(matrix_type& A, vector_type& b,
     316              :                                      ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     317              :                                      const std::vector<number>& vScaleMass,
     318              :                                      const std::vector<number>& vScaleStiff)
     319              :                 {assemble_linear(A,b,vSol,vScaleMass,vScaleStiff, GridLevel());}
     320              : 
     321              :         /// Assembles Right-Hand-Side for a linear problem
     322              :         /**
     323              :          * Assembles Right-Hand-Side for a linear problem
     324              :          *
     325              :          * \param[out] b                        Right-Hand-Side of the discretization
     326              :          * \param[in]  vSol                     vector of previous and current (iterated) solution
     327              :          * \param[in]  vScaleMass       scaling factors for mass matrix
     328              :          * \param[in]  vScaleStiff      scaling factors for stiffness matrix
     329              :          * \param[in]  dd                       DoF Distribution
     330              :          */
     331              :                 virtual void assemble_rhs(       vector_type& b,
     332              :                                                                          ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     333              :                                                                          const std::vector<number>& vScaleMass,
     334              :                                                                          const std::vector<number>& vScaleStiff,
     335              :                                                                          const GridLevel& gl) = 0;
     336              :                 virtual void assemble_rhs(       vector_type& b,
     337              :                                                                          ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     338              :                                                                          const std::vector<number>& vScaleMass,
     339              :                                                                          const std::vector<number>& vScaleStiff,
     340              :                                                                          ConstSmartPtr<DoFDistribution> dd) = 0;
     341              : 
     342              :         ///     assembles rhs on surface level
     343              :                 void assemble_rhs(vector_type& b,
     344              :                                                          ConstSmartPtr<VectorTimeSeries<vector_type> > vSol,
     345              :                                                          const std::vector<number>& vScaleMass,
     346              :                                                          const std::vector<number>& vScaleStiff)
     347              :                 {assemble_rhs(b,vSol,vScaleMass,vScaleStiff, GridLevel());}
     348              : 
     349              : 
     350              :         /// sets dirichlet values in solution vector
     351              :         /**
     352              :          * Sets dirichlet values of the Solution u when components are dirichlet
     353              :          *
     354              :          * \param[in]  u                Solution to set values at
     355              :          * \param[in]  time             time of next (to be computed) timestep
     356              :          * \param[in]  dd               DoF Distribution
     357              :          */
     358              :                 virtual void adjust_solution(vector_type& u, number time, const GridLevel& gl) = 0;
     359              :                 virtual void adjust_solution(vector_type& u, number time, ConstSmartPtr<DoFDistribution> dd) = 0;
     360              : 
     361              :         ///     adjust solution on surface level
     362              :                 void adjust_solution(vector_type& u, number time)
     363              :                 {adjust_solution(u,time, GridLevel());}
     364              : 
     365              :         /// finishes time step
     366              :         /**
     367              :          * Finishes time step at a given solution u.
     368              :          * This method is called only once after any time step.
     369              :          *
     370              :          * \param[in]  vSol                     vector of previous and current (iterated) solution
     371              :          * \param[in]  dd                       DoF distribution
     372              :          */
     373              :                 virtual void finish_timestep(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, ConstSmartPtr<DoFDistribution> dd) = 0;
     374              :                 virtual void finish_timestep(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, const GridLevel& gl) = 0;
     375            0 :                 virtual void finish_timestep(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol)
     376            0 :                 {finish_timestep(vSol, GridLevel());}
     377              : 
     378              :         /// finishes timestep
     379              :         /**
     380              :          * finishes timestep at a given Solution u.
     381              :          *
     382              :          * \param[in]  vSol                     vector of previous and current (iterated) solution
     383              :          * \param[in]  dd                       DoF Distribution
     384              :          */
     385              :                 virtual void finish_timestep_elem(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, const GridLevel& gl) = 0;
     386              :                 virtual void finish_timestep_elem(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol, ConstSmartPtr<DoFDistribution> dd) = 0;
     387              : 
     388              :         ///     finishes timestep on surface level
     389              :                 void finish_timestep_elem(ConstSmartPtr<VectorTimeSeries<vector_type> > vSol)
     390              :                         {finish_timestep_elem(vSol, GridLevel());}
     391              : 
     392              : 
     393              : 
     394              : 
     395              :         ///     returns the number of post processes
     396              :                 virtual size_t num_constraints() const = 0;
     397              : 
     398              :         ///     returns the i'th post process
     399              :                 virtual SmartPtr<IConstraint<TAlgebra> > constraint(size_t i) = 0;
     400              : };
     401              : 
     402              : /// @}
     403              : 
     404              : }; // namespace ug
     405              : 
     406              : #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DOMAIN_DISC_INTERFACE__ */
        

Generated by: LCOV version 2.0-1