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
OpenFoamParAgent.H
Go to the documentation of this file.
1 #ifndef __OPEN_FOAM_PAR_AGENT_H__
2 #define __OPEN_FOAM_PAR_AGENT_H__
3 
4 #include "Orchestrator.H"
5 #include "InterfaceLayer.H"
6 
7 class openfoamagentpar : public impact::orchestrator::agentbase, public SolverUtils::FEM::SolverAgent {
8 public:
9  virtual int Initialize(const std::string interfaceName, int verblevel = 1){
10  componentInterfaceNames.push_back(interfaceName);
11  componentFunctionHandles[INIT] = COM_get_function_handle(std::string(interfaceName+".InitFoam").c_str());
12  int fluidsInitHandle = componentFunctionHandles[INIT];
13  if(fluidsInitHandle < 0){
14  WriteErr("Failed to get fluids initialization handle.\n");
15  return(1);
16  }
17 
18  int fluidsStepHandle = COM_get_function_handle(std::string(interfaceName+".StepFluid").c_str());
19  if(fluidsStepHandle < 0){
20  WriteErr("Failed to get fluids step handle.\n");
21  return(1);
22  }
23  componentFunctionHandles[RUN] = fluidsStepHandle;
24 
25 
26  WriteOut("Calling OpenFOAM Initialization.\n");
27 
28  int myArgc = 2;
29  char *myArgv[2];
30  myArgv[0] = const_cast<char *>("dummy");
31  myArgv[1] = const_cast<char *>("-parallel");
32  int verbIn = verblevel;
33  COM_call_function(componentFunctionHandles[INIT], &myArgc, &myArgv, &verbIn);
34 
35 
36  std::vector<int> paneIDs;
37  COM_get_panes(interfaceName.c_str(),paneIDs);
38  if(!paneIDs.empty())
39  paneID = paneIDs[0];
40 
41  double *nodalCoordinates;
42  int stride = 0;
43  int cap = 0;
44  std::string coordinateName(interfaceName+".nc");
45  std::string newDataItemName;
46  if (!paneIDs.empty()) {
47  COM_get_array(coordinateName.c_str(),paneID,&nodalCoordinates,&stride,&cap);
48  int arraySize = (stride*cap);
49  nodeCoordinates.resize(arraySize);
50  for(int i = 0;i < arraySize;i++)
51  nodeCoordinates[i] = nodalCoordinates[i];
52  newDataItemName = interfaceName+".coords";
53  COM_new_dataitem(newDataItemName.c_str(),'n',COM_DOUBLE,3,"m");
54  COM_set_array(newDataItemName.c_str(),paneID,&nodeCoordinates[0]);
55  }
56 
57  // setting up probe
58  newDataItemName = interfaceName+".setsProb";
59  COM_new_dataitem(newDataItemName.c_str(),'w',COM_INT,1,"");
60  newDataItemName = interfaceName+".probProcId";
61  COM_new_dataitem(newDataItemName.c_str(),'w',COM_INT,1,"");
62  newDataItemName = interfaceName+".probNdeId";
63  COM_new_dataitem(newDataItemName.c_str(),'w',COM_INT,1,"");
64 
65  COM_window_init_done(interfaceName);
66 
67  if (!paneIDs.empty()) {
68  if(SolverUtils::PopulateSolverAgentFromWindow(interfaceName,*this))
69  return(1);
70  }
71  WriteOut("OpenFOAM Initialization done!\n");
72  return(0);
73  };
74 
75  const std::vector<double> &Coordinates() const {return(nodeCoordinates);};
76  int PaneID(){return(paneID);};
77  virtual int Run(double endTime){
78  COM_call_function(componentFunctionHandles[RUN]);
79  return(0);
80  };
81 
82  std::vector<double> virtual returnNodeCoords(){
83  return nodeCoordinates;
84  };
85 
86  std::vector<double> virtual returnFaceCoords(){
87  return faceCoordinates;
88  };
89 
90 private:
91  int paneID;
92  std::vector<double> nodeCoordinates;
93  std::vector<double> faceCoordinates;
94 };
95 
96 #endif
std::vector< int > componentFunctionHandles
Definition: Orchestrator.H:13
virtual int Initialize(const std::string interfaceName, int verblevel=1)
std::vector< double > nodeCoordinates
virtual std::vector< double > returnFaceCoords()
virtual int Run(double endTime)
std::vector< std::string > componentInterfaceNames
Definition: Orchestrator.H:11
std::vector< double > faceCoordinates
const std::vector< double > & Coordinates() const
virtual std::vector< double > returnNodeCoords()
virtual void WriteErr(const std::string &output)
Definition: Orchestrator.H:32
virtual void WriteOut(const std::string &output)
Definition: Orchestrator.H:28