text: /*
  
  The MIT License (MIT)
  
  Copyright (c) 2017 Tim Warburton, Noel Chalmers, Jesse Chan, Ali Karakus
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
  
  */
  
  #include "esdg.hpp"
  
  #define RUN_FROM_CMD_LINE 1
  
  #if (RUN_FROM_CMD_LINE)
  int main(const int argc, const char** argv)
  #else
  int esdgMain(const int argc, const char **argv)   // called by SIM driver
  #endif
  {
  
  #if (RUN_FROM_CMD_LINE)
    int procid=0, nprocs=1;
    MPI_Init(&argc, (char***)&argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &procid);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
  #else
    // MPI managed by driver
  #endif
  
    MPI_Comm comm = MPI_COMM_WORLD;
  
    if (argc != 2)
      LIBP_ABORT(string("Usage: ./esdgMain setupfile"));
  
  #if (0)
    //#######################################################
    // open log files for this run 
    // Note: may need to create output directory
    //      initLogFiles(path, procid);
    // e.g: initLogFiles("./logs", procid);
    //#######################################################
  #endif
  
    // create default settings
    platformSettings_t platformSettings(comm);
    meshSettings_t meshSettings(comm);
    esdgSettings_t esdgSettings(comm);
  
    // load settings from file
    esdgSettings.parseFromFile(platformSettings, meshSettings, argv[1]);
  
    // set up platform
    platform_t platform(platformSettings);
  
    platformSettings.report();
    meshSettings.report();
    esdgSettings.report();
  
    // set up mesh
    mesh_t& mesh = mesh_t::Setup(platform, meshSettings, comm);
    
    // set up super nodal mesh
    int snNinc = 0;
    esdgSettings.getSetting("SUPER NODAL DEGREE INCREMENT", snNinc);
  
    int snN = mesh.N + snNinc;
    mesh_t& snMesh = mesh.SetupNewDegree(snN);
    bool free_snMesh = false;
    if (snN != mesh.N) {
      free_snMesh = true;
    }
  
    // set up euler solver
    esdg_t& esdg = esdg_t::Setup(platform, mesh, snMesh, esdgSettings);
  
  #if (1)
    // run
    esdg.Run();
  #else
    nnLOG(1, "\n\n*** Setup complete. Exiting without running. ***\n\n ");
  #endif
  
    // check clean up:
    delete & esdg;
    delete &mesh;
    if (free_snMesh) {
      delete& snMesh;
    }
  
  #if (RUN_FROM_CMD_LINE)
    closeLogFiles();
    MPI_Finalize();
  #endif
  
    return LIBP_SUCCESS;
  }
  
  
  //#########################################################
  // NBN: allow driver to load user options into onelab GUI
  //#########################################################
  
  bool esdgLoadGlobals(const stdS& setupFile, MPI_Comm comm)
  {
  #if (THIS_IS_READY)
  
    // create default settings
    platformSettings_t platformSettings(comm);
    meshSettings_t meshSettings(comm);
    esdgSettings_t esdgSettings(comm);
  
    // load settings from file
    esdgSettings.parseFromFile(platformSettings, meshSettings, setupFile);
  
    if (0) {
      // echo all setting to screen/log
      platformSettings.report();
      meshSettings.report();
      esdgSettings.report();
    }
  
    int Ndim, eType;
    meshSettings.getSetting("MESH FILE", g_meshFile);
    meshSettings.getSetting("MESH DIMENSION", Ndim);
    meshSettings.getSetting("POLYNOMIAL DEGREE", g_ordN);
    meshSettings.getSetting("ELEMENT TYPE", eType);
  
    esdgSettings.getSetting("MEAN FLOW DENSITY",   g_rbar);
    esdgSettings.getSetting("MEAN FLOW XVELOCITY", g_ubar);
    esdgSettings.getSetting("MEAN FLOW YVELOCITY", g_vbar);
    esdgSettings.getSetting("MEAN FLOW PRESSURE",  g_pbar);
  
    // ------------------------------------------------------
    // M = |U|/c = 1/sqrt(gamma*p/rho) => p = 1/(gamma*M^2)
    // mach { 0.3,     0.6,     0.9,     1.2,     1.5}
    // [MEAN FLOW PRESSURE]
    //        7.936,   1.984,   0.882,   0.496,   0.317
    // ------------------------------------------------------
  
    esdgSettings.getSetting("LAME MU", g_mu);
    esdgSettings.getSetting("FINAL TIME", g_finalTime);
    esdgSettings.getSetting("OUTPUT INTERVAL", g_outputInterval);
  
  
    nnMSG(1, "\n*** TODO: init GUI params from file: %s ***\n", setupFile.c_str());
    nnMSG(1,   "   meshfile: %s \n", g_meshFile.c_str());
    nnMSG(1,   "   order N: %d   dim %d   etype %d  mu %0.3e\n", g_ordN, Ndim, eType, g_mu);
    nnMSG(1,   "   outputInterval: %g  finalTime %0.3lf\n\n", g_outputInterval, g_finalTime);
  
  #endif // (THIS_IS_READY)
  
    return true;
  }
  