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
ElmerAgent.H
Go to the documentation of this file.
1 #ifndef __ELMER_AGENT_H__
2 #define __ELMER_AGENT_H__
3 
4 
5 #include "Orchestrator.H"
6 
7 class elmeragent : public impact::orchestrator::agentbase, public SolverUtils::FEM::SolverAgent {
8 
9 public:
10  virtual int Initialize(const std::string &interfaceName, int verblevel=1){
11  int structuresInitHandle = COM_get_function_handle(std::string(interfaceName+".Initialize").c_str());
12  if(structuresInitHandle < 0){
13  WriteErr("Failed to get Elmer initialization handle.\n");
14  return(1);
15  }
16  componentFunctionHandles[INIT] = structuresInitHandle;
17 
18  int structuresRunHandle = COM_get_function_handle(std::string(interfaceName+".Run").c_str());
19  if(structuresRunHandle < 0){
20  WriteErr("Failed to get Elmer run handle.\n");
21  return(1);
22  }
23  componentFunctionHandles[RUN] = structuresRunHandle;
24 
25  int structuresFinalizeHandle = COM_get_function_handle(std::string(interfaceName+".Finalize").c_str());
26  if(structuresFinalizeHandle < 0){
27  WriteErr("Failed to get structures finalize handle.\n");
28  return(1);
29  }
30  componentFunctionHandles[FINALIZE] = structuresFinalizeHandle;
31 
32  int runs = 0;
33  int verbIn = verblevel;
34  COM_call_function(componentFunctionHandles[INIT],&runs, &verbIn);
35  if(!runs){
36  WriteErr("Elmer failed to initialize!\n");
37  return(1);
38  }
39 
40  std::vector<int> paneIDs;
41  COM_get_panes(interfaceName.c_str(),paneIDs);
42  if(!paneIDs.empty())
43  paneID = paneIDs[0];
44 
45  double *nodalCoordinates;
46  int stride = 0;
47  int cap = 0;
48  std::string coordinateName(interfaceName+".nc");
49  COM_get_array(coordinateName.c_str(),paneID,&nodalCoordinates,&stride,&cap);
50  int arraySize = (stride*cap);
51  std::cout << "Stride = " << stride << " Cap = " << cap << std::endl;
52  nodeCoordinates.resize(arraySize);
53  for(int i = 0;i < arraySize;i++)
54  nodeCoordinates[i] = nodalCoordinates[i];
55 
56 
57  std::string newDataItem(interfaceName+".coords");
58  COM_new_dataitem(newDataItem.c_str(),'n',COM_DOUBLE,3,"m");
59  COM_set_array(newDataItem.c_str(),paneID,&nodeCoordinates[0]);
60 
61  COM_window_init_done(interfaceName);
62 
63  if(SolverUtils::PopulateSolverAgentFromWindow(interfaceName,*this))
64  return(1);
65 
66 
67 
68  WriteOut("Elmer Initialization done!\n");
69  return(0);
70  };
71  int virtual Run(double time){
72  int runs = 0;
73  COM_call_function(componentFunctionHandles[RUN],&runs,&time);
74  if(!runs){
75  WriteErr("Elmer failed to run!\n");
76  return(1);
77  }
78  };
79  const std::vector<double> &Coordinates() const {return(nodeCoordinates);};
80  int PaneID(){return(paneID);};
81  int virtual Finalize(){
82  int runs = 0;
83  WriteOut("Calling Elmer finalize.\n");
84  COM_call_function(componentFunctionHandles[FINALIZE],&runs);
85  WriteOut("Elmer finalize done.\n");
86  if(!runs){
87  WriteErr("Elmer failed to finalize!\n");
88  return(1);
89  }
90  };
91 
92  std::vector<double> virtual returnNodeCoords(){
93  return nodeCoordinates;
94  };
95 
96  std::vector<double> virtual returnFaceCoords(){
97  return faceCoordinates;
98  };
99 
100 private:
101  int paneID;
102  std::vector<double> nodeCoordinates;
103  std::vector<double> faceCoordinates;
104 };
105 
106 #endif
std::vector< int > componentFunctionHandles
Definition: Orchestrator.H:13
std::vector< double > faceCoordinates
Definition: ElmerAgent.H:103
virtual std::vector< double > returnNodeCoords()
Definition: ElmerAgent.H:92
virtual int Initialize(const std::string &interfaceName, int verblevel=1)
Definition: ElmerAgent.H:10
virtual std::vector< double > returnFaceCoords()
Definition: ElmerAgent.H:96
virtual int Finalize()
Definition: ElmerAgent.H:81
int paneID
Definition: ElmerAgent.H:98
int PaneID()
Definition: ElmerAgent.H:80
const std::vector< double > & Coordinates() const
Definition: ElmerAgent.H:79
std::vector< double > nodeCoordinates
Definition: ElmerAgent.H:102
virtual int Run(double time)
Definition: ElmerAgent.H:71
virtual void WriteErr(const std::string &output)
Definition: Orchestrator.H:32
virtual void WriteOut(const std::string &output)
Definition: Orchestrator.H:28