Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BurnAgent.C
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  *********************************************************************/
23 // $Id: BurnAgent.C,v 1.36 2010/02/18 21:47:40 juzhang Exp $
24 
25 #include "sys/types.h"
26 #include "sys/stat.h"
27 
28 #include "rocman.h"
29 #include "BurnAgent.h"
30 #include "Interpolate.h"
31 
32 #ifdef STATIC_LINK
33 extern "C" void COM_F_FUNC2(rocburn_load_module, ROCBURN_LOAD_MODULE)( const char *, int);
34 extern "C" void COM_F_FUNC2(rocburn_unload_module, ROCBURN_UNLOAD_MODULE)( const char *, int);
35 #endif
36 
37 const char *BurnAgent::window_name = "BurnAgent";
38 
39 BurnAgent::BurnAgent(Coupling *coup, std::string mod, std::string obj, MPI_Comm com, const std::string parentwin) :
40  Agent(coup, mod, obj, "Burn-Agent", com, false), parentWin(parentwin)
41 {
42  load_module();
43 
44  ignmodel = false;
45  std::string ModName(coup->get_control_param()->burn_module);
46  if(ModName == "RocburnPY")
47  ignmodel = true;
48 
49  iburn_all = "iburn_all"; // for registering attributes
50 
51  iburn_ng = "iburn_ng"; // burnBuf
52 
53  // Material names in files.
54  iburn = "iburn"; // for input
55  burn = "burn";
56 
57  // Rocin windows
58  burnSurfIN = "BurnSurfIN";
59  burnVolIN = "BurnVolIN";
60 
61  burnIntBak = "BurnIntBak";
62 
63  burnBufOUT = "BurnBufOUT";
64 
66 }
67 
69 {
70  MAN_DEBUG(3, ("[%d] Rocstar: BurnAgent::load_module %s %s.\n", comm_rank, rocmod_name.c_str(), mod_instance.c_str()));
71 #ifdef STATIC_LINK
72  COM_assertion_msg(rocmod_name == "Rocburn", "Unknown BurnAgent mod!");
73  COM_F_FUNC2( rocburn_load_module, ROCBURN_LOAD_MODULE)( mod_instance.c_str(), mod_instance.length());
74 #else
75  COM_load_module(rocmod_name.c_str(), mod_instance.c_str());
76 #endif
77 
78  init_function_handles(); // defined in Agent
79 }
80 
82 {
83  MAN_DEBUG(3, ("Rocstar: BurnAgent::unload_module %s %s.\n", rocmod_name.c_str(), mod_instance.c_str()));
84 #ifdef STATIC_LINK
85  COM_assertion_msg(rocmod_name == "Rocburn", "Unknown BurnAgent mod!");
86  COM_F_FUNC2( rocburn_unload_module, ROCBURN_UNLOAD_MODULE)( mod_instance.c_str(), mod_instance.length());
87 #else
88  if (get_coupling()->in_restart())
89  COM_close_module(rocmod_name.c_str(), mod_instance.c_str());
90  else
91  COM_unload_module(rocmod_name.c_str(), mod_instance.c_str());
92 #endif
93 }
94 
95 void BurnAgent::input( double t) {
96  int status;
97  status = read_by_control_file( t, iburn, burnSurfIN);
98  if (status == -1) {
101  }
102 
103  status = read_by_control_file( t, burn, burnVolIN);
104  if (status == -1) {
107  }
108 }
109 
110 void BurnAgent::init_module( double t, double dt) {
111  MAN_DEBUG(3, ("BurnAgent::init_module called t:%f.\n", t));
112 
113  Agent::init_module(t, dt);
114 
115  int initial_start = get_coupling()->initial_start();
116 
117  if (initial_start ||
119  {
120  COM_use_attribute( burnSurfIN+".mesh", parentWin+".mesh", 0);
121  COM_use_attribute( burnSurfIN+".bflag", parentWin+".bflag", 0);
122 // COM_window_init_done( burnSurfIN);
123  }
124 
126 
127  if (initial_start)
128  {
129  // Change burnVolIN to use parent windows' mesh without ghost
130  COM_use_attribute( burnVolIN+".mesh", parentWin+".mesh", 0);
132  }
133 
134  // Call initialization routine of physics module
135  // rocman.f90:INITIALIZE()
136  // call to INIT_WRAPPER() in rocburn_2D.f90
138  burnSurfIN.c_str(), burnVolIN.c_str(),
140 
141  tbl_flag = *(int *)option_data;
142  MAN_DEBUG(3, ("BurnAgent: tbl_flag = %d.\n", tbl_flag));
143 
144  // Delete input buffer windows
147 }
148 
150 {
152 
153  // Precondition: The window burnWin should have been defined and contain
154  // the following variables: pf_alp, qc_alp, qr_alp, rhos_alp, Tf_alp,
155  // rb, and Tflm. It should have uses the attributes rb,
156  // pf, qc, qr, rhos_alp, Tf, and Tflm_alp from parent window.
157 
158  int with_qc = COM_get_attribute_handle_const( surf_window+".qc_alp") > 0;
159  int with_qr = COM_get_attribute_handle_const( surf_window+".qr_alp") > 0;
160  int with_Tf = COM_get_attribute_handle_const( surf_window+".Tf_alp") > 0;
161  int with_Tv = COM_get_attribute_handle_const( surf_window+".Tv_alp") > 0;
162  int with_dn = COM_get_attribute_handle_const( surf_window+".dn_alp") > 0;
163  int with_rhos = COM_get_attribute_handle_const( surf_window+".rhos_alp") > 0;
164 
165  MAN_DEBUG(3, ("with_qc=%d with_qr=%d with_Tf=%d with_rhos=%d\n with_Tv=%d\n with_dn=%d\n",
166  with_qc, with_qr, with_Tf,with_rhos,with_Tv,with_dn));
167 
168  COM_use_attribute( iburn_all, parentWin+".Tflm_alp");
169  COM_clone_attribute( iburn_all+".Tflm_old", surf_window+".Tflm");
170 
173  if (with_qc) COM_use_attribute( iburn_all, parentWin+".qc");
174  if (with_qr) COM_use_attribute( iburn_all, parentWin+".qr");
175  if (with_Tf) COM_use_attribute( iburn_all, parentWin+".Tf");
176  if (with_Tv) COM_use_attribute( iburn_all, parentWin+".Tv");
177  if (with_dn) COM_use_attribute( iburn_all, parentWin+".dn");
178 
179  COM_clone_attribute( iburn_all+".rb_alp", surf_window+".rb");
180  COM_clone_attribute( iburn_all+".rb_old", surf_window+".rb");
181  COM_clone_attribute( iburn_all+".rb_grad", surf_window+".rb");
182 
183  // Create back-up data fields if predictor-corrector iteration is on
184  COM_clone_attribute( iburn_all+".pf_old", surf_window+".pf_alp");
185  if ( with_qc ) {
186  COM_clone_attribute( iburn_all+".qc_old", surf_window+".qc_alp");
187  COM_clone_attribute( iburn_all+".qc_grad", surf_window+".qc_alp");
188  }
189  if ( with_qr) {
190  COM_clone_attribute( iburn_all+".qr_old", surf_window+".qr_alp");
191  COM_clone_attribute( iburn_all+".qr_grad", surf_window+".qr_alp");
192  }
193  if ( with_rhos)
194  COM_clone_attribute( iburn_all+".rhos_old", surf_window+".rhos_alp");
195  if (with_Tf)
196  COM_clone_attribute( iburn_all+".Tf_old", surf_window+".Tf_alp");
197  if (with_Tv)
198  COM_clone_attribute( iburn_all+".Tv_old", surf_window+".Tv_alp");
199  if (with_dn)
200  COM_clone_attribute( iburn_all+".dn_old", surf_window+".dn_alp");
201 
204 
205  // no ghost
207  COM_use_attribute( iburn_ng+".all", surf_window+".all", 0);
211 
212  // Create windows for writing interface data
215 
218  COM_use_attribute( burnBufOUT, iburn_all+".Tflm_old");
219  if ( with_qc)
221  if ( with_qr)
223  if (with_Tf)
225  if (with_Tv)
227  if (with_dn)
230 
231  // Create a window for backing up the internal data of Rocburn
232  // if predictor-corrector iteration is on.
233  int maxPredCorr = get_coupling()->get_max_ipc();
234  if ( maxPredCorr>1) {
235  // Create window for backing up Rocburn's internal data
237  COM_use_attribute( burnIntBak+".mesh", vol_window+".mesh");
239 
241 
242  pc_hdls[0][0] = COM_get_attribute_handle( vol_window+".atts");
243  pc_hdls[1][0] = COM_get_attribute_handle( burnIntBak+".atts");
244  pc_count = 1;
245  }
246 
247  if (!get_coupling()->initial_start()) read_restart_data();
248 }
249 
251 {
252  int atts_hdl = COM_get_attribute_handle_const(burnSurfIN+".atts");
253  int buf_hdl = COM_get_attribute_handle( iburn_all+".atts");
254  COM_call_function( obtain_attr_handle, &atts_hdl, &buf_hdl);
255 }
256 
258  static const std::string iburn_prefix = "iburn_all";
259 
260  // Write out surface sub-windows
261  //write_data_files( t, iburn_prefix, iburn_all+".all");
262  write_data_files( t, iburn_prefix, burnBufOUT+".all");
263  write_control_file( t, "iburn*", surf_window.c_str());
264 
265  // Write out volume window
266  write_data_files( t, burn, (vol_window+".all").c_str());
267  write_control_file( t, burn, vol_window.c_str());
268 }
269 
270 // Visualization window buffers
271 static const char *iburn_vis = "iburn_vis";
272 static const char *burn_vis = "burn_vis";
273 static const char *burn_plag_vis = "burn_plag_vis";
274 
275 static const char *iburn_b_vis = "iburn_b_vis";
276 static const char *iburn_nb_vis = "iburn_nb_vis";
277 static const char *iburn_ni_vis = "iburn_ni_vis";
278 
279 
281  // TODO: Define visualization sub-windows
282 }
283 
285 {
288  int maxPredCorr = get_coupling()->get_max_ipc();
289  if ( maxPredCorr>1)
291 
292  Agent::finalize();
293 }
294 
295 
296 
297 
298 
299 
300 
301 
char burn_module[MAXLEN]
Definition: Coupling.h:48
std::string burnIntBak
Definition: BurnAgent.h:65
int get_max_ipc() const
Definition: Coupling.h:161
static const char * iburn_ni_vis
Definition: BurnAgent.C:277
std::string burnBufOUT
Definition: BurnAgent.h:67
int ic_handle
Definition: Agent.h:136
string rocmod_name
Definition: Agent.h:141
virtual void init_module(double t, double dt)
Definition: Agent.C:416
void write_data_files(double t, const std::string base, const std::string attr, const char *ref=NULL)
Definition: Agent.C:631
std::string burnVolIN
Definition: BurnAgent.h:63
virtual void input(double t)
Definition: BurnAgent.C:95
T mod(const T &x, const T &m)
Return the modulo of a number.
Definition: CImg.h:4788
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
#define COM_assertion_msg(EX, msg)
virtual void unload_module()
Definition: BurnAgent.C:81
virtual void read_restart_data()
Definition: BurnAgent.C:250
int in_restart() const
Definition: Coupling.h:164
static const char * window_name
Definition: BurnAgent.h:48
std::string iburn
Definition: BurnAgent.h:58
int init_handle
Definition: Agent.h:131
int pc_hdls[2][3]
Definition: Agent.h:158
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
#define COM_F_FUNC2(lowcase, uppercase)
Definition: roccom_basic.h:87
BurnAgent(Coupling *coup, std::string mod, std::string obj, MPI_Comm com, const std::string parent)
Definition: BurnAgent.C:39
std::string iburn_ng
Definition: BurnAgent.h:55
virtual void finalize()
Definition: BurnAgent.C:284
static const char * iburn_vis
Definition: BurnAgent.C:271
static const char * burn_plag_vis
Definition: BurnAgent.C:273
virtual void create_buffer_all()
Definition: BurnAgent.C:149
static const char * iburn_nb_vis
Definition: BurnAgent.C:276
Definition: Agent.h:110
void COM_load_module(const char *libname, const char *winname)
Definition: roccom_c++.h:75
void COM_use_attribute(const char *wname, const char *attr, int wg=1, const char *ptnname=0, int val=0)
Use the subset of panes of another window of which the given pane attribute has value val...
Definition: roccom_c++.h:224
std::string vol_window
Definition: Agent.h:148
Coupling * get_coupling()
Definition: Agent.h:213
static const char * iburn_b_vis
Definition: BurnAgent.C:275
int read_by_control_file(double t, const std::string base, const std::string window)
Definition: Agent.C:588
void COM_close_module(const char *libname, const char *winname=NULL)
Definition: roccom_c++.h:81
static const char * burn_vis
Definition: BurnAgent.C:272
virtual void create_buffer_all()
Definition: Agent.C:361
subroutine rocburn_load_module(module_name)
std::string surf_window
Definition: Agent.h:148
std::string tmp_window
Definition: Agent.h:149
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
MPI_Comm communicator
Definition: Agent.h:114
void COM_clone_attribute(const char *wname, const char *attr, int wg=1, const char *ptnname=0, int val=0)
Clone the subset of panes of another window of which the given pane attribute has value val...
Definition: roccom_c++.h:234
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
void COM_unload_module(const char *libname, const char *winname=NULL)
Definition: roccom_c++.h:78
std::string burnSurfIN
Definition: BurnAgent.h:62
void write_control_file(double t, const std::string base, const std::string window)
Definition: Agent.C:657
std::string iburn_all
Definition: BurnAgent.h:54
int COM_get_attribute_handle_const(const char *waname)
Definition: roccom_c++.h:420
void init_function_handles()
Definition: Agent.C:234
virtual void finalize()
Definition: Agent.C:466
virtual void output_visualization_files(double t)
Definition: BurnAgent.C:280
virtual void load_module()
Definition: BurnAgent.C:68
#define MAN_DEBUG(l, x)
Definition: rocman.h:98
bool ignmodel
Definition: BurnAgent.h:68
int tbl_flag
Definition: BurnAgent.h:49
int pc_count
Definition: Agent.h:160
void create_registered_window_attributes(std::string target_window)
Definition: Agent.C:350
virtual void output_restart_files(double t)
Definition: BurnAgent.C:257
std::string parentWin
Definition: BurnAgent.h:51
static int obtain_attr_handle
Definition: Agent.h:125
string mod_instance
Definition: Agent.h:141
void * option_data
Definition: Agent.h:150
virtual void init_module(double t, double dt)
Definition: BurnAgent.C:110
const Control_parameters * get_control_param()
Definition: Coupling.h:183
subroutine rocburn_unload_module(module_name)
int initial_start() const
Definition: Coupling.h:163
int comm_rank
Definition: Agent.h:130
std::string burn
Definition: BurnAgent.h:59