9 #ifndef __FSI_COUPLING_PAR_H__
10 #define __FSI_COUPLING_PAR_H__
13 #include "InterfaceLayer.H"
27 typedef IRAD::Global::ParallelGlobalObj<CommTypeIrad,StackType,int,ProfilerType>
PGlobalType;
67 SetName(
"fsicouplingpar");
74 void SetProbe(
int inProbProcId,
int inProbNdeId, std::string inProbSlvName) {
75 if (inProbProcId!=-1) {
86 transferAgent->Interpolate(
"Displacements",
"solidDisplacement");
103 std::stringstream outString;
104 double *fluidCoordinates = NULL;
105 double *solidCoordinates = NULL;
108 COM_get_array(fluidsCoordinateName.c_str(),
fluidsAgent->
PaneID(),&fluidCoordinates);
112 if(!fluidCoordinates || !solidCoordinates){
113 outString <<
"FSICoupling::TestTransfer:Error: Failed to get coordinate arrays. Exiting."
115 StdOut(outString.str(),0,
true);
120 double tolerance = 1e-12;
124 outString <<
"BEFORE TRANSFER: " << std::endl;
125 for(
int i = 0; i < numberFluidNodes;i++){
126 outString <<
"F(" << fluidCoordArray[i*3] <<
"," << fluidCoordArray[i*3+1] <<
","
127 << fluidCoordArray[i*3+2] <<
")" << std::endl;
129 for(
int i = 0; i < numberSolidNodes;i++){
130 outString <<
"S(" << structCoordArray[i*3] <<
"," << structCoordArray[i*3+1] <<
","
131 << structCoordArray[i*3+2] <<
")" << std::endl;
133 StdOut(outString.str(),3,
true);
138 outString <<
"FLUIDS AFTER TRANSFER: " << std::endl;
139 for(
int i = 0; i < numberFluidNodes;i++){
140 double diff1 = std::abs(fluidCoordinates[i*3] - fluidCoordArray[i*3]);
141 double diff2 = std::abs(fluidCoordinates[i*3+1] - fluidCoordArray[i*3+1]);
142 double diff3 = std::abs(fluidCoordinates[i*3+2] - fluidCoordArray[i*3+2]);
143 double diff = std::sqrt(diff1*diff1 + diff2*diff2 + diff3*diff3);
144 if(diff > maxdiff) maxdiff = diff;
145 if(diff > tolerance){
146 outString <<
"FSICoupling::TestTransfer: Coordinate transfer tolerance exceeded for node " << i+1
147 <<
" (" << diff <<
")" << std::endl
148 <<
"(" << fluidCoordinates[i*3] <<
"," << fluidCoordinates[i*3+1] <<
"," << fluidCoordinates[i*3+2]
149 <<
") : (" << fluidCoordArray[i*3] <<
"," << fluidCoordArray[i*3+1] <<
"," << fluidCoordArray[i*3+2]
153 outString <<
"FSICoupling::TestTransfer: Maximum transferred (s->f) coordinate difference: " << maxdiff << std::endl;
154 StdOut(outString.str(),3,
true);
161 std::stringstream outString;
162 if(inMode ==
"Fluid" ||
165 }
else if(inMode ==
"Structure" ||
166 inMode ==
"structure" ||
180 int WriteAgentToVTK(
const std::string &nameRoot,SolverUtils::FEM::SolverAgent &solverAgent)
182 std::stringstream outString;
184 std::ostringstream timeString;
186 std::string fileName(nameRoot+
"_"+timeString.str()+
".vtk");
187 outStream.open(fileName.c_str());
189 outString <<
"FSICoupling::DumpSolution:Error: Could not open output file, "
190 << fileName <<
"." << std::endl;
191 StdOut(outString.str(),0,
true);
196 SolverUtils::WriteVTKToStream(nameRoot, solverAgent, outStream);
202 std::stringstream outString;
203 outString <<
"FSICoupling: Dumping solutions." << std::endl;
204 StdOut(outString.str(),2,
true);
219 outString <<
"FSICoupling: Done with solution dump." << std::endl;
220 StdOut(outString.str(),2,
true);
226 void virtual writeWin(
const char* winName, std::string timeMark, std::string& wFnameHdf)
229 int OUT_write = COM_get_function_handle( (
simoutInterfaceName +
".write_dataitem").c_str());
230 int OUT_write_ctrl = COM_get_function_handle( (
simoutInterfaceName +
".write_rocin_control_file").c_str());
232 std::string win_out_pre( winName);
233 win_out_pre.append(
".");
234 int OUT_all = COM_get_dataitem_handle((win_out_pre+
"all").c_str());
237 std::stringstream ss;
243 std::string hdf_fname, ctrl_fname;
244 hdf_fname = (std::string)winName +
"_window" + ss.str();
245 ctrl_fname = (std::string)winName +
"_time_" + timeMark +
".txt";
247 COM_call_function( OUT_set,
"format",
"HDF4");
248 COM_call_function( OUT_write, (hdf_fname +
".hdf").c_str(), &OUT_all, winName,
"0000");
249 COM_call_function( OUT_write_ctrl, winName, hdf_fname.c_str(), ctrl_fname.c_str());
251 wFnameHdf = (std::string)winName +
"_window_proc_*.hdf";
254 virtual int Initialize(std::vector<std::string> &componentInterfaceNames,
255 double finalTime,
double timeStep){
257 FunctionEntry(
"Initialize");
258 std::stringstream outString;
259 outString <<
"Final Time = " << finalTime << std::endl;
260 outString <<
"Time Step = " << timeStep << std::endl;
261 StdOut(outString.str(),0,
true);
265 if(componentInterfaceNames.size() < 2)
283 Communicator().Barrier();
285 Communicator().Barrier();
292 Communicator().Barrier();
318 COM_set_array(newDataItemName.c_str(),0,&
probProcId);
320 COM_set_array(newDataItemName.c_str(),0,&
probNdeId);
334 FunctionExit(
"Initialize");
341 FunctionEntry(
"Run");
344 int maxSubSteps = 1000;
345 int dumpinterval = 1;
349 time_t nowStart = time(0);
350 char* dtChar = ctime(&nowStart);
352 gethostname(hostName, 150);
354 std::stringstream outString;
355 outString << std::endl << std::endl
356 <<
"************************************************* " << std::endl;
357 outString <<
"* Starting Stepping in Time * " << std::endl;
358 outString <<
"************************************************* " << std::endl;
359 outString <<
"* Starting Simulation at " << dtChar;
360 outString <<
"* Summary of the simulation: " << std::endl;
361 outString <<
"* " << std::endl;
362 outString <<
"* Simulation Type = ElmerFoamFSIPar " << std::endl;
363 outString <<
"* Simulation start time = " <<
simulationTime << std::endl;
367 outString <<
"* " <<std::endl;
368 outString <<
"* Hostname = " << hostName << std::endl;
369 outString <<
"* Number of processors = " << NProc() << std::endl;
370 outString <<
"************************************************* " << std::endl;
371 outString << std::endl;
372 StdOut(outString.str(),0,
true);
378 outString <<
"System timestep " << ++systemStep
380 StdOut(outString.str(),1,
true);
387 outString <<
"Transferring displacements from structures to fluids @ time("
389 StdOut(outString.str(),1,
true);
398 outString <<
"Stepping fluids to time("
400 StdOut(outString.str(),1,
true);
407 outString <<
"Transferring loads from fluids to structures @ time("
409 StdOut(outString.str(),1,
true);
419 outString <<
"Stepping structures to time("
421 StdOut(outString.str(),1,
true);
428 bool converged =
true;
431 outString <<
"Converged at time("
433 StdOut(outString.str(),1,
true);
443 if(innerCount > maxSubSteps){
444 outString <<
"Failed to converge after "
445 << maxSubSteps <<
", giving up." << std::endl;
446 StdOut(outString.str(),0,
true);
453 StdOut(outString.str(),0,
true);
457 if(!(systemStep%dumpinterval)){
462 Communicator().Barrier();
465 time_t nowEnd = time(0);
466 dtChar = ctime(&nowEnd);
467 outString << std::endl << std::endl
468 <<
"************************************************* " << std::endl;
469 outString <<
"* Finishing Stepping in Time * " << std::endl;
470 outString <<
"************************************************* " << std::endl;
471 outString <<
"* Ending simulation at " << dtChar;
472 outString <<
"* Total simulation time (s) = " << nowEnd - nowStart << std::endl;
473 outString <<
"* Summary of the simulation: " << std::endl;
474 outString <<
"* " << std::endl;
475 outString <<
"* Simulation Type = ElmerFoamFSIPar " << std::endl;
479 outString <<
"* " <<std::endl;
480 outString <<
"* Hostname = " << hostName << std::endl;
481 outString <<
"* Number of processors = " << NProc() << std::endl;
482 outString <<
"************************************************* " << std::endl;
483 outString << std::endl;
484 StdOut(outString.str(),0,
true);
505 std::vector<std::string> varVector;
std::string fluidsWinFnameHDF
const std::vector< double > & Coordinates() const
std::string getFluidIntName()
void WriteHDF(bool toggle)
transferagentpar * transferAgent
double simulationTimeStep
solidagentpar * structuresAgent
fluidagentpar * getFluidAgent()
std::string fluidsInterfaceName
virtual int Initialize(const std::string interfaceName, int verblevel=1)
std::string siminInterfaceName
int TransferDisplacementsToFluid(solidagentpar *solidAgent, fluidagentpar *fluidAgent)
virtual int Initialize(const std::string &interfaceName, int verblevel=1)
std::string structuresInterfaceName
double getSimulationTimeStep()
SolverUtils::TransferObjectPar transferagentpar
virtual int FinalizeTimeStep(double time)
std::vector< impact::orchestrator::agentbase * > componentAgents
fsicouplingpar(PGlobalType &globin)
virtual void writeWin(const char *winName, std::string timeMark, std::string &wFnameHdf)
double getSimulationFinalTime()
std::vector< std::string > getVariable()
Helper functions for accessing protected data members.
int TransferLoadsToStructures(fluidagentpar *fluidAgent, solidagentpar *solidAgent)
std::string transferInterfaceName
std::string StackType
Convenience type definition for program stack.
openfoamagentpar fluidagentpar
int WriteAgentToVTK(const std::string &nameRoot, SolverUtils::FEM::SolverAgent &solverAgent)
void SetVerbLevel(int verb)
double getSimulationTime()
elmeragentpar solidagentpar
virtual int Initialize(std::vector< std::string > &componentInterfaceNames, double finalTime, double timeStep)
virtual int Run(double endTime)
virtual int DumpSolution()
virtual int InitializeTimeStep(double time)
std::string simpalInterfaceName
virtual int Run(double time)
void SetProbe(int inProbProcId, int inProbNdeId, std::string inProbSlvName)
void SetRunMode(const std::string &inMode)
IRAD::Profiler::ProfilerObj ProfilerType
Encapsulate example program-specific code constructs.
const std::vector< double > & Coordinates() const
void WriteVTK(bool toggle)
fluidagentpar * fluidsAgent
std::string probSolverName
IRAD::Global::ParallelGlobalObj< CommTypeIrad, StackType, int, ProfilerType > PGlobalType
std::string getSolidIntName()
solidagentpar * getStructureAgent()
std::string simoutInterfaceName
std::string surfUtilInterfaceName
double simulationFinalTime
IRAD::Comm::CommunicatorObject CommTypeIrad
std::string structuresWinFnameHDF