PlasCom2  1.0
XPACC Multi-physics simluation application
TestPlasCom2Scalar.C
Go to the documentation of this file.
1 #include "Testing.H"
2 #include "PlasCom2.H"
3 #include "Simulation.H"
4 #include "RKTestFixtures.H"
5 #include "EulerRHS.H"
6 #include "Stencil.H"
7 #include "PCPPCommUtil.H"
8 #include "PCPPReport.H"
9 #include "PCPPIntervalUtils.H"
10 #include "TestFixtures.H"
11 #include "EulerTestFixtures.H"
12 #include "PC2Util.H"
13 
14 #include <cmath>
15 
17 
22 
23 
25  pcpp::CommunicatorType &testComm)
26 {
27 
28  bool scalarAdvectionTestResult = true;
29 
30  const std::string testFunctionName("TestPlasCom2_ScalarAdvection2DX");
31  const std::string testSuiteName("ScalarTest/Advection");
32  const std::string testCaseName("xPeriodic");
33  const std::string testDirectory(testSuiteName+"/"+testCaseName);
34  const std::string originalDirectory(ix::sys::CWD());
35  std::ostringstream compareStream;
36  double errorTolerance = 5e-3;
37 
38  int myRank = testComm.Rank();
39 
40  if(myRank == 0)
41  std::cout << "Executing " << testFunctionName << std::endl;
42 
43  testComm.Barrier();
44 
45  int argc = 4;
46  const char *argv[] = {"plascom2x","-c","scalar2d.config",NULL};
47 
48  plascom2::application simulationApplication(argc,const_cast<char **>(argv),
49  testComm.Comm());
50  int returnValue = 0;
51 
52  if(!ix::sys::FILEEXISTS(testDirectory)){
53  scalarAdvectionTestResult = false;
54  if(myRank == 0){
55  std::cout << testFunctionName << ": testing directory ("
56  << testDirectory << ") did not exist. Aborting test."
57  << std::endl;
58  }
59  goto endTest;
60  }
61 
62  ix::sys::ChDir(testDirectory);
63 
64  // dimensional run
65  {
66  //ix::sys::ChDir("nonDimenPC1X");
67 
68  //if(!ix::sys::FILEEXISTS("accepted/accepted_shock2d_nd2_1000.h5")){
69  //if(myRank == 0)
70  //std::cout << testFunctionName << ": Accepted solution file ("
71  //<< "accepted/accepted_shock2d_nd_1000.h5) not found."
72  //<< " Aborting test." << std::endl;
73  //scalarAdvectionTestResult = false;
74  //goto endTest;
75  //}
76 
77  //ix::sys::ChDir("regression");
78  if(myRank == 0)
79  ix::sys::Remove("PlasCom2_000000202.h5");
80  testComm.Barrier();
81 
82  if(myRank == 0)
83  std::cout << "Running dimensional PlasCom2..." << std::endl;
84 
85  returnValue = application::ApplicationDriver(simulationApplication);
86 
87  if(myRank == 0)
88  std::cout << "Done running dimensional PlasCom2." << std::endl;
89 
90  if(returnValue > 0){
91  std::cout << testFunctionName << ": PlasCom2 returned error code ("
92  << returnValue << "). Test failed." << std::endl;
93  scalarAdvectionTestResult = false;
94  goto endTest;
95  }
96 
97  if(!ix::sys::FILEEXISTS("PlasCom2_000000202.h5")){
98  std::cout << testFunctionName << ": PlasCom2 failed to produce expected"
99  << std::endl
100  << "output file (PlasCom2_000000202.h5). Test failed." << std::endl;
101  scalarAdvectionTestResult = false;
102  goto endTest;
103  }
104 
105  //ix::sys::ChDir("../");
106 
107  if(myRank == 0){
108  std::cout << "Comparing results to expected result...";
109  returnValue = plascom2::util::PC2Compare("PlasCom2_000000202.h5",
110  "PlasCom2_000000000.h5",
111  errorTolerance,compareStream);
112  if(returnValue == 0)
113  std::cout << "passed." << std::endl;
114  else {
115  std::cout << "failed." << std::endl;
116  scalarAdvectionTestResult = false;
117  std::cout << testFunctionName << ": Resulting state "
118  << "comparison yielded negative result:"
119  << std::endl
120  << compareStream.str()
121  << std::endl;
122  }
123  }
124  //ix::sys::ChDir("../");
125  }
126  scalarAdvectionTestResult = CheckResult(scalarAdvectionTestResult,testComm);
127 
128  endTest:
129  {
131  ix::sys::ChDir(originalDirectory);
132  parallelUnitResults.UpdateResult("PlasCom2:Scalar:Advection2DX",scalarAdvectionTestResult);
133  }
134 
135  return;
136 
137 }
138 
140  pcpp::CommunicatorType &testComm)
141 {
142 
143 
144  global_t myGlobal;
145  myGlobal.Init("AdvectionDiffusion2DX",testComm);
146  myGlobal.SetVerbLevel(3);
147  myGlobal.Profiling(true);
148 
149  bool scalarAdvectionTestResult = true;
150 
151  const std::string testFunctionName("TestPlasCom2_ScalarAdvectionDiffusion2DX");
152  const std::string testSuiteName("ScalarTest/AdvectionDiffusion");
153  const std::string testCaseName("xPeriodic");
154  const std::string testDirectory(testSuiteName+"/"+testCaseName);
155  const std::string originalDirectory(ix::sys::CWD());
156  std::ostringstream compareStream;
157 
158  double errorTolerance = 1.0e-8;
159 
160  int myRank = testComm.Rank();
161 
162  if(myRank == 0)
163  std::cout << "Executing " << testFunctionName << std::endl;
164 
165  testComm.Barrier();
166 
167  int argc = 4;
168  const char *argv[] = {"plascom2x","-c","scalar2d.config",NULL};
169 
170  plascom2::application simulationApplication(argc,const_cast<char **>(argv),
171  testComm.Comm());
172  int returnValue = 0;
173  if(!ix::sys::FILEEXISTS(testDirectory)){
174  scalarAdvectionTestResult = false;
175  if(myRank == 0){
176  std::cout << testFunctionName << ": testing directory ("
177  << testDirectory << ") did not exist. Aborting test."
178  << std::endl;
179  testComm.SetErr(1);
180  }
181  }
182  if(testComm.Check())
183  goto endTest;
184 
185  ix::sys::ChDir(testDirectory);
186 
187  // dimensional run
188  {
189 
190  if(myRank == 0){
191  ix::sys::Remove("PlasCom2_000001001.h5");
192  std::cout << "Running PlasCom2..." << std::endl;
193  }
194 
195  testComm.Barrier();
196  returnValue = application::ApplicationDriver(simulationApplication);
197  testComm.Barrier();
198 
199  if(myRank == 0)
200  std::cout << "Done running dimensional PlasCom2." << std::endl;
201 
202  if(returnValue > 0){
203  std::cout << testFunctionName << ": PlasCom2 returned error code ("
204  << returnValue << "). Test failed." << std::endl;
205  scalarAdvectionTestResult = false;
206  testComm.SetErr(1);
207  }
208  if(testComm.Check())
209  goto endTest;
210 
211  if(myRank == 0){
212  if(!ix::sys::FILEEXISTS("PlasCom2_000001001.h5")){
213  std::cout << testFunctionName << ": PlasCom2 failed to produce expected"
214  << std::endl
215  << "output file (PlasCom2_000001001.h5). Test failed." << std::endl;
216  scalarAdvectionTestResult = false;
217  testComm.SetErr(1);
218  }
219  }
220  if(testComm.Check())
221  goto endTest;
222 
223  if(myRank == 0){
224  std::cout << "Comparing results to expected result...";
225  returnValue = plascom2::util::PC2Compare("PlasCom2_000001001.h5",
226  "accepted/PlasCom2_000001001.h5",
227  errorTolerance,compareStream);
228  if(returnValue == 0)
229  std::cout << "passed." << std::endl;
230  else {
231  std::cout << "failed." << std::endl;
232  scalarAdvectionTestResult = false;
233  std::cout << testFunctionName << ": Resulting state "
234  << "comparison yielded negative result:"
235  << std::endl
236  << compareStream.str()
237  << std::endl;
238  }
239  }
240  }
241  scalarAdvectionTestResult = CheckResult(scalarAdvectionTestResult,testComm);
242 
243  endTest:
244  {
246  ix::sys::ChDir(originalDirectory);
247  parallelUnitResults.UpdateResult("PlasCom2:Scalar:AdvectionDiffusion2DX",scalarAdvectionTestResult);
248  }
249 
250  return;
251 
252 }
253 
255  pcpp::CommunicatorType &testComm)
256 {
257 
258 
259  global_t myGlobal;
260  myGlobal.Init("AdvectionDiffusion2DY",testComm);
261  myGlobal.SetVerbLevel(3);
262  myGlobal.Profiling(true);
263 
264  bool scalarAdvectionTestResult = true;
265 
266  const std::string testFunctionName("TestPlasCom2_ScalarAdvectionDiffusion2DY");
267  const std::string testSuiteName("ScalarTest/AdvectionDiffusion");
268  const std::string testCaseName("yPeriodic");
269  const std::string testDirectory(testSuiteName+"/"+testCaseName);
270  const std::string originalDirectory(ix::sys::CWD());
271  std::ostringstream compareStream;
272 
273  double errorTolerance = 1.0e-8;
274 
275  int myRank = testComm.Rank();
276 
277  if(myRank == 0)
278  std::cout << "Executing " << testFunctionName << std::endl;
279 
280  testComm.Barrier();
281 
282  int argc = 4;
283  const char *argv[] = {"plascom2x","-c","scalar2d.config",NULL};
284 
285  plascom2::application simulationApplication(argc,const_cast<char **>(argv),
286  testComm.Comm());
287  int returnValue = 0;
288  if(!ix::sys::FILEEXISTS(testDirectory)){
289  scalarAdvectionTestResult = false;
290  if(myRank == 0){
291  std::cout << testFunctionName << ": testing directory ("
292  << testDirectory << ") did not exist. Aborting test."
293  << std::endl;
294  testComm.SetErr(1);
295  }
296  }
297  if(testComm.Check())
298  goto endTest;
299 
300  ix::sys::ChDir(testDirectory);
301 
302  // dimensional run
303  {
304 
305  if(myRank == 0){
306  ix::sys::Remove("PlasCom2_000001001.h5");
307  std::cout << "Running PlasCom2..." << std::endl;
308  }
309 
310  testComm.Barrier();
311  returnValue = application::ApplicationDriver(simulationApplication);
312  testComm.Barrier();
313 
314  if(myRank == 0)
315  std::cout << "Done running dimensional PlasCom2." << std::endl;
316 
317  if(returnValue > 0){
318  std::cout << testFunctionName << ": PlasCom2 returned error code ("
319  << returnValue << "). Test failed." << std::endl;
320  scalarAdvectionTestResult = false;
321  testComm.SetErr(1);
322  }
323  if(testComm.Check())
324  goto endTest;
325 
326  if(myRank == 0){
327  if(!ix::sys::FILEEXISTS("PlasCom2_000001001.h5")){
328  std::cout << testFunctionName << ": PlasCom2 failed to produce expected"
329  << std::endl
330  << "output file (PlasCom2_000001001.h5). Test failed." << std::endl;
331  scalarAdvectionTestResult = false;
332  testComm.SetErr(1);
333  }
334  }
335  if(testComm.Check())
336  goto endTest;
337 
338  if(myRank == 0){
339  std::cout << "Comparing results to expected result...";
340  returnValue = plascom2::util::PC2Compare("PlasCom2_000001001.h5",
341  "accepted/PlasCom2_000001001.h5",
342  errorTolerance,compareStream);
343  if(returnValue == 0)
344  std::cout << "passed." << std::endl;
345  else {
346  std::cout << "failed." << std::endl;
347  scalarAdvectionTestResult = false;
348  std::cout << testFunctionName << ": Resulting state "
349  << "comparison yielded negative result:"
350  << std::endl
351  << compareStream.str()
352  << std::endl;
353  }
354  }
355  }
356  scalarAdvectionTestResult = CheckResult(scalarAdvectionTestResult,testComm);
357 
358  endTest:
359  {
361  ix::sys::ChDir(originalDirectory);
362  parallelUnitResults.UpdateResult("PlasCom2:Scalar:AdvectionDiffusion2DY",scalarAdvectionTestResult);
363  }
364 
365  return;
366 
367 }
368 
370  pcpp::CommunicatorType &testComm)
371 {
372 
373  bool scalarAdvectionTestResult = true;
374 
375  const std::string testFunctionName("TestPlasCom2_ScalarAdvection2DY");
376  const std::string testSuiteName("ScalarTest/Advection");
377  const std::string testCaseName("ySlipWalls");
378  const std::string testDirectory(testSuiteName+"/"+testCaseName);
379  const std::string originalDirectory(ix::sys::CWD());
380  std::ostringstream compareStream;
381  double errorTolerance = 0.005;
382 
383  int myRank = testComm.Rank();
384 
385  if(myRank == 0)
386  std::cout << "Executing " << testFunctionName << std::endl;
387 
388  testComm.Barrier();
389 
390  int argc = 4;
391  const char *argv[] = {"plascom2x","-c","scalar2d.config",NULL};
392 
393  plascom2::application simulationApplication(argc,const_cast<char **>(argv),
394  testComm.Comm());
395  int returnValue = 0;
396 
397  if(!ix::sys::FILEEXISTS(testDirectory)){
398  scalarAdvectionTestResult = false;
399  if(myRank == 0){
400  std::cout << testFunctionName << ": testing directory ("
401  << testDirectory << ") did not exist. Aborting test."
402  << std::endl;
403  }
404  goto endTest;
405  }
406 
407  ix::sys::ChDir(testDirectory);
408 
409  // dimensional run
410  {
411  if(myRank == 0)
412  ix::sys::Remove("PlasCom2_000001010.h5");
413  testComm.Barrier();
414 
415  if(myRank == 0)
416  std::cout << "Running dimensional PlasCom2..." << std::endl;
417 
418  returnValue = application::ApplicationDriver(simulationApplication);
419 
420  if(myRank == 0)
421  std::cout << "Done running dimensional PlasCom2." << std::endl;
422 
423  if(returnValue > 0){
424  std::cout << testFunctionName << ": PlasCom2 returned error code ("
425  << returnValue << "). Test failed." << std::endl;
426  scalarAdvectionTestResult = false;
427  goto endTest;
428  }
429 
430  if(!ix::sys::FILEEXISTS("PlasCom2_000001010.h5")){
431  std::cout << testFunctionName << ": PlasCom2 failed to produce expected"
432  << std::endl
433  << "output file (PlasCom2_000001010.h5). Test failed." << std::endl;
434  scalarAdvectionTestResult = false;
435  goto endTest;
436  }
437 
438  if(myRank == 0){
439  std::cout << "Comparing results to expected result...";
440  returnValue = plascom2::util::PC2Compare("PlasCom2_000001010.h5",
441  "PlasCom2_000000000.h5",
442  errorTolerance,compareStream);
443  if(returnValue == 0)
444  std::cout << "passed." << std::endl;
445  else {
446  std::cout << "failed." << std::endl;
447  scalarAdvectionTestResult = false;
448  std::cout << testFunctionName << ": Resulting state "
449  << "comparison yielded negative result:"
450  << std::endl
451  << compareStream.str()
452  << std::endl;
453  }
454  }
455  }
456  scalarAdvectionTestResult = CheckResult(scalarAdvectionTestResult,testComm);
457 
458  endTest:
459  {
461  ix::sys::ChDir(originalDirectory);
462  parallelUnitResults.UpdateResult("PlasCom2:Scalar:Advection2DY",scalarAdvectionTestResult);
463  }
464 
465  return;
466 
467 }
468 
470  pcpp::CommunicatorType &testComm)
471 {
472 
473  bool scalarAdvectionTestResult = true;
474 
475  const std::string testFunctionName("TestPlasCom2_ScalarAdvection3DZ");
476  const std::string testSuiteName("ScalarTest/Advection");
477  const std::string testCaseName("zPeriodicCube");
478  const std::string testDirectory(testSuiteName+"/"+testCaseName);
479  const std::string originalDirectory(ix::sys::CWD());
480  std::ostringstream compareStream;
481  double errorTolerance = 0.15;
482 
483  int myRank = testComm.Rank();
484 
485  if(myRank == 0)
486  std::cout << "Executing " << testFunctionName << std::endl;
487 
488  testComm.Barrier();
489 
490  int argc = 4;
491  const char *argv[] = {"plascom2x","-c","scalar3d.config",NULL};
492 
493  plascom2::application simulationApplication(argc,const_cast<char **>(argv),
494  testComm.Comm());
495  int returnValue = 0;
496 
497  if(!ix::sys::FILEEXISTS(testDirectory)){
498  scalarAdvectionTestResult = false;
499  if(myRank == 0){
500  std::cout << testFunctionName << ": testing directory ("
501  << testDirectory << ") did not exist. Aborting test."
502  << std::endl;
503  }
504  goto endTest;
505  }
506 
507  ix::sys::ChDir(testDirectory);
508 
509  // dimensional run
510  {
511  if(myRank == 0)
512  ix::sys::Remove("PlasCom2_000000500.h5");
513  testComm.Barrier();
514 
515  if(myRank == 0)
516  std::cout << "Running dimensional PlasCom2..." << std::endl;
517 
518  returnValue = application::ApplicationDriver(simulationApplication);
519 
520  if(myRank == 0)
521  std::cout << "Done running dimensional PlasCom2." << std::endl;
522 
523  if(returnValue > 0){
524  std::cout << testFunctionName << ": PlasCom2 returned error code ("
525  << returnValue << "). Test failed." << std::endl;
526  scalarAdvectionTestResult = false;
527  goto endTest;
528  }
529 
530  if(!ix::sys::FILEEXISTS("PlasCom2_000000500.h5")){
531  std::cout << testFunctionName << ": PlasCom2 failed to produce expected"
532  << std::endl
533  << "output file (PlasCom2_000000500.h5). Test failed." << std::endl;
534  scalarAdvectionTestResult = false;
535  goto endTest;
536  }
537 
538  if(myRank == 0){
539  std::cout << "Comparing results to expected result...";
540  returnValue = plascom2::util::PC2Compare("PlasCom2_000000500.h5",
541  "PlasCom2_000000000.h5",
542  errorTolerance,compareStream);
543  if(returnValue == 0)
544  std::cout << "passed." << std::endl;
545  else {
546  std::cout << "failed." << std::endl;
547  scalarAdvectionTestResult = false;
548  std::cout << testFunctionName << ": Resulting state "
549  << "comparison yielded negative result:"
550  << std::endl
551  << compareStream.str()
552  << std::endl;
553  }
554  }
555  }
556  scalarAdvectionTestResult = CheckResult(scalarAdvectionTestResult,testComm);
557 
558  endTest:
559  {
561  ix::sys::ChDir(originalDirectory);
562  parallelUnitResults.UpdateResult("Integrated:Scalar:Advection3DZ",scalarAdvectionTestResult);
563  }
564 
565  return;
566 
567 }
pcpp::ParallelGlobalType global_t
void TestPlasCom2_Scalar_Advection2DX(ix::test::results &parallelUnitResults, pcpp::CommunicatorType &testComm)
int ApplicationDriver(ApplicationType &simulationApplication)
void TestPlasCom2_Scalar_Advection2DY(ix::test::results &parallelUnitResults, pcpp::CommunicatorType &testComm)
int Remove(const std::string &fname)
Definition: UnixUtils.C:141
std::vector< DomainBaseType > domainvector
Definition: Simulation.H:32
virtual bool Profiling()
Get profiling state.
Definition: Global.H:229
int PC2Compare(const std::string &redFileName, const std::string &blueFileName, double errTolerance, std::ostream &outStream)
Read two HDF5 files and compare the state data therein.
Definition: PC2Util.C:30
bool CheckResult(bool &localResult, pcpp::CommunicatorType &testComm)
Definition: PCPPCommUtil.C:176
int ChDir(const std::string &path)
Definition: UnixUtils.C:297
int SetErr(int errin)
Definition: COMM.H:110
virtual int Init(const std::string &name, CommunicatorType &incomm)
Definition: Global.H:578
void TestPlasCom2_Scalar_AdvectionDiffusion2DX(ix::test::results &parallelUnitResults, pcpp::CommunicatorType &testComm)
Encapsulating class for collections of test results.
Definition: Testing.H:18
void TestPlasCom2_Scalar_AdvectionDiffusion2DY(ix::test::results &parallelUnitResults, pcpp::CommunicatorType &testComm)
simulation::grid::parallel_blockstructured pbsgrid_t
int Check(comm::Ops op=comm::MAXOP)
Definition: COMM.C:355
bool FILEEXISTS(const std::string &fname)
Definition: UnixUtils.C:189
Main encapsulation of MPI.
Definition: COMM.H:62
Testing constructs for unit testing.
void TestIntegrated_Scalar_Advection3DZ(ix::test::results &parallelUnitResults, pcpp::CommunicatorType &testComm)
const std::string CWD()
Definition: UnixUtils.C:291
plascom2::application::domainvector DomainVector
void UpdateResult(const std::string &name, const ValueType &result)
Updates an existing test result.
Definition: Testing.H:55
void SetVerbLevel(unsigned char l)
Definition: Global.H:393
simulation::state::base state_t