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
OpenFoamAgent.H
Go to the documentation of this file.
1 #ifndef __OPEN_FOAM_AGENT_H__
2 #define __OPEN_FOAM_AGENT_H__
3 
4 #include "Orchestrator.H"
5 #include "InterfaceLayer.H"
6 
7 class openfoamagent : 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 argc_dupe = 1;
29  char *argv[2];
30  argv[0] = const_cast<char *>("test");
31  argv[1] = NULL;
32  int verbIn = verblevel;
33  COM_call_function(componentFunctionHandles[INIT],&argc_dupe,argv,&verbIn);
34 
35  std::vector<int> paneIDs;
36  COM_get_panes(interfaceName.c_str(),paneIDs);
37  if(!paneIDs.empty())
38  paneID = paneIDs[0];
39 
40  double *nodalCoordinates;
41  int stride = 0;
42  int cap = 0;
43  std::string coordinateName(interfaceName+".nc");
44  COM_get_array(coordinateName.c_str(),paneID,&nodalCoordinates,&stride,&cap);
45  int arraySize = (stride*cap);
46  nodeCoordinates.resize(arraySize);
47  for(int i = 0;i < arraySize;i++)
48  nodeCoordinates[i] = nodalCoordinates[i];
49 
50 
51  std::string newDataItem(interfaceName+".coords");
52  COM_new_dataitem(newDataItem.c_str(),'n',COM_DOUBLE,3,"m");
53  COM_set_array(newDataItem.c_str(),paneID,&nodeCoordinates[0]);
54 
55  COM_window_init_done(interfaceName);
56 
57  if(SolverUtils::PopulateSolverAgentFromWindow(interfaceName,*this))
58  return(1);
59 
60  WriteOut("OpenFOAM Initialization done!\n");
61  return(0);
62  };
63  const std::vector<double> &Coordinates() const {return(nodeCoordinates);};
64  int PaneID(){return(paneID);};
65  virtual int Run(double endTime){
66  COM_call_function(componentFunctionHandles[RUN]);
67  return(0);
68  };
69 
70  std::vector<double> virtual returnNodeCoords(){
71  return nodeCoordinates;
72  };
73 
74  std::vector<double> virtual returnFaceCoords(){
75  return faceCoordinates;
76  };
77 
78 private:
79  int paneID;
80  std::vector<double> nodeCoordinates;
81  std::vector<double> faceCoordinates;
82 };
83 
84 #endif
std::vector< double > nodeCoordinates
Definition: OpenFoamAgent.H:80
virtual std::vector< double > returnNodeCoords()
Definition: OpenFoamAgent.H:70
std::vector< int > componentFunctionHandles
Definition: Orchestrator.H:13
virtual int Run(double endTime)
Definition: OpenFoamAgent.H:65
std::vector< double > faceCoordinates
Definition: OpenFoamAgent.H:81
std::vector< std::string > componentInterfaceNames
Definition: Orchestrator.H:11
virtual std::vector< double > returnFaceCoords()
Definition: OpenFoamAgent.H:74
const std::vector< double > & Coordinates() const
Definition: OpenFoamAgent.H:63
virtual void WriteErr(const std::string &output)
Definition: Orchestrator.H:32
virtual int Initialize(const std::string interfaceName, int verblevel=1)
Definition: OpenFoamAgent.H:9
virtual void WriteOut(const std::string &output)
Definition: Orchestrator.H:28