Seismo-VLAB  1.3
An Open-Source Finite Element Software for Meso-Scale Simulations
Utilities.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // Seismo Virtual Laboratory
4 // Module for Serial and Parallel Analysis of seismic
5 // wave propagation and soil-structure interaction simulation
6 // Copyright (C) 2018-2021, The California Institute of Technology
7 // All Rights Reserved.
8 //
9 // Commercial use of this program without express permission of the California
10 // Institute of Technology, is strictly prohibited. See file "COPYRIGHT" in
11 // main directory for information on usage and redistribution, and for a
12 // DISCLAIMER OF ALL WARRANTIES.
13 //
14 //==============================================================================
15 //
16 // Written by:
17 // Danilo S. Kusanovic (dkusanov@caltech.edu)
18 // Elnaz E. Seylabi (elnaze@unr.edu)
19 //
20 // Supervised by:
21 // Domniki M. Asimaki (domniki@caltech.edu)
22 //
23 // References :
24 // [1]
25 //
26 // Description:
27 // These set of functions gets the command line user's inputs.
28 //------------------------------------------------------------------------------
29 
30 #ifndef _UTILITIES_HPP_
31 #define _UTILITIES_HPP_
32 
33 #include <ctime>
34 #include <string>
35 #include <iostream>
36 #include <stdlib.h>
37 #include "Definitions.hpp"
38 
41 
47 
49 void
50 printHelp(bool &help){
51  //Command Help.
52  if(rank == 0){
53  help = true;
54  std::cout << " COMMAND LINE FLAGS TO PROVIDE: \n";
55  std::cout << " -dir : Location of the working directory. \n";
56  std::cout << " -file : Name of the SeismoVLAB file to be loaded. \n";
57  std::cout << " \n";
58  std::cout << " \x1B[33mRun \x1B[0m: mpirun -np n ./SeismoVLAB.exe -dir '/path/to/files' -file 'model.#.$.json'\n\n";
59  }
60 }
61 
63 void
65  //SeismoVLab Logo.
66  if(rank == 0){
67  time_t t = time(0);
68  tm *timePtr = localtime(&t);
69  unsigned int year = timePtr->tm_year + 1900;
70 
71  std::cout << " \n";
72  std::cout << " ░ \n";
73  std::cout << " ███████╗ ░░░░ ░░░░ ░░░░░░░ ░░░░ ██╗ ██╗ ██╗ ░░░ ░░░░ \n";
74  std::cout << " ██╔════╝ ░ ░ ░ ░ ░ ░ ░ ░ ██║ ██║ ██║ ░ ░ ░ ░ \n";
75  std::cout << " ███████╗ ░░░ ░ ░░░░ ░ ░ ░ ░███╗██║ ██║ ██║ ░ ░ ░░░░ \n";
76  std::cout << " ╚════██║ ░ ░ ░ ░ ░ ░ ░╚═░╝╚██╗ ██╔╝ ██║ ░░░░░ ░ ░ \n";
77  std::cout << " ███████║ ░░░░ ░ ░░░░ ░ ░ ░ ░░░░ ╚████╔╝ ███████╗ ░ ░░░░ \n";
78  std::cout << " ╚══════╝ ╚═══╝ ╚══════╝ \n";
79  std::cout << " Seismo Virtual Laboratory \n";
80  std::cout << " Module for Serial and Parallel Analysis of seismic \n";
81  std::cout << " wave propagation and soil-structure interaction simulation \n";
82  std::cout << " Copyright (C) " << year << ", The California Institute of Technology\n";
83  std::cout << " All Rights Reserved. \n";
84  std::cout << " \n";
85  std::cout << " \033[1;34mWritten by: \033[1;0m\n";
86  std::cout << " Danilo S. Kusanovic (dkusanov@caltech.edu) \n";
87  std::cout << " Elnaz E. Seylabi (elnaze@unr.edu) \n";
88  std::cout << " \n";
89  std::cout << " \033[1;33mSupervised by: \033[1;0m\n";
90  std::cout << " Domniki M. Asimaki (domniki@caltech.edu) \n";
91  std::cout << " \n";
92  }
93 }
94 
96 void
97 CommandLine(int argc, char **argv){
98  //Auxiliary Variable.
99  int iter = 0;
100  int nfile = 0;
101  int count = 0;
102  bool help = false;
103  driverFile = false;
104 
105  //Find help flag is active.
106  while(iter < argc){
107  //Help Command Line Output is Active.
108  if(strcasecmp(argv[iter],"--help") == 0){
109  printHelp(help);
110  }
111  else if(strcasecmp(argv[iter],"--h") == 0){
112  printHelp(help);
113  }
114  iter++;
115  }
116 
117  //SeismoVLAB analysis variables.
118  iter = 0;
119  while(iter < argc){
120  //Name of the Mesh input file.
121  if(strcasecmp(argv[iter],"-file") == 0){
122  while(true){
123  nfile++;
124 
125  //Saves the file name in list
126  std::string jsonfile = std::string(argv[iter + nfile]);
127  fileName.push_back(jsonfile);
128 
129  //Conditions to break loop
130  if((iter + nfile + 1) < argc){
131  if(strcasecmp(argv[iter + nfile + 1], "--h" ) == 0) break;
132  if(strcasecmp(argv[iter + nfile + 1], "-dir" ) == 0) break;
133  if(strcasecmp(argv[iter + nfile + 1], "--help") == 0) break;
134  }
135  else{
136  break;
137  }
138  }
139  count++;
140  }
141  //Location of the Mesh File:
142  if(strcasecmp(argv[iter],"-dir") == 0){
143  filePath = std::string(argv[iter + 1]);
144  count++;
145  }
146  iter++;
147  }
148 
149  //No Enough Number of Input Arguments.
150  if(count == 2){
151  driverFile = true;
152  }
153  else{
154  if(!help){
155  if(rank == 0){
156  printHelp(help);
157  std::cout << "\x1B[31m ERROR: \x1B[0mNOT ENOUGH Command line input arguments.\n";
158  }
159  }
160  }
161 }
162 
163 #endif
void printHelp(bool &help)
Prints out Command Line help.
Definition: Utilities.hpp:50
int rank
The processor number.
This file sets the global variables to be used during SeismoVLAB execution.
std::vector< std::string > fileName
The file name to be loaded.
void CommandLine(int argc, char **argv)
Parse Command Line Inputs.
Definition: Utilities.hpp:97
bool driverFile
Whether the driver (JSON) file is provided.
std::string filePath
The folder path where the file is loaded.
void printLogo()
Prints Seismo-VLAB software header.
Definition: Utilities.hpp:64