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
virtual void Test__ElmerUnitTests ( ResultsType &  result)
inlinevirtual

Definition at line 415 of file ElmerModuleDriverTest.H.

References TestingObject< ResultsType >::GetInputData().

Referenced by TestingObject< ResultsType >::Process(), and TestingObject< ResultsType >::RunTest().

415  {
416  std::cout << "Running Test__ElmerUnitTests" << std::endl;
417 
418  int IntDir;
419  std::string OrgDir, TestDir;
420  bool ItAllWorks = true;
421 
422  // Arrays that old data for check *******************************************
423  double CoordCheck[15][3] =
424  { {2.2999999999999998, 0.19296300000000000, 0.0000000000000000},
425  {2.2999999999999998, 0.00000000000000000, 0.0000000000000000},
426  {2.2999999999999998, 0.39523399999999997, 0.0000000000000000},
427  {2.2999999999999998, 0.60476600000000003, 0.0000000000000000},
428  {2.2999999999999998, 0.80703700000000000, 0.0000000000000000},
429  {2.2999999999999998, 1.00000000000000000, 0.0000000000000000},
430  {2.3585799999999999, 1.14142000000000010, 0.0000000000000000},
431  {2.5000000000000000, 1.20000000000000000, 0.0000000000000000},
432  {2.6414200000000001, 1.14142000000000010, 0.0000000000000000},
433  {2.7000000000000002, 1.00000000000000000, 0.0000000000000000},
434  {2.7000000000000002, 0.80703700000000000, 0.0000000000000000},
435  {2.7000000000000002, 0.60476600000000003, 0.0000000000000000},
436  {2.7000000000000002, 0.39523399999999997, 0.0000000000000000},
437  {2.7000000000000002, 0.19296300000000000, 0.0000000000000000},
438  {2.7000000000000002, 0.00000000000000000, 0.0000000000000000} };
439  int ConnCheck[14][2] =
440  { {1,2}, {3,1}, {4,3}, {5,4}, {6,5}, {7,6}, {8,7}, {9,8}, {10,9},
441  {11,10}, {12,11}, {13,12}, {14,13}, {15,14} };
442 
443  // Getting Input data********************************************************
444  //***************************************************************************
445 
446  //Call GetInputData to copy input test data to temp directory for running tests.
447  std::string suffix = "/share/Testing/test_data/FSIobstacle";
448 
449  //Make path for directory to run the test in.
450  TestDir = IRAD::Sys::CWD() + "/UnitTestData";
451  IntDir = GetInputData(suffix, TestDir);
452 
453  //Check if GetInputData exited correctly.
454  if(IntDir != 0){
455  std::cout << "ElmerUnitTests Error: GetInputData call failed."
456  << std::endl;
457  result.UpdateResult("ElmerUnitTests:Run", false);
458  return;
459  }
460 
461  //Check if TestDir directory (from GetInputData) exists in current directory
462  if(!IRAD::Sys::FILEEXISTS(TestDir)){
463  std::cout << "ElmerUnitTests Error: Could not find directory, "
464  << TestDir << ", for running tests." << std::endl;
465  result.UpdateResult("ElmerUnitTests:Run", false);
466  return;
467  }
468 
469  //Save original directory name for later
470  OrgDir = IRAD::Sys::CWD();
471 
472  //Change directories to TestDir directory for running
473  IntDir = IRAD::Sys::ChDir(TestDir);
474  if(IntDir == -1){
475  std::cout << "ElmerUnitTests Error: Could not change directories to "
476  << TestDir << "." << std::endl;
477  result.UpdateResult("ElmerUnitTests:Run", false);
478  return;
479  }
480 
481  //load Elmer module**********************************************************
482  //***************************************************************************
483  COM_LOAD_MODULE_STATIC_DYNAMIC( ElmerCSC, "Window1");
484 
485  bool load_unload = true;
486 
487  //Get Winodw handle
488  int h=COM_get_window_handle("Window1");
489  if(h <= 0){
490  std::cout << " After loading, COM_get_window_handle(\"Window1\") returns "
491  << h << std::endl;
492  load_unload=false;
493  std::cout << "ElmerUnitTests Error: Could not get window handle."
494  << "." << std::endl;
495  result.UpdateResult("LoadSolverModule:Works",false);
496  result.UpdateResult("ElmerUnitTests:Run", false);
497  return;
498  }
499  else
500  result.UpdateResult("LoadSolverModule:Works",true);
501 
503  // Get Initialize function handle and call Function
505  int init_handle = COM_get_function_handle("Window1.Initialize");
506  bool init_func = (init_handle > 0);
507  int init_runs = 0;
508  int verb=3;
509  std::cout << "init = " << init_handle << std::endl;
510  if(init_handle){
511  //Call the function
512  COM_call_function(init_handle, &init_runs, &verb);
513  }
514  else{
515  std::cout << "InitializeRuns Error: Could not get function handle."
516  << "." << std::endl;
517  result.UpdateResult("Initialize:Runs", false);
518  return;
519  }
520 
521  //Check if function changed value of runs properly
522  if(init_runs == 1){
523  result.UpdateResult("Initialize:Runs", true);
524  }
525  else{
526  result.UpdateResult("Initialize:Runs", false);
527  ItAllWorks = false;
528  }
529 
531  // Check coordinate values
533  int coord_handle = COM_get_dataitem_handle("Window1.nc");
534  int CoordSize=0;
535  bool coordData = (coord_handle > 0);
536  bool coordCorrect = true;
537  std::cout << "coord_handle = " << coord_handle << std::endl;
538  if(coordData){
539  COM_get_size("Window1.nc",11,&CoordSize);
540  if(CoordSize != 15){
541  std::cout << "ElmerUnitTests Error:"
542  << " Coord array is incorrect size!" << std::endl;
543  ItAllWorks = false;
544  coordCorrect = false;
545  }
546  else{
547  // Get the FSI mesh from the structures solver and print
548  // it out to check
549  double* Coord;
550  COM_get_array("Window1.nc",11,&Coord);
551  std::cout << "Coord:" << std::endl;
552  for(int i=0; i < CoordSize; i++){
553  for(int j=0; j < 3; j++){
554  std::cout << Coord[i*3+j] << " ";
555  if(fabs(CoordCheck[i][j] - Coord[i*3+j]) > 1.0e-12){
556  ItAllWorks = false;
557  coordCorrect = false;
558  }
559  }
560  std::cout << std::endl;
561  }
562  }
563  result.UpdateResult("CoordinateData:Correct", coordCorrect);
564  result.UpdateResult("CoordinateData:Registered", true);
565  }
566  else{
567  result.UpdateResult("CoordinateData:Registered", false);
568  result.UpdateResult("CoordinateData:Correct", false);
569  ItAllWorks = false;
570  }
571 
573  // Check connectivity values
575  bool connCorrect = true;
576  int ConnSize = 0;
577  int* Conn = NULL;
578 
579  // Get the FSI mesh from the structures solver
580  COM_get_array("Window1.:b2:",11,&Conn);
581  if(Conn){
582  // Get the FSI mesh size from the structures solver
583  COM_get_size("Window1.:b2:",11,&ConnSize);
584  if(ConnSize != 14){
585  std::cout << "ElmerUnitTests Error:"
586  << " Conn array is incorrect size!" << std::endl;
587  ItAllWorks = false;
588  connCorrect = false;
589  }
590  else{
591  // check the values
592  std::cout << "Conn:" << std::endl;
593  for(int i=0; i < ConnSize; i++){
594  for(int j=0; j < 2; j++){
595  std::cout << Conn[i*2+j] << " ";
596  if( (ConnCheck[i][j] - Conn[i*2+j]) != 0){
597  ItAllWorks = false;
598  connCorrect = false;
599  }
600  }
601  std::cout << std::endl;
602  }
603  }
604  result.UpdateResult("ConnectivityData:Correct", connCorrect);
605  result.UpdateResult("ConnectivityData:Registered", true);
606  }
607  else{
608  result.UpdateResult("ConnectivityData:Registered", false);
609  result.UpdateResult("ConnectivityData:Correct", false);
610  ItAllWorks = false;
611  }
612 
614  // Check load registration & initialization
616  double* Loads = NULL;
617  int LoadsSize = 0;
618  bool loadsRegistered = true, loadsInitialized = true;
619  // Get the FSI loads from the structures solver
620  COM_get_array("Window1.Loads",11,&Loads);
621  if(Loads){
622  std::cout << "Loads not NULL" << std::endl;
623  // Get the FSI load size from the structures solver
624  COM_get_size("Window1.Loads",11,&LoadsSize);
625  if(LoadsSize != 15){
626  std::cout << "ElmerUnitTests Error:"
627  << " Loads array is incorrect size!" << std::endl;
628  ItAllWorks = false;
629  loadsInitialized = false;
630  }
631  else{
632  // check the values
633  for(int i=0; i < LoadsSize; i++){
634  for(int j=0; j < 3; j++){
635  if(fabs(Loads[i*3 + j]) > 1.0e-12){
636  loadsInitialized = false;
637  ItAllWorks = false;
638  }
639  }
640  }
641  }
642  }
643  else{
644  std::cout << "Loads are NULL" << std::endl;
645  loadsRegistered = false;
646  loadsInitialized = false;
647  ItAllWorks = false;
648  }
649  result.UpdateResult("LoadData:Registered", loadsRegistered);
650  result.UpdateResult("LoadData:Initialized", loadsInitialized);
651 
653  // Get TimeStepper function handle and call Function
655 
656  // Arrays that hold disp data for check *********************************
657  double DispTime1[15][3] =
658  {{ 7.1605980866005031E-002, 3.5788052113870331E-002, 0.0000000000000000},
659  { -6.8871825230548747E-026, -6.7515261027908644E-026, 0.0000000000000000},
660  { 0.16559117138148402 , 6.1512134471618775E-002, 0.0000000000000000},
661  { 0.27105716643234351 , 7.0647177803958988E-002, 0.0000000000000000},
662  { 0.37408733220172607 , 6.6788253467455649E-002, 0.0000000000000000},
663  { 0.46975382688278072 , 5.5232228766620040E-002, 0.0000000000000000},
664  { 0.53059533135003267 , 1.7568173579321143E-002, 0.0000000000000000},
665  { 0.54088718131665003 , -5.0723278288525193E-002, 0.0000000000000000},
666  { 0.49733519851449115 , -0.10431856777439819 , 0.0000000000000000},
667  { 0.42342243323024942 , -0.11544236710979815 , 0.0000000000000000},
668  { 0.32858350010626158 , -9.6940873722311166E-002, 0.0000000000000000},
669  { 0.22913389910789400 , -7.6890455177259009E-002, 0.0000000000000000},
670  { 0.13256597264490513 , -5.4789959945688596E-002, 0.0000000000000000},
671  { 5.4547795662606154E-002, -2.9570884780950012E-002, 0.0000000000000000},
672  { -6.8871825230548747E-026, -6.7515261027908632E-026, 0.0000000000000000}};
673  double DispTime2[15][3] =
674  {{ 7.8382763777475994E-002, 3.7159701956680058E-002, 0.0000000000000000},
675  { -1.3908554346559520E-053, -1.3634598387444821E-053, 0.0000000000000000},
676  { 0.17746729339780631 , 6.3782065644847119E-002, 0.0000000000000000},
677  { 0.28589059231716707 , 7.3724507560836025E-002, 0.0000000000000000},
678  { 0.39007099539893136 , 7.0647599706400666E-002, 0.0000000000000000},
679  { 0.48577572075292708 , 5.9851545424915178E-002, 0.0000000000000000},
680  { 0.54619785916039254 , 2.2562624600359866E-002, 0.0000000000000000},
681  { 0.55515630051911513 , -4.5683794688744256E-002, 0.0000000000000000},
682  { 0.51164185034902454 , -9.8434990773815095E-002, 0.0000000000000000},
683  { 0.43876588136755668 , -0.10966508014917155 , 0.0000000000000000},
684  { 0.34337311330396592 , -9.2057033659364212E-002, 0.0000000000000000},
685  { 0.24185886373003795 , -7.3235312951635573E-002, 0.0000000000000000},
686  { 0.14168683127415216 , -5.2598213602584751E-002, 0.0000000000000000},
687  { 5.9082767678702033E-002, -2.8938645702423191E-002, 0.0000000000000000},
688  { -1.3908554346559520E-053, -1.3634598387444801E-053, 0.0000000000000000}};
689  //*********************************************************************
690  int runs_handle = COM_get_function_handle("Window1.Run");
691  bool runs_func = (runs_handle > 0);
692  bool DispCorrect = true;
693  int runs_runs = 0;
694  double time1 = 8.0;
695  double time2 = 100.0;
696  double* Disp = NULL;
697  int DispSize = 0;
698  COM_get_array("Window1.Displacements",11,&Disp);
699  std::cout << "runs = " << runs_handle << std::endl;
700  if(runs_handle){
701  //Call the run function for Time1
702  if(Loads){
703  std::cout << "Changing load values" << std::endl;
704  for(int i=0; i < LoadsSize; i++){
705  for(int j=0; j < 3; j++){
706  Loads[i*3 + j] = double(i*3 + j);
707  std::cout << Loads[i*3 + j] << " ";
708  }
709  std::cout << std::endl;
710  }
711  }
712  COM_call_function(runs_handle, &runs_runs, &time1);
713  }
714  else{
715  std::cout << "TimeStepperRuns Error: Could not get function handle."
716  << "." << std::endl;
717  result.UpdateResult("TimeStepper:Runs", false);
718  return;
719  }
720 
721  //Check if function changed value of runs properly
722  if(runs_runs > 0){
723  result.UpdateResult("TimeStepper:Runs", true);
724  }
725  else{
726  result.UpdateResult("TimeStepper:Runs", false);
727  ItAllWorks = false;
728  }
729 
730  // Check reigstration of displacement data
731  if (Disp){
732  result.UpdateResult("DisplacementData:Registered", true);
733  // Get the FSI displacement size from the structures solver
734  COM_get_size("Window1.Displacements",11,&DispSize);
735  if(DispSize != 15){
736  std::cout << "ElmerUnitTests Error:"
737  << " Disp array is incorrect size!" << std::endl;
738  ItAllWorks = false;
739  DispCorrect = false;
740  }
741  }
742  else{
743  result.UpdateResult("DisplacementData:Registered", false);
744  DispCorrect = false;
745  ItAllWorks = false;
746  }
747 
748  // Check values of displacements after Run func @ Time1
749  if (Disp && runs_handle && DispCorrect){
750  std::cout << "Checking Displacements Time 1 (" << time1 << ")" << std::endl;
751  for(int i=0; i < DispSize; i++){
752  for(int j=0; j < 3; j++){
753  std::cout << Disp[i*3+j] << " ";
754  if(fabs(DispTime1[i][j] - Disp[i*3+j]) > 1.0e-12){
755  ItAllWorks = false;
756  DispCorrect = false;
757  }
758  }
759  std::cout << std::endl;
760  }
761  //Change the load values again for testing
762  if(Loads){
763  std::cout << "Changing load values" << std::endl;
764  for(int i=0; i < LoadsSize; i++){
765  for(int j=0; j < 3; j++){
766  Loads[i*3 + j] = double(i*3 + j) + 1.0;
767  std::cout << Loads[i*3 + j] << " ";
768  }
769  std::cout << std::endl;
770  }
771  }
772  //Call the run function for Time2
773  int runs_runs2 = 0;
774  COM_call_function(runs_handle, &runs_runs2, &time2);
775  // Check values of displacements after Run func @ Time1
776  std::cout << "Checking Displacements Time 2 (" << time2 << ")" << std::endl;
777  for(int i=0; i < DispSize; i++){
778  for(int j=0; j < 3; j++){
779  std::cout << Disp[i*3+j] << " ";
780  if(fabs(DispTime2[i][j] - Disp[i*3+j]) > 1.0e-12){
781  ItAllWorks = false;
782  DispCorrect = false;
783  }
784  }
785  std::cout << std::endl;
786  }
787  //Check if function changed value of runs properly in Loads function
788  if(runs_runs > 1 && runs_runs2 > 1){
789  result.UpdateResult("TimeLoads:Runs", true);
790  }
791  else{
792  std::cout << "runs_runs = " << runs_runs << std::endl;
793  std::cout << "runs_runs2 = " << runs_runs2 << std::endl;
794  result.UpdateResult("TimeLoads:Runs", false);
795  ItAllWorks = false;
796  }
797  }
798  result.UpdateResult("DisplacementData:Correct", DispCorrect);
799 
800 
802  // Get Finalize function handle and call Function
804  int final_handle = COM_get_function_handle("Window1.Finalize");
805  bool final_func = (final_handle > 0);
806  int final_runs = 0;
807  std::cout << "final = " << final_handle << std::endl;
808  if(final_handle){
809  //Call the function
810  COM_call_function(final_handle, &final_runs);
811  }
812  else{
813  std::cout << "FinalizeRuns Error: Could not get function handle."
814  << "." << std::endl;
815  result.UpdateResult("Finalize:Runs", false);
816  return;
817  }
818 
819  //Check if function changed value of runs properly
820  if(final_runs == 1){
821  result.UpdateResult("Finalize:Runs", true);
822  }
823  else{
824  result.UpdateResult("Finalize:Runs", false);
825  ItAllWorks = false;
826  }
828 
829  //Unload Elmer module********************************************************
830  //***************************************************************************
831  COM_UNLOAD_MODULE_STATIC_DYNAMIC( ElmerCSC, "Window1");
832 
833  //Make sure module unloaded
834  h=COM_get_window_handle("Window1");
835  if(h > 0){
836  std::cout << "After unloading, COM_get_window_handle(\"Window1\") returns "
837  << h << std::endl;
838  load_unload=false;
839  std::cout << "ElmerUnitTests Error: Did not properly unload module."
840  << "." << std::endl;
841  result.UpdateResult("ElmerUnitTests:Run", false);
842  result.UpdateResult("UnloadSolverModule:Works",false);
843  return;
844  }
845  else
846  result.UpdateResult("UnloadSolverModule:Works",true);
847 
848  //Change directories out of TestDir directory back to original directory
849  IntDir = IRAD::Sys::ChDir(OrgDir);
850  if(IntDir == -1){
851  std::cout << "ElmerUnitTests Error: Could not change directories to "
852  << OrgDir << "." << std::endl;
853  result.UpdateResult("ElmerUnitTests:Run", false);
854  return;
855  }
856 
857  result.UpdateResult("ElmerUnitTests:Run", ItAllWorks);
858 
859  }
virtual int GetInputData(std::string suffix, std::string TestDir)
Function to copy input data from source testing directory for use in unit tests.

Here is the call graph for this function:

Here is the caller graph for this function: