Quinoa all test code coverage report
Current view: top level - PDE - PDEStack.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 42 46 91.3 %
Date: 2024-04-29 14:42:33 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 44 106 41.5 %

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

Generated by: LCOV version 1.14