52 std::cout <<
"OFModuleDriver:Main: Setting up parallel communicator..." << std::endl;
54 MPI_Comm masterComm = communicator.GetCommunicator();
55 int rank = communicator.Rank();
56 int nproc = communicator.Size();
57 std::cout <<
"OFModuleDriver:Main:Rank #"
65 COM_init( &argc, &argv);
72 if(rank == -1) color=0;
82 MPI_Comm newComm = communicator.GetCommunicator();
86 bool regression =
true;
88 bool prescribedDisplacement =
false;
90 bool runParallel =
false;
101 for (
int i=1; i<argc; ++i) {
105 if (ss.str() ==
"--driverRegression") {
107 }
else if (ss.str() ==
"--driverPrescribedDisplacement") {
109 prescribedDisplacement =
true;
110 }
else if (ss.str() ==
"--parallel") {
112 }
else if (ss.str() ==
"--dryrun") {
125 COM_set_default_communicator(newComm);
126 std::cout <<
"OFModuleDriver:Main:Rank #" << rank
127 <<
", Default communicator for COM is now "
131 test_comm = COM_get_default_communicator();
132 if (test_comm != newComm)
133 std::cout <<
"OFModuleDriver:Main:Rank #"
135 <<
", default communicator is not set to "
142 COM_LOAD_MODULE_STATIC_DYNAMIC( OpenFoamFSIPar,
"OFModule");
145 COM_LOAD_MODULE_STATIC_DYNAMIC( SimOUT,
"OUT");
150 COM_get_array(
"OFModule.nproc", 0, &nProcReg);
151 std::cout <<
"The communicator registered in OFModule uses "
152 << *nProcReg <<
" prcesses" << std::endl;
161 int init_handle = COM_get_function_handle(
"OFModule.InitFoam");
162 if(init_handle <= 0) {
163 std::cout <<
"OFModuleDriver:Main:Rank #" << rank
164 <<
", could not get handle for init function." << std::endl;
177 myArgv[1] =
const_cast<char *
>(
"-parallel");
184 COM_call_function(init_handle, &myArgc, &myArgv, &verb);
192 COM_get_dataitems(
"OFModule", &numDataItems, output);
193 std::istringstream Istr(output);
194 std::vector<std::string> dataItemNames;
196 for (
int i=0; i<numDataItems; ++i) {
199 dataItemNames.push_back(name);
200 std::cout <<
"Rank #" << rank
201 <<
", OFModuleDriver:main: DataItem # " << i <<
": " << name << std::endl;
210 COM_get_panes(
"OFModule", &nPane, &paneList, paneRank);
211 std::cout <<
"Rank #" << rank <<
", I see "<<nPane<<
" pane in the process rank #"
212 << paneRank << std::endl;
213 std::cout <<
"Here is the list:" << std::endl;
214 for (
int i=0; i<nPane; ++i)
215 std::cout <<
"Pane ID # " << i+1 <<
"=" << paneList[i] << std::endl;
221 COM_get_panes(
"OFModule", &numPanes, &paneList);
222 std::cout <<
"Rank #" << rank
223 <<
", OFModuleDriver:main: Number of Panes " << numPanes << std::endl;
224 for (
int i=0; i<numPanes; ++i)
225 std::cout <<
"Rank #" << rank
226 <<
", OFModuleDriver:main: Pane ID # " << i+1 <<
"=" << paneList[i] << std::endl;
228 int pane = paneList[0];
232 COM_get_array(
"OFModule.nc", pane, &Coord);
235 COM_get_size(
"OFModule.nc", pane, &numNodes);
239 std::string stringNames;
240 COM_get_connectivities(
"OFModule", pane, &numConn, stringNames);
241 std::istringstream ConnISS(stringNames);
242 std::vector<std::string> connNames;
243 for (
int i=0; i<numConn; ++i) {
246 connNames.push_back(name);
247 std::cout <<
"Rank #" << rank
248 <<
", OFModuleDriver:main: Connectivity Table # " << i+1 <<
": " << name << std::endl;
252 COM_Type getDataItemType;
254 std::string getDataItemUnits;
255 std::string fullConnName(
"OFModule."+connNames[0]);
256 COM_get_dataitem(fullConnName, &getDataItemLoc, &getDataItemType,
257 &numElementNodes, &getDataItemUnits);
258 std::cout <<
"Rank #" << rank
259 <<
", OFModuleDriver:main: getDataItemLoc " << getDataItemLoc << std::endl;
260 std::cout <<
"Rank #" << rank
261 <<
", OFModuleDriver:main: getDataItemType " << getDataItemType << std::endl;
262 std::cout <<
"Rank #" << rank
263 <<
", OFModuleDriver:main: numElementNodes " << numElementNodes << std::endl;
264 std::cout <<
"Rank #" << rank
265 <<
", OFModuleDriver:main: getDataItemUnits " << getDataItemUnits << std::endl;
270 COM_get_array(fullConnName.c_str(), pane, &Conn);
271 COM_get_size(fullConnName, pane, &numElem);
274 std::vector<unsigned int> connVector;
275 for (
int i=0; i<numElem; ++i) {
276 for (
int j=0; j<numElementNodes; ++j) {
277 connVector.push_back((Conn[i*numElementNodes+j]));
283 std::string name(
"OFModule.time");
284 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
285 &arrayLength, &getDataItemUnits);
287 COM_get_array(name.c_str(), pane, &time);
288 name =
"OFModule.endTime";
289 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
290 &arrayLength, &getDataItemUnits);
292 COM_get_array(name.c_str(), pane, &endTime);
296 SolverUtils::FEM::SolverAgent myAgent;
300 myAgent.Solution().Meta().AddField(
"time",
's', 1, 8,
"s");
301 myAgent.Solution().Meta().AddField(
"endTime",
's', 1, 8,
"s");
307 myAgent.Mesh().nc.init(numNodes, Coord);
309 myAgent.Mesh().con.AddElements(numElem, numElementNodes, connVector);
312 name =
"OFModule.pressure";
313 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
314 &arrayLength, &getDataItemUnits);
315 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: Pressure Get DataItem" << std::endl;
316 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
317 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
318 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: arrayLength: " << arrayLength << std::endl;
319 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
322 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
325 std::cout <<
"OFModuleDriver:main: Unknown Data Item Location" << std::endl;
329 if (getDataItemType == COM_DOUBLE) {
332 std::cout <<
"OFModuleDriver:main: Unknown Data Item Type" << std::endl;
335 myAgent.Solution().Meta().AddField(
"surfacePressure", myDataItemLoc, arrayLength,
336 myDataItemType, getDataItemUnits);
337 double* surfacePressure;
338 COM_get_array(name.c_str(), pane, &surfacePressure);
341 name =
"OFModule.traction";
342 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
343 &arrayLength, &getDataItemUnits);
344 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: Traction Get DataItem" << std::endl;
345 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
346 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
347 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: arrayLength: " << arrayLength << std::endl;
348 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
350 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
353 std::cout <<
"OFModuleDriver:main: Unknown Data Item Location" << std::endl;
356 if (getDataItemType == COM_DOUBLE) {
359 std::cout <<
"OFModuleDriver:main: Unknown Data Item Type" << std::endl;
362 myAgent.Solution().Meta().AddField(
"surfaceTraction", myDataItemLoc, arrayLength,
363 myDataItemType, getDataItemUnits);
364 double* surfaceTraction;
365 COM_get_array(name.c_str(), pane, &surfaceTraction);
368 name =
"OFModule.solidDisplacement";
369 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
370 &arrayLength, &getDataItemUnits);
371 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: Solid Displacement Get DataItem" << std::endl;
372 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
373 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
374 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: arrayLength: " << arrayLength << std::endl;
375 std::cout <<
"Rank #" << rank <<
" ,OFModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
377 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
379 }
else if (getDataItemLoc ==
'n' || getDataItemLoc ==
'N') {
382 std::cout <<
"OFModuleDriver:main: Unknown Data Item Location" << std::endl;
385 if (getDataItemType == COM_DOUBLE) {
388 std::cout <<
"OFModuleDriver:main: Unknown Data Item Type" << std::endl;
391 myAgent.Solution().Meta().AddField(
"solidDisplacement", myDataItemLoc, arrayLength,
392 myDataItemType, getDataItemUnits);
393 double* solidDisplacement;
394 COM_get_array(
"OFModule.solidDisplacement", pane, &solidDisplacement);
397 myAgent.CreateSoln();
398 unsigned int nnodes = myAgent.Mesh().nc.NNodes();
399 unsigned int nelem = myAgent.Mesh().con.Nelem();
401 myAgent.Solution().SetFieldBuffer(
"time", time);
402 myAgent.Solution().SetFieldBuffer(
"endTime", endTime);
403 myAgent.Solution().SetFieldBuffer(
"surfacePressure", surfacePressure);
404 myAgent.Solution().SetFieldBuffer(
"surfaceTraction", surfaceTraction);
405 myAgent.Solution().SetFieldBuffer(
"solidDisplacement", solidDisplacement);
414 std::string filename;
415 filename =
"fsi_" + ss.str() +
".vtk";
416 Ouf.open(filename.c_str());
418 std::cerr <<
"OFModuleDriver:main: OFModuleDriver::DumpSolution:Error: Could not open output file, "
419 << filename <<
"." << std::endl;
422 std::cout <<
"Rank #" << rank <<
", OFModuleDriver:main: WriteVTKToStream time " << time[0] << std::endl;
423 SolverUtils::WriteVTKToStream(
"OFModule", myAgent, Ouf);
435 std::cout <<
"Rank #"<<rank<<
"...Reaching to barrier"<<std::endl;
436 communicator.Barrier();
439 std::vector<double> surfPresVec;
440 std::vector<double> surfPresTotVec;
441 std::vector<int> nSendAllVec;
443 for (
int iElem=0; iElem<numElem; ++iElem)
444 surfPresVec.push_back(surfacePressure[iElem]);
445 std::cout <<
"Rank #"<<rank<<
", surfPresVec size = "<<surfPresVec.size()<<std::endl;
446 gatherErr = communicator.Gatherv(surfPresVec, surfPresTotVec, nSendAllVec);
448 std::cout <<
"Error in gathering information from processes." << std::endl;
449 std::cout <<
"Rank #" << rank
450 <<
", size of surfPresTotVec = " << surfPresTotVec.size()
454 std::cout <<
"Rank #"<<rank<<
"...Reaching to barrier"<<std::endl;
455 communicator.Barrier();
459 std::vector<int> numNodesVec;
460 std::vector<int> numNodesTotVec;
461 std::vector<int> nNodesAllVec;
462 numNodesVec.push_back(numNodes);
464 gatherErr = communicator.Gatherv(numNodesVec, numNodesTotVec, nNodesAllVec);
466 std::cout <<
"Error in gathering information from processes." << std::endl;
468 for (
int iProc=0; iProc<numNodesTotVec.size(); iProc++)
469 std::cout <<
"Rank #"<<rank
470 <<
", numNodesTotVec["<<iProc<<
"] = "<<numNodesTotVec[iProc]<<std::endl;
472 std::vector<double> surfDispVec;
473 std::vector<double> surfDispVecTot;
474 std::vector<int> nRecvAllVec;
478 for (
int iProc=0; iProc<numNodesTotVec.size(); iProc++){
479 numNodesTot+= numNodesTotVec[iProc];
480 nRecvAllVec.push_back(3*numNodesTotVec[iProc]);
482 surfDispVecTot.resize(3*numNodesTot, -0.1);
483 std::cout<<
"Rank #"<<rank<<
", numNodesTot = "<<numNodesTot<<std::endl;
484 std::cout<<
"Rank #"<<rank<<
", surfDispVecTot = "<<surfDispVecTot.size()<<std::endl;
486 scatterErr = communicator.Scatterv(surfDispVecTot, nRecvAllVec, surfDispVec);
488 std::cout <<
"Error in scattering information to processes." << std::endl;
489 std::cout <<
"Rank #" << rank
490 <<
", size surfDispVec = " << surfDispVec.size()
491 <<
", first element of which = " << surfDispVec[0]
497 int run_handle = COM_get_function_handle(
"OFModule.RunFoam");
498 if(run_handle <= 0) {
499 std::cout <<
"OFModuleDriver:main: Could not get handle for run function." << std::endl;
506 step_handle = COM_get_function_handle(
"OFModule.StepFoam");
507 std::cout <<
"OFModuleDriver:main: StepFoam will be running shortly." << std::endl;
508 if(step_handle <= 0) {
509 std::cout <<
"OFModuleDriver:main: Could not get handle for step function." << std::endl;
512 }
else if (prescribedDisplacement) {
513 step_handle = COM_get_function_handle(
"OFModule.StepFluid");
514 std::cout <<
"OFModuleDriver:main: StepFluid will be running shortly." << std::endl;
515 if(step_handle <= 0) {
516 std::cout <<
"OFModuleDriver:main: Could not get handle for step fluid alone function." << std::endl;
522 std::cout <<
"Rank #" << rank
523 <<
", OFModuleDriver:main: In Driver:" <<
" time=" << time[0]
524 <<
" endTime=" << endTime[0] << std::endl;
526 while(time[0] <= endTime[0]) {
529 if (prescribedDisplacement) {
532 double alpha = 3.141592/(2.0*(xmax-xmin));
533 double beta = 2*3.141592/endTime[0];
534 for(
int i = 0;i < numNodes;i++){
535 double xpos = Coord[i*3] - xmin;
538 solidDisplacement[i*3] = solidDisplacement[i*3+2] = 0.0;
539 solidDisplacement[i*3+1] = 0.001*std::sin(xpos)*std::sin(beta*time[0]);
543 COM_call_function(step_handle);
551 std::string filename;
552 filename =
"fsi_" + ss.str() +
".vtk";
553 Ouf.open(filename.c_str());
555 std::cerr <<
"OFModuleDriver::DumpSolution:Error: Could not open output file, "
556 << filename <<
"." << std::endl;
559 std::cout <<
"Rank #" << rank
560 <<
", OFModuleDriver:main: WriteVTKToStream time "
561 << time[0] << std::endl;
562 SolverUtils::WriteVTKToStream(
"OFModule", myAgent, Ouf);
571 communicator.Barrier();
585 int OUT_set = COM_get_function_handle(
"OUT.set_option");
586 int OUT_write = COM_get_function_handle(
"OUT.write_dataitem");
587 int OUT_write_ctrl = COM_get_function_handle(
"OUT.write_rocin_control_file");
588 const char *win_out=
"OFModule";
589 std::string win_out_pre( win_out);
590 win_out_pre.append(
".");
591 int OUT_all = COM_get_dataitem_handle((win_out_pre+
"all").c_str());
597 std::string fname, ctrl_fname;
598 fileOut =
"OFModule_window" + ss.str();
599 fname = (std::string)win_out +
"_0_";
600 ctrl_fname = (std::string)win_out +
"_in_0.txt";
601 COM_call_function( OUT_set,
"format",
"HDF4");
602 COM_call_function( OUT_write, (fileOut +
".hdf").c_str(), &OUT_all, win_out,
604 COM_call_function( OUT_write_ctrl, win_out, fileOut.c_str(), ctrl_fname.c_str());
610 COM_UNLOAD_MODULE_STATIC_DYNAMIC( SimOUT,
"OUT");
612 COM_UNLOAD_MODULE_STATIC_DYNAMIC(OpenFoamFSIPar,
"OFModule");
616 communicator.Finalize();
IRAD::Comm::CommunicatorObject CommType