root/src/grid_FEfunSet.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. FEfun_set
  2. FEfun_set
  3. write
  4. read
  5. Tiny_FEfun_set
  6. compose_dgfName

   1 /*! \file grid_FEfunSet.h
   2     \brief Basic struct with input output 
   3            member functions for a generic numerical experiment
   4 
   5     Revision history
   6     --------------------------------------------------
   7 
   8           Revised by Christian Power April 2016
   9           Revised by Christian Power March 2016
  10           Originally written by Christian Power
  11                (power22c@gmail.com) March 2016
  12 
  13      Idea
  14      --------------------------------------------------
  15 
  16      This header provides model classes and operator classes to solve 
  17      a tumor growth model proposed by Elliott and Styles via the ESFEM.  
  18 
  19     \author Christian Power
  20     \date 22. April 2016
  21     \copyright Copyright (c) 2016 Christian Power.  All rights reserved.
  22 */
  23 
  24 #ifndef GRID_FEFFUNSET_H
  25 #define GRID_FEFFUNSET_H
  26 
  27 #include "esfem_fwd.h"
  28 #include "io_dgf.h"
  29 #include "grid.h"
  30 
  31 namespace Esfem{
  32   //! Analytically given evolving grids and finite element functions
  33   namespace Grid{
  34     //! 3-dim. vector valued finite element functions
  35     struct r3fef{
  36       //! First component
  37       Scal_FEfun x;
  38       //! Second component
  39       Scal_FEfun y;
  40       //! Third component
  41       Scal_FEfun z;
  42       //! Forward construct
  43       r3fef(const std::string& name, const Grid_and_time& gt)
  44         :x {name, gt}, y {name, gt}, z {name, gt} {}
  45     };
  46     template<typename FEfun>
  47     struct FEfun_set{
  48       FEfun fun; /*!< \brief Numerical solution */
  49       FEfun app; /*!< \brief BDF approximation to the numerical solution */
  50       FEfun exact; /*!< \brief Reference solution */
  51       FEfun rhs_les; /*!< \brief Right-hand side for the solver */
  52       FEfun_set(const std::string& name, const Grid::Grid_and_time&);
  53       /*!< \brief Standard constructor
  54         \param name Member get concated names like name + "_app" etc.
  55       */
  56       FEfun_set(const FEfun_set&, const Grid::Grid_and_time&);
  57       /*!< \brief Pseudo copy constructor
  58         
  59         `Grid_and_time` is needed to get the correct finite element space.
  60       */
  61 
  62       void write(const Esfem::Io::Dgf::Handler&,
  63                  const std::string& dir = "/tmp/");
  64       /*! \brief Save nodal values in a dgf file. */
  65       void read(const Esfem::Io::Dgf::Handler&,
  66                 const std::string& dir = "/tmp/");
  67       /*! \brief Read nodal values from a dgf file. */
  68     };
  69     /*!< \brief Minimal set of finite element functions to perform
  70       higher order BDF-ESFEM with input output helper functions
  71     */
  72     template<typename FEfun>
  73     struct Tiny_FEfun_set{
  74       FEfun fun; /*!< \brief Numerical solution */
  75       FEfun rhs_les; /*!< \brief Right-hand side for the solver */
  76 
  77       Tiny_FEfun_set(const FEfun_set<FEfun>&, const Grid::Grid_and_time&);
  78       /*!< \brief `FEfun_set` is a superset of `Tiny_FEfun_set`.
  79                   Hence this is something like a pseudo copy constructor.
  80         
  81         `Grid_and_time` is needed to get the correct finite element space.
  82       */
  83 
  84     };
  85     /*!< \brief A smaller version of `FEfun_set`.  This is the minimal
  86       set of functions to prepare the right-hand side of the PDE.
  87     */
  88 
  89     using Scal_FEfun_set = FEfun_set<Scal_FEfun>;
  90     /*!< \brief Four functions of type \f$ f\colon \R^3 \to \R \f$ */
  91     using Vec_FEfun_set = FEfun_set<Vec_FEfun>;
  92     /*!< \brief Four functions of type \f$ f\colon \R^3 \to \R^3 \f$ */
  93     using Scal_tiny_FEfun_set = Tiny_FEfun_set<Scal_FEfun>;
  94     /*!< \brief Two functions of type \f$ f\colon \R^3 \to \R \f$ */    
  95     using Vec_tiny_FEfun_set = Tiny_FEfun_set<Vec_FEfun>;
  96     /*!< \brief Two functions of type \f$ f\colon \R^3 \to \R^3 \f$ */
  97 
  98     inline std::string compose_dgfName(const std::string& fun_name,
  99                                        const std::string& dir = "./");
 100     /*!< \brief Returns dune grid format filename
 101       \param fun_name Expects the result of
 102                       Grid::Scal_FEfun::name()
 103                       or Grid::Vec_FEfun::name()
 104       \param dir Directory with trailing backslash
 105     */  
 106 
 107     // ======================================================================
 108     // Implemenation
 109     
 110     // ----------------------------------------------------------------------
 111     // Template implementation
 112 
 113     template<typename FEfun>
 114     FEfun_set<FEfun>::
 115     FEfun_set(const std::string& name,
 116               const Esfem::Grid::Grid_and_time& gt)
 117       : fun {name, gt}, app {name + "_app", gt},
 118       exact {name + "_exact", gt}, rhs_les {name + "_rhs_les", gt}
 119     {}
 120     template<typename FEfun>
 121     FEfun_set<FEfun>::
 122     FEfun_set(const FEfun_set& other, const Esfem::Grid::Grid_and_time& gt)
 123       : fun {other.fun, gt}, app {other.app, gt}, 
 124       exact {other.exact, gt}, rhs_les {other.rhs_les, gt}
 125     {}
 126 
 127     template<typename FEfun>
 128     void FEfun_set<FEfun>::
 129     write(const Esfem::Io::Dgf::Handler& h,
 130           const std::string& dir){
 131       h.write(compose_dgfName(fun.name(), dir), fun);
 132       h.write(compose_dgfName(app.name(), dir), app);
 133       h.write(compose_dgfName(exact.name(), dir), exact);
 134       h.write(compose_dgfName(rhs_les.name(), dir), rhs_les);
 135     }
 136     template<typename FEfun>
 137     void FEfun_set<FEfun>::
 138     read(const Esfem::Io::Dgf::Handler& h, const std::string& dir){
 139       h.read(compose_dgfName(fun.name(), dir), fun);
 140       h.read(compose_dgfName(app.name(), dir), app);
 141       h.read(compose_dgfName(exact.name(), dir), exact);
 142       h.read(compose_dgfName(rhs_les.name(), dir), rhs_les);
 143     }
 144 
 145     template<typename FEfun>
 146     Tiny_FEfun_set<FEfun>::
 147     Tiny_FEfun_set(const FEfun_set<FEfun>& fef, const Grid::Grid_and_time& gt)
 148       : fun {fef.fun, gt}, 
 149       rhs_les {fef.rhs_les, gt}
 150     {}
 151 
 152     // ----------------------------------------------------------------------
 153     // Inline implementation
 154 
 155     inline std::string compose_dgfName(const std::string& fun_name,
 156                                        const std::string& dir){
 157       constexpr auto suffix= ".dgf";
 158       return dir + fun_name + suffix;
 159     }
 160   }     // namespace Grid
 161 }       // namespace Esfem
 162 
 163 #endif // GRID_FEFFUNSET_H

/* [<][>][^][v][top][bottom][index][help] */