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 int GetInputData ( std::string  sourceDir,
std::string  destDir 
)
inlinevirtual

Function to copy input data from source testing directory for use in unit tests.

Parameters
sourceDirstd::string directory containing the input data
destDirstd::string destination directory for the data

Definition at line 145 of file OpenFoamModuleDriverTest.H.

Referenced by TestingObject< ResultsType >::Test__LoadUnitTestData(), TestingObject< ResultsType >::Test__ModuleFunctionInitialize(), TestingObject< ResultsType >::Test__ModuleFunctionStepFluid(), TestingObject< ResultsType >::Test__ModuleMeshRegistration(), and TestingObject< ResultsType >::Test__ModuleSurfaceData().

145  {
146 
147  //std::string DirName;
148  std::string OrgDir;
149 
150  //Save original working directory for later
151  OrgDir = IRAD::Sys::CWD();
152 
153  //Check if data directory exists
154  if(!IRAD::Sys::FILEEXISTS(sourceDir)){
155  std::cout << "GetInputData Error: Could not find data directory, "
156  << sourceDir << ". Exiting (fail)." << std::endl;
157  return -1;
158  }
159 
160  std::ifstream Inf;
161  std::ofstream Ouf;
162  std::string InFileName;
163  std::string OutFileName;
164  int IntDir;
165 
166  //Create destDir directory in current directory (if it doesn't
167  //already exist) to run our tests in.
168  if(!IRAD::Sys::FILEEXISTS(destDir)){
169  IntDir = IRAD::Sys::CreateDirectory(destDir);
170  if(IntDir == -1){
171  std::cout << "GetInputData Error: Could not make directory, "
172  << destDir << ". Exiting (fail)." << std::endl;
173  return -1;
174  }
175  }
176 
177  //Open the input test data directory
178  IRAD::Sys::Directory SourceDir(sourceDir);
179 
180  //Change directories to destDir directory for running
181  IntDir = IRAD::Sys::ChDir(destDir);
182  if(IntDir == -1){
183  std::cout << "GetInputData Error: Could not change directories to "
184  << destDir << ". Exiting (fail)." << std::endl;
185  return -1;
186  }
187 
188  //Copy input data to destDir directory for running
189  for(std::vector<std::string>::iterator it = SourceDir.begin();
190  it != SourceDir.end(); ++it){
191  InFileName = sourceDir + "/" + *it;
192  OutFileName = IRAD::Sys::CWD() + "/" + *it;
193 
194  if(IRAD::Sys::ISLINK(InFileName))
195  // preserve links, don't traverse
196  int IntDir = IRAD::Sys::SymLink(InFileName, OutFileName);
197  else if(IRAD::Sys::ISDIR(InFileName)) {
198  // recursively copy directories
199  int IntDir = GetInputData(InFileName, OutFileName);
200  } else {
201  // copy files, travserse into directories recursively
202  Inf.open(InFileName.c_str());
203  Ouf.open(OutFileName.c_str());
204  Ouf << Inf.rdbuf();
205  Ouf.close();
206  Inf.close();
207  }
208  }
209 
210  //Change directories to back to original directory
211  IntDir = IRAD::Sys::ChDir(OrgDir);
212  if(IntDir == -1){
213  std::cout << "GetInputData Error: Could not change directories to "
214  << OrgDir << ". Exiting (fail)." << std::endl;
215  return -1;
216  }
217 
218  return 0;
219  }
virtual int GetInputData(std::string sourceDir, std::string destDir)
Function to copy input data from source testing directory for use in unit tests.

Here is the caller graph for this function: