Quinoa all test code coverage report
Current view: top level - PDE - PDEStack.cpp (source / functions) Hit Total Coverage
Commit: Quinoa_v0.3-957-gb4f0efae0 Lines: 36 39 92.3 %
Date: 2021-11-09 15:14:18 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 86 43.0 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/PDE/PDEStack.cpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     Stack of partial differential equations
       9                 :            :   \details   This file defines class PDEStack, which implements various
      10                 :            :     functionality related to registering and instantiating partial differential
      11                 :            :     equation types. Registration and instantiation use a partial differential
      12                 :            :     equation factory, which is a std::map (an associative container),
      13                 :            :     associating unique partial differential equation keys to their constructor
      14                 :            :     calls. For more details, see the in-code documentation of the constructor.
      15                 :            : */
      16                 :            : // *****************************************************************************
      17                 :            : 
      18                 :            : #include "PDEStack.hpp"
      19                 :            : #include "Tags.hpp"
      20                 :            : 
      21                 :            : #include "ConfigureTransport.hpp"
      22                 :            : #include "ConfigureCompFlow.hpp"
      23                 :            : #include "ConfigureMultiMat.hpp"
      24                 :            : 
      25                 :            : using inciter::PDEStack;
      26                 :            : 
      27                 :       1565 : PDEStack::PDEStack() : m_cgfactory(), m_dgfactory(),
      28         [ +  - ]:       1565 :                        m_cgEqTypes(), m_dgEqTypes()
      29                 :            : // *****************************************************************************
      30                 :            : //  Constructor: register all partial differential equations into factory
      31                 :            : //! \details This constructor consists of several blocks, each registering a
      32                 :            : //!   potentially large number of entries in a partial differential equation
      33                 :            : //!   factory, a standard associative container. At this time, each type of
      34                 :            : //!   partial differential equation can be configured to use a unique _physics
      35                 :            : //!   policy_ and a unique _problem policy_. (More types of policies might be
      36                 :            : //!   introduced in the future.) Policy classes are template arguments to the
      37                 :            : //!   partial differential equation classes and influence their behavior in a
      38                 :            : //!   different way, abstracting away certain functions, e.g., how to set
      39                 :            : //!   problem-specific initial and/or boundary conditions and how to update
      40                 :            : //!   their coefficients during time integration. For more information on
      41                 :            : //!   policy-based design, see http://en.wikipedia.org/wiki/Policy-based_design.
      42                 :            : //!   This abstraction allows [separation of concerns]
      43                 :            : //!   (http://en.wikipedia.org/wiki/Separation_of_concerns).
      44                 :            : //!
      45                 :            : //!   Since the functionality of the policies are orthogonal to each other,
      46                 :            : //!   i.e., they do not depend on each other or their host (the partial
      47                 :            : //!   differential equation class), a Cartesian product of combinations are
      48                 :            : //!   possible, depending on which policies are selected. _This constructor
      49                 :            : //!   registers all possible combinations of policies for all available
      50                 :            : //!   differential equations._ By _register_, we mean, an entry is recorded in
      51                 :            : //!   an associative container, a std::map, that associates a lightweight key of
      52                 :            : //!   type inciter::ctr::PDEKey, consisting of only an enum for each policy
      53                 :            : //!   type, to an std::function object that holds the constructor bound to its
      54                 :            : //!   arguments corresponding to a particular partial differential equation +
      55                 :            : //!   policies combination. Note that registering these entries in the map does
      56                 :            : //!   not invoke the constructors. The mapped value simply stores how the
      57                 :            : //!   constructors should be invoked at a later time. At some point later,
      58                 :            : //!   based on user input, we then instantiate only the partial differential
      59                 :            : //!   equations (and only those configurations) that are requested by the user.
      60                 :            : //!
      61                 :            : //!   Since all partial differential equation types (registered in the factory)
      62                 :            : //!   "inherit" from a common "base", client-code is unform and generic, and
      63                 :            : //!   thus immune to changes in the inner workings of the particular partial
      64                 :            : //!   differential equations as long as they fullfill certain concepts, i.e.,
      65                 :            : //!   implement certain member functinos, enforced by the _common base_, PDE.
      66                 :            : //!   The words "inherit and "base" are quoted here, because the common base
      67                 :            : //!   does not use inheritance in the normal OOP sense and does not use
      68                 :            : //!   reference semantics, i.e., pointers, visible to client-code either. The
      69                 :            : //!   relationship is more of a _models a_-type, which simplifies client-code
      70                 :            : //!   and allows for the benfits of runtime inheritance with value-semantics
      71                 :            : //!   which is less error prone and easier to read. See more about the
      72                 :            : //!   _models-a_ relationship and its implementation in, e.g., PDE/CGPDE.h.
      73                 :            : //!
      74                 :            : //!   The design discussed above allows the registration, instantiation, and
      75                 :            : //!   use of the partial differential equations to be generic, which eliminates
      76                 :            : //!   a lot of boiler-plate code and makes client-code uniform.
      77                 :            : //!
      78                 :            : //!   _Details of registration using brigand::for_each and
      79                 :            : //!   tk::cartesian_product:_
      80                 :            : //!
      81                 :            : //!   The template argument to brigand::for_each, as used below, requires a
      82                 :            : //!   list of list of types. We use brigand::list of brigand::list of types,
      83                 :            : //!   listing all possible policies, where the inner list must have exactly two
      84                 :            : //!   types, as the list of lists is constructed from two lists using the
      85                 :            : //!   cartesian product, and the length of the outer list (the list of lists) is
      86                 :            : //!   arbitrary. The constructor argument to brigand::for_each is a functor that
      87                 :            : //!   is to be applied to all members of the outer list. tk::cartesian_product
      88                 :            : //!   will create all possible combinations of these types and call the functor
      89                 :            : //!   with each type of the created sequence as a template parameter. The
      90                 :            : //!   functor here inherits from registerPDE, which, i.e., its constructor call,
      91                 :            : //!   needs a single template argument, a class templated on policy classes.
      92                 :            : //!   This is the partial differential equation class to be configured by
      93                 :            : //!   selecting policies and to be registered. The arguments to registerPDE's
      94                 :            : //!   constructor are the factory, the enum denoting the differential equation
      95                 :            : //!   type, and a reference to a variable of type std::set< ctr::PDEType >,
      96                 :            : //!   which is only used internally to PDEStack for counting up the number of
      97                 :            : //!   unique differential equation types registered, used for diagnostics
      98                 :            : //!   purposes.
      99                 :            : // *****************************************************************************
     100                 :            : {
     101         [ +  - ]:       1565 :   registerTransport( m_cgfactory, m_dgfactory, m_cgEqTypes, m_dgEqTypes );
     102         [ +  - ]:       1565 :   registerCompFlow( m_cgfactory, m_dgfactory, m_cgEqTypes, m_dgEqTypes );
     103         [ +  - ]:       1565 :   registerMultiMat( m_dgfactory, m_dgEqTypes );
     104                 :       1565 : }
     105                 :            : 
     106                 :            : std::vector< inciter::CGPDE >
     107         [ +  + ]:        666 : PDEStack::selectedCG() const
     108                 :            : // *****************************************************************************
     109                 :            : //  Instantiate all selected PDEs using continuous Galerkin discretization
     110                 :            : //! \return std::vector of instantiated partial differential equation objects
     111                 :            : // *****************************************************************************
     112                 :            : {
     113                 :            :   std::map< ctr::PDEType, ncomp_t > cnt;    // count PDEs per type
     114                 :            :   std::vector< CGPDE > pdes;                // will store instantiated PDEs
     115                 :            : 
     116                 :        666 :   const auto sch = g_inputdeck.get< tag::discr, tag::scheme >();
     117         [ +  + ]:        666 :   if (sch == ctr::SchemeType::DiagCG || sch == ctr::SchemeType::ALECG) {
     118                 :            : 
     119         [ +  + ]:        786 :     for (const auto& d : g_inputdeck.get< tag::selected, tag::pde >()) {
     120         [ +  + ]:        393 :       if (d == ctr::PDEType::TRANSPORT)
     121                 :        232 :         pdes.push_back( createCG< tag::transport >( d, cnt ) );
     122         [ +  - ]:        161 :       else if (d == ctr::PDEType::COMPFLOW)
     123                 :        161 :         pdes.push_back( createCG< tag::compflow >( d, cnt ) );
     124 [ -  - ][ -  - ]:          0 :       else Throw( "Can't find selected CGPDE" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     125                 :            :     }
     126                 :            : 
     127                 :            :   }
     128                 :            : 
     129                 :        666 :   return pdes;
     130                 :            : }
     131                 :            : 
     132                 :            : std::vector< inciter::DGPDE >
     133         [ +  + ]:        666 : PDEStack::selectedDG() const
     134                 :            : // *****************************************************************************
     135                 :            : //  Instantiate all selected PDEs using discontinuous Galerkin discretization
     136                 :            : //! \return std::vector of instantiated partial differential equation objects
     137                 :            : // *****************************************************************************
     138                 :            : {
     139                 :            :   std::map< ctr::PDEType, ncomp_t > cnt;    // count PDEs per type
     140                 :            :   std::vector< DGPDE > pdes;                // will store instantiated PDEs
     141                 :            : 
     142                 :        666 :   auto sch = g_inputdeck.get< tag::discr, tag::scheme >();
     143                 :        666 :   if (sch == ctr::SchemeType::DG ||
     144                 :            :       sch == ctr::SchemeType::P0P1 || sch == ctr::SchemeType::DGP1 ||
     145         [ +  + ]:        666 :       sch == ctr::SchemeType::DGP2 || sch == ctr::SchemeType::PDG) {
     146                 :            : 
     147         [ +  + ]:        546 :     for (const auto& d : g_inputdeck.get< tag::selected, tag::pde >()) {
     148         [ +  + ]:        273 :       if (d == ctr::PDEType::TRANSPORT)
     149                 :        163 :         pdes.push_back( createDG< tag::transport >( d, cnt ) );
     150         [ +  + ]:        110 :       else if (d == ctr::PDEType::COMPFLOW)
     151                 :         80 :         pdes.push_back( createDG< tag::compflow >( d, cnt ) );
     152         [ +  - ]:         30 :       else if (d == ctr::PDEType::MULTIMAT)
     153                 :         30 :         pdes.push_back( createDG< tag::multimat >( d, cnt ) );
     154 [ -  - ][ -  - ]:          0 :       else Throw( "Can't find selected DGPDE" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     155                 :            :     }
     156                 :            : 
     157                 :            :   }
     158                 :            : 
     159                 :        666 :   return pdes;
     160                 :            : }
     161                 :            : 
     162                 :            : std::vector< std::vector< std::pair< std::string, std::string > > >
     163                 :        233 : PDEStack::info() const
     164                 :            : // *****************************************************************************
     165                 :            : //  Return information on all selected partial differential equations
     166                 :            : //! \return A vector of vector of pair of strings, containing the configuration
     167                 :            : //!   for each selected partial differential equation
     168                 :            : // *****************************************************************************
     169                 :            : {
     170                 :            :   std::map< ctr::PDEType, ncomp_t > cnt; // count PDEs per type
     171                 :            :   // will store info on all differential equations selected
     172                 :            :   std::vector< std::vector< std::pair< std::string, std::string > > > nfo;
     173                 :            : 
     174         [ +  + ]:        466 :   for (const auto& d : g_inputdeck.get< tag::selected, tag::pde >()) {
     175         [ +  + ]:        233 :     if (d == ctr::PDEType::TRANSPORT)
     176 [ +  - ][ +  - ]:        126 :       nfo.emplace_back( infoTransport( cnt ) );
     177         [ +  + ]:        107 :     else if (d == ctr::PDEType::COMPFLOW)
     178 [ +  - ][ +  - ]:         95 :       nfo.emplace_back( infoCompFlow( cnt ) );
     179         [ +  - ]:         12 :     else if (d == ctr::PDEType::MULTIMAT)
     180 [ +  - ][ +  - ]:         12 :       nfo.emplace_back( infoMultiMat( cnt ) );
     181 [ -  - ][ -  - ]:          0 :     else Throw( "Can't find selected PDE" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     182                 :            :   }
     183                 :            : 
     184                 :        233 :   return nfo;
     185                 :            : }

Generated by: LCOV version 1.14