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
src/ExampleSerialProgram.C
Go to the documentation of this file.
1 
9 #include "ExampleProgram.H"
10 
11 
12 namespace ElmerFoamFSI {
13 
14  namespace ExampleProgram {
15 
17  {
18  // FunctionEntry("NAME"): Updates the user-defined stack and
19  // the program profiles with timing information. The placement
20  // of FunctionEntry and FunctionExit calls is at the developer's
21  // discretion.
22  FunctionEntry("Run");
23 
24  // ---------- The Program -----------------
25  // This program just "copies" the input file
26  // to the output file.
27  //
28 
29  // Open the specified input file for reading
30  Inf.open(input_name.c_str());
31  if(!Inf){
32  // If the input file failed to open, notify to
33  // the error stream and return non-zero
34  std::ostringstream Ostr;
35  Ostr << "Error: Could not open input file, '"
36  << input_name << "'.\n";
37  ErrOut(Ostr.str());
38  // don't forget to tell the profiler/stacker the
39  // function is exiting.
40  FunctionExit("Run");
41  return(1);
42  }
43 
44  // Open the specified output file for writing
45  bool use_outfile = false;
46  if(!output_name.empty()){
47  use_outfile = true;
48  Ouf.open(output_name.c_str());
49  if(!Ouf){
50  // If the output file failed to open, notify
51  // to error stream and return non-zero
52  std::ostringstream Ostr;
53  Ostr << "Error: Unable to open output file, " << output_name << ".";
54  ErrOut(Ostr.str());
55  // don't forget to tell the profiler/stacker the
56  // function is exiting.
57  FunctionExit("Run");
58  return(1);
59  }
60  }
61 
62  // Read lines from the input file and repeat them
63  // to the output file.
64  std::string line;
65  while(std::getline(Inf,line)){
66  if(use_outfile)
67  Ouf << line << std::endl;
68  else
69  StdOut(line+"\n");
70  }
71  // Close both files
72  Ouf.close();
73  Inf.close();
74 
75  //
76  // ---------- Program End -----------------
77 
78 
79  // Update the stacker/profiler that we are exiting
80  // this function.
81  FunctionExit("Run");
82  // return 0 for success
83  return(0);
84  };
85  };
86 };
std::ofstream Ouf
Outfile stream for output.
std::ifstream Inf
Infile stream for input.
virtual int Run()
This function implements the main function executed by the program.
std::string output_name
Name of file for output.