Xyst test code coverage report
Current view: top level - Control - MeshConvConfig.hpp (source / functions) Coverage Total Hit
Commit: 1fb74642dd9d7732b67f32dec2f2762e238d3fa7 Lines: 83.3 % 36 30
Test Date: 2025-08-13 22:18:46 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 45.9 % 37 17

             Branch data     Line data    Source code
       1                 :             : // *****************************************************************************
       2                 :             : /*!
       3                 :             :   \file      src/Control/MeshConvConfig.hpp
       4                 :             :   \copyright 2012-2015 J. Bakosi,
       5                 :             :              2016-2018 Los Alamos National Security, LLC.,
       6                 :             :              2019-2021 Triad National Security, LLC.,
       7                 :             :              2022-2025 J. Bakosi
       8                 :             :              All rights reserved. See the LICENSE file for details.
       9                 :             :   \brief     MeshConv's command line
      10                 :             : */
      11                 :             : // *****************************************************************************
      12                 :             : #pragma once
      13                 :             : 
      14                 :             : #include <getopt.h>
      15                 :             : #include <csignal>
      16                 :             : 
      17                 :             : #include "NoWarning/charm++.hpp"
      18                 :             : 
      19                 :             : #include "XystConfig.hpp"
      20                 :             : #include "Exception.hpp"
      21                 :             : #include "Print.hpp"
      22                 :             : #include "TaggedTuple.hpp"
      23                 :             : #include "PrintTaggedTupleDeep.hpp"
      24                 :             : #include "Writer.hpp"
      25                 :             : 
      26                 :             : namespace tag {
      27                 :             : DEFTAG( input );
      28                 :             : DEFTAG( output );
      29                 :             : DEFTAG( reorder );
      30                 :             : DEFTAG( quiescence );
      31                 :             : } // tag::
      32                 :             : 
      33                 :             : namespace meshconv {
      34                 :             : //! Mesh converter control facilitating user input to internal data transfer
      35                 :             : namespace ctr {
      36                 :             : 
      37                 :             : //! Member data for tagged tuple
      38                 :             : using ConfigMembers = brigand::list<
      39                 :             :     tag::input, std::string     // input mesh file
      40                 :             :   , tag::output, std::string    // output mesh file
      41                 :             :   , tag::reorder, bool          // reorder nodes
      42                 :             :   , tag::quiescence, bool       // enable quiescence detection
      43                 :             : >;
      44                 :             : 
      45                 :             : //! Config is a TaggedTuple specialized to MeshConv
      46                 :           0 : class Config : public tk::TaggedTuple< ConfigMembers > {
      47                 :             : 
      48                 :             :   public:
      49                 :             :     //! Parse meshconv command line
      50                 :          23 :     void cmdline( int argc, char** argv ) {
      51         [ -  + ]:          23 :       if (argc == 1) {
      52                 :           0 :         help( argv );
      53                 :           0 :         CkExit( EXIT_FAILURE );
      54                 :             :       }
      55                 :             :       tk::Print print;
      56                 :             : 
      57                 :             :       // Process command line arguments
      58                 :             :       int c; 
      59         [ +  + ]:          86 :       while ((c = getopt( argc, argv, "h?i:o:qrs:v" )) != -1) {
      60 [ +  + ][ +  + ]:          66 :         switch (c) {
            [ +  + ][ + ]
      61                 :           1 :           case '?':
      62                 :             :           case 'h':
      63                 :             :           default:
      64                 :           1 :             help( argv );
      65                 :           1 :             CkExit();
      66                 :             :             break;
      67                 :          21 :           case 'i':
      68                 :          21 :             get< tag::input >() = optarg;
      69                 :             :             break;
      70                 :          21 :           case 'o':
      71                 :          21 :             get< tag::output >() = optarg;
      72                 :             :             break;
      73                 :          20 :           case 'q':
      74                 :          20 :             get< tag::quiescence >() = true;
      75                 :          20 :             break;
      76                 :           1 :           case 'r':
      77                 :           1 :             get< tag::reorder >() = true;
      78                 :           1 :             break;
      79                 :             :           case 's':
      80                 :           2 :             std::raise( std::stoi( optarg ) );
      81                 :           0 :             break;
      82                 :           1 :           case 'v':
      83                 :             :             print << '\n';
      84 [ +  - ][ +  - ]:           2 :             print.version( tk::meshconv_executable(), tk::git_commit() );
      85                 :           1 :             CkExit();
      86                 :             :             break;
      87                 :             :         }
      88                 :             :       }
      89                 :             : 
      90         [ -  + ]:          20 :       if (optind != argc) {
      91                 :             :         print << "\nA non-option was supplied";
      92                 :           0 :         help( argv );
      93                 :           0 :         CkExit( EXIT_FAILURE );
      94                 :             :       }
      95 [ -  + ][ -  - ]:          20 :       ErrChk( not get< tag::input >().empty(),
         [ -  - ][ -  - ]
      96                 :             :               "Mandatory input file not specified. Use -i <filename>." );
      97 [ -  + ][ -  - ]:          20 :       ErrChk( not get< tag::output >().empty(),
         [ -  - ][ -  - ]
      98                 :             :               "Mandatory output file not specified. Use -o <filename>." );
      99                 :             :     
     100                 :             :       // Output state to file
     101                 :          20 :       auto logfilename = tk::meshconv_executable() + "_cmdline.log";
     102         [ +  - ]:          40 :       tk::Writer log( logfilename );
     103         [ +  - ]:          20 :       tk::print( log.stream(), *this );
     104                 :          20 :     }
     105                 :             : 
     106                 :           1 :     void help( char** argv ) {
     107                 :             :       tk::Print() <<
     108                 :             :         "\nUsage: " << argv[0] << " -i <in.msh> -o <out.exo> [OPTION]...\n"
     109                 :             :         "\n"
     110                 :             :         "  -h, -?       Print out this help\n"
     111                 :             :         "  -i <in.msh>  Specify input file\n"
     112                 :             :         "  -o <out.exo> Specify output file\n"
     113                 :             :         "  -r           Reorder mesh nodes\n"
     114                 :             :         "  -q           Enable quiescence detection\n"
     115                 :             :         "  -v           Print revision information\n"
     116                 :             :         "\n";
     117                 :           1 :     }
     118                 :             : 
     119                 :             :     /** @name Pack/Unpack: Serialize Config object for Charm++ */
     120                 :             :     ///@{
     121                 :             :     //! \brief Pack/Unpack serialize member function
     122                 :             :     //! \param[in,out] p Charm++'s PUP::er serializer object reference
     123                 :             :     void pup( PUP::er& p ) { tk::TaggedTuple< ConfigMembers >::pup(p); }
     124                 :             :     //! \brief Pack/Unpack serialize operator|
     125                 :             :     //! \param[in,out] p Charm++'s PUP::er serializer object reference
     126                 :             :     //! \param[in,out] c Config object reference
     127                 :             :     friend void operator|( PUP::er& p, Config& c ) { c.pup(p); }
     128                 :             :     //@}
     129                 :             : };
     130                 :             : 
     131                 :             : } // ctr::
     132                 :             : } // meshconv::
        

Generated by: LCOV version 2.0-1