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

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2022:  G-CSC, Goethe University Frankfurt
       3              :  * Authors: Arne Naegel
       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              : /*
      34              :  * andreasvogel used scale_add_linker ass template
      35              :  */
      36              : 
      37              : #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__LINKER_ADAPTER__
      38              : #define __H__UG__LIB_DISC__SPATIAL_DISC__LINKER_ADAPTER__
      39              : 
      40              : #include "linker.h"
      41              : 
      42              : namespace ug{
      43              : 
      44              : 
      45              : template <int dim>
      46              : class UserVectorEntryAdapter
      47              :         : public StdDataLinker< UserVectorEntryAdapter<dim>, number, dim>
      48              : {
      49              : public:
      50              :         ///     Base class type
      51              :                 typedef StdDataLinker< UserVectorEntryAdapter<dim>, number, dim> base_type;
      52              : 
      53              :                 typedef number data_type;
      54              :                 typedef CplUserData<data_type, dim> user_data_base_type;
      55              : 
      56              :                 typedef MathVector<dim> encapsulated_type;
      57              :                 typedef CplUserData<encapsulated_type, dim> input_type;
      58              : 
      59              :         public:
      60              : 
      61            0 :                 UserVectorEntryAdapter() :  m_index(0), m_spEncaps(NULL)
      62              :                 {
      63              :                         this->set_num_input(_INPUT_+1); //   this linker has one inoput
      64            0 :                 }
      65              : 
      66              : 
      67              :                 inline void evaluate (data_type& value,
      68              :                                       const MathVector<dim>& globIP,
      69              :                                       number time, int si) const
      70              :                 {
      71              :                         encapsulated_type dummy;
      72            0 :                         (*m_spEncaps)(dummy, globIP, time, si);
      73            0 :                         value = dummy[m_index];
      74              :                 }
      75              : 
      76              :                 template <int refDim>
      77            0 :                 inline void evaluate(data_type vValue[],
      78              :                                      const MathVector<dim> vGlobIP[],
      79              :                                      number time, int si,
      80              :                                      GridObject* elem,
      81              :                                      const MathVector<dim> vCornerCoords[],
      82              :                                      const MathVector<refDim> vLocIP[],
      83              :                                      const size_t nip,
      84              :                                      LocalVector* u,
      85              :                                      const MathMatrix<refDim, dim>* vJT = NULL) const
      86              :                 {
      87            0 :                     std::vector<encapsulated_type> dummy(nip);
      88              : 
      89              : 
      90            0 :                     (*m_spEncaps)(&dummy[0], vGlobIP, time, si,
      91              :                                                                 elem, vCornerCoords, vLocIP, nip, u, vJT);
      92              : 
      93              : 
      94            0 :                         for (size_t ip=0; ip<nip; ++ip)
      95            0 :                         { vValue[ip] = dummy[ip][m_index]; }
      96            0 :                 }
      97              : 
      98              :                 template <int refDim>
      99            0 :                 void eval_and_deriv(data_type vValue[],
     100              :                                     const MathVector<dim> vGlobIP[],
     101              :                                     number time, int si,
     102              :                                     GridObject* elem,
     103              :                                     const MathVector<dim> vCornerCoords[],
     104              :                                     const MathVector<refDim> vLocIP[],
     105              :                                     const size_t nip,
     106              :                                     LocalVector* u,
     107              :                                     bool bDeriv,
     108              :                                     int s,
     109              :                                     std::vector<std::vector<data_type > > vvvDeriv[],
     110              :                                     const MathMatrix<refDim, dim>* vJT = NULL) const
     111              :                 {
     112              :                         //      get the data of the ip series
     113            0 :                         const encapsulated_type* vDummy = m_spEncaps->values(s);
     114              : 
     115            0 :                         for(size_t ip = 0; ip < nip; ++ip)
     116            0 :                         { vValue[ip] = vDummy[ip][m_index]; }
     117              : 
     118              :                         //      check if something to do
     119            0 :                         if(!bDeriv || this->zero_derivative()) return;
     120              : 
     121              :                         //      clear all derivative values
     122            0 :                         this->set_zero(vvvDeriv, nip);
     123              : 
     124              :                         //      Derivatives w.r.t  input
     125            0 :                         if( m_spDEncaps.invalid() || m_spDEncaps->zero_derivative()) return;
     126              : 
     127              :                         // loop integration points
     128            0 :                         for(size_t ip = 0; ip < nip; ++ip){
     129              : 
     130              :                                 // loop functions
     131            0 :                                 for(size_t fct = 0; fct < m_spDEncaps->num_fct(); ++fct)
     132              :                                 {
     133              :                                         //      get derivative of  w.r.t. to all functions
     134              :                                         const encapsulated_type* vDInputFct = m_spDEncaps->deriv(s, ip, fct);
     135              : 
     136              :                                         //      get common fct id for this function
     137              :                                         const size_t commonFct = this->input_common_fct(_INPUT_, fct);
     138              : 
     139              :                                         //      loop all shapes and set the derivative
     140            0 :                                         for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
     141              :                                         {
     142              :                                                 UG_ASSERT(commonFct < vvvDeriv[ip].size(), commonFct<<", "<<vvvDeriv[ip].size());
     143            0 :                                                 vvvDeriv[ip][commonFct][sh] += vDInputFct[sh][m_index]; // TODO: double check this!
     144              :                                         }
     145              : 
     146              :                                 }
     147              :                         }
     148              : 
     149              :                 }
     150              : 
     151              :         public:
     152              :         ///     set conc import
     153            0 :                 void set_vector(SmartPtr<input_type> data, size_t index)
     154              :                 {
     155            0 :                         m_spEncaps = data;  // for evaluation
     156            0 :                         m_spDEncaps = data.template cast_dynamic<DependentUserData<encapsulated_type, dim> >(); // for derivatives
     157            0 :                         base_type::set_input(_INPUT_, data, data);
     158            0 :                         m_index = index;
     159            0 :                 }
     160              : 
     161              : 
     162              : 
     163              :         protected:
     164              :                 size_t m_index;
     165              : 
     166              :                 const static int _INPUT_= 0;
     167              : 
     168              :         ///     import for concentration
     169              :                 SmartPtr<input_type> m_spEncaps;
     170              :                 SmartPtr<DependentUserData<encapsulated_type, dim> > m_spDEncaps;
     171              : 
     172              : 
     173              : };
     174              : 
     175              : } // namespace ug
     176              : 
     177              : #endif /*  __H__UG__LIB_DISC__SPATIAL_DISC__LINKER_ADAPTER__ */
        

Generated by: LCOV version 2.0-1