Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rocstar_driver.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: rocstar_driver.C,v 1.94 2009/08/12 04:17:05 mtcampbe Exp $
24 
29 /* Author: Gengbin Zheng */
30 
31 #include <fstream>
32 #include <limits>
33 #include <cstdlib>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37 
38 #include "rocman.h"
39 #if __CHARMC__
40 #include "charm++.h"
41 #endif
42 #include "builtin_couplings.h"
43 #include "derived_couplings.h"
44 #ifdef ROCPROF
45 #include "Rocprof.H"
46 #endif
47 
50 #ifdef WITH_PANDA
51 COM_EXTERN_MODULE(Rocpanda);
52 #endif
53 void init_profiling(Control_parameters &param, int comm_rank);
54 
55 int man_verbose = 1;
56 void RocstarShutdown(int = 0);
57 
58 void
59 RocstarShutdown(int status)
60 {
61  /* Finalize Roccom. */
62  COM_finalize();
63 #ifdef ROCPROF
64  Rocprof_Finalize(true);
65 #endif
66  /* Close down MPI. */
67  MPI_Finalize();
68  exit(status);
69 }
70 
71 double
72 get_restart_time(const string &restart_file)
73 {
74  int curStep = 0;
75  double curTime = 0.0;
76 #if 0
77  std::ifstream Inf;
78  Inf.open(restart_file.c_str());
79  if(!Inf)
80  return(0.0);
81  while(Inf)
82  Inf >> curStep >> curTime;
83  Inf.close();
84 #else
85  FILE *fp = fopen(restart_file.c_str(), "r");
86  if (fp == NULL) return 0.0;
87  while (!feof(fp)) {
88  fscanf(fp, "%d %le", &curStep, &curTime);
89  }
90  fclose(fp);
91 #endif
92  return(curTime);
93 }
94 
96  const std::string &name = param.coupling_scheme;
97 
98  if ( name == "FluidAlone")
99  return new FluidAlone( param.fluid_module, param.communicator, &param, &rocman_param);
100  else if ( name == "FluidBurnAlone")
101  return new FluidBurnAlone( param.fluid_module, param.burn_module, param.communicator, &param, &rocman_param);
102  else if ( name == "SolidAlone")
103  return new SolidAlone( param.solid_module, param.communicator, &param, &rocman_param);
104  else if ( name == "SolidBurn")
105  return new SolidBurn( param.solid_module, param.burn_module, param.communicator, &param, &rocman_param);
106  else if ( name == "SolidFluidSPC")
107  return new SolidFluidSPC( param.fluid_module, param.solid_module, param.communicator, &param, &rocman_param);
108  else if ( name == "FluidSolidISS")
109  return new FluidSolidISS( param.fluid_module, param.solid_module, param.communicator, &param, &rocman_param);
110  else if ( name == "SolidFluidBurnSPC")
111  return new SolidFluidBurnSPC( param.fluid_module, param.solid_module, param.burn_module, param.communicator, &param, &rocman_param);
112  else if ( name == "SolidFluidBurnEnergySPC")
113  return new SolidFluidBurnEnergySPC( param.fluid_module, param.solid_module, param.burn_module, param.communicator, &param, &rocman_param);
114  else if ( name == "Test" || name.empty()){
117  COM_LOAD_MODULE_STATIC_DYNAMIC(Rocface,"FACETEST");
118  COM_LOAD_MODULE_STATIC_DYNAMIC(Rocon,"PROPCONTEST");
120  COM_LOAD_MODULE_STATIC_DYNAMIC(Rocflu,"FLUTEST");
121  COM_LOAD_MODULE_STATIC_DYNAMIC(Rocflo,"FLOTEST");
123  COM_LOAD_MODULE_STATIC_DYNAMIC(Rocfrac,"FRACTEST");
124  }
125  else {
126  std::cerr << "Rocstar: ERROR: Unknown coupling scheme: " << name << std::endl;
127  std::cerr << std::endl;
128  std::cerr << "Rocstar: Rocstar Supported coupling schemes: " << std::endl;
129  std::cerr << "Rocstar: FluidAlone: Fluid alone with no burn" << std::endl;
130  std::cerr << "Rocstar: FluidBurnAlone: Fluid alone with burn" << std::endl;
131  std::cerr << "Rocstar: SolidAlone: Solid alone with no burn" << std::endl;
132  std::cerr << "Rocstar: SolidFluidBurnSPC: FullyCoupled simple staggered scheme with P-C" << std::endl;
133  std::cerr << "Rocstar: SolidFluidSPC: FullyCoupled no burn" << std::endl;
134  std::cerr << "Rocstar: FluidSolidISS: FullyCoupled no burn with improved staggered scheme" << std::endl;
135  std::cerr << "Rocstar: SolidFluidBurnEnergySPC: FullyCoupled with burn energy" << std::endl;
136  COM_assertion_msg(0, "ERROR: Unknown coupling scheme!");
137  }
138  return NULL;
139 }
140 
141 #define COM_DOUBLE_ATTRIBUTE(attrname, varname) \
142  attr = winname+"."+attrname; \
143  COM_new_attribute( attr.c_str(),'w',COM_DOUBLE,1,""); \
144  COM_set_size( attr.c_str(),0,1); \
145  COM_set_array( attr.c_str(),0, &varname);
146 
147 #define COM_INT_ATTRIBUTE(attrname, varname) \
148  attr = winname+"."+attrname; \
149  COM_new_attribute( attr.c_str(),'w',COM_INT,1,""); \
150  COM_set_size( attr.c_str(),0,1); \
151  COM_set_array( attr.c_str(),0, &varname);
152 
153 #define COM_STRING_ATTRIBUTE(attrname, varname) \
154  attr = winname+"."+attrname; \
155  COM_new_attribute( attr.c_str(),'w',COM_CHAR,1,""); \
156  COM_set_size( attr.c_str(),0,MAXLEN); \
157  COM_set_array( attr.c_str(),0,varname,MAXLEN);
158 
159 #define COM_BOOL_ATTRIBUTE(attrname, varname) \
160  attr = winname+"."+attrname; \
161  COM_new_attribute( attr.c_str(),'w',COM_BOOL,1,""); \
162  COM_set_size( attr.c_str(),0,1); \
163  COM_set_array( attr.c_str(),0,&varname);
164 
165 
167 {
168  // default
170  zoomFactor = 0;
171  cur_step = 0;
172  maxwalltime = 3.15E7;
173  simue_time = 1.0E12;
174  strcpy(timingDataDir, "./");
175  AutoRestart = 0;
176  InterruptFlag = 0;
177  maxNumDumps = 0;
178  current_dump = 0;
182  strcpy(output_module,"Rocout");
183  strcpy(timingDataDir,"Rocman/Profiles");
184  controlVerb = 5;
185 }
186 
188 {
189  // Load I/O modules
191 
192  string winname = "RocmanParam";
193  COM_new_window(winname.c_str());
194 
195  string attr;
196  COM_STRING_ATTRIBUTE("CouplingScheme", coupling_scheme);
197 
198  COM_STRING_ATTRIBUTE("FluidModule", fluid_module);
199 
200  COM_STRING_ATTRIBUTE("SolidModule", solid_module);
201 
202  COM_STRING_ATTRIBUTE("BurnModule", burn_module);
203 
204  COM_STRING_ATTRIBUTE("OutputModule", output_module);
205 
206  COM_DOUBLE_ATTRIBUTE("InitialTime", current_time);
207 
208  COM_DOUBLE_ATTRIBUTE("MaximumTime", simue_time);
209 
210  COM_DOUBLE_ATTRIBUTE("MaxWallTime", maxwalltime);
211 
212  COM_INT_ATTRIBUTE("MaxNumPredCorrCycles", maxNumPredCorrCycles);
213 
214  COM_INT_ATTRIBUTE("MaxNumTimeSteps", maxNumTimeSteps);
215 
216  COM_DOUBLE_ATTRIBUTE("CurrentTimeStep", time_step);
217 
218  COM_DOUBLE_ATTRIBUTE("OutputIntervalTime", outputIntervalTime);
219 
220  COM_DOUBLE_ATTRIBUTE("ZoomFactor", zoomFactor);
221 
222  // Tolerances for convergence check
223  COM_DOUBLE_ATTRIBUTE("TolerTract", tolerTract);
224 
225  COM_DOUBLE_ATTRIBUTE("TolerVelo", tolerVelo);
226 
227  COM_DOUBLE_ATTRIBUTE("TolerMass", tolerMass);
228 
229  COM_DOUBLE_ATTRIBUTE("TolerDisp", tolerDisp);
230 
231  COM_STRING_ATTRIBUTE("GENXTimingDataDir", timingDataDir);
232  COM_STRING_ATTRIBUTE("ProfileDir", timingDataDir);
233  COM_BOOL_ATTRIBUTE("AutoRestart",AutoRestart);
234  COM_INT_ATTRIBUTE("MaxNumDumps",maxNumDumps);
235  //
236  COM_window_init_done(winname.c_str());
237 
238  //===== Read in parameter file using Rocin
239  int IN_param = COM_get_function_handle( "IN.read_parameter_file");
240 
241  COM_call_function(IN_param, "RocstarControl.txt", (winname).c_str());
242 
243  // post process
244  strcat(timingDataDir, "/");
245 
246  if(AutoRestart)
247  current_time = get_restart_time("Restart.txt");
248 
249  init_time = current_time; // init time, remain constant
250  iOutput = (int)((1.000001*current_time)/outputIntervalTime)+1;
251 
252  COM_delete_window(winname.c_str());
253 
254  // load output module
255  const std::string &outputModule = output_module;
256  if (outputModule == "Rocout") {
257  MAN_DEBUG(3, ("[%d] Rocstar: load_module Rocout.\n", COMMPI_Comm_rank(communicator)));
259  }
260 #ifdef WITH_PANDA
261  else if (outputModule == "Rocpanda") {
262  MAN_DEBUG(3, ("[%d] Rocstar: load_module Rocpanda.\n", COMMPI_Comm_rank(communicator)));
263  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocpanda, "OUT");
264  // Rocpanda server processes won't return
265  }
266 #endif
267  else {
269  printf("Rocstar: Error: Unknown output module %s!\n", output_module);
270  MPI_Abort(MPI_COMM_WORLD, -1);
271  }
272 
273  // get the MPI communicator set by Rocpanda
274  // this is important, update communicator if it is Rocpanda
276 
278 
279  // initialize profiling file
280  init_profiling(*this, myRank);
281 
282  if (myRank == 0) startTime = MPI_Wtime();
283  MPI_Bcast( &startTime, 1, MPI_DOUBLE, 0, communicator);
284 }
285 
286 // Rocpanda may require change to communicator
288 {
289  int get_comm = COM_get_function_handle( "OUT.get_comm");
290  if (get_comm > 0) {
291  COM_call_function( get_comm, &communicator);
293  }
294 }
295 
297 {
298  printf("================ Rocstar Control file ================\n");
299  printf("Rocstar: CouplingScheme: '%s'\n", coupling_scheme);
300  printf("Rocstar: InitialTime: %f\n", current_time);
301  printf("Rocstar: MaximumTime: %f\n", simue_time);
302  printf("Rocstar: MaxWallTime: %f\n", maxwalltime);
303  printf("Rocstar: AutoRestart: %s\n",(AutoRestart ? "Yes" : "No"));
304  printf("Rocstar: MaxNumPredCorrCycles: %d\n", maxNumPredCorrCycles);
305  printf("Rocstar: MaxNumTimeSteps: %d\n", maxNumTimeSteps);
306  if(maxNumDumps > 0)
307  printf("Rocstar: MaxNumOutputDumps: %d\n", maxNumDumps);
308  printf("Rocstar: CurrentTimeStep: %e\n", time_step);
309  printf("Rocstar: OutputIntervalTime: %e\n", outputIntervalTime);
310  printf("Rocstar: ZoomFactor: %f\n", zoomFactor);
311  printf("Rocstar: TolerTract: %f\n", tolerTract);
312  printf("Rocstar: TolerVelo: %f\n", tolerVelo);
313  printf("Rocstar: TolerMass: %f\n", tolerMass);
314  printf("Rocstar: TolerDisp: %f\n", tolerDisp);
315  printf("Rocstar: ProfileDir: %s\n", timingDataDir);
316  printf("Rocstar: ProfileFile: %s\n", timingDataFile.c_str());
317  printf("=======================================================\n");
318 }
319 
320 //
322 {
323  cur_step = step;
324  current_time = t;
325  LastOutputTime = t;
327  // set output seq no
328  iOutput = (int)((1.000001*current_time)/outputIntervalTime)+1;
329 }
330 
332 {
333  // default
334  verbose = 1;
335  separate_out = 0;
336 
337  order = 0;
338  traction_mode = 1; // NO_SHEER;
339  rhoc = 1703.0;
340  pressure = 6.8e6;
341  burn_rate = 0.01;
342  P_ambient = 0.0;
343  PROP_fom = 0;
344  PROP_rediter = 2;
345  PROP_fangle = 35.;
346  PROPCON_enabled = 0;
347  PROPCON_ndiv = 100;
348  async_in = 0;
349  async_out = 0;
350  rfc_verb = 1;
351  rfc_order = 2;
352  rfc_iter = 100;
353  rfc_tol=1.e-6;
354 
355  // internal
356  remeshed = 0;
357 }
358 
359 void RocmanControl_parameters::read( MPI_Comm comm, int comm_rank)
360 {
361  const std::string filename = "Rocman/RocmanControl.txt";
362 
363  struct stat statBuf;
364 
365  string winname = "RocmanControlParam";
366  COM_new_window(winname.c_str());
367 
368  string attr;
369  COM_INT_ATTRIBUTE("Verbose", verbose);
370  COM_INT_ATTRIBUTE("Separate_out", separate_out);
371 
372  COM_INT_ATTRIBUTE("InterpolationOrder", order);
373  COM_INT_ATTRIBUTE("TractionMode", traction_mode);
374  COM_DOUBLE_ATTRIBUTE("P_ambient", P_ambient);
375 
376  COM_DOUBLE_ATTRIBUTE("Rhoc", rhoc);
377  COM_DOUBLE_ATTRIBUTE("Pressure", pressure);
378  COM_DOUBLE_ATTRIBUTE("BurnRate", burn_rate);
379 
380  COM_INT_ATTRIBUTE("RFC_verb", rfc_verb);
381  COM_INT_ATTRIBUTE("RFC_order", rfc_order);
382  COM_INT_ATTRIBUTE("RFC_iteration", rfc_iter);
383  COM_DOUBLE_ATTRIBUTE("RFC_tolerance", rfc_tol);
384 
385  COM_BOOL_ATTRIBUTE("Face-offsetting", PROP_fom);
386  COM_BOOL_ATTRIBUTE("PROPCON_enabled", PROPCON_enabled);
387  COM_INT_ATTRIBUTE("PROP_rediter", PROP_rediter);
388  COM_INT_ATTRIBUTE("PROPCON_ndiv", PROPCON_ndiv);
389  COM_DOUBLE_ATTRIBUTE("PROP_fangle", PROP_fangle);
390 
391  COM_BOOL_ATTRIBUTE("AsyncInput", async_in);
392  COM_BOOL_ATTRIBUTE("AsyncOutput", async_out);
393 
394  //
395  COM_window_init_done(winname.c_str());
396 
397  if (stat(filename.c_str(), &statBuf) == 0)
398  {
399  if ( comm_rank == 0) { // only rank 0 reads
400  //===== Read in parameter file using Rocin
401  int IN_param = COM_get_function_handle( "IN.read_parameter_file");
402 
403  COM_call_function(IN_param, filename.c_str(), (winname).c_str());
404  }
405 
406  MPI_Bcast(&verbose, 1, MPI_INT, 0, comm);
407  MPI_Bcast(&separate_out, 1, MPI_INT, 0, comm);
408  MPI_Bcast(&order, 1, MPI_INT, 0, comm);
409  MPI_Bcast(&traction_mode, 1, MPI_INT, 0, comm);
410  MPI_Bcast(&P_ambient, 1, MPI_DOUBLE, 0, comm);
411  MPI_Bcast(&rhoc, 1, MPI_DOUBLE, 0, comm);
412  MPI_Bcast(&pressure, 1, MPI_DOUBLE, 0, comm);
413  MPI_Bcast(&burn_rate, 1, MPI_DOUBLE, 0, comm);
414  MPI_Bcast(&rfc_verb, 1, MPI_INT, 0, comm);
415  MPI_Bcast(&rfc_order, 1, MPI_INT, 0, comm);
416  MPI_Bcast(&rfc_iter, 1, MPI_INT, 0, comm);
417  MPI_Bcast(&rfc_tol, 1, MPI_DOUBLE, 0, comm);
418  MPI_Bcast(&PROP_fom, 1, MPI_CHAR, 0, comm);
419  MPI_Bcast(&PROP_rediter, 1, MPI_INT, 0, comm);
420  MPI_Bcast(&PROPCON_enabled, 1, MPI_CHAR, 0, comm);
421  MPI_Bcast(&PROPCON_ndiv, 1, MPI_INT, 0, comm);
422  MPI_Bcast(&PROP_fangle, 1, MPI_DOUBLE, 0, comm);
423  MPI_Bcast(&async_in, 1, MPI_CHAR, 0, comm);
424  MPI_Bcast(&async_out, 1, MPI_CHAR, 0, comm);
425  }
426 
427  COM_delete_window(winname.c_str());
428 
430 
431  // set options for Rocout
432  int OUT_set_option = COM_get_function_handle( "OUT.set_option");
433  const char *rankWidth = "4";
434  COM_call_function( OUT_set_option, "rankwidth", rankWidth);
435  COM_call_function( OUT_set_option, "pnidwidth", "0");
436  //const char *ioFormat = "HDF";
437  const char *ioFormat = "CGNS";
438  COM_call_function( OUT_set_option, "format", ioFormat);
439  if ( async_out)
440  COM_call_function( OUT_set_option, "async", "on");
441  else
442  COM_call_function( OUT_set_option, "async", "off");
443  if ( separate_out)
444  COM_call_function( OUT_set_option, "rankdir", "on");
445  else
446  COM_call_function( OUT_set_option, "rankdir", "off");
447 }
448 
450 {
451  printf("========== Rocman Parameter file read ==========\n");
452  printf("Rocstar: verbosity level is %d\n", verbose);
453  printf("Rocstar: The order of interpolation is %d\n", order);
454  printf("Rocstar: Traction mode is %d (1 for no sheer, 2 for with sheer)\n", traction_mode);
455  printf("Rocstar: ambient pressure is %f\n", P_ambient);
456  printf("Rocstar: Solid density (Rhoc) is %f kg/m^3\n", rhoc);
457  printf("Rocstar: Pressure is %f Pa\n", pressure);
458  printf("Rocstar: Burning rate is %f m/s\n", burn_rate);
459  printf("Rocstar: RFC_verb: %d\n", rfc_verb);
460  printf("Rocstar: Order of quadrature rule (RFC_order): %d\n", rfc_order);
461  printf("Rocstar: Max iterations for iterative solver: %d\n", rfc_iter);
462  printf("Rocstar: tolerance for iterative solver (RFC_tolerance): %f\n", rfc_tol);
463  if (PROP_fom)
464  printf("Rocstar: Using face-offsetting method for surface propagation.\n");
465  else
466  printf("Rocstar: Using marker-particle method for surface propagation.\n");
467  if(PROPCON_enabled)
468  printf("Rocstar: Using Rocon propagation constraints, (ndiv = %d).\n",PROPCON_ndiv);
469  printf("Rocstar: Number of smoothing iterations in Rocprop: %d\n", PROP_rediter);
470  printf("Rocstar: Feature-angle threshold in Rocprop: %f\n", PROP_fangle);
471  printf("Rocstar: Async Input: %c\n", async_in?'T':'F');
472  printf("Rocstar: Async Output: %c\n", async_out?'T':'F');
473  printf("==================================================\n");
474 }
475 
476 // MaximumTime, maxNumTimeSteps
478  // if exceed max num of steps
479  if (param.cur_step>=param.maxNumTimeSteps) {
480  MAN_DEBUG(2, ("\nRocstar: reached_simulation_time returns TRUE with cur_step: %d\n", param.cur_step));
481  return true;
482  }
483 
484  int verb = param.controlVerb;
485 
486  // if exceed max wall time
487  double startTimeLoopTime;
488  if (param.myRank == 0) startTimeLoopTime = MPI_Wtime();
489  MPI_Bcast( &startTimeLoopTime, 1, MPI_DOUBLE, 0, param.communicator);
490  const double elaped_time = startTimeLoopTime - param.startTime;
491  if (elaped_time >= param.maxwalltime ) {
492  if (param.myRank == 0 && verb > 1)
493  printf("Rocstar: Quitting; elapsed wall clock time = %f\n", elaped_time);
494  return true;
495  }
496  else {
497  if (param.myRank == 0) {
498  MAN_DEBUG(2, ("\nRocstar: reached_simulation_time: elapsed wall time = %f \n", elaped_time));
499  }
500  }
501 
502  // if exceed MaximumTime the simulation time
503  if (param.current_time >= param.simue_time) { // MaximumTime
504  if (param.myRank == 0 && verb > 0)
505  printf("Rocstar: Quitting; CurrentTime = %e, MaximumTime = %e\n", param.current_time, param.simue_time);
506  return true;
507  }
508 
509  // if exceed the Maximum Number of dumps
510  if( (param.maxNumDumps > 0 ) && (param.current_dump >= param.maxNumDumps)){
511  if(param.myRank == 0 && verb > 0)
512  printf("Rocstar: Quitting; Reached the maximum number of dumps for this run. (%d)\n",param.current_dump);
513  return true;
514  }
515 
516  return false;
517 }
518 
520  bool result = param.current_time + param.time_step*0.4 >=
521  param.iOutput*param.outputIntervalTime;
522  if (result == true) {
523  param.iOutput++;
524  if(param.myRank == 0)
525  MAN_DEBUG(1, ("\nRocstar: reached_restartdump_time with current_time: %e time_step: %e iOutput: %d outputIntervalTime: %e\n", param.current_time, param.time_step, param.iOutput, param.outputIntervalTime));
526  }
527  return result;
528 }
529 
531  // TODO: Implement this
532  return false;
533 }
535 {
536  int interrupt_code = 0;
537  std::string message("Interrupted by file");
538  // std::string therest;
539  if(param.myRank == 0) {
540  std::ifstream InterruptFile;
541  InterruptFile.open("RocstarInterrupt.txt");
542  if(InterruptFile){
543  std::cout << "Rocstar: Processing interrupt from file." << std::endl;
544  InterruptFile >> interrupt_code;
545  std::getline(InterruptFile,message);
546  InterruptFile.close();
547  unlink("RocstarInterrupt.txt");
548  std::ofstream InterruptOut;
549  InterruptOut.open("RocstarInterrupt.txt.processed");
550  InterruptOut << interrupt_code << " " << message << std::endl;
551  InterruptOut.close();
552  }
553  }
554  MPI_Bcast(&interrupt_code,1,MPI_INTEGER,0,param.communicator);
555  if(interrupt_code > 0){
556  coup->Interrupt(&interrupt_code,message.c_str());
557  return(interrupt_code);
558  }
559  return(0);
560 }
561 
562 void rocstar_driver( int verb, int remeshed, bool debug) {
563  // Read in config files to initialize param
564  Control_parameters *param_ptr = new Control_parameters;
565  Control_parameters &param = *param_ptr;
566  param.read();
567 
568  int comm_rank = param.myRank;
569 
570 
571  param.controlVerb = verb;
572  param.controlDebug = debug;
573 
574  // Read in rocman config files to initialize param
575  RocmanControl_parameters *rocman_param_ptr = new RocmanControl_parameters;
576  RocmanControl_parameters &rocman_param = *rocman_param_ptr;
577  rocman_param.read( param.communicator, comm_rank);
578  rocman_param.remeshed = remeshed;
579 
580  if ( comm_rank == 0 ) {
581  if(debug)
582  printf("Rocstar: Call CouplingInitialize\n");
583  if(verb > 1){
584  param.print();
585  rocman_param.print();
586  }
587  COM_set_verbose( verb); // shift by 2 to depress first level printing
588  COM_set_debug( debug);
589  }
590 
591  MPI_Barrier(MPI_COMM_WORLD);
592  // if(!comm_rank)
593  // std::cout << "Rocstar: creating coupling." << std::endl;
594 
595  // Construct coupling object and schedule the actions
596  Coupling *coup = create_coupling( param, rocman_param);
597  if(!coup){
598  if(comm_rank == 0)
599  std::cerr << "Rocstar: Error: No coupling created. Exiting." << std::endl;
600  return;
601  }
602  coup->schedule();
603 
604  // std::cout << "Rocstar(" << comm_rank << "): coupling created." << std::endl;
605  MPI_Barrier(MPI_COMM_WORLD);
606  // if(!comm_rank)
607  // std::cout << "Rocstar: All couplings created." << std::endl;
608  // visualization
609  // std::string fname = std::string(param.coupling_scheme) + ".gdl";
610  // coup->print(fname.c_str());
611 
612  // Load other service modules
613  RocBlas::init();
614  MPI_Barrier(MPI_COMM_WORLD);
615  // if(!comm_rank)
616  // std::cout << "Rocstar: Rocblas initd." << std::endl;
617 
618  // Have Roccom profile all the calls to COM_call_function.
619  COM_set_profiling( 1);
620  MPI_Barrier(MPI_COMM_WORLD);
621  // if(!comm_rank)
622  // std::cout << "Rocstar: profiling set." << std::endl;
623 
624  int with_pciter = (param.maxNumPredCorrCycles > 1);
625  if ( comm_rank == 0 && verb > 1) {
626  std::cout << "Rocstar: The maximum number of PC-iterations is " << param.maxNumPredCorrCycles << std::endl;
627  }
628 
629  // in case of restarting, reset cur_step and current_time from Restart.txt
630  coup->read_restart_info();
631 
632  MPI_Barrier(MPI_COMM_WORLD);
633  if(!comm_rank && debug)
634  std::cout << "Rocstar: Read restart information, initializing" << std::endl;
635 
636  // call input, init and run_initactions
637  coup->initialize();
638 
639  // std::cout << "Rocstar(" << comm_rank << "): Coupling initialized." << std::endl;
640  MPI_Barrier(MPI_COMM_WORLD);
641  // if(!comm_rank)
642  // std::cout << "Rocstar: All couplings initd" << std::endl;
643 
644  if ( param.current_time == 0.0) {
645  MPI_Barrier(param.communicator);
646  if(comm_rank == 0 && verb > 0)
647  std::cout << "Rocstar: Performing time 0 dump..." << std::endl;
648  coup->update_integrals( param.current_time);
649  coup->update_distances( param.current_time);
650  coup->output_restart_files( param.current_time);
651  MPI_Barrier(param.communicator);
652  if(comm_rank == 0 && debug)
653  std::cout << "Rocstar: done." << std::endl;
654  }
655 
656  MPI_Barrier(param.communicator);
657  param.LastOutputTime = param.current_time;
658  param.LastOutputStep = param.cur_step;
659 
660  if (comm_rank == 0 && verb > 0) {
661  std::cout << "Rocstar: Starting with step " << param.cur_step+1 << ", at time " << param.current_time << std::endl;
662  }
663 
664  char header[100];
665  sprintf(header, "************** Initialization times at time step %d *****************\n", param.cur_step);
666  COM_print_profile( param.timingDataFile.c_str(), header);
667  COM_set_profiling( 1); // Reset profiler;
668 
669  if (param.current_time == 0.0)
670  coup->write_restart_info( param.current_time, 1);
671 
672  // March through time until either the specified maximum time or the maximum
673  // number of time steps have been exceeded (whichever comes first).
674  int InterfaceConverged;
675  MPI_Barrier(param.communicator);
676  // if(comm_rank == 0)
677  // std::cout << "Rocstar: Preparig to step..." << std::endl;
678  while ( !reached_simulation_time(param) ) {
679  param.cur_step ++;
680 
681  for (int iPredCorr = 1; iPredCorr <= param.maxNumPredCorrCycles; iPredCorr++)
682  {
683  if ( comm_rank == 0 && verb > 0) {
684  std::cout << "Rocstar:" << std::endl
685  << "Rocstar: ================================================================" << std::endl
686  << "Rocstar: System Time Step : " << param.cur_step << " PC(" << iPredCorr << ")" << std::endl
687  << "Rocstar: ================================================================" << std::endl
688  << "Rocstar:" << std::endl
689  << "Rocstar: CurrentTime, CurrentTimeStep";
690  if(verb > 1)
691  std::cout << ", ZoomFactor";
692  std::cout << ": "
693  << param.current_time << " "
694  << param.time_step << " ";
695  if(verb > 1)
696  std::cout << param.zoomFactor;
697  std::cout << std::endl << "Rocstar:" << std::endl;
698  }
699 
700  MPI_Barrier(param.communicator);
701  // if(comm_rank == 0)
702  // std::cout << "Rocstar: initializing convergence checking" << std::endl;
703  if ( with_pciter)
704  coup->init_convergence( iPredCorr);
705  MPI_Barrier(param.communicator);
706  // if(comm_rank == 0)
707  // std::cout << "Rocstar: convergence checking initialized" << std::endl;
708 
709  // invoke time integration of coupling scheme by passing in
710  // current time and desired time step and obtaining new time
711  MPI_Barrier(param.communicator);
712  // if(comm_rank == 0)
713  // std::cout << "Rocstar: Running coupling.." << std::endl;
714  double new_current_time = coup->run( param.current_time, param.time_step,
715  iPredCorr, param.zoomFactor);
716 
717  // Check for interrupt
718  check_for_interrupt(coup,param);
719 
720  // std::cout << comm_rank << ": solver done on this rank." << std::endl;
721  MPI_Barrier(param.communicator);
722  // if(comm_rank == 0)
723  // std::cout << "Rocstar: coupling done." << std::endl;
724 
725  InterfaceConverged = 1;
726  if ( with_pciter)
727  InterfaceConverged = coup->check_convergence();
728 
729  if ( comm_rank == 0 && debug )
730  std::cout << "Rocstar:" << std::endl
731  << "Rocstar: iPredCorr = " << iPredCorr << " is done" << std::endl;
732  if ( InterfaceConverged ) {
733  param.current_time = new_current_time;
734  if ( comm_rank == 0 && verb > 1)
735  std::cout << "Rocstar: Success: predictor-corrector converged at time " << param.current_time << std::endl;
736  break;
737  }
738  else {
739  if ( comm_rank == 0 && debug ) {
740  std::cout << "Rocstar:" << std::endl
741  << "Rocstar: Interface has -NOT- converged!" << std::endl
742  << "Rocstar: iPredCorr = " << iPredCorr << " is done" << std::endl;
743  }
744  }
745  } // end of iPredCorr
746 
747  // New function to parse flags set by interrupt returns false if no action
748  if(coup->ProcessInterrupt())
749  continue;
750 
751  if ( !InterfaceConverged) {
752  if (comm_rank == 0)
753  std::cerr << "Rocstar: Disaster: predictor-corrector did not converge" << std::endl;
754  MPI_Abort( MPI_COMM_WORLD, -1);
755  }
756 
757 #if 0
758  // warm restart at step 3
759  if (param.cur_step == 320) {
760  static int didit = 0; // do it only once
761  if (!didit) {
762  coup->restart_at_time(param.LastOutputTime, param.LastOutputStep);
763  didit = 1;
764  continue; // skip the rest !
765  }
766  }
767 #endif
768 
769  // if reached time for restart dump
770  if ( reached_restartdump_time( param) ) {
771  MPI_Barrier(param.communicator);
772  // Compute integrals and write them into files for conservation-check
773  coup->update_integrals( param.current_time);
774  coup->update_distances( param.current_time);
775 
776  // invoke restart output (as well as visualization data)
777  if(comm_rank == 0 && verb > 0)
778  std::cout << "Rocstar: Dumping restart files... " << std::endl;
779  coup->output_restart_files( param.current_time);
780  coup->write_restart_info( param.current_time, param.cur_step+1);
781  param.LastOutputTime = param.current_time;
782  param.LastOutputStep = param.cur_step;
783  param.current_dump++;
784  MPI_Barrier(param.communicator);
785  //if(comm_rank == 0)
786  //std::cout << "done." << std::endl;
787  }
788  else if ( reached_visdump_time( param)) {
789  if(comm_rank == 0 && verb > 0)
790  std::cout << "Rocstar: Dumping coupling viz files." << std::endl;
791  // output visualization files
793  }
794 
795  // Write out profile data
796  if ( param.cur_step <= 100 || param.LastOutputTime == param.current_time) {
797  sprintf(header, "************** Solver times up to time step %d since last output *********\n", param.cur_step);
798  COM_print_profile( param.timingDataFile.c_str(), header);
799  COM_set_profiling( 1); // Reset profiler;
800  }
801  //if(comm_rank == 0)
802  //std::cout << "Rocstar:" << std::endl;
803  } // end time step
804 
805  // Write final solution.
806  if (param.current_time != param.LastOutputTime) {
807  MPI_Barrier(param.communicator);
808  if(comm_rank == 0 && verb > 0)
809  std::cout << "Rocstar: Performing final dump..." << std::endl;
810  coup->output_restart_files( param.current_time);
811  coup->write_restart_info( param.current_time, std::min(param.cur_step, param.maxNumTimeSteps)+1);
812  MPI_Barrier(param.communicator);
813  if(comm_rank == 0 && debug)
814  std::cout << "Rocstar: done." << std::endl;
815  }
816 
817  // Finalize coupling
818  coup->finalize();
819 
820 #ifdef WITH_PANDA
821  // unload Rocpanda to exit gracefully
822  if ( strcasecmp(param.output_module, "Rocpanda") == 0) {
823  MAN_DEBUG(3, ("[%d] Rocstar: unload_module Rocpanda.\n", param.myRank));
824  COM_UNLOAD_MODULE_STATIC_DYNAMIC( Rocpanda, "OUT");
825  }
826 #endif
827 
828  // Write out the final profile data
829  sprintf(header, "************** Finalization times after time step %d *****************\n", param.cur_step);
830  COM_print_profile( param.timingDataFile.c_str(), header);
831 
832  delete coup;
833 }
834 
835 void init_profiling(Control_parameters &param, int comm_rank)
836 {
837  std::string fname = "RocstarProfile";
838  int data = comm_rank;
839  int u = 10; // <0, 99>
840  int c = 2;
841  int numProcs = COMMPI_Comm_size( param.communicator);
842  while (numProcs >= u*10) {
843  u *= 10;
844  c ++;
845  }
846  for (int i=0; i<c; i++) {
847  int d = data / u;
848  data %= u;
849  u /= 10;
850  fname += ('0'+d);
851  }
852  fname += ".txt";
853  param.timingDataFile = param.timingDataDir;
854  param.timingDataFile += fname;
855 
856  int status = 1; // new
857  FILE *fd;
858  if (param.current_time == 0.0) {
859  fd = fopen( param.timingDataFile.c_str(), "w");
860  }
861  else {
862  fd = fopen( param.timingDataFile.c_str(), "r");
863  if (fd == NULL)
864  fd = fopen( param.timingDataFile.c_str(), "w");
865  else
866  status = 0; // old
867  }
868  if (fd == NULL) {
869  param.timingDataFile = "./";
870  param.timingDataFile += fname;
871  if (param.current_time == 0) {
872  fd = fopen( param.timingDataFile.c_str(), "w");
873  }
874  else {
875  fd = fopen( param.timingDataFile.c_str(), "r");
876  if (fd == NULL)
877  fd = fopen( param.timingDataFile.c_str(), "w");
878  else
879  status = 0;
880  }
881  if (fd == NULL) {
882  std::cerr << "Rocstar: Rank " << comm_rank << " could not open "
883  << param.timingDataFile.c_str() << "!" << std::endl;
884  MPI_Abort( MPI_COMM_WORLD, -1);
885  }
886  else if(param.controlVerb > 1)
887  printf("Rocstar: Rank %d using %s instead for timing data!\n", comm_rank, param.timingDataFile.c_str());
888  }
889 
890  int NumProcs;
891  NumProcs = COMMPI_Comm_size( param.communicator);
892 
893  if (param.current_time == 0.0 || status == 1) {
894  fprintf(fd, "\n");
895  fprintf(fd, "Number of processors = %d\n", NumProcs);
896  fprintf(fd, "\n");
897  fprintf(fd, "MyId = %d\n", comm_rank);
898  fprintf(fd, "\n");
899  }
900  fclose(fd);
901 }
902 
903 // print double data of an attribute on a pane
904 void debug_print(const std::string str, int pane, int pe, MPI_Comm comm, const char *memo)
905 {
906  int comm_rank = COMMPI_Comm_rank(comm);
907  if (comm_rank == pe) {
908  double *vm;
909  int strid, cap;
910  printf("%s %s: before %p\n", str.c_str(), memo?memo:"", vm);
911  COM_get_array(str.c_str(), pane, &vm, &strid, &cap);
912  printf("%s %s: after %p \n", str.c_str(), memo?memo:"", vm);
913  for (int i=0; i<strid*cap; i++) printf("%.17e ", vm[i]);
914  printf("\n");
915  }
916 }
917 
918 void debug_int_print(const std::string str, int pane, int pe, MPI_Comm comm, const char *memo)
919 {
920  int comm_rank = COMMPI_Comm_rank(comm);
921  if (comm_rank == pe) {
922  int *vm;
923  int strid, cap;
924  printf("%s %s: before %p\n", str.c_str(), memo?memo:"", vm);
925  COM_get_array(str.c_str(), pane, &vm, &strid, &cap);
926  printf("%s %s: after %p \n", str.c_str(), memo?memo:"", vm);
927  for (int i=0; i<strid*cap; i++) printf("%d ", vm[i]);
928  printf("\n");
929  }
930 }
931 
932 
933 
934 
935 
936 
int COMMPI_Comm_rank(MPI_Comm c)
Definition: commpi.h:162
virtual void update_integrals(double currentTime)
Definition: Coupling.h:174
char burn_module[MAXLEN]
Definition: Coupling.h:48
void update_start_time(int step, double t)
void init_profiling(Control_parameters &param, int comm_rank)
void COM_set_debug(bool debug)
Definition: roccom_c++.h:546
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
void write_restart_info(double CurrentTime, int iStep)
Definition: Coupling.C:337
void rocstar_driver(int verb, int remeshed, bool debug)
double time_step
Definition: Coupling.h:55
const NT & d
double init_time
Definition: Coupling.h:53
double simue_time
Definition: Coupling.h:52
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
#define COM_DOUBLE_ATTRIBUTE(attrname, varname)
#define COM_assertion_msg(EX, msg)
void RocstarShutdown(int=0)
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
int check_convergence()
Definition: Coupling.C:284
double get_restart_time(const string &restart_file)
void COM_set_default_communicator(MPI_Comm comm)
Definition: roccom_c++.h:67
double tolerTract
Definition: Coupling.h:66
#define COM_STRING_ATTRIBUTE(attrname, varname)
void COM_get_array(const char *wa_str, int pane_id, void **addr, int *strd, int *cap)
Get the address for an attribute on a specific pane.
A Roccom mesh optimization module.
Definition: Rocmop.h:41
static void init()
Definition: Coupling.C:87
double maxwalltime
Definition: Coupling.h:56
char coupling_scheme[MAXLEN]
Definition: Coupling.h:45
MPI_Comm communicator
Definition: Coupling.h:51
int fclose(std::FILE *file)
Close a file, and check for possible errors.
Definition: CImg.h:5507
int maxNumPredCorrCycles
Definition: Coupling.h:60
void COM_set_verbose(int i)
Definition: roccom_c++.h:543
void debug_int_print(const std::string str, int pane, int pe, MPI_Comm comm, const char *memo=NULL)
void output_visualization_files(double t)
Definition: Coupling.C:306
void restart_at_time(double t, int step)
Definition: Coupling.C:372
double tolerMass
Definition: Coupling.h:68
void schedule()
Schedule the top-level actions of the coupling scheme and the actions of the agents.
Definition: Coupling.C:181
bool reached_visdump_time(const Control_parameters &param)
int COMMPI_Comm_size(MPI_Comm c)
Definition: commpi.h:165
int ProcessInterrupt()
Definition: Coupling.C:572
void init_convergence(int iPredCorr)
Definition: Coupling.C:275
int man_verbose
void read(MPI_Comm comm, int commrank)
char output_module[MAXLEN]
Definition: Coupling.h:49
char timingDataDir[MAXLEN]
Definition: Coupling.h:71
void Interrupt(int *, const char *)
Definition: Coupling.C:480
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
double LastOutputTime
Definition: Coupling.h:76
void COM_finalize()
Definition: roccom_c++.h:59
int strcasecmp(const char *const s1, const char *const s2)
Compare two C-strings, ignoring the case.
Definition: CImg.h:4928
virtual void update_distances(double currentTime)
Definition: Coupling.h:175
void COM_print_profile(const char *fname, const char *header)
Definition: roccom_c++.h:557
double tolerVelo
Definition: Coupling.h:67
Definition: Rocin.h:64
Definition: Rocout.h:81
bool reached_restartdump_time(Control_parameters &param)
blockLoc i
Definition: read.cpp:79
double zoomFactor
Definition: Coupling.h:64
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
Coupling * create_coupling(Control_parameters &param, const RocmanControl_parameters &rocman_param)
void debug_print(const std::string str, int pane, int pe, MPI_Comm comm, const char *memo=NULL)
bool reached_simulation_time(const Control_parameters &param)
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_set_profiling(int i)
Definition: roccom_c++.h:550
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
double tolerDisp
Definition: Coupling.h:69
std::string timingDataFile
Definition: Coupling.h:72
double run(double t, double dt, int iPredCorr, double zoom)
Invoke the scheduler.
Definition: Coupling.C:238
void output_restart_files(double t)
Definition: Coupling.C:299
#define MAN_DEBUG(l, x)
Definition: rocman.h:98
double current_time
Definition: Coupling.h:54
Definition: Rocon.H:61
double startTime
Definition: Coupling.h:87
void finalize()
Invoke finalization of the actions in the scheduler and the agents.
Definition: Coupling.C:230
#define COM_BOOL_ATTRIBUTE(attrname, varname)
void initialize(int reinit=0)
Definition: Coupling.C:355
std::FILE * fopen(const char *const path, const char *const mode)
Open a file, and check for possible errors.
Definition: CImg.h:5494
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428
void read_restart_info()
Definition: Coupling.C:313
int check_for_interrupt(Coupling *coup, const Control_parameters &param)
char fluid_module[MAXLEN]
Definition: Coupling.h:46
char solid_module[MAXLEN]
Definition: Coupling.h:47
#define COM_INT_ATTRIBUTE(attrname, varname)
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116
double outputIntervalTime
Definition: Coupling.h:63