Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Agent.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
27 /* Author: Gengbin Zheng */
28 
29 #ifndef _AGENT_H_
30 #define _AGENT_H_
31 
32 using namespace std;
33 #include <vector>
34 #include <cstring>
35 
36 #include "roccom.h"
37 #include "commpi.h"
38 
39 class Scheduler;
40 class Action;
41 class Agent;
42 class Coupling;
43 class InterpolateBase;
44 
46 public:
48  std::string target_window;
49  std::string attr;
50 public:
51  AttributeBase( Agent *ag, std::string target_window_, std::string attr_):
52  agent(ag), target_window(target_window_), attr(attr_) {}
53  virtual ~AttributeBase() {}
54  virtual void create(std::string bufname);
55  virtual void assign(std::string bufname);
56 };
57 
58 class NewAttribute : public AttributeBase {
59 protected:
60  // new_attribute
61  char loc;
62  int type;
63  int ncomp;
64  const char *unit;
65 public:
66  NewAttribute(Agent *ag, std::string target_window_, std::string attr_, char loc_, int type_, int ncomp_, const char * unit_);
67  void create(std::string bufname);
68 };
69 
70 // clone_attribute
71 class CloneAttribute : public AttributeBase {
72 protected:
73  std::string parent_window;
74  std::string parent_attr;
75  int wg;
76  const char * ptnname;
77  int val;
78  int condition;
79 public:
80  CloneAttribute(Agent *ag, int cond, std::string target_window_, std::string attr_, std::string parent_window_, std::string parent_attr_, int wg_=1, const char *ptnname_=0, int val_=0);
81  void create(std::string bufname);
82 };
83 
84 // use_attribute
85 class UseAttribute : public AttributeBase {
86 protected:
87  std::string parent_window;
88  std::string parent_attr;
89  int wg;
90  const char * ptnname;
91  int val;
92 public:
93  UseAttribute(Agent *ag, std::string target_window_, std::string attr_, std::string parent_window_, std::string parent_attr_, int wg_=1, const char *ptnname_=0, int val_=0);
94  void create(std::string bufname);
95 };
96 
97 typedef vector< UserScheduler* > SchdulerList;
98 
99 class PhysicsAction: public Action {
100 private:
102 public:
103  PhysicsAction(Agent *ag): Action(0, (const char **)NULL, NULL, NULL, (char *)"PhysicsAction"), agent(ag) {}
104  void run(double t, double dt, double alpha);
105  void declare(Scheduler &) {}
106  virtual void print(FILE *f);
107  virtual char *name();
108 };
109 
110 class Agent: public COM_Object {
111 friend class PhysicsAction;
112 protected:
113  const std::string agent_name;
114  MPI_Comm communicator;
121 
122  // Rocin and Rocout function handles
124  static int read_files_handle;
125  static int obtain_attr_handle;
126  static int write_attr_handle;
127  static int write_ctrl_handle;
128 
129  // Handles to routines provided by physics modules
131  int init_handle, update_handle;
132  int pre_hdf_handle, post_hdf_handle;
133  int finalize_handle, compute_integrals_handle; // fluid code handles
134 
135  // Hanldes to routines provided by agent to physics modules
136  int ic_handle, bc_handle, gm_handle;
137  bool withgm;
138 
139  int dobackup; // do backup on interpolation
140 
141  string rocmod_name, mod_instance;
142  string inDir, outDir, suffix;
143 
144  double initial_time, timestamp, current_time, current_deltatime, old_dt;
145 
146  // surf_window can be solidWin of INITIALIZE_SOLID() in SolidAgent ,
147  // or fluidSurf of INITIALIZE_FLUID() in FluidAgent
148  std::string surf_window, vol_window;
149  std::string tmp_window;
150  void *option_data;
151 
152  typedef vector< InterpolateBase* > InterpolateList;
154 
155  typedef vector< AttributeBase* > AttributeList;
157 
158  int pc_hdls[2][3]; // Handles for attributes to be
159  // stored/restored for PC-iterations
160  int pc_count; // burn only has one pc_hdls
161 
162  double integrals[MAN_INTEG_SIZE]; // Array for storing integrals
163 
165 public:
166  Agent(Coupling *cp, std::string mod, std::string obj,
167  const char *agent_name, MPI_Comm com, bool wgm=false, bool skipio=false);
168  virtual ~Agent();
169  virtual void load_module() {}
170  virtual void unload_module() {}
171  virtual void init_module(double t, double dt);
172  void init_subscheduler(double t);
173  void callMethod(Scheduler_voidfn1_t fn, double t);
174  void schedule();
175  virtual void finalize();
176 
177  virtual void input(double t) = 0;
178  virtual void output_restart_files(double t) = 0;
179  virtual void output_visualization_files(double t) = 0;
180 
181  double max_timestep(double t, double dt);
182 
183  Action *get_main_action() { return &action; }
184 
185  // for creating attributes by Actions
186  void register_new_attribute(std::string target_window_, std::string attr_, char loc_, int type_, int ncomp_, const char* unit_);
187  void register_clone_attribute(int cond, std::string target_window_, std::string attr_, std::string parent_window_, std::string parent_attr_, int wg_=1, const char *ptnname_=0, int val_=0);
188  void register_use_attribute(std::string target_window_, std::string attr_, std::string parent_window_, std::string parent_attr_, int wg_=1, const char *ptnname_=0, int val_=0);
189  void create_registered_attributes(std::string tmpBuf);
190  void create_registered_window_attributes(std::string target_window);
191  virtual void create_buffer_all();
192  void assign_attributes();
193  virtual void read_restart_data() {}
194 
195  void add_data() { /* TODO */ }
196  void add_icaction(Action *act);
197  void add_bcaction(Action *act, int l=1);
198  void add_bcinitaction(Action *act);
199  void add_gmaction(Action *act);
200 
201  void init_callback( const char *surf_win, const char *vol_win,
202  void *option=NULL);
203 
204  void init_bcactions(double t);
205  void obtain_bc(double *a, int *l=NULL);
206 
207  void init_gmactions(double t);
208  void obtain_gm(double *da);
209 
210  void init_bcinitaction(double t);
211  void run_bcinitaction(double t, double dt);
212 
213  Coupling *get_coupling() { return coupling; }
214 
215  void register_interpolate(InterpolateBase *ip);
216 
217  std::string get_surface_window() const { return surf_window; }
218  std::string get_volume_window() const { return vol_window; }
219 
220  MPI_Comm get_communicator() const { return communicator; }
221  std::string get_rocmod_name() const { return rocmod_name; }
222  std::string get_modinstance_name() const { return mod_instance; }
223  std::string get_agent_name() const { return agent_name; }
224  int get_comm_rank() const { return comm_rank; }
225 
226  double get_old_dt() const { return old_dt; }
227 
228  virtual void init_convergence( int iPredCorr);
229  virtual int check_convergence( double tolerMass, double tolerTract, double tolerVelo) { return 1; }
230 
231  virtual int compute_integrals() { return 0; }
232  double * get_integrals() { return integrals; }
233 
234  void print(FILE *f);
235 
236  void get_time_string( double t, std::string &s);
237 
238 protected:
239  Scheduler * get_bcScheduler(unsigned int level) { return level-1<bcScheduler.size()?bcScheduler[level-1]:NULL; }
240 
241  void init_function_handles();
242  void create_window(const char *window_name);
243 
244  // Split surface window into separate ones for output.
245  void split_surface_window( const std::string surfAll,
246  const std::string surf_i,
247  const std::string surf_nb,
248  const std::string surf_b,
249  const std::string surf_ni);
250 
251  // Read in HDF/CGNS files by control file. Return 0 if succeeds.
252  // Return -1 if control file was not found.
253  int read_by_control_file( double t, const std::string base, const std::string window);
254 
255  // Write out the given attribute into HDF/CGNS files with the given base
256  // file name. If ref exist, then refer to it for mesh data.
257  void write_data_files( double t, const std::string base,
258  const std::string attr, const char *ref=NULL);
259 
260  // Write out Rocin file with the given base file name and window name.
261  void write_control_file( double t, const std::string base, const std::string window);
262 
263  virtual void store_solutions( int converged);
264  int check_convergence_help( int vcur, int vpre, double tol, std::string str);
265 };
266 
267 
268 #endif
269 
270 
271 
272 
273 
274 
std::string target_window
Definition: Agent.h:48
virtual void unload_module()
Definition: Agent.h:170
int ic_handle
Definition: Agent.h:136
string rocmod_name
Definition: Agent.h:141
vector< AttributeBase * > AttributeList
Definition: Agent.h:155
std::string get_modinstance_name() const
Definition: Agent.h:222
double get_old_dt() const
Definition: Agent.h:226
vector< UserScheduler * > SchdulerList
Definition: Agent.h:97
std::string parent_window
Definition: Agent.h:73
SchdulerList bcScheduler
Definition: Agent.h:117
const char * option(const char *const name, const int argc, const char *const *const argv, const char *defaut, const char *const usage=0)
Definition: CImg.h:5604
Scheduler * get_bcScheduler(unsigned int level)
Definition: Agent.h:239
T mod(const T &x, const T &m)
Return the modulo of a number.
Definition: CImg.h:4788
int val
Definition: Agent.h:91
int condition
Definition: Agent.h:78
double s
Definition: blastest.C:80
std::string get_agent_name() const
Definition: Agent.h:223
This file contains the prototypes for Roccom API.
const char * unit
Definition: Agent.h:64
virtual void load_module()
Definition: Agent.h:169
InterpolateList interpolateList
Definition: Agent.h:153
Coupling * coupling
Definition: Agent.h:115
char loc
Definition: Agent.h:61
virtual void finalize()
Definition: Action.h:52
std::string parent_attr
Definition: Agent.h:88
virtual void print(FILE *f)
Definition: Agent.C:75
Definition: Action.h:32
int update_handle
Definition: Agent.h:131
std::string get_surface_window() const
Definition: Agent.h:217
void add_data()
Definition: Agent.h:195
const std::string agent_name
Definition: Agent.h:113
bool assign(T &t, const Object &o)
Definition: Object.h:138
Definition: Agent.h:110
int wg
Definition: Agent.h:89
int ncomp
Definition: Agent.h:63
char ** attr
Definition: Action.h:37
virtual ~AttributeBase()
Definition: Agent.h:53
std::string vol_window
Definition: Agent.h:148
Coupling * get_coupling()
Definition: Agent.h:213
virtual int compute_integrals()
Definition: Agent.h:231
std::string get_rocmod_name() const
Definition: Agent.h:221
vector< InterpolateBase * > InterpolateList
Definition: Agent.h:152
Agent * agent
Definition: Agent.h:47
static int write_ctrl_handle
Definition: Agent.h:127
UserScheduler gmScheduler
Definition: Agent.h:119
void declare(Scheduler &)
Definition: Agent.h:105
Contains declarations of MPI subroutines used in Roccom.
std::string tmp_window
Definition: Agent.h:149
static int write_attr_handle
Definition: Agent.h:126
MPI_Comm communicator
Definition: Agent.h:114
int pre_hdf_handle
Definition: Agent.h:132
Agent * agent
Definition: Agent.h:101
static int read_by_control_handle
Definition: Agent.h:123
AttributeBase(Agent *ag, std::string target_window_, std::string attr_)
Definition: Agent.h:51
int dobackup
Definition: Agent.h:139
void(Scheduler::* Scheduler_voidfn1_t)(double)
Definition: Scheduler.h:104
virtual void schedule()
Definition: Action.h:57
virtual int check_convergence(double tolerMass, double tolerTract, double tolerVelo)
Definition: Agent.h:229
int type
Definition: Agent.h:62
int get_comm_rank() const
Definition: Agent.h:224
PhysicsAction(Agent *ag)
Definition: Agent.h:103
string suffix
Definition: Agent.h:142
int pc_count
Definition: Agent.h:160
UserScheduler bcInitScheduler
Definition: Agent.h:118
std::string parent_window
Definition: Agent.h:87
static int read_files_handle
Definition: Agent.h:124
PhysicsAction action
Definition: Agent.h:116
virtual void read_restart_data()
Definition: Agent.h:193
bool skipInputIO
Definition: Agent.h:164
double * get_integrals()
Definition: Agent.h:232
std::string attr
Definition: Agent.h:49
static int obtain_attr_handle
Definition: Agent.h:125
int finalize_handle
Definition: Agent.h:133
#define MAN_INTEG_SIZE
Definition: rocman.h:38
MPI_Comm get_communicator() const
Definition: Agent.h:220
std::string parent_attr
Definition: Agent.h:74
void * option_data
Definition: Agent.h:150
UserScheduler icScheduler
Definition: Agent.h:120
const char * ptnname
Definition: Agent.h:76
Action * get_main_action()
Definition: Agent.h:183
double timestamp
Definition: Agent.h:144
std::string get_volume_window() const
Definition: Agent.h:218
int comm_rank
Definition: Agent.h:130
AttributeList attributeList
Definition: Agent.h:156
bool withgm
Definition: Agent.h:137
const char * ptnname
Definition: Agent.h:90