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__ElasticBeam3D_LoadFunction ( ResultsType &  result)
inlinevirtual

Definition at line 871 of file ElmerModuleDriverTest.H.

References TestingObject< ResultsType >::GetInputData(), and TestingObject< ResultsType >::streamdiff().

Referenced by TestingObject< ResultsType >::RunTest().

871  {
872  std::cout << "Running Test__ElasticBeam3D_LoadFunction" << std::endl;
873 
874  int IntDir;
875  std::string OrgDir, TestDir;
876  bool ItAllWorks = true;
877 
878  // Getting Input data********************************************************
879  //***************************************************************************
880 
881  //Call GetInputData to copy input test data to temp directory for running tests.
882  std::string suffix = "/share/Testing/test_data/ElasticBeam3D_LoadFunction";
883 
884  //Make path for directory to run the test in.
885  TestDir = IRAD::Sys::CWD() + "/ElasticBeam3D_TestData";
886  IntDir = GetInputData(suffix, TestDir);
887 
888  //Check if GetInputData exited correctly.
889  if(IntDir != 0){
890  std::cout << "ElasticBeam3D_LoadFunction Error: GetInputData call failed."
891  << std::endl;
892  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
893  return;
894  }
895 
896  //Check if TestDir directory (from GetInputData) exists in current directory
897  if(!IRAD::Sys::FILEEXISTS(TestDir)){
898  std::cout << "ElasticBeam3D_LoadFunction Error: Could not find directory, "
899  << TestDir << ", for running tests." << std::endl;
900  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
901  return;
902  }
903 
904  //Save original directory name for later
905  OrgDir = IRAD::Sys::CWD();
906 
907  //Change directories to TestDir directory for running
908  IntDir = IRAD::Sys::ChDir(TestDir);
909  if(IntDir == -1){
910  std::cout << "ElasticBeam3D_LoadFunction Error: Could not change directories to "
911  << TestDir << "." << std::endl;
912  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
913  return;
914  }
915 
916  //load Elmer module**********************************************************
917  //***************************************************************************
918  COM_LOAD_MODULE_STATIC_DYNAMIC( ElmerCSC, "Window1");
919 
920  bool load_unload = true;
921 
922  //Get Winodw handle
923  int h=COM_get_window_handle("Window1");
924  if(h <= 0){
925  std::cout << " After loading, COM_get_window_handle(\"Window1\") returns "
926  << h << std::endl;
927  load_unload=false;
928  std::cout << "ElasticBeam3D_LoadFunction Error: Could not get window handle."
929  << "." << std::endl;
930  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
931  return;
932  }
933 
935  // Get Initialize function handle and call Function
937  int init_handle = COM_get_function_handle("Window1.Initialize");
938  bool init_func = (init_handle > 0);
939  int init_runs = 0;
940  int verb=3;
941  std::cout << "init = " << init_handle << std::endl;
942  if(init_handle){
943  //Call the function
944  COM_call_function(init_handle, &init_runs, &verb);
945  }
946  else{
947  std::cout << "ElasticBeam3D_LoadFunction Error: Could not get function handle."
948  << "." << std::endl;
949  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
950  return;
951  }
952 
954  // Check load registration & initialization
956  double* Loads = NULL;
957  int LoadsSize = 0;
958  bool loadsRegistered = true, loadsInitialized = true;
959  // Get the FSI mesh from the structures solver
960  COM_get_array("Window1.Loads",11,&Loads);
961  if(Loads){
962  COM_get_size("Window1.Loads",11,&LoadsSize);
963  std::cout << "Loads not NULL" << std::endl;
964  std::cout << "LoadsSize = " << LoadsSize << std::endl;
965  // check the values
966  for(int i=0; i < LoadsSize; i++){
967  for(int j=0; j < 3; j++){
968  if(fabs(Loads[i*3 + j]) > 1.0e-12){
969  std::cout << "Loads were not intialized to 0.0!" << std::endl;
970  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
971  return;
972  }
973  }
974  }
975  }
976  else{
977  std::cout << "Loads are NULL" << std::endl;
978  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
979  return;
980  }
981 
983  // Get TimeStepper function handle and call Function
985 
986  int runs_handle = COM_get_function_handle("Window1.Run");
987  bool runs_func = (runs_handle > 0);
988  bool DispCorrect = true;
989  int runs_runs = 0;
990  double time1 = 1.0;
991  double* Disp = NULL;
992  std::cout << "runs = " << runs_handle << std::endl;
993  if(runs_handle){
994  //Call the run function for Time1
995  if(Loads){
996  std::cout << "Changing load values" << std::endl;
997  for(int i=0; i < LoadsSize; i++){
998  Loads[i*3 + 1] = -4.0e5;
999  for(int j=0; j < 3; j++){
1000  std::cout << Loads[i*3 + j] << " ";
1001  }
1002  std::cout << std::endl;
1003  }
1004  }
1005  COM_call_function(runs_handle, &runs_runs, &time1);
1006  }
1007  else{
1008  std::cout << "ElasticBeam3D_LoadFunction Error: Could not get function handle."
1009  << "." << std::endl;
1010  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
1011  return;
1012  }
1013 
1015  // Get Finalize function handle and call Function
1017  int final_handle = COM_get_function_handle("Window1.Finalize");
1018  bool final_func = (final_handle > 0);
1019  int final_runs = 0;
1020  std::cout << "final = " << final_handle << std::endl;
1021  if(final_handle){
1022  //Call the function
1023  COM_call_function(final_handle, &final_runs);
1024  }
1025  else{
1026  std::cout << "ElasticBeam3D_LoadFunction Error: Could not get function handle."
1027  << "." << std::endl;
1028  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
1029  return;
1030  }
1031 
1033 
1035  // Compare the output file with an archived output file
1037  std::ifstream Inf, InfComp;
1038  std::stringstream ss;
1039  std::string word, line;
1040 
1041  Inf.open("case.ep");
1042  InfComp.open("case.ep_check");
1043 
1044  std::getline(Inf,line);
1045  std::getline(Inf,line);
1046  std::getline(InfComp,line);
1047  std::getline(InfComp,line);
1048 
1049  bool LoadWorks = true;
1050  int diffReturn = -1;
1051 
1052  diffReturn = streamdiff(Inf, InfComp, &ss);
1053 
1054  if(diffReturn){
1055  std::cout << "ElasticBeam3D_LoadFunction Error: case.ep "
1056  << "case.ep_check differ!" << std::endl;
1057  std::cout << ss.str() << std::endl;
1058  if(ss.str() != " ")
1059  LoadWorks = false;
1060  }
1061 
1062  std::cout << "LoadWorks = " << LoadWorks << std::endl;
1063  result.UpdateResult("ElasticBeam3D_LoadFunction:Works",LoadWorks);
1064 
1065  //Unload Elmer module********************************************************
1066  //***************************************************************************
1067  COM_UNLOAD_MODULE_STATIC_DYNAMIC( ElmerCSC , "Window1");
1068 
1069  //Make sure module unloaded
1070  h=COM_get_window_handle("Window1");
1071  if(h > 0){
1072  std::cout << "After unloading, COM_get_window_handle(\"Window1\") returns "
1073  << h << std::endl;
1074  load_unload=false;
1075  std::cout << "ElasticBeam3D_LoadFunction Error: Did not properly unload module."
1076  << "." << std::endl;
1077  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
1078  return;
1079  }
1080 
1081  //Change directories out of TestDir directory back to original directory
1082  IntDir = IRAD::Sys::ChDir(OrgDir);
1083  if(IntDir == -1){
1084  std::cout << "ElasticBeam3D_LoadFunction Error: Could not change directories to "
1085  << OrgDir << "." << std::endl;
1086  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", false);
1087  return;
1088  }
1089 
1090  result.UpdateResult("ElasticBeam3D_LoadFunction:Runs", true);
1091 
1092  }
int streamdiff(std::istream &stream1, std::istream &stream2, std::stringstream *ss=NULL)
Function to compare two files.
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: