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
ElmerParAgent.H
Go to the documentation of this file.
1 #ifndef __ELMER_PAR_AGENT_H__
2 #define __ELMER_PAR_AGENT_H__
3 
4 
5 #include "Orchestrator.H"
6 
7 class elmeragentpar : 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  // extra variables to register
57  std::string newDataItemName(interfaceName+".coords");
58  COM_new_dataitem(newDataItemName.c_str(),'n',COM_DOUBLE,3,"m");
59  COM_set_array(newDataItemName.c_str(),paneID,&nodeCoordinates[0]);
60 
61  // setting up probe
62  newDataItemName = interfaceName+".setsProb";
63  COM_new_dataitem(newDataItemName.c_str(),'w',COM_INT,1,"");
64  newDataItemName = interfaceName+".probProcId";
65  COM_new_dataitem(newDataItemName.c_str(),'w',COM_INT,1,"");
66  newDataItemName = interfaceName+".probNdeId";
67  COM_new_dataitem(newDataItemName.c_str(),'w',COM_INT,1,"");
68 
69  COM_window_init_done(interfaceName);
70 
71 
72  if(SolverUtils::PopulateSolverAgentFromWindow(interfaceName,*this))
73  return(1);
74 
75 
76  WriteOut("Elmer Initialization done!\n");
77  return(0);
78  };
79  int virtual Run(double time){
80  int runs = 0;
81  COM_call_function(componentFunctionHandles[RUN],&runs,&time);
82  if(!runs){
83  WriteErr("Elmer failed to run!\n");
84  return(1);
85  }
86  };
87  const std::vector<double> &Coordinates() const {return(nodeCoordinates);};
88  int PaneID(){return(paneID);};
89  int virtual Finalize(){
90  int runs = 0;
91  WriteOut("Calling Elmer finalize.\n");
92  COM_call_function(componentFunctionHandles[FINALIZE],&runs);
93  WriteOut("Elmer finalize done.\n");
94  if(!runs){
95  WriteErr("Elmer failed to finalize!\n");
96  return(1);
97  }
98  };
99 
100  std::vector<double> virtual returnNodeCoords(){
101  return nodeCoordinates;
102  };
103 
104  std::vector<double> virtual returnFaceCoords(){
105  return faceCoordinates;
106  };
107 
108 private:
109  int paneID;
110  std::vector<double> nodeCoordinates;
111  std::vector<double> faceCoordinates;
112 };
113 
114 #endif
const std::vector< double > & Coordinates() const
Definition: ElmerParAgent.H:87
virtual std::vector< double > returnFaceCoords()
std::vector< int > componentFunctionHandles
Definition: Orchestrator.H:13
virtual std::vector< double > returnNodeCoords()
virtual int Initialize(const std::string &interfaceName, int verblevel=1)
Definition: ElmerParAgent.H:10
std::vector< double > faceCoordinates
virtual int Run(double time)
Definition: ElmerParAgent.H:79
virtual int Finalize()
Definition: ElmerParAgent.H:89
std::vector< double > nodeCoordinates
virtual void WriteErr(const std::string &output)
Definition: Orchestrator.H:32
virtual void WriteOut(const std::string &output)
Definition: Orchestrator.H:28