11 #include "com_devel.hpp"
16 #include "primitive_utilities.H"
17 #include "SolverAgent.H"
18 #include "InterfaceLayer.H"
25 int main(
int argc,
char *argv[]){
26 COM_init( &argc, &argv);
31 bool regression =
true;
33 bool prescribedDisplacement =
false;
42 for (
int i=1; i<argc; ++i) {
46 if (ss.str() ==
"--driverRegression") {
48 }
else if (ss.str() ==
"--driverPrescribedDisplacement") {
50 prescribedDisplacement =
true;
58 COM_LOAD_MODULE_STATIC_DYNAMIC( OpenFoamFSI,
"OFModule");
61 int init_handle = COM_get_function_handle(
"OFModule.InitFoam");
62 if(init_handle <= 0) {
63 std::cout <<
"OFModuleDriver:main: Could not get handle for init function." << std::endl;
75 COM_call_function(init_handle, &myArgc, &myArgv, &verb);
80 COM_get_dataitems(
"OFModule", &numDataItems, output);
81 std::istringstream Istr(output);
82 std::vector<std::string> dataItemNames;
84 for (
int i=0; i<numDataItems; ++i) {
87 dataItemNames.push_back(name);
88 std::cout <<
"OFModuleDriver:main: DataItem # " << i <<
": " << name << std::endl;
94 COM_get_panes(
"OFModule", &numPanes, &paneList);
95 std::cout <<
"OFModuleDriver:main: Number of Panes " << numPanes << std::endl;
96 for (
int i=0; i<numPanes; ++i)
97 std::cout <<
"OFModuleDriver:main: Pane ID # " << i+1 <<
"=" << paneList[i] << std::endl;
100 int pane = paneList[0];
103 COM_get_array(
"OFModule.nc", pane, &Coord);
107 COM_get_size(
"OFModule.nc", pane, &numNodes);
111 std::string stringNames;
112 COM_get_connectivities(
"OFModule", pane, &numConn, stringNames);
113 std::istringstream ConnISS(stringNames);
114 std::vector<std::string> connNames;
116 for (
int i=0; i<numConn; ++i) {
119 connNames.push_back(name);
120 std::cout <<
"OFModuleDriver:main: Connectivity Table # " << i+1 <<
": " << name << std::endl;
125 COM_Type getDataItemType;
127 std::string getDataItemUnits;
128 std::string fullConnName(
"OFModule."+connNames[0]);
129 COM_get_dataitem(fullConnName, &getDataItemLoc, &getDataItemType,
130 &numElementNodes, &getDataItemUnits);
132 std::cout <<
"OFModuleDriver:main: getDataItemLoc " << getDataItemLoc << std::endl;
133 std::cout <<
"OFModuleDriver:main: getDataItemType " << getDataItemType << std::endl;
134 std::cout <<
"OFModuleDriver:main: numElementNodes " << numElementNodes << std::endl;
135 std::cout <<
"OFModuleDriver:main: getDataItemUnits " << getDataItemUnits << std::endl;
139 COM_get_array(fullConnName.c_str(), pane, &Conn);
140 COM_get_size(fullConnName, pane, &numElem);
143 std::vector<unsigned int> connVector;
144 for (
int i=0; i<numElem; ++i) {
145 for (
int j=0; j<numElementNodes; ++j) {
146 connVector.push_back((Conn[i*numElementNodes+j]));
152 std::string name(
"OFModule.time");
153 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
154 &arrayLength, &getDataItemUnits);
156 COM_get_array(name.c_str(), pane, &time);
158 name =
"OFModule.endTime";
159 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
160 &arrayLength, &getDataItemUnits);
162 COM_get_array(name.c_str(), pane, &endTime);
166 SolverUtils::FEM::SolverAgent myAgent;
171 myAgent.Solution().Meta().AddField(
"time",
's', 1, 8,
"s");
172 myAgent.Solution().Meta().AddField(
"endTime",
's', 1, 8,
"s");
179 myAgent.Mesh().nc.init(numNodes, Coord);
181 myAgent.Mesh().con.AddElements(numElem, numElementNodes, connVector);
184 name =
"OFModule.pressure";
185 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
186 &arrayLength, &getDataItemUnits);
188 std::cout <<
"OFModuleDriver:main: Pressure Get DataItem" << std::endl;
189 std::cout <<
"OFModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
190 std::cout <<
"OFModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
191 std::cout <<
"OFModuleDriver:main: arrayLength: " << arrayLength << std::endl;
192 std::cout <<
"OFModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
196 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
199 std::cout <<
"OFModuleDriver:main: Unknown Data Item Location" << std::endl;
204 if (getDataItemType == COM_DOUBLE) {
207 std::cout <<
"OFModuleDriver:main: Unknown Data Item Type" << std::endl;
211 myAgent.Solution().Meta().AddField(
"surfacePressure", myDataItemLoc, arrayLength,
212 myDataItemType, getDataItemUnits);
213 double* surfacePressure;
214 COM_get_array(name.c_str(), pane, &surfacePressure);
216 name =
"OFModule.traction";
217 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
218 &arrayLength, &getDataItemUnits);
220 std::cout <<
"OFModuleDriver:main: Traction Get DataItem" << std::endl;
221 std::cout <<
"OFModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
222 std::cout <<
"OFModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
223 std::cout <<
"OFModuleDriver:main: arrayLength: " << arrayLength << std::endl;
224 std::cout <<
"OFModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
227 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
230 std::cout <<
"OFModuleDriver:main: Unknown Data Item Location" << std::endl;
234 if (getDataItemType == COM_DOUBLE) {
237 std::cout <<
"OFModuleDriver:main: Unknown Data Item Type" << std::endl;
241 myAgent.Solution().Meta().AddField(
"surfaceTraction", myDataItemLoc, arrayLength,
242 myDataItemType, getDataItemUnits);
243 double* surfaceTraction;
244 COM_get_array(name.c_str(), pane, &surfaceTraction);
246 name =
"OFModule.solidDisplacement";
247 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
248 &arrayLength, &getDataItemUnits);
250 std::cout <<
"OFModuleDriver:main: Solid Displacement Get DataItem" << std::endl;
251 std::cout <<
"OFModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
252 std::cout <<
"OFModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
253 std::cout <<
"OFModuleDriver:main: arrayLength: " << arrayLength << std::endl;
254 std::cout <<
"OFModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
257 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
259 }
else if (getDataItemLoc ==
'n' || getDataItemLoc ==
'N') {
262 std::cout <<
"OFModuleDriver:main: Unknown Data Item Location" << std::endl;
266 if (getDataItemType == COM_DOUBLE) {
269 std::cout <<
"OFModuleDriver:main: Unknown Data Item Type" << std::endl;
273 myAgent.Solution().Meta().AddField(
"solidDisplacement", myDataItemLoc, arrayLength,
274 myDataItemType, getDataItemUnits);
275 double* solidDisplacement;
276 COM_get_array(
"OFModule.solidDisplacement", pane, &solidDisplacement);
279 myAgent.CreateSoln();
281 unsigned int nnodes = myAgent.Mesh().nc.NNodes();
282 unsigned int nelem = myAgent.Mesh().con.Nelem();
285 myAgent.Solution().SetFieldBuffer(
"time", time);
286 myAgent.Solution().SetFieldBuffer(
"endTime", endTime);
287 myAgent.Solution().SetFieldBuffer(
"surfacePressure", surfacePressure);
288 myAgent.Solution().SetFieldBuffer(
"surfaceTraction", surfaceTraction);
289 myAgent.Solution().SetFieldBuffer(
"solidDisplacement", solidDisplacement);
292 int run_handle = COM_get_function_handle(
"OFModule.RunFoam");
293 if(run_handle <= 0) {
294 std::cout <<
"OFModuleDriver:main: Could not get handle for run function." << std::endl;
301 step_handle = COM_get_function_handle(
"OFModule.StepFoam");
302 std::cout <<
"OFModuleDriver:main: StepFoam will be running shortly." << std::endl;
303 if(step_handle <= 0) {
304 std::cout <<
"OFModuleDriver:main: Could not get handle for step function." << std::endl;
307 }
else if (prescribedDisplacement) {
308 step_handle = COM_get_function_handle(
"OFModule.StepFluid");
309 std::cout <<
"OFModuleDriver:main: StepFluid will be running shortly." << std::endl;
310 if(step_handle <= 0) {
311 std::cout <<
"OFModuleDriver:main: Could not get handle for step fluid alone function." << std::endl;
321 std::string filename;
322 filename =
"fsi" + ss.str() +
".vtk";
323 Ouf.open(filename.c_str());
325 std::cerr <<
"OFModuleDriver:main: OFModuleDriver::DumpSolution:Error: Could not open output file, "
326 << filename <<
"." << std::endl;
329 std::cout <<
"OFModuleDriver:main: WriteVTKToStream time " << time[0] << std::endl;
330 SolverUtils::WriteVTKToStream(
"OFModule", myAgent, Ouf);
333 std::cout <<
"OFModuleDriver:main: In Driver:" <<
" time=" << time[0] <<
" endTime=" << endTime[0] << std::endl;
334 while(time[0] <= endTime[0]) {
337 if (prescribedDisplacement) {
340 double alpha = 3.141592/(2.0*(xmax-xmin));
341 double beta = 2*3.141592/endTime[0];
342 for(
int i = 0;i < numNodes;i++){
343 double xpos = Coord[i*3] - xmin;
346 solidDisplacement[i*3] = solidDisplacement[i*3+2] = 0.0;
347 solidDisplacement[i*3+1] = 0.001*std::sin(xpos)*std::sin(beta*time[0]);
351 COM_call_function(step_handle);
357 std::string filename;
358 filename =
"fsi" + ss.str() +
".vtk";
359 Ouf.open(filename.c_str());
361 std::cerr <<
"OFModuleDriver::DumpSolution:Error: Could not open output file, "
362 << filename <<
"." << std::endl;
365 std::cout <<
"OFModuleDriver:main: WriteVTKToStream time " << time[0] << std::endl;
366 SolverUtils::WriteVTKToStream(
"OFModule", myAgent, Ouf);
370 COM_UNLOAD_MODULE_STATIC_DYNAMIC(OpenFoamFSI,
"OFModule");
377 std::cout <<
"Usage: " << std::endl;
378 std::cout << exec <<
"<flags>" << std::endl
379 <<
"OFModuleDriver:Usage: Where flags is either --driverRegression or --driverPrescribedDisplacement" << std::endl
380 <<
"--driver Regresion runs a standard openFoam simulation" << std::endl
381 <<
"--driverPrescribedMotion runs openFoam with a fluid only solver and applies"
382 <<
"a prescribed displacement to the solid/fluid boundary" << std::endl;
COM_EXTERN_MODULE(OpenFoamFSI)