flow_boundary.hh 3.77 KB
Newer Older
Dion Haefner's avatar
Dion Haefner committed
1 2 3 4
// -*- tab-width: 4; indent-tabs-mode: nil -*-
#ifndef DUNE_DORIE_RICHARDS_BOUNDARY_HH
#define DUNE_DORIE_RICHARDS_BOUNDARY_HH

5 6 7 8 9
#include <memory>

#include <dune/common/exceptions.hh>
#include <dune/common/parametertree.hh>

10
#include <dune/dorie/common/boundary_condition.hh>
Santiago Ospina's avatar
Santiago Ospina committed
11

Dion Haefner's avatar
Dion Haefner committed
12 13
namespace Dune{
  namespace Dorie{
Dion Haefner's avatar
Dion Haefner committed
14

Dion Haefner's avatar
Dion Haefner committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    /// Boundary type and condition value queries
    /** This class containts functions that return the type of boundary conditions
     *  and the values of the boundary condition parameters. Both types of queries
     *  can be time dependent.
     */
    template<typename Traits>
      class FlowBoundary
      {
        private:

        typedef typename Traits::RangeField         RF;
        typedef typename Traits::Domain             Domain;
        typedef typename Traits::IntersectionDomain ID;
        typedef typename Traits::Intersection       Intersection;

        enum {dim = Traits::dim};

        //! Object for handling the BC data file and function queries
        std::unique_ptr<BCReadoutInterface<Traits>> bcDataHandler;

        public:

        /// Read BC file type and create data handling object
        /** \see Dune::Dorie::BCReadoutInterface
Dion Haefner's avatar
Dion Haefner committed
39
         *  \throw Dune::IOError BC File Type not supported
Dion Haefner's avatar
Dion Haefner committed
40 41 42
         */
        FlowBoundary(const Dune::ParameterTree& config)
        {
43
          std::string bcFileType = config.get<std::string>("boundary.fileType");
Dion Haefner's avatar
Dion Haefner committed
44
          if(bcFileType == "rectangularGrid") {
45
            bcDataHandler = std::make_unique<RectangularGrid<Traits>>(config);
Dion Haefner's avatar
Dion Haefner committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
          }
          else
            DUNE_THROW(IOError,"unknown bcFileType specified!");
        }

        /// Return next time at which any boundary condition changes. Return -1.0 by default
        /** \param time Current time
         */
        RF getNextTimeStamp (const RF& time) const {
          if(bcDataHandler)
            return bcDataHandler->getNextTimeStamp(time);
          return -1.0;
        }

        /// Return Boundary Condition Type at certain position and time
        /** \param is Intersection enitity
        * \param x Position in local entity coordinates
        * \param time Time value
        * \param xGlobal Global coordinate
        * \return Boundary condition type enumerator
        */
        BoundaryCondition::Type bc (const Intersection& is, const ID& x, const RF& time) const
        {
          const Domain xGlobal = is.geometry().global(x);
          if(is.boundary()) {
            return bcDataHandler->getBCtype(xGlobal, time);
Dion Haefner's avatar
Dion Haefner committed
72
          }
Dion Haefner's avatar
Dion Haefner committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
          return BoundaryCondition::Other; // unknown
        }

        /**
         * @brief Dirichlet boundary condition at certain position and time
         * \param is Intersection enitity
         * \param x Position in local entity coordinates
         * \param time Time value
         * \param xglobal Global coordinate
         * \return Value of matric head
         */
        RF g (const Intersection& is, const ID& x, const RF& time) const
        {
          const Domain xGlobal = is.geometry().global(x);
          if(is.boundary()) {
            if(bcDataHandler)
              return bcDataHandler->getHeadValue(xGlobal, time);
          }
          return 0.0;
        }

        /**
         * @brief Neumann boundary condition at certain position and time
         * \param is Intersection enitity
         * \param x Position in local entity coordinates
         * \param time Time value
         * \param xglobal Global coordinate
         * \return Value of flux
         */
        RF j (const Intersection& is, const ID& x, const RF& time) const
        {
          const Domain xGlobal = is.geometry().global(x);
          if(is.boundary()) {
            if(bcDataHandler)
              return bcDataHandler->getFluxValue(xGlobal, time);
          }
          return 0.0;
        }
      };
  }
}

Dion Haefner's avatar
Dion Haefner committed
115
#endif