Quinoa all test code coverage report
Current view: top level - Inciter - ALE.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 28 28 100.0 %
Date: 2024-04-22 13:03:21 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Inciter/ALE.hpp
       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     Declarations file for distributed ALE mesh motion
       9                 :            :   \details   Declarations file for asynchronous distributed
      10                 :            :              arbitrary Lagrangian-Eulerian (ALE) mesh motion using Charm++.
      11                 :            : 
      12                 :            :     There are a potentially large number of ALE Charm++ chares.
      13                 :            :     Each ALE chare gets a chunk of the full load, due to partiting the mesh.
      14                 :            : 
      15                 :            :     The implementation uses the Charm++ runtime system and is fully
      16                 :            :     asynchronous, overlapping computation and communication. The algorithm
      17                 :            :     utilizes the structured dagger (SDAG) Charm++ functionality.
      18                 :            : */
      19                 :            : // *****************************************************************************
      20                 :            : #ifndef ALE_h
      21                 :            : #define ALE_h
      22                 :            : 
      23                 :            : #include "ConjugateGradients.hpp"
      24                 :            : #include "Inciter/Options/MeshVelocitySmoother.hpp"
      25                 :            : #include "Options/UserTable.hpp"
      26                 :            : #include "Fields.hpp"
      27                 :            : #include "Table.hpp"
      28                 :            : 
      29                 :            : #include "NoWarning/ale.decl.h"
      30                 :            : 
      31                 :            : namespace inciter {
      32                 :            : 
      33                 :            : //! ALE Charm++ chare array used to perform arbitrary ALE mesh movement
      34                 :            : class ALE : public CBase_ALE {
      35                 :            : 
      36                 :            :   public:
      37                 :            :     #if defined(__clang__)
      38                 :            :       #pragma clang diagnostic push
      39                 :            :       #pragma clang diagnostic ignored "-Wunused-parameter"
      40                 :            :       #pragma clang diagnostic ignored "-Wdeprecated-declarations"
      41                 :            :     #elif defined(STRICT_GNUC)
      42                 :            :       #pragma GCC diagnostic push
      43                 :            :       #pragma GCC diagnostic ignored "-Wunused-parameter"
      44                 :            :       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
      45                 :            :     #elif defined(__INTEL_COMPILER)
      46                 :            :       #pragma warning( push )
      47                 :            :       #pragma warning( disable: 1478 )
      48                 :            :     #endif
      49                 :            :     // Include Charm++ SDAG code. See http://charm.cs.illinois.edu/manuals/html/
      50                 :            :     // charm++/manual.html, Sec. "Structured Control Flow: Structured Dagger".
      51                 :            :     ALE_SDAG_CODE
      52                 :            :     #if defined(__clang__)
      53                 :            :       #pragma clang diagnostic pop
      54                 :            :     #elif defined(STRICT_GNUC)
      55                 :            :       #pragma GCC diagnostic pop
      56                 :            :     #elif defined(__INTEL_COMPILER)
      57                 :            :       #pragma warning( pop )
      58                 :            :     #endif
      59                 :            : 
      60                 :            :     //! Constructor
      61                 :            :     explicit
      62                 :            :     ALE( const tk::CProxy_ConjugateGradients& conjugategradientsproxy,
      63                 :            :          const std::array< std::vector< tk::real >, 3 >& coord,
      64                 :            :          const std::vector< std::size_t >& inpoel,
      65                 :            :          const std::vector< std::size_t >& gid,
      66                 :            :          const std::unordered_map< std::size_t, std::size_t >& lid,
      67                 :            :          const tk::NodeCommMap& nodecommmap );
      68                 :            : 
      69                 :            :     #if defined(__clang__)
      70                 :            :       #pragma clang diagnostic push
      71                 :            :       #pragma clang diagnostic ignored "-Wundefined-func-template"
      72                 :            :     #endif
      73                 :            :     //! Migrate constructor
      74                 :            :     // cppcheck-suppress uninitMemberVar
      75                 :        106 :     explicit ALE( CkMigrateMessage* ) {}
      76                 :            :     #if defined(__clang__)
      77                 :            :       #pragma clang diagnostic pop
      78                 :            :     #endif
      79                 :            : 
      80                 :            :     //! Solve linear system to smooth ALE mesh velocity
      81                 :            :     void solve( CkCallback c );
      82                 :            : 
      83                 :            :     //! Query the solution of the Conjugrate Gradients linear solver
      84                 :            :     bool converged() const;
      85                 :            : 
      86                 :            :     //! Start computing new mesh velocity for ALE mesh motion
      87                 :            :     void start(
      88                 :            :       const tk::UnsMesh::Coords vel,
      89                 :            :       const std::vector< tk::real >& soundspeed,
      90                 :            :       CkCallback done,
      91                 :            :       const std::array< std::vector< tk::real >, 3 >& coord,
      92                 :            :       const tk::UnsMesh::Coords coordn,
      93                 :            :       const std::vector< tk::real >& vol0,
      94                 :            :       const std::vector< tk::real >& vol,
      95                 :            :       const std::unordered_map< int,
      96                 :            :         std::unordered_map< std::size_t, std::array< tk::real, 4 > > >& bnorm,
      97                 :            :       std::size_t initial,
      98                 :            :       std::size_t it,
      99                 :            :       tk::real t,
     100                 :            :       tk::real adt );
     101                 :            : 
     102                 :            :     //! Query the mesh velocity
     103         [ -  + ]:       2235 :     const tk::Fields& meshvel() const { return m_w; }
     104                 :            : 
     105                 :            :     //! \brief Query mesh velocity boundary conditions node lists and node list
     106                 :            :     //!    at which ALE moves boundaries
     107                 :            :     void meshvelBnd( const std::map< int, std::vector< std::size_t > >& bface,
     108                 :            :                      const std::map< int, std::vector< std::size_t > >& bnode,
     109                 :            :                      const std::vector< std::size_t >& triinpoel );
     110                 :            : 
     111                 :            :     //! Receive contributions to vorticity on chare-boundaries
     112                 :            :     void comvort( const std::vector< std::size_t >& gid,
     113                 :            :                   const std::vector< std::array< tk::real, 3 > >& v );
     114                 :            : 
     115                 :            :     //! Receive contributions to velocity divergence on chare-boundaries
     116                 :            :     void comdiv( const std::vector< std::size_t >& gid,
     117                 :            :                  const std::vector< tk::real >& v );
     118                 :            : 
     119                 :            :     //! Receive contributions to scalar potential gradient on chare-boundaries
     120                 :            :     void compot( const std::vector< std::size_t >& gid,
     121                 :            :                  const std::vector< std::array< tk::real, 3 > >& v );
     122                 :            : 
     123                 :            :     //! Receive contributions to ALE mesh force on chare-boundaries
     124                 :            :     void comfor( const std::vector< std::size_t >& gid,
     125                 :            :                  const std::vector< std::array< tk::real, 3 > >& w );
     126                 :            : 
     127                 :            :     //! Apply mesh velocity smoother boundary conditions for ALE mesh motion
     128                 :            :     void meshvelbc( tk::real maxv = 0.0 );
     129                 :            : 
     130                 :            :     //! Solve mesh velocity linear solve for ALE mesh motion
     131                 :            :     void applied( CkDataMsg* msg = nullptr );
     132                 :            : 
     133                 :            :     //! Mesh velocity smoother linear solver converged
     134                 :            :     void solved( CkDataMsg* msg = nullptr );
     135                 :            : 
     136                 :            :     //! Compute the gradient of the scalar potential for ALE
     137                 :            :     void helmholtz( CkDataMsg* msg = nullptr );
     138                 :            : 
     139                 :            :     /** @name Pack/unpack (Charm++ serialization) routines */
     140                 :            :     ///@{
     141                 :            :     //! \brief Pack/Unpack serialize member function
     142                 :            :     //! \param[in,out] p Charm++'s PUP::er serializer object reference
     143                 :        349 :     void pup( PUP::er &p ) override {
     144                 :        349 :       p | m_conjugategradients;
     145                 :        349 :       p | m_done;
     146                 :        349 :       p | m_soundspeed;
     147                 :        349 :       p | m_nvort;
     148                 :        349 :       p | m_ndiv;
     149                 :        349 :       p | m_npot;
     150                 :        349 :       p | m_nwf;
     151                 :        349 :       p | m_nodeCommMap;
     152                 :        349 :       p | m_lid;
     153                 :            :       p | m_coord0;
     154                 :            :       p | m_coord;
     155                 :        349 :       p | m_inpoel;
     156                 :        349 :       p | m_vol0;
     157                 :        349 :       p | m_vol;
     158                 :        349 :       p | m_it;
     159                 :        349 :       p | m_t;
     160                 :        349 :       p | m_adt;
     161                 :        349 :       p | m_w;
     162                 :        349 :       p | m_wf;
     163                 :        349 :       p | m_wfc;
     164                 :        349 :       p | m_veldiv;
     165                 :        349 :       p | m_veldivc;
     166                 :            :       p | m_gradpot;
     167                 :            :       p | m_gradpotc;
     168                 :            :       p | m_vorticity;
     169                 :            :       p | m_vorticityc;
     170                 :        349 :       p | m_bnorm;
     171                 :        349 :       p | m_meshveldirbcnodes;
     172                 :        349 :       p | m_meshvelsymbcnodes;
     173                 :        349 :       p | m_move;
     174                 :        349 :     }
     175                 :            :     //! \brief Pack/Unpack serialize operator|
     176                 :            :     //! \param[in,out] p Charm++'s PUP::er serializer object reference
     177                 :            :     //! \param[in,out] a ALE object reference
     178                 :            :     friend void operator|( PUP::er& p, ALE& a ) { a.pup(p); }
     179                 :            :     ///@}
     180                 :            : 
     181                 :            :   private:
     182                 :            :     //! Distributed conjugrate gradients solver proxy
     183                 :            :     tk::CProxy_ConjugateGradients m_conjugategradients;
     184                 :            :     //! Function call to continue with when mesh velocity has been computed
     185                 :            :     CkCallback m_done;
     186                 :            :     //! Speed of sound in mesh nodes
     187                 :            :     std::vector< tk::real > m_soundspeed;
     188                 :            :     //! Counter for communicating the vorticity for ALE
     189                 :            :     std::size_t m_nvort;
     190                 :            :     //! Counter for communicating the velocity divergence for ALE
     191                 :            :     std::size_t m_ndiv;
     192                 :            :     //! Counter for communicating the gradient of the scalar potential for ALE
     193                 :            :     std::size_t m_npot;
     194                 :            :     //! Counter for communicating the mesh force for ALE
     195                 :            :     std::size_t m_nwf;
     196                 :            :     //! \brief Global mesh node IDs bordering the mesh chunk held by fellow
     197                 :            :     //!   Discretization chares associated to their chare IDs
     198                 :            :     tk::NodeCommMap m_nodeCommMap;
     199                 :            :     //! Local node ids associated to the global ones of owned elements
     200                 :            :     std::unordered_map< std::size_t, std::size_t > m_lid;
     201                 :            :     //! Mesh coordinates at the time 0 for ALE
     202                 :            :     tk::UnsMesh::Coords m_coord0;
     203                 :            :     //! Mesh point coordinates
     204                 :            :     tk::UnsMesh::Coords m_coord;
     205                 :            :     //! Element connectivity
     206                 :            :     std::vector< std::size_t > m_inpoel;
     207                 :            :     //! Mesh element volumes at t=t0
     208                 :            :     std::vector< tk::real > m_vol0;
     209                 :            :     //! Volume of nodes
     210                 :            :     //! \details This is the volume of the mesh associated to nodes of owned
     211                 :            :     //!   elements (sum of surrounding cell volumes / 4) with contributions from
     212                 :            :     //!   other chares on chare-boundaries
     213                 :            :     std::vector< tk::real > m_vol;
     214                 :            :     //! Iteration count
     215                 :            :     std::size_t m_it;
     216                 :            :     //! Physics time
     217                 :            :     tk::real m_t;
     218                 :            :     //! alpha*dt of the Runge-Kutta time step
     219                 :            :     tk::real m_adt;
     220                 :            :     //! Mesh velocity for ALE mesh motion
     221                 :            :     tk::Fields m_w;
     222                 :            :     //! Mesh force for ALE mesh motion
     223                 :            :     tk::Fields m_wf;
     224                 :            :     //! Receive buffer for the mesh force for ALE
     225                 :            :     //! \details Key: global node id, value: mesh force in nodes
     226                 :            :     std::unordered_map< std::size_t, std::array< tk::real, 3 > > m_wfc;
     227                 :            :     //! Fluid velocity divergence for ALE mesh motion
     228                 :            :     std::vector< tk::real > m_veldiv;
     229                 :            :     //! Receive buffer for communication of the velocity divergence for ALE
     230                 :            :     //! \details Key: global node id, value: divergence in nodes
     231                 :            :     std::unordered_map< std::size_t, tk::real > m_veldivc;
     232                 :            :     //! Gradient of the scalar potentinal for ALE mesh motion
     233                 :            :     tk::UnsMesh::Coords m_gradpot;
     234                 :            :     //! Receive buffer for the gradient of the scalar potential for ALE
     235                 :            :     //! \details Key: global node id, value: scalar potential gradient in nodes
     236                 :            :     std::unordered_map< std::size_t, std::array< tk::real, 3 > > m_gradpotc;
     237                 :            :     //! Vorticity for ALE
     238                 :            :     tk::UnsMesh::Coords m_vorticity;
     239                 :            :     //! Receive buffer for communication of the vorticity for ALE
     240                 :            :     //! \details Key: global node id, value: vorticity in nodes
     241                 :            :     std::unordered_map< std::size_t, std::array< tk::real, 3 > > m_vorticityc;
     242                 :            :     //! Face normals in boundary points associated to side sets
     243                 :            :     //! \details Key: local node id, value: unit normal and inverse distance
     244                 :            :     //!   square between face centroids and points, outer key: side set id
     245                 :            :     std::unordered_map< int,
     246                 :            :       std::unordered_map< std::size_t, std::array< tk::real, 4 > > > m_bnorm;
     247                 :            :     //! Unique set of nodes at which ALE mesh velocity Dirichlet BCs are set
     248                 :            :     std::unordered_set< std::size_t > m_meshveldirbcnodes;
     249                 :            :     //! Unique set of nodes at which ALE mesh velocity symmetry BCs are set
     250                 :            :     std::unordered_set< std::size_t > m_meshvelsymbcnodes;
     251                 :            :     //! Data structure storing configuration for moving boundaries with ALE
     252                 :            :     //! \details Tuple: 0: user-defined function type (i.e., how it should be
     253                 :            :     //!    interpreted), (1) user-defined function for, and (2) unique set of
     254                 :            :     //!    boundary nodes for each move ... end input file block (vector).
     255                 :            :     std::vector<
     256                 :            :       std::tuple< tk::ctr::UserTableType,
     257                 :            :                   tk::Table<3>,
     258                 :            :                   std::unordered_set< std::size_t > >
     259                 :            :     > m_move;
     260                 :            : 
     261                 :            :     //! Generate {A,x,b} for Laplacian mesh velocity smoother
     262                 :            :     std::tuple< tk::CSR, std::vector< tk::real >, std::vector< tk::real > >
     263                 :            :     Laplacian( std::size_t ncomp,
     264                 :            :                const std::array< std::vector< tk::real >, 3 >& coord ) const;
     265                 :            : 
     266                 :            :     //! Initialize user-defined functions for ALE moving sides
     267                 :            :     decltype(m_move) moveCfg();
     268                 :            : 
     269                 :            :     //! Find Dirichlet BCs on mesh velocity with prescribed movement
     270                 :            :     bool move( std::size_t i ) const;
     271                 :            : 
     272                 :            :     //! Finalize computing fluid vorticity and velocity divergence for ALE
     273                 :            :     void mergevel();
     274                 :            : 
     275                 :            :     //! Finalize computing the scalar potential gradient for ALE
     276                 :            :     void gradpot();
     277                 :            : 
     278                 :            :     //! Compute mesh force for the ALE mesh velocity
     279                 :            :     void startforce();
     280                 :            : 
     281                 :            :     //! Apply mesh force
     282                 :            :     void meshforce();
     283                 :            : };
     284                 :            : 
     285                 :            : } // inciter::
     286                 :            : 
     287                 :            : #endif // ALE_h

Generated by: LCOV version 1.14