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

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2011-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__DATA_EXPORT__
      34              : #define __H__UG__LIB_DISC__SPATIAL_DISC__DATA_EXPORT__
      35              : 
      36              : #include "lib_disc/common/function_group.h"
      37              : #include "lib_disc/common/local_algebra.h"
      38              : #include "lib_disc/common/groups_util.h"
      39              : #include "common/util/string_util.h"
      40              : 
      41              : #include "lib_disc/reference_element/reference_mapping_provider.h"
      42              : #include "lib_disc/local_finite_element/local_finite_element_provider.h"
      43              : 
      44              : #include "std_user_data.h"
      45              : 
      46              : namespace ug{
      47              : 
      48              : 
      49              : ////////////////////////////////////////////////////////////////////////////////
      50              : // ValueDataExport
      51              : ////////////////////////////////////////////////////////////////////////////////
      52              : 
      53              : template <int dim>
      54              : class ValueDataExport
      55              :         : public StdDependentUserData<ValueDataExport<dim>,number,dim>
      56              : {
      57              :         public:
      58            0 :                 ValueDataExport(const char* functions){this->set_functions(functions);}
      59              : 
      60              :                 template <int refDim>
      61              :                 void eval_and_deriv(number vValue[],
      62              :                                     const MathVector<dim> vGlobIP[],
      63              :                                     number time, int si,
      64              :                                     GridObject* elem,
      65              :                                     const MathVector<dim> vCornerCoords[],
      66              :                                     const MathVector<refDim> vLocIP[],
      67              :                                     const size_t nip,
      68              :                                     LocalVector* u,
      69              :                                     bool bDeriv,
      70              :                                     int s,
      71              :                                     std::vector<std::vector<number> > vvvDeriv[],
      72              :                                     const MathMatrix<refDim, dim>* vJT = NULL) const;
      73              : 
      74              :                 virtual void check_setup() const;
      75              : 
      76              :                 virtual bool continuous() const;
      77              : };
      78              : 
      79              : ////////////////////////////////////////////////////////////////////////////////
      80              : // GradientDataExport
      81              : ////////////////////////////////////////////////////////////////////////////////
      82              : 
      83              : template <int dim>
      84              : class GradientDataExport
      85              :         : public StdDependentUserData<GradientDataExport<dim>, MathVector<dim>,dim>
      86              : {
      87              :         public:
      88            0 :                 GradientDataExport(const char* functions){this->set_functions(functions);}
      89              : 
      90              :                 template <int refDim>
      91              :                 void eval_and_deriv(MathVector<dim> vValue[],
      92              :                                     const MathVector<dim> vGlobIP[],
      93              :                                     number time, int si,
      94              :                                     GridObject* elem,
      95              :                                     const MathVector<dim> vCornerCoords[],
      96              :                                     const MathVector<refDim> vLocIP[],
      97              :                                     const size_t nip,
      98              :                                     LocalVector* u,
      99              :                                     bool bDeriv,
     100              :                                     int s,
     101              :                                     std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
     102              :                                     const MathMatrix<refDim, dim>* vJT = NULL) const;
     103              : 
     104              :                 virtual void check_setup() const;
     105              : 
     106            0 :                 virtual bool continuous() const{return false;}
     107              : };
     108              : 
     109              : ////////////////////////////////////////////////////////////////////////////////
     110              : // VectorDataExport
     111              : ////////////////////////////////////////////////////////////////////////////////
     112              : 
     113              : template <int dim>
     114              : class VectorDataExport
     115              :         : public StdDependentUserData<VectorDataExport<dim>, MathVector<dim>,dim>
     116              : {
     117              :         public:
     118            0 :                 VectorDataExport(const char* functions){this->set_functions(functions);}
     119              : 
     120              :                 template <int refDim>
     121              :                 void eval_and_deriv(MathVector<dim> vValue[],
     122              :                                                         const MathVector<dim> vGlobIP[],
     123              :                                                         number time, int si,
     124              :                                                         GridObject* elem,
     125              :                                                         const MathVector<dim> vCornerCoords[],
     126              :                                                         const MathVector<refDim> vLocIP[],
     127              :                                                         const size_t nip,
     128              :                                                         LocalVector* u,
     129              :                                                         bool bDeriv,
     130              :                                                         int s,
     131              :                                                         std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
     132              :                                                         const MathMatrix<refDim, dim>* vJT = NULL) const;
     133              : 
     134              :                 virtual void check_setup() const;
     135              : 
     136              :                 virtual bool continuous() const;
     137              : };
     138              : 
     139              : ////////////////////////////////////////////////////////////////////////////////
     140              : // Data Export
     141              : ////////////////////////////////////////////////////////////////////////////////
     142              : 
     143              : /// Data export
     144              : /**
     145              :  * A DataExport is user data produced by an element discretization.
     146              :  */
     147              : template <typename TData, int dim>
     148              : class DataExport :
     149              :         public StdDependentUserData<DataExport<TData,dim>, TData, dim>
     150              : {
     151              :         public:
     152              :         ///     default constructor
     153              :                 DataExport(const char* functions);
     154              : 
     155              :                 template <int refDim>
     156              :                 void eval_and_deriv(TData vValue[],
     157              :                                     const MathVector<dim> vGlobIP[],
     158              :                                     number time, int si,
     159              :                                     GridObject* elem,
     160              :                                     const MathVector<dim> vCornerCoords[],
     161              :                                     const MathVector<refDim> vLocIP[],
     162              :                                     const size_t nip,
     163              :                                     LocalVector* u,
     164              :                                     bool bDeriv,
     165              :                                     int s,
     166              :                                     std::vector<std::vector<TData> > vvvDeriv[],
     167              :                                     const MathMatrix<refDim, dim>* vJT = NULL) const;
     168              : 
     169              :         ///     register evaluation of export function
     170              :                 template <typename TClass, int refDim>
     171              :                 void set_fct(ReferenceObjectID id, TClass* obj,
     172              :                              void (TClass::*func)(      TData vValue[],
     173              :                                                                                 const MathVector<dim> vGlobIP[],
     174              :                                                                                 number time, int si,
     175              :                                                                                 const LocalVector& u,
     176              :                                                                                 GridObject* elem,
     177              :                                                                                 const MathVector<dim> vCornerCoords[],
     178              :                                                                                 const MathVector<refDim> vLocIP[],
     179              :                                                                                 const size_t nip,
     180              :                                                                                 bool bDeriv,
     181              :                                                                                 std::vector<std::vector<TData> > vvvDeriv[]));
     182              : 
     183              :         ///     register evaluation of export function
     184              :                 template <int refDim>
     185              :                 void set_fct(ReferenceObjectID id,
     186              :                              void (*func)(      TData vValue[],
     187              :                                                                         const MathVector<dim> vGlobIP[],
     188              :                                                                         number time, int si,
     189              :                                                                         const LocalVector& u,
     190              :                                                                         GridObject* elem,
     191              :                                                                         const MathVector<dim> vCornerCoords[],
     192              :                                                                         const MathVector<refDim> vLocIP[],
     193              :                                                                         const size_t nip,
     194              :                                                                         bool bDeriv,
     195              :                                                                         std::vector<std::vector<TData> > vvvDeriv[]));
     196              : 
     197              :         ///     clears all export functions
     198              :                 void clear_fct();
     199              : 
     200              :         ///     clear dependent data
     201              :                 void clear() {m_vDependData.clear();}
     202              : 
     203              :         ///     add data dependency
     204              :                 void add_needed_data(SmartPtr<ICplUserData<dim> > data);
     205              : 
     206              :         ///     remove needed data
     207              :                 void remove_needed_data(SmartPtr<ICplUserData<dim> > data);
     208              : 
     209              :         ///     number of other Data this data depends on
     210            0 :                 virtual size_t num_needed_data() const {return m_vDependData.size();}
     211              : 
     212              :         ///     return needed data
     213            0 :                 virtual SmartPtr<ICplUserData<dim> > needed_data(size_t i) {return m_vDependData.at(i);}
     214              : 
     215              :         ///     returns if provided data is continuous over geometric object boundaries
     216            0 :                 virtual bool continuous() const {return false;}
     217              : 
     218              :         ///     returns if grid function is needed for evaluation
     219            0 :                 virtual bool requires_grid_fct() const {return true;}
     220              : 
     221              :         protected:
     222              :                 /* The following classes are used to implement the functors to support
     223              :                  * free functions and member functions. We do not use boost::bind or
     224              :                  * loki here, since they usually do not support that many arguments. In
     225              :                  * addition arguments are known and can simply be hardcoded.
     226              :                  */
     227              : 
     228              :                 // base class
     229              :                 template <int refDim>
     230              :                 class FunctorBase{
     231              :                         public:
     232              :                                 virtual void operator()(TData vValue[],
     233              :                                                 const MathVector<dim> vGlobIP[],
     234              :                                                                 number time, int si,
     235              :                                                 const LocalVector& u,
     236              :                                                 GridObject* elem,
     237              :                                                 const MathVector<dim> vCornerCoords[],
     238              :                                                 const MathVector<refDim> vLocIP[],
     239              :                                                 const size_t nip,
     240              :                                                 bool bDeriv,
     241              :                                                 std::vector<std::vector<TData> > vvvDeriv[]) const = 0;
     242              :                                 virtual ~FunctorBase() {}
     243              :                 };
     244              : 
     245              :                 // free function functor
     246              :                 template <int refDim>
     247              :                 class FreeFunctionFunctor : public FunctorBase<refDim>{
     248              :                         typedef void (*FreeFunc)(TData vValue[],
     249              :                                                                 const MathVector<dim> vGlobIP[],
     250              :                                                                 number time, int si,
     251              :                                                                 const LocalVector& u,
     252              :                                                                 GridObject* elem,
     253              :                                                                 const MathVector<dim> vCornerCoords[],
     254              :                                                                 const MathVector<refDim> vLocIP[],
     255              :                                                                 const size_t nip,
     256              :                                                                 bool bDeriv,
     257              :                                                                 std::vector<std::vector<TData> > vvvDeriv[]);
     258              : 
     259              :                         public:
     260              :                                 FreeFunctionFunctor(FreeFunc f) : m_f(f) {}
     261              : 
     262              :                                 void operator()(TData vValue[],
     263              :                                                 const MathVector<dim> vGlobIP[],
     264              :                                                                 number time, int si,
     265              :                                                 const LocalVector& u,
     266              :                                                 GridObject* elem,
     267              :                                                 const MathVector<dim> vCornerCoords[],
     268              :                                                 const MathVector<refDim> vLocIP[],
     269              :                                                 const size_t nip,
     270              :                                                 bool bDeriv,
     271              :                                                 std::vector<std::vector<TData> > vvvDeriv[]) const
     272              :                                 {
     273              :                                         m_f(vValue, vGlobIP, time, si, u, elem, vCornerCoords, vLocIP, nip, bDeriv, vvvDeriv);
     274              :                                 }
     275              : 
     276              :                         protected:
     277              :                                 FreeFunc m_f;
     278              :                 };
     279              : 
     280              :                 // member function functor
     281              :                 template <typename TClass, int refDim>
     282              :                 class MemberFunctionFunctor : public FunctorBase<refDim>{
     283              :                         typedef void (TClass::*MemFunc)(TData vValue[],
     284              :                                                                 const MathVector<dim> vGlobIP[],
     285              :                                                                 number time, int si,
     286              :                                                                 const LocalVector& u,
     287              :                                                                 GridObject* elem,
     288              :                                                                 const MathVector<dim> vCornerCoords[],
     289              :                                                                 const MathVector<refDim> vLocIP[],
     290              :                                                                 const size_t nip,
     291              :                                                                 bool bDeriv,
     292              :                                                                 std::vector<std::vector<TData> > vvvDeriv[]);
     293              : 
     294              :                         public:
     295            0 :                                 MemberFunctionFunctor(TClass* obj, MemFunc f) : m_pObj(obj), m_mf(f) {}
     296              : 
     297            0 :                                 void operator()(TData vValue[],
     298              :                                                 const MathVector<dim> vGlobIP[],
     299              :                                                                 number time, int si,
     300              :                                                 const LocalVector& u,
     301              :                                                 GridObject* elem,
     302              :                                                 const MathVector<dim> vCornerCoords[],
     303              :                                                 const MathVector<refDim> vLocIP[],
     304              :                                                 const size_t nip,
     305              :                                                 bool bDeriv,
     306              :                                                 std::vector<std::vector<TData> > vvvDeriv[]) const
     307              :                                 {
     308            0 :                                         ((m_pObj)->*m_mf)(vValue, vGlobIP, time, si, u, elem, vCornerCoords, vLocIP, nip, bDeriv, vvvDeriv);
     309            0 :                                 }
     310              : 
     311              :                         protected:
     312              :                                 TClass* m_pObj;
     313              :                                 MemFunc m_mf;
     314              :                 };
     315              : 
     316              :                 // generic functor for both types
     317              :                 template <int refDim>
     318            0 :                 class Functor{
     319              :                         public:
     320              :                                 Functor() : m_spImpl(NULL) {}
     321              : 
     322              :                                 template <typename FreeFunc>
     323              :                                 Functor(FreeFunc f) : m_spImpl(new FreeFunctionFunctor<refDim>(f)) {}
     324              : 
     325              :                                 template <typename TClass, typename MemFunc>
     326            0 :                                 Functor(TClass* obj, MemFunc f) : m_spImpl(new MemberFunctionFunctor<TClass, refDim>(obj, f)) {}
     327              : 
     328              :                                 void operator()(TData vValue[],
     329              :                                                 const MathVector<dim> vGlobIP[],
     330              :                                                                 number time, int si,
     331              :                                                 const LocalVector& u,
     332              :                                                 GridObject* elem,
     333              :                                                 const MathVector<dim> vCornerCoords[],
     334              :                                                 const MathVector<refDim> vLocIP[],
     335              :                                                 const size_t nip,
     336              :                                                 bool bDeriv,
     337              :                                                 std::vector<std::vector<TData> > vvvDeriv[]) const
     338              :                                 {
     339            0 :                                         (*m_spImpl)(vValue, vGlobIP, time, si, u, elem, vCornerCoords, vLocIP, nip, bDeriv, vvvDeriv);
     340              :                                 }
     341              : 
     342              :                                 bool valid() const {return m_spImpl.valid();}
     343              :                                 bool invalid() const {return m_spImpl.invalid();}
     344            0 :                                 void invalidate() {m_spImpl = SmartPtr<FunctorBase<refDim> >();}
     345              : 
     346              :                         protected:
     347              :                                 ConstSmartPtr<FunctorBase<refDim> > m_spImpl;
     348              :                 };
     349              : 
     350              :                 template <int refDim>
     351              :                 Functor<refDim>& eval_fct(ReferenceObjectID id) {return eval_fct(id, Int2Type<refDim>());}
     352              :                 template <int refDim>
     353              :                 const Functor<refDim>& eval_fct(ReferenceObjectID id) const {return eval_fct(id, Int2Type<refDim>());}
     354              : 
     355            0 :                 Functor<1>& eval_fct(ReferenceObjectID id, Int2Type<1>) {return m_vCompFct1d[id];}
     356            0 :                 Functor<2>& eval_fct(ReferenceObjectID id, Int2Type<2>) {return m_vCompFct2d[id];}
     357            0 :                 Functor<3>& eval_fct(ReferenceObjectID id, Int2Type<3>) {return m_vCompFct3d[id];}
     358            0 :                 const Functor<1>& eval_fct(ReferenceObjectID id, Int2Type<1>) const {return m_vCompFct1d[id];}
     359            0 :                 const Functor<2>& eval_fct(ReferenceObjectID id, Int2Type<2>) const {return m_vCompFct2d[id];}
     360            0 :                 const Functor<3>& eval_fct(ReferenceObjectID id, Int2Type<3>) const {return m_vCompFct3d[id];}
     361              :                 Functor<1> m_vCompFct1d[NUM_REFERENCE_OBJECTS];
     362              :                 Functor<2> m_vCompFct2d[NUM_REFERENCE_OBJECTS];
     363              :                 Functor<3> m_vCompFct3d[NUM_REFERENCE_OBJECTS];
     364              : 
     365              :                 bool eval_fct_set(ReferenceObjectID id) const;
     366              : 
     367              :         protected:
     368              :         ///     data the export depends on
     369              :                 std::vector<SmartPtr<ICplUserData<dim> > > m_vDependData;
     370              : };
     371              : 
     372              : } // end namespace ug
     373              : 
     374              : #include "data_export_impl.h"
     375              : 
     376              : #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DATA_EXPORT__ */
        

Generated by: LCOV version 2.0-1