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
ElmerTest/trunk/src/SolverModuleDriver.C
Go to the documentation of this file.
1 #include "com.h"
10 #include "com_devel.hpp"
11 #include <iostream>
12 #include <cstring>
13 #include <cstdlib>
14 #include <stdlib.h>
15 #include <sstream>
16 
17 COM_EXTERN_MODULE( SolverModule);
18 
19 using namespace std;
20 
21 void usage(char *exec){
22  std::cout << "Usage: " << std::endl
23  << exec << " timeNext timeNext ... timeFinal" << std::endl
24  << "where at least timeFinal is required." << std::endl
25  << "NOTES: *steady state problems will always use a timestep" << std::endl
26  << "of 1.0, and should only have a timeFinal" << std::endl
27  << "*each time must be greater than the previous time" << std::endl
28  << "because the simulation begins at the previous time and runs" << std::endl
29  << "to the current time" << std::endl;
30  std::exit(1);
31 }
32 
33 int main(int argc, char *argv[]){
34  COM_init( &argc, &argv);
35 
36  std::cout << "After COM_init" << std::endl;
37 
38  std::vector<double> tNext;
39  stringstream ss;
40  double var;
41  bool isNum = false;
42  std::string arg;
43 
44  std::cout << "argc = " << argc << std::endl;
45 
46  if(argc > 1){
47  for(int i=1; i < argc; i++){
48  ss.clear();
49  ss.str("");
50  ss << argv[i];
51  for(int j=0; j < ss.str().size(); j++){
52  if(!isdigit(ss.str()[j]) && ss.str()[j] != 'e'
53  && ss.str()[j] != 'E' && ss.str()[j] != '-'
54  && ss.str()[j] != '.')
55  usage(argv[0]);
56  }
57  ss >> var;
58  tNext.push_back(var);
59  }
60  }
61  else
62  usage(argv[0]);
63 
64  std::cout << "line " << __LINE__ << std::endl;
65 
66  for(int i=0; i < tNext.size(); i++)
67  std::cout << tNext[i] << std::endl;
68 
69  for(int i=1; i < tNext.size(); i++){
70  std::cout << tNext[i] << " " << tNext[i-1] << std::endl;
71  if(tNext[i] <= tNext[i-1])
72  usage(argv[0]);
73  }
74 
75  COM_LOAD_MODULE_STATIC_DYNAMIC( SolverModule, "Window1");
76 
78  int init_handle = COM_get_function_handle("Window1.Initialize");
79  bool init_func = (init_handle > 0);
80  std::cout << "init = " << init_handle << std::endl;
81  if(init_handle){
82  COM_call_function(init_handle);
83  }
84 
86  int run_handle = COM_get_function_handle("Window1.Run");
87  bool run_func = (run_handle > 0);
88  std::cout << "run = " << run_handle << std::endl;
89  if(run_handle){
90  for(int i=0; i < tNext.size(); i++){
91  std::cout << "Calling run function from driver" << std::endl;
92  COM_call_function(run_handle,&tNext[i]);
93  }
94  }
95 
97  int final_handle = COM_get_function_handle("Window1.Finalize");
98  bool final_func = (final_handle > 0);
99  std::cout << "final = " << final_handle << std::endl;
100  if(final_handle){
101  COM_call_function(final_handle);
102  }
103 
104  COM_UNLOAD_MODULE_STATIC_DYNAMIC( SolverModule, "Window1");
105 
106  COM_finalize();
107  std::cout << "After COM_finalize" << std::endl;
108 
109 }
void usage(char *exec)
COM_EXTERN_MODULE(OpenFoamFSI)
#define main
Definition: icoFoamModule.C:2