10 #include "com_devel.hpp"
16 #include "primitive_utilities.H"
17 #include "SolverAgent.H"
18 #include "InterfaceLayer.H"
30 typedef IRAD::Comm::CommunicatorObject
CommType;
33 std::cout << std::endl
34 <<
"Usage: " << std::endl << std::endl
35 <<
" " << exec <<
" [-com-mpi] [-fsi] [-loads] time[0] [time[1] ... time[Final]]"
37 <<
" where at least timeFinal is required. Here is the description of switches :"
38 << std::endl << std::endl
39 <<
" -com-mpi:" << std::endl
40 <<
" It is not required to use the -com-mpi flag." << std::endl << std::endl
41 <<
" -fsi :" << std::endl
42 <<
" Should be used for fluid-solid interaction (FSI) problems to register" << std::endl
43 <<
" mesh and solution for each given timestep. A vtk file will be created" << std::endl
44 <<
" for each timestep containing FSI surface mesh and solution values." << std::endl
45 <<
" It is assumed that all processes share FSI boundaries." << std::endl<<std::endl
46 <<
" -loads :" << std::endl
47 <<
" Should be used to change loads during simulaiton" << std::endl<< std::endl
48 <<
" time[i], i>0:" << std::endl
49 <<
" At least one timestep should be given. For steady state problem a timestep" << std::endl
50 <<
" of 1.0 is enough. Values given should increase monotonically." << std::endl;
55 std::cout <<
"SoverModuleDriver: running initializer ... " << std::endl;
60 for(
int i=1; i < argc; i++){
64 if(
ss.str() ==
"-com-mpi")
66 if(
ss.str() ==
"-fsi"){
70 if(
ss.str() ==
"-loads"){
74 for(
int j=0; j<
ss.str().size(); j++){
75 if(!isdigit(
ss.str()[j]) &&
ss.str()[j] !=
'e'
76 &&
ss.str()[j] !=
'E' &&
ss.str()[j] !=
'-'
77 &&
ss.str()[j] !=
'.')
81 tNext.push_back(tmpTime);
87 for(
int i=1; i <
tNext.size(); i++){
95 COM_LOAD_MODULE_STATIC_DYNAMIC(ElmerCSCParallel,
"ELMModule");
98 COM_LOAD_MODULE_STATIC_DYNAMIC( SimOUT,
"OUT");
102 outfile <<
"Checking ELMModule" << std::endl;
103 outfile <<
"comm_check = " << comm_check << std::endl;
104 COM_get_communicator(
"ELMModule", &comm_check);
105 if(comm_check ==
Comm)
106 outfile <<
"comm_check == Comm!" << std::endl;
107 else if(comm_check == MPI_COMM_WORLD)
108 outfile <<
"comm_check == MPI_COMM_WORLD!" << std::endl;
109 else if(comm_check == MPI_COMM_SELF)
110 outfile <<
"comm_check == MPI_COMM_SELF!" << std::endl;
112 outfile <<
"comm_check == None!" << std::endl;
117 int init_handle = COM_get_function_handle(
"ELMModule.Initialize");
118 bool init_func = (init_handle > 0);
122 COM_call_function(init_handle, &
runs, &verb);
128 COM_Type getDataItemType;
129 std::string getDataItemUnits;
136 std::string stringNames;
137 COM_get_connectivities(
"ELMModule",
myPaneId, &
nConn, stringNames);
138 std::istringstream ConnISS(stringNames);
139 std::vector<std::string> connNames;
140 for (
int i=0; i<
nConn; ++i) {
143 connNames.push_back(name);
144 std::cout <<
"Rank #" <<
myRank
145 <<
", ELMModuleDriver:main: Connectivity Table # " << i+1 <<
": " << name << std::endl;
148 std::string fullConnName(
"ELMModule."+connNames[0]);
149 COM_get_dataitem(fullConnName, &getDataItemLoc, &getDataItemType,
151 std::cout <<
"Rank #" <<
myRank
152 <<
", ELMModuleDriver:main: getDataItemLoc " << getDataItemLoc << std::endl;
153 std::cout <<
"Rank #" <<
myRank
154 <<
", ELMModuleDriver:main: getDataItemType " << getDataItemType << std::endl;
155 std::cout <<
"Rank #" <<
myRank
156 <<
", ELMModuleDriver:main: nElemNodes " <<
nElemNodes << std::endl;
157 std::cout <<
"Rank #" <<
myRank
158 <<
", ELMModuleDriver:main: getDataItemUnits " << getDataItemUnits << std::endl;
196 int run_handle = COM_get_function_handle(
"ELMModule.Run");
197 bool run_func = (run_handle > 0);
201 for(
int i=0; i <
tNext.size(); i++){
203 std::cout <<
"SoverModuleDriver:run: Calling run function from driver" << std::endl;
204 COM_call_function(run_handle,&
runs,&
tNext[i]);
219 COM_Type getDataItemType;
220 std::string getDataItemUnits;
224 name =
"ELMModule.Displacements";
225 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
226 &
nDisp, &getDataItemUnits);
227 std::cout <<
"Rank #" <<
myRank
228 <<
", ELMModuleDriver:main: Displacement Get DataItem"
230 std::cout <<
"Rank #" <<
myRank
231 <<
", ELMModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
232 std::cout <<
"Rank #" <<
myRank
233 <<
", ELMModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
234 std::cout <<
"Rank #" <<
myRank
235 <<
", ELMModuleDriver:main: arrayLength: " <<
nDisp << std::endl;
236 std::cout <<
"Rank #" <<
myRank
237 <<
", ELMModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
240 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
242 }
else if (getDataItemLoc ==
'n' || getDataItemLoc ==
'N') {
245 std::cout <<
"ELMModuleDriver:main: Unknown Data Item Location" << std::endl;
248 if (getDataItemType == COM_DOUBLE_PRECISION) {
251 std::cout <<
"ELMModuleDriver:main: Unknown Data Item Type" << std::endl;
255 COM_get_array(
"ELMModule.Displacements",
myPaneId, &
Disp);
257 name =
"ELMModule.Loads";
258 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
259 &
nLoads, &getDataItemUnits);
260 std::cout <<
"Rank #" <<
myRank
261 <<
", ELMModuleDriver:main: Load Get DataItem"
263 std::cout <<
"Rank #" <<
myRank
264 <<
", ELMModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
265 std::cout <<
"Rank #" <<
myRank
266 <<
", ELMModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
267 std::cout <<
"Rank #" <<
myRank
268 <<
", ELMModuleDriver:main: arrayLength: " <<
nLoads << std::endl;
269 std::cout <<
"Rank #" <<
myRank
270 <<
", ELMModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
272 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
274 }
else if (getDataItemLoc ==
'n' || getDataItemLoc ==
'N') {
277 std::cout <<
"ELMModuleDriver:main: Unknown Data Item Location" << std::endl;
280 if (getDataItemType == COM_DOUBLE_PRECISION) {
283 std::cout <<
"ELMModuleDriver:main: Unknown Data Item Type" << std::endl;
289 name =
"ELMModule.Pressures";
290 COM_get_dataitem(name, &getDataItemLoc, &getDataItemType,
291 &
nPress, &getDataItemUnits);
292 std::cout <<
"Rank #" <<
myRank
293 <<
", ELMModuleDriver:main: Pressures Get DataItem"
295 std::cout <<
"Rank #" <<
myRank
296 <<
", ELMModuleDriver:main: getDataItemLoc: " << getDataItemLoc << std::endl;
297 std::cout <<
"Rank #" <<
myRank
298 <<
", ELMModuleDriver:main: getDataItemType: " << getDataItemType << std::endl;
299 std::cout <<
"Rank #" <<
myRank
300 <<
", ELMModuleDriver:main: arrayLength: " <<
nPress << std::endl;
301 std::cout <<
"Rank #" <<
myRank
302 <<
", ELMModuleDriver:main: getDataItemUnits: " << getDataItemUnits << std::endl;
304 if (getDataItemLoc ==
'e' || getDataItemLoc ==
'E') {
307 std::cout <<
"ELMModuleDriver:main: Unknown Data Item Location" << std::endl;
310 if (getDataItemType == COM_DOUBLE_PRECISION) {
313 std::cout <<
"ELMModuleDriver:main: Unknown Data Item Type" << std::endl;
324 int final_handle = COM_get_function_handle(
"ELMModule.Finalize");
325 bool final_func = (final_handle > 0);
328 COM_call_function(final_handle,&
runs);
331 COM_UNLOAD_MODULE_STATIC_DYNAMIC( ElmerCSCParallel,
"ELMModule");
332 COM_UNLOAD_MODULE_STATIC_DYNAMIC(SimOUT,
"OUT");
342 COM_Type getDataItemType;
343 std::string getDataItemUnits;
348 std::vector<unsigned int> connVector;
349 for (
int i=0; i<
nElem; ++i) {
351 connVector.push_back((
Conn[i*nElemNodes+j]));
355 myAgent.Solution().Meta().AddField(
"time",
's', 1, 8,
"s");
356 myAgent.Solution().Meta().AddField(
"endTime",
's', 1, 8,
"s");
373 unsigned int nnodes =
myAgent.Mesh().nc.NNodes();
374 unsigned int nelem =
myAgent.Mesh().con.Nelem();
376 myAgent.Solution().SetFieldBuffer(
"Displacement",
Disp);
386 std::string filename;
387 filename =
"fsi_" +
ss.str() +
".vtk";
388 Ouf.open(filename.c_str());
390 std::cerr <<
"ELMModuleDriver:main: DumpSolution: Error: Could not open output file, "
391 << filename <<
"." << std::endl;
394 std::cout <<
"Rank #" << myRank
395 <<
", ELMModuleDriver:main: WriteVTKToStream for " << timeMark << std::endl;
396 SolverUtils::WriteVTKToStream(
"ELMModule",
myAgent, Ouf);
405 std::cout <<
"ElmerModuleDriver:Main: Setting up parallel communicator..." << std::endl;
407 MPI_Comm masterComm = communicator.GetCommunicator();
408 int rank = communicator.Rank();
409 int nproc = communicator.Size();
411 std::cout <<
"ElmerModuleDriver:Main:Rank #"
418 COM_init( &argc, &argv);
427 std::cout <<
"Hi, I am a streamer ..." << std::endl;
430 std::string outfile_name;
431 std::stringstream ss;
432 std::string str_rank;
435 outfile_name =
"out" + str_rank +
".dat";
436 driverObject.
outfile.open(outfile_name.c_str());
440 driverObject.
outfile <<
"color = " << color << std::endl;
441 driverObject.
outfile <<
"rank = " << rank << std::endl;
443 communicator.Split(color, rank, newCommunicator);
444 driverObject.
outfile <<
"communicator.Size() = " << communicator.Size() << std::endl;
445 driverObject.
outfile <<
"newCommunicator.Size() = " << newCommunicator.Size() << std::endl;
446 driverObject.
setComm(newCommunicator.GetCommunicator());
448 newComm = newCommunicator.GetCommunicator();
449 COM_set_default_communicator(newComm);
453 driverObject.
init(argc, argv);
458 COM_get_dataitems(
"ELMModule", &numDataItems, output);
459 std::istringstream Istr(output);
460 std::vector<std::string> dataItemNames;
461 for (
int i=0; i<numDataItems; ++i) {
464 dataItemNames.push_back(name);
465 std::cout <<
"Rank #" << rank
466 <<
", ElmerModuleDriver:main: DataItem # " << i <<
": " << name << std::endl;
472 COM_get_panes(
"ELMModule", &numPanes, &paneList);
473 std::cout <<
"Rank #" << rank
474 <<
", ELMModuleDriver:main: Number of Panes " << numPanes << std::endl;
475 for (
int i=0; i<numPanes; ++i)
476 std::cout <<
"Rank #" << rank
477 <<
", ELMModuleDriver:main: Pane ID # " << i+1 <<
"=" << paneList[i] << std::endl;
489 std::vector<int> nLoadsVec;
490 std::vector<int> nLoadsTotVec;
491 std::vector<int> nRecvAllVec;
492 nLoadsVec.push_back(driverObject.
nNodes*driverObject.
nLoads);
493 std::cout <<
"Rank #"<<rank
494 <<
", nLoadsVec["<<rank<<
"] = "<<nLoadsVec[rank]<<std::endl;
495 parErr = newCommunicator.Gatherv(nLoadsVec, nLoadsTotVec, nRecvAllVec);
497 std::cout <<
"Error in gathering information from processes." << std::endl;
499 for (
int iProc=0; iProc<nLoadsTotVec.size(); iProc++)
500 std::cout <<
"Rank #"<<rank
501 <<
", nLoadsTotVec["<<iProc<<
"] = "<<nLoadsTotVec[iProc]<<std::endl;
504 std::vector<double> loadsVec;
505 std::vector<double> loadsTotVec;
508 for (
int iProc=0; iProc < nLoadsTotVec.size(); iProc++){
509 nLoadsTot += nLoadsTotVec[iProc];
511 loadsTotVec.resize(nLoadsTot,0.0);
512 for (
int iLoad=1; iLoad < nLoadsTot; iLoad+=3)
513 loadsTotVec[iLoad] = 1.0;
514 std::cout <<
"Size of loadsTotVec = " << loadsTotVec.size() << std::endl;
517 parErr = newCommunicator.Scatterv(loadsTotVec, nLoadsTotVec, loadsVec);
519 std::cout <<
"Error in scattering information to processes." << std::endl;
520 std::cout <<
"Rank #" << rank
521 <<
", number of load components I received = " << loadsVec.size()
524 for (
int iLoad=0; iLoad<(driverObject.
nLoads*driverObject.
nNodes); ++iLoad){
525 driverObject.
Loads[iLoad] = loadsVec[iLoad];
526 std::cout <<
"Rank #" << rank
527 <<
", driverObject.Loads ["<<iLoad<<
"] = "
528 << driverObject.
Loads[iLoad] << std::endl;
531 std::cout <<
"Rank #"<<rank<<
"...Reaching to barrier"<<std::endl;
532 newCommunicator.Barrier();
537 newCommunicator.Barrier();
542 std::vector<double> dispVec;
543 std::vector<double> dispTotVec;
544 std::vector<int> nSendAllVec;
545 for (
int iDisp=0; iDisp<(driverObject.
nDisp*driverObject.
nNodes); ++iDisp){
546 dispVec.push_back(driverObject.
Disp[iDisp]);
547 std::cout <<
"Rank #" << rank
548 <<
", dispVec ["<<iDisp<<
"] = " << dispVec[iDisp] << std::endl;
550 std::cout <<
"Rank #" << rank
551 <<
", dispVec size = " << dispVec.size() << std::endl;
553 parErr = newCommunicator.Gatherv(dispVec, dispTotVec, nSendAllVec);
555 std::cout <<
"Error in gathering information from processes." << std::endl;
556 std::cout <<
"Rank #" << rank
557 <<
", size of dispTotVec = " << dispTotVec.size()
560 std::cout <<
"Rank #"<<rank<<
"...Reaching to barrier"<<std::endl;
561 newCommunicator.Barrier();
564 double maxDisp = 0.0;
565 double minDisp = 0.0;
566 for (
int iDisp=0; iDisp<dispTotVec.size(); iDisp++){
567 maxDisp = std::max(dispTotVec[iDisp], maxDisp);
568 minDisp = std::min(dispTotVec[iDisp], minDisp);
569 std::cout <<
"Rank #0, dispTotVec [" << iDisp <<
"] = "
570 << dispTotVec[iDisp] << std::endl;
572 outfile_name =
"maxMinDisp.dat";
573 std::ofstream testFile;
574 testFile.open(outfile_name.c_str());
575 testFile << maxDisp << std::endl << minDisp << std::endl;
579 int OUT_set = COM_get_function_handle(
"OUT.set_option");
580 int OUT_write = COM_get_function_handle(
"OUT.write_dataitem");
581 const char *win_out=
"ELMModule";
582 std::string win_out_pre(win_out);
583 win_out_pre.append(
".");
584 int OUT_all = COM_get_dataitem_handle((win_out_pre+
"all").c_str());
590 fileOut =
"ELMModule_window" + ss.str();
591 COM_call_function( OUT_set,
"format",
"HDF4");
592 COM_call_function( OUT_write, (fileOut +
".hdf").c_str(), &OUT_all, win_out,
606 communicator.Finalize();
611 int main(
int argc,
char** argv) {
int parallelProgram(int argc, char *argv[])
IRAD::Comm::CommunicatorObject CommType
void setColor(int colorValue)
int vtkDump(double timeMark)
int init(int argc, char *argv[])
void setComm(MPI_Comm newComm)
std::vector< double > tNext
COM_EXTERN_MODULE(OpenFoamFSI)
void setRank(int rankValue)