Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SolidAgent.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: SolidAgent.C,v 1.53 2009/05/12 20:17:48 mtcampbe Exp $
24 
25 #include "sys/types.h"
26 #include "sys/stat.h"
27 
28 #include "rocman.h"
29 #include "SolidAgent.h"
30 #include "Interpolate.h"
31 
32 #ifdef STATIC_LINK
33 extern "C" void COM_F_FUNC2(rocsolid_load_module, ROCSOLID_LOAD_MODULE)( const char *, int);
34 extern "C" void COM_F_FUNC2(rocsolid_unload_module, ROCSOLID_UNLOAD_MODULE)( const char *, int);
35 #ifdef ROCFRAC3
36 extern "C" void COM_F_FUNC2(rocfrac3_load_module, ROCFRAC3_LOAD_MODULE)( const char *, int);
37 extern "C" void COM_F_FUNC2(rocfrac3_unload_module, ROCFRAC3_UNLOAD_MODULE)( const char *, int);
38 #else
39 extern "C" void COM_F_FUNC2(rocfrac_load_module, ROCFRAC_LOAD_MODULE)( const char *, int);
40 extern "C" void COM_F_FUNC2(rocfrac_unload_module, ROCFRAC_UNLOAD_MODULE)( const char *, int);
41 #endif
42 #endif
43 
44 //const char *SolidAgent::window_name = "SolidAgent";
45 
46 static std::string agentCount = "0"; // only support up to 10 solid agents
47 
48 SolidAgent::SolidAgent(Coupling *coup, std::string mod, std::string obj, MPI_Comm com, int withFluid) :
49  Agent(coup, mod, obj, "Solid", com, false), with_fluid(withFluid)
50 {
51  load_module();
52 
53  withALE = 0;
54 
55  // TODO: need to personalize these variables
56  if (agentCount.length()==1) agentCount[0] ++;
57  isolid_i = "isolid"; isolid_i += agentCount; // "SolidBuf"
58  isolid_all = "isolid_all"; isolid_all += agentCount; //for registering attributes
59 
60  solidBufBase = "SolidBufBase"; solidBufBase += agentCount;
61  solidBuf = "SolidBuf"; solidBuf += agentCount; // for registering attributes
62  propBufAll = "SolidPropAll"; // for surface propagation (containing all panes)
64  propBuf = "SolidProp"; propBuf += agentCount;
65 
66  // Surface windows for Rocout
67  isolid_b = "isolid_b"; // buring
69  isolid_nb = "isolid_nb"; // non-buring
71  isolid_ni = "isolid_ni"; // noninteracting
73 
74  // Material names in files.
75  isolid = "isolid"; // for input
76  solid = "solid";
77 
78  // Rocin windows
79  solidSurfIN = "SolidSurfIN"; solidSurfIN += agentCount;
80  solidVolIN = "SolidVolIN"; solidVolIN += agentCount;
81 
82  solidBufBak = "SolidBufBak"; solidBufBak += agentCount;
83  solidVolBak = "SolidVolBak"; solidVolBak += agentCount;
84 
86 }
87 
89 {
90  MAN_DEBUG(3, ("[%d] Rocstar: SolidAgent::load_module %s %s.\n", comm_rank, rocmod_name.c_str(), mod_instance.c_str()));
91 
92 #ifdef STATIC_LINK
93  if (rocmod_name == "Rocsolid")
94  COM_F_FUNC2( rocsolid_load_module, ROCSOLID_LOAD_MODULE)( mod_instance.c_str(), mod_instance.length());
95 #ifdef ROCFRAC3
96  else if (rocmod_name == "Rocfrac3")
97  COM_F_FUNC2( rocfrac3_load_module, ROCFRAC3_LOAD_MODULE)( mod_instance.c_str(), mod_instance.length());
98 #else
99  else if (rocmod_name == "Rocfrac")
100  COM_F_FUNC2( rocfrac_load_module, ROCFRAC_LOAD_MODULE)( mod_instance.c_str(), mod_instance.length());
101 #endif
102  else
103  COM_assertion_msg(0, "Unknown SolidAgent mod!");
104 #else
105  // dynamic loading
106  COM_assertion_msg(rocmod_name == "Rocsolid" || rocmod_name == "Rocfrac"
107  || rocmod_name == "Rocfrac3",
108  (std::string("Unknown SolidAgent module:")+rocmod_name).c_str());
109  COM_load_module(rocmod_name.c_str(), mod_instance.c_str());
110 #endif
111 
112  init_function_handles(); // defined in Agent
113 }
114 
116 {
117  MAN_DEBUG(3, ("[%d] Rocstar: SolidAgent::unload_module %s.\n", comm_rank, rocmod_name.c_str()));
118 #ifdef STATIC_LINK
119  if (rocmod_name == "Rocsolid")
120  COM_F_FUNC2( rocsolid_unload_module, ROCSOLID_UNLOAD_MODULE)( mod_instance.c_str(), mod_instance.length());
121 #ifdef ROCFRAC3
122  else if (rocmod_name == "Rocfrac3")
123  COM_F_FUNC2( rocfrac3_unload_module, ROCFRAC3_UNLOAD_MODULE)( mod_instance.c_str(), mod_instance.length());
124 #else
125  else if (rocmod_name == "Rocfrac")
126  COM_F_FUNC2( rocfrac_unload_module, ROCFRAC_UNLOAD_MODULE)( mod_instance.c_str(), mod_instance.length());
127 #endif
128 #else
129  if (get_coupling()->in_restart())
130  COM_close_module(rocmod_name.c_str(), mod_instance.c_str());
131  else
132  COM_unload_module(rocmod_name.c_str(), mod_instance.c_str());
133 #endif
134 }
135 
136 void SolidAgent::input( double t) {
139 }
140 
141 void SolidAgent::init_module( double t, double dt) {
142  MAN_DEBUG(3, ("Rocstar: SolidAgent::init_module t=%e dt=%e.\n", t, dt));
143 
144  Agent::init_module(t, dt);
145 
146  // Call initialization routine of physics module
147  // rocman.f90:INITIALIZE()
149  solidSurfIN.c_str(), solidVolIN.c_str(),
151 
152  // Delete input buffer windows
155 
156  // Split surface window for output
157  // ifluid is fluidBuf in INITIALIZE_FLUID() ???
158  //split_surface_window( isolid_all, isolid_i, isolid_nb, isolid_b, isolid_ni);
159 }
160 
161 // called from callback
163 {
164 
165  int dummy = COM_get_attribute_handle_const( surf_window+".vbar_alp");
166  withALE = (dummy > 0);
167 
168  if (comm_rank == 0)
169  MAN_DEBUG(2, ("Rocstar: *** Solid with ALE is %d \n", withALE));
170 
173 
174  if (withALE) {
176  COM_use_attribute( propBufAll+".mesh", surf_window+".mesh");
177  COM_use_attribute( propBufAll+".vbar_alp", surf_window+".vbar_alp");
178  COM_clone_attribute( propBufAll+".vbar", surf_window+".vbar_alp");
179  COM_clone_attribute( propBufAll+".vbar_old", surf_window+".vbar_alp");
180  COM_clone_attribute( propBufAll+".vbar_grad", surf_window+".vbar_alp");
181  COM_new_attribute( propBufAll+".rb", 'e', COM_DOUBLE, 1, "m/s");
182  COM_new_attribute( propBufAll+".positions",'n',COM_DOUBLE,3,"m");
183  COM_new_attribute( propBufAll+".constrained",'n',COM_INTEGER,1,"");
184  COM_resize_array( propBufAll+".positions" );
185  COM_resize_array( propBufAll+".constrained");
186  COM_resize_array( propBufAll+".rb" );
189 
191  std::string bc_str = surf_window+".bcflag";
192  COM_use_attribute( propBuf+".mesh", surf_window+".mesh", 1, bc_str.c_str(), 1);
193  COM_use_attribute( propBuf+".pconn", propBufAll+".pconn");
194  if ( COM_get_attribute_handle( surf_window+".cnstr_type") >0) {
195  COM_use_attribute( propBuf, surf_window+".cnstr_type");
196  }
197  COM_use_attribute( propBuf+".vbar_alp", propBufAll+".vbar_alp");
198  COM_use_attribute( propBuf+".vbar", propBufAll+".vbar");
199  COM_use_attribute( propBuf+".vbar_old", propBufAll+".vbar_old");
200  COM_use_attribute( propBuf+".vbar_grad", propBufAll+".vbar_grad");
201  COM_use_attribute( propBuf+".rb", propBufAll+".rb");
204  }
205 
207  std::string bcflag = surf_window+".bcflag";
208  COM_use_attribute( solidBufBase+".mesh", surf_window+".mesh", 1, bcflag.c_str(), 0);
209  COM_use_attribute( solidBufBase+".mesh", surf_window+".mesh", 1, bcflag.c_str(), 1);
210  if (withALE) {
211  COM_new_attribute(solidBufBase+".areas", 'e', COM_DOUBLE, 1, "m^2");
212  COM_resize_array(solidBufBase+".areas");
213  COM_new_attribute(solidBufBase+".mdot", 'e', COM_DOUBLE, 1, "kg/(m^2 s)");
215  }
216  COM_clone_attribute( solidBufBase+".ts", surf_window+".ts_alp");
217  COM_clone_attribute( solidBufBase+".ts_old", surf_window+".ts_alp");
218  COM_clone_attribute( solidBufBase+".ts_grad", surf_window+".ts_alp");
221 
225  if (withALE)
227  if (with_fluid == 1) { // coupled
230  }
233 
235 
239 
240  // Create a window for output solid non-burning patch data
242  COM_use_attribute( isolid_nb+".mesh", surf_window+".mesh", 1, bcflag.c_str(), 0);
244 
245  if ( withALE) {
246  COM_use_attribute( isolid_nb+".pconn", propBufAll+".pconn");
248  COM_use_attribute( isolid_nb, propBufAll+".vbar_old");
250  }
251 
255 
256  // Create a window for output solid interface data
258  COM_use_attribute( isolid_b+".mesh", surf_window+".mesh", 1, bcflag.c_str(), 1);
260 
261  if ( withALE) {
262  COM_use_attribute( isolid_b+".pconn", propBufAll+".pconn");
264  COM_use_attribute( isolid_b, propBufAll+".vbar_old");
266  }
267 
271 
272  // Create a window for non-solid/fluid interface
274  COM_use_attribute( isolid_ni+".mesh", surf_window+".mesh", 1, bcflag.c_str(), 2);
276  if ( withALE) {
277  COM_use_attribute( isolid_ni+".pconn", propBufAll+".pconn");
279  COM_use_attribute( isolid_ni, propBufAll+".vbar_old");
281  }
283 
284  // setup for pc iterations
285  int maxPredCorr = get_coupling()->get_max_ipc();
286  if ( maxPredCorr>1) {
287  // Create window for backing surface data
289  COM_use_attribute( solidBufBak+".mesh", solidBuf+".mesh");
293 
294  // Create window for backing up volume data
296  COM_use_attribute( solidVolBak+".mesh", vol_window+".mesh");
300 
301  // Initlaize the attribute handles to be stored/restored
304 
307  pc_hdls[0][2] = COM_get_attribute_handle( solidBuf+".nc");
309  pc_count = 3;
310  }
311 
312  // update
314 
315  // setup variables
317 
318  std::string unit;
319  char loc;
320  COM_get_attribute( isolid_all+".rhos", &loc, &dummy, &dummy, &unit);
321  if (loc=='w' || loc=='p')
322  rhos_mode = 1;
323  else {
324  if (loc != 'n' && loc != 'e') {
325  printf("Rocstar: Error: Unknown type of location of rohs: %c\n", loc);
326  exit(1);
327  }
328  rhos_mode = 2;
329  }
330 
331  COM_get_attribute( solidBufBase+".ts", &loc, &dummy, &size_ts, &unit);
332  if (size_ts == 1 && traction_mode != NO_SHEER) {
333  COM_assertion_msg(0, "If traction mode is with sheer, then solid tractions must be vectors!");
334  MPI_Abort(MPI_COMM_WORLD, -1);
335  }
336 
337  // for compute_distances
339 
340  if (!get_coupling()->initial_start()) read_restart_data();
341 }
342 
344 {
345  int atts_hdl = COM_get_attribute_handle_const( solidSurfIN+".atts");
346  int buf_hdl = COM_get_attribute_handle( solidBufBase+".atts");
347  COM_call_function( obtain_attr_handle, &atts_hdl, &buf_hdl);
348 
349  if ( withALE) {
350  // Obtain data for surface propagation if ALE is enabled
351  int propBufAll_hdl = COM_get_attribute_handle( propBufAll+".atts");
352  COM_call_function( obtain_attr_handle, &atts_hdl, &propBufAll_hdl);
353 
354  // Obtain pconn for surface propagation
355  int pconn_hdl_const = COM_get_attribute_handle_const( solidSurfIN+".pconn");
356  int pconn_hdl = COM_get_attribute_handle( solidSurfIN+".pconn");
357  COM_call_function( obtain_attr_handle, &pconn_hdl_const, &pconn_hdl);
358  COM_clone_attribute( propBufAll+".pconn", solidSurfIN+".pconn");
359  }
360 }
361 
363  static const std::string isolid_prefix = "isolid_all";
364 
365  // Write out surface sub-windows
366 #if 1
367  write_data_files( t, isolid_b, isolid_b+".all");
368  write_data_files( t, isolid_nb, isolid_nb+".all");
369  write_data_files( t, isolid_ni, isolid_ni+".all");
370 #else
371  write_data_files( t, isolid_prefix, isolid_all+".all");
372 #endif
373  write_control_file( t, "isolid*", surf_window.c_str());
374 
375  // Write out volume window
376  write_data_files( t, solid, (vol_window+".all").c_str());
377  write_control_file( t, solid, vol_window.c_str());
378 }
379 
380 // Visualization window buffers
381 static const char *isolid_vis = "isolid_vis";
382 static const char *solid_vis = "solid_vis";
383 static const char *solid_plag_vis = "solid_plag_vis";
384 
385 static const char *isolid_b_vis = "isolid_b_vis";
386 static const char *isolid_nb_vis = "isolid_nb_vis";
387 static const char *isolid_ni_vis = "isolid_ni_vis";
388 
389 
391  // TODO: Define visualization sub-windows
392 }
393 
395 {
396  int maxPredCorr = get_coupling()->get_max_ipc();
397  if ( maxPredCorr>1) {
400  }
401 
409  if ( withALE) {
412  }
413 
414  Agent::finalize();
415 }
416 
418 {
419  if (compute_integrals_handle > 0) {
420  MAN_DEBUG(3, ("Rocstar: SolidAgent::compute_integrals.\n"));
422  }
423  return 1;
424 }
425 
426 
427 
428 
429 
430 
static const char * isolid_vis
Definition: SolidAgent.C:381
static const char * isolid_ni_vis
Definition: SolidAgent.C:387
int get_max_ipc() const
Definition: Coupling.h:161
std::string solidVolBak
Definition: SolidAgent.h:81
int ic_handle
Definition: Agent.h:136
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
string rocmod_name
Definition: Agent.h:141
virtual void init_module(double t, double dt)
Definition: Agent.C:416
virtual void output_restart_files(double t)
Definition: SolidAgent.C:362
void write_data_files(double t, const std::string base, const std::string attr, const char *ref=NULL)
Definition: Agent.C:631
T mod(const T &x, const T &m)
Return the modulo of a number.
Definition: CImg.h:4788
SolidAgent(Coupling *coup, std::string mod, std::string obj, MPI_Comm com, int withFluid=0)
Definition: SolidAgent.C:48
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
static std::string agentCount
Definition: SolidAgent.C:46
void COM_get_attribute(const std::string wa_str, char *loc, int *type, int *ncomp, std::string *unit)
Definition: roccom_c++.h:269
std::string solidSurfIN
Definition: SolidAgent.h:77
#define COM_assertion_msg(EX, msg)
int in_restart() const
Definition: Coupling.h:164
int withALE
Definition: SolidAgent.h:84
std::string isolid
Definition: SolidAgent.h:73
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
static const char * isolid_nb_vis
Definition: SolidAgent.C:386
std::string propBuf
Definition: SolidAgent.h:70
std::string isolid_nb
Definition: SolidAgent.h:64
virtual void read_restart_data()
Definition: SolidAgent.C:343
int compute_integrals_handle
Definition: Agent.h:133
std::string isolid_ni
Definition: SolidAgent.h:65
virtual void finalize()
Definition: SolidAgent.C:394
std::string solidBufBase
Definition: SolidAgent.h:67
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
std::string isolid_i
Definition: SolidAgent.h:60
Coupling * get_coupling()
Definition: Agent.h:213
std::string solidBuf
Definition: SolidAgent.h:68
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
void split_surface_window(const std::string surfAll, const std::string surf_i, const std::string surf_nb, const std::string surf_b, const std::string surf_ni)
Definition: Agent.C:690
int size_ts
Definition: SolidAgent.h:86
virtual void create_buffer_all()
Definition: Agent.C:361
std::string isolid_all
Definition: SolidAgent.h:62
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
std::string solid
Definition: SolidAgent.h:74
virtual void create_buffer_all()
Definition: SolidAgent.C:162
std::string solidVolIN
Definition: SolidAgent.h:78
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
std::string propBufAll
Definition: SolidAgent.h:69
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
void write_control_file(double t, const std::string base, const std::string window)
Definition: Agent.C:657
const int NO_SHEER
Definition: SolidAgent.h:31
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: SolidAgent.C:390
virtual int compute_integrals()
Definition: SolidAgent.C:417
std::string solidBufBak
Definition: SolidAgent.h:80
virtual void unload_module()
Definition: SolidAgent.C:115
#define MAN_DEBUG(l, x)
Definition: rocman.h:98
static const char * solid_vis
Definition: SolidAgent.C:382
const RocmanControl_parameters * get_rocmancontrol_param()
Definition: Coupling.h:184
int pc_count
Definition: Agent.h:160
void create_registered_window_attributes(std::string target_window)
Definition: Agent.C:350
static const char * solid_plag_vis
Definition: SolidAgent.C:383
void COM_new_attribute(const char *wa_str, const char loc, const int type, int ncomp, const char *unit)
Registering an attribute type.
Definition: roccom_c++.h:118
virtual void input(double t)
Definition: SolidAgent.C:136
static int obtain_attr_handle
Definition: Agent.h:125
subroutine rocfrac_unload_module(module_name)
std::string isolid_b
Definition: SolidAgent.h:63
virtual void load_module()
Definition: SolidAgent.C:88
string mod_instance
Definition: Agent.h:141
subroutine rocfrac_load_module(module_name)
static const char * isolid_b_vis
Definition: SolidAgent.C:385
int with_fluid
Definition: SolidAgent.h:83
double integrals[MAN_INTEG_SIZE]
Definition: Agent.h:162
void COM_resize_array(const char *wa_str, int pane_id=0, void **addr=NULL, int strd=-1, int cap=0)
Resize an attribute on a specific pane and return the address by setting addr.
Definition: roccom_c++.h:200
virtual void init_module(double t, double dt)
Definition: SolidAgent.C:141
int comm_rank
Definition: Agent.h:130
int traction_mode
Definition: SolidAgent.h:87
int rhos_mode
Definition: SolidAgent.h:85