ElmerFoamFSI  2.0
ElmerFoamFSI is fluid-solid interaction simulation application built up from OpenFOAM CFD and Elmer CSM coupled through the IMPACT multiphysics software integration infrastructure.
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Groups Pages
int ElmerFoamFSI::ParallelTest ( int  argc,
char *  argv[] 
)

Drives the ElmerFoamFSI::TestObject.

Parameters
argcnumber of string command line tokens
argvstring command line tokens
Returns
0 if successful, 1 otherwise

Drives the ElmerFoamFSI::TestObject, which should encapsulate all the tests for the ElmerFoamFSI namespace (and thus the project).

Command line documentation:

      elmerfoamfsi_test [-h] [-v [level] -o <filename> -l <filename> -n <TestName> ] 

      -h,--help
         Print out long version of help and exit.

      -v,--verblevel [level]
         Set the verbosity level. (default = 0)

      -o,--output <filename>
         Set the output file to <filename>. (default = stdout)

      -l,--list <filename>
         Set the list file name to <filename>. (no default). The list file should be a text file with one test name per line.

      -n,--name <TestName>
         Run test by name. (no default)

Definition at line 50 of file ParallelTestElmerFoamFSI.C.

References TestComLine::Initialize().

Referenced by main().

51  {
52 
53  int com_initialized = COM_initialized();
54  bool com_initialized_pass = (com_initialized <= 0);
55 
56  COM_init(&argc, &argv);
57  if(com_initialized_pass)
58  com_initialized = (COM_initialized() > 0);
59 
60  // The default verbosity is 0
61  int verblevel = 0;
62 
63  // This sets everything up with MPI
64  ElmerFoamFSI::CommType communicator(&argc,&argv);
65  int rank = communicator.Rank();
66  int nproc = communicator.Size();
67  bool do_stdout = !rank;
68 
69  // This line creates the ElmerFoamFSI::TestComLine object and passes in
70  // the command line arguments as a (const char **).
71  TestComLine comline((const char **)(argv));
72  // The call to comline.Initialize() reads the command line arguments
73  // from the array passed in the previous line.
74  comline.Initialize();
75 
76 
77  // The ProcessOptions() call does detailed examination of the command
78  // line arguments to check for user errors or other problems. This call
79  // will return non-zero if there were errors on the commandline.
80  int clerr = comline.ProcessOptions();
81  // Check if the user just wanted to get the help and exit
82  if(!comline.GetOption("help").empty()){
83  // Print out the "long usage" (i.e. help) message to stdout
84  if(do_stdout){
85  std::cout << comline.LongUsage() << std::endl;
86  if(verblevel > 1)
87  std::cout << "ElmerFoamFSI::ParallelTest: Exiting test function (success)"
88  << std::endl;
89  }
90  communicator.SetExit(1);
91  }
92  if(communicator.Check())
93  return(0);
94  if(clerr){
95  if(do_stdout){
96  std::cout << comline.ErrorReport() << std::endl
97  << std::endl << comline.ShortUsage() << std::endl;
98  if(verblevel > 2)
99  std::cout << "ElmerFoamFSI::ParallelTest: Exiting test function (fail)" << std::endl;
100  }
101  communicator.SetExit(1);
102  }
103  if(communicator.Check())
104  return(1);
105 
106  // These outstreams allow the output to file to be set up and separated
107  // from the stdout.
108  std::ofstream Ouf;
109  std::ostream *Out = NULL;
110  if(do_stdout)
111  Out = &std::cout;
112 
113  // The next few lines populate some strings based on the
114  // users input from the commandline.
115  std::string OutFileName(comline.GetOption("output"));
116  std::string TestName(comline.GetOption("name"));
117  std::string ListName(comline.GetOption("list"));
118  std::string sverb(comline.GetOption("verblevel"));
119  std::string SourcePath(comline.GetOption("source"));
120 
121  // The following block parses and sets the verbosity level
122  if(!sverb.empty()){
123  verblevel = 1;
124  if(sverb != ".true."){
125  std::istringstream Istr(sverb);
126  Istr >> verblevel;
127  if(verblevel < 0)
128  verblevel = 1;
129  }
130  }
131 
132  // This block sets up the output file if the user specified one
133  if(!OutFileName.empty()){
134  if(Out){
135  Ouf.open(OutFileName.c_str());
136  if(!Ouf){
137  std::cout << "ElmerFoamFSI::ParallelTest> Error: Could not open output file, "
138  << OutFileName << " for test output. Exiting (fail)." << std::endl;
139  communicator.SetExit(1);
140  }
141  Out = &Ouf;
142  }
143  if(communicator.Check())
144  return(1);
145  }
146 
147  if(verblevel > 1 && Out)
148  *Out << "ElmerFoamFSI::ParallelTest: Entering test function" << std::endl;
149 
150  // Make an instance of the ElmerFoamFSI testing object, ElmerFoamFSI::ParallelTestingObject
151  ElmerFoamFSI::ParallelTestingObject<ElmerFoamFSI::CommType,ElmerFoamFSI::TestResults> test(communicator);
152  // Make an instance of the ElmerFoamFSI results object, ElmerFoamFSI::TestResults
154 
155  //Set the source directory for the testing object if it was input
156  if(!SourcePath.empty()){
157  test.SetSourceDirPath(SourcePath);
158  }
159 
160  // If the user specified a name, then run only the named test
161  if(!TestName.empty()){
162  // This call runs a test by name
163  if (do_stdout)
164  std::cout << "Processing test : " << TestName << std::endl;
165  test.RunTest(TestName,results);
166  }
167  // Otherwise, if the user specified a list, then read the list and
168  // run the listed tests.
169  else if(!ListName.empty()){
170  if (do_stdout)
171  std::cout << "Processing list of tests" << std::endl;
172  std::ifstream ListInf;
173  ListInf.open(ListName.c_str());
174  if(!ListInf){
175  if(Out)
176  *Out << "ElmerFoamFSI::ParallelTest> Error: Could not open list of tests in file "
177  << ListName << ". Exiting (fail)." << std::endl;
178  communicator.SetExit(1);
179  }
180  if(communicator.Check())
181  return(1);
182  std::string testname;
183  while(std::getline(ListInf,testname))
184  test.RunTest(testname,results);
185  ListInf.close();
186  }
187  else {
188  // This call runs all the tests for the ElmerFoamFSI namespace.
189  if (do_stdout)
190  std::cout << "Processing all of the tests" << std::endl;
191  test.Process(results);
192  }
193  if(Out)
194  *Out << results << std::endl;
195 
196  if(Out && Ouf)
197  Ouf.close();
198 
199  if((verblevel > 1) && Out)
200  *Out << "ElmerFoamFSI::ParallelTest: Exiting test function (success)" << std::endl;
201 
202  return(0);
203  }
IRAD::Comm::CommunicatorObject CommType
Convenience typedef for CommunicatorObject.
IRAD::Util::TestResults TestResults
Project-specific test results type.

Here is the call graph for this function:

Here is the caller graph for this function: