Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Coupling.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: Coupling.C,v 1.53 2008/12/06 08:45:22 mtcampbe Exp $
24 
25 #include "rocman.h"
26 
28 COM_EXTERN_MODULE(Rocface);
31 
32 class SolidAgent;
33 class FluidAgent;
34 
35 void RocstarShutdown(int = 0);
36 #ifdef ARM
37 int Rocrem_remesh(const char* solver, const char* indir, const char* outdir,
38  double time, bool pt,bool remesh_surf,
39  bool transfer_surf, double scaleFactor, MPI_Comm myComm,
40  int fieldWidth, int fileBase, int debug, int ngLayers);
41 #endif
42 
43 int RocBlas::copy_scalar = 0;
44 int RocBlas::copy = 0;
45 int RocBlas::add = 0;
46 int RocBlas::sub = 0;
47 int RocBlas::div_scalar = 0;
48 int RocBlas::limit1 = 0;
49 int RocBlas::sub_scalar = 0;
50 int RocBlas::axpy_scalar = 0;
51 int RocBlas::mul = 0;
52 int RocBlas::div = 0;
53 int RocBlas::neg = 0;
54 int RocBlas::axpy = 0;
55 int RocBlas::nrm2 = 0;
56 int RocBlas::mul_scalar = 0;
61 int RocBlas::maxof_scalar = 0;
62 
63 
65 {
66  copy_scalar = COM_get_function_handle( "BLAS.copy_scalar");
67  sub_scalar = COM_get_function_handle( "BLAS.sub_scalar");
68  copy = COM_get_function_handle( "BLAS.copy");
69  add = COM_get_function_handle( "BLAS.add");
70  sub = COM_get_function_handle( "BLAS.sub");
71  axpy = COM_get_function_handle( "BLAS.axpy");
72  limit1 = COM_get_function_handle( "BLAS.limit1");
73  mul = COM_get_function_handle( "BLAS.mul");
74  div = COM_get_function_handle( "BLAS.div");
75  neg = COM_get_function_handle( "BLAS.neg");
76  nrm2 = COM_get_function_handle( "BLAS.nrm2");
77  div_scalar = COM_get_function_handle( "BLAS.div_scalar");
78  axpy_scalar = COM_get_function_handle( "BLAS.axpy_scalar");
79  mul_scalar = COM_get_function_handle( "BLAS.mul_scalar");
80  max_scalar_MPI = COM_get_function_handle( "BLAS.max_scalar_MPI");
81  min_scalar_MPI = COM_get_function_handle( "BLAS.min_scalar_MPI");
82  sum_scalar_MPI = COM_get_function_handle( "BLAS.sum_scalar_MPI");
83  nrm2_scalar_MPI = COM_get_function_handle( "BLAS.nrm2_scalar_MPI");
84  maxof_scalar = COM_get_function_handle( "BLAS.maxof_scalar");
85 }
86 
88 {
90  initHandles();
91 }
92 
94 {
95  iPredCorr = 0;
97  restarting = 0;
100  restartInfo = "Restart.txt";
101  integFname = "Rocman/Modout/GENX_integ.txt";
102  distFname = "Rocman/Modout/GENX_dist.txt";
104  if ( param->current_time != 0.0) {
105  FILE *fp = fopen(integFname.c_str(), "r");
106  if (!fp) overwrite_integ = 1;
107  fp = fopen(distFname.c_str(), "r");
108  if (!fp) overwrite_dist = 1;
109  }
110  else {
111  overwrite_integ = 1;
112  overwrite_dist = 1;
113  }
114  // experimental Interrupt
115  std::string manwinname = "Rocman";
116  std::string manfuncname = manwinname+".interrupt";
117  std::string coupobjname = manwinname+".coup";
118  COM_Type types[3];
119  types[0] = COM_RAWDATA;
120  types[1] = COM_INT;
121  types[2] = COM_STRING;
122  COM_new_window(manwinname);
123  COM_new_attribute(coupobjname, 'w',COM_VOID, 1, "");
124  COM_set_object(coupobjname.c_str(),0,this);
125  COM_set_member_function(manfuncname.c_str(),
126  (Member_func_ptr)&Coupling::Interrupt,
127  coupobjname.c_str(),"bii",types);
128 }
129 
130 Coupling::Coupling(const char *coupl_name, const char *name,
131  Control_parameters *param_,
132  const RocmanControl_parameters *mp):
133  coupling_name(coupl_name), param(param_), rocmanparam(mp)
134 {
135  modules.push_back(name);
136  baseInit();
137 }
138 
139 Coupling::Coupling(const char *coupl_name, const char *fluidname,
140  const char *solidname,
141  Control_parameters *param_,
142  const RocmanControl_parameters *mp):
143  coupling_name(coupl_name), param(param_), rocmanparam(mp)
144 {
145  modules.push_back(fluidname);
146  modules.push_back(solidname);
147  baseInit();
148 }
149 
150 Coupling::Coupling(const char *coupl_name, const char *fluidname,
151  const char *solidname, const char *burnname,
152  Control_parameters *param_,
153  const RocmanControl_parameters *mp):
154  coupling_name(coupl_name), param(param_), rocmanparam(mp)
155 {
156  modules.push_back(fluidname);
157  modules.push_back(solidname);
158  modules.push_back(burnname);
159  baseInit();
160 }
161 
162 // Delete all agents
164  for ( int i=0, n=agents.size(); i<n; ++i) {
165  delete agents[i];
166  }
167  agents.clear();
168 }
169 
170 int Coupling::new_start(double t) const {
171  return t==0.0 || (rocmanparam->remeshed && t == param->init_time);
172 }
173 
175 {
176  agents.push_back(agent);
177  return agent;
178 }
179 
180 // Schedule the actions for the scheduler and the agents
184 
185  for ( int i=0, n=agents.size(); i<n; ++i) {
186  agents[i]->schedule();
187  }
188 }
189 
190 // Invoke initialization of the actions in the scheduler and the agents
191 void Coupling::init( double t, double dt, int reinit) {
192  int i, n;
193 
194 #if 0
195  for ( i=0, n=agents.size(); i<n; ++i)
196  agents[i]->init_module( t);
197 
198  for ( i=0, n=agents.size(); i<n; ++i)
199  agents[i]->init_buffers( t);
200 #else
201 // void _load_rocface(FluidAgent *fagent, SolidAgent *sagent, const RocmanControl_parameters *param);
202  for ( i=0, n=agents.size(); i<n; ++i) {
203 // if (i==2) _load_rocface(agents[0], agents[1], rocmanparam);
204  agents[i]->init_module( t, dt);
205 // agents[i]->init_buffers( t);
206  }
207 #endif
208 
209  // in warm restart, reset scheduler so that it can be re-inited
210  if (reinit)
212 
214 }
215 
216 // invoke method fn to all schedulers, and all schedulers of agents
218 {
219  int i, n;
220 
221  (init_scheduler.*fn)( t);
222 
223  for ( i=0, n=agents.size(); i<n; ++i)
224  agents[i]->callMethod(fn, t);
225 
226  (scheduler.*fn)( t);
227 }
228 
229 // Invoke finalize of the actions in the scheduler and the agents
233 
234  for ( int i=0, n=agents.size(); i<n; ++i)
235  agents[i]->finalize();
236 }
237 
238 double Coupling::run( double t, double dt, int pred, double zoom)
239 {
240  iPredCorr = pred;
241 
242  // Change dt to the maximum time setp allowed.
243  for ( int i=0, n=agents.size(); i<n; ++i) {
244  dt = std::min( dt, agents[i]->max_timestep(t, dt));
245  }
246 
247  MAN_DEBUG(3, ("[%d] Rocstar: Coupling::run with t: %f dt: %f.\n", comm_rank, t, dt));
248 
249  scheduler.run_actions( t, dt);
250 
251  // Return the new time as t + dt
252  if (zoom > 0.0)
253  return t + dt*zoom;
254  else
255  return t + dt;
256 }
257 
258 void Coupling::run_initactions( double t, double dt)
259 {
260  MAN_DEBUG(3, ("[%d] Rocstar: %s::run_initactions called with t:%e dt:%e.\n", comm_rank, name(), t, dt));
262  init_scheduler.run_actions( t, dt);
263 
264  init_started = 0;
265  init_remeshed = 0;
266 }
267 
268 // Invoke input functions of the agents
269 void Coupling::input( double t) {
270  for ( int i=0, n=agents.size(); i<n; ++i) {
271  agents[i]->input( t);
272  }
273 }
274 
275 void Coupling::init_convergence( int iPredCorr)
276 {
277  if ( maxPredCorr>1 && iPredCorr > 0) {
278  for ( int i=0, n=agents.size(); i<n; ++i) {
279  agents[i]->init_convergence( iPredCorr);
280  }
281  }
282 }
283 
285 {
286  int InterfaceConverged;
287  if ( maxPredCorr>1) {
288  InterfaceConverged = 0;
289  for ( int i=0, n=agents.size(); i<n; ++i)
290  if (!agents[i]->check_convergence( param->tolerMass, param->tolerTract, param->tolerVelo)) return InterfaceConverged;
291  InterfaceConverged = 1;
292  }
293  else
294  InterfaceConverged = 1;
295  return InterfaceConverged;
296 }
297 
298 // Write out restart files (including visualization data)
300  for ( int i=0, n=agents.size(); i<n; ++i) {
301  agents[i]->output_restart_files( t);
302  }
303 }
304 
305 // Write out visualization files
307  for ( int i=0, n=agents.size(); i<n; ++i) {
308  agents[i]->output_visualization_files( t);
309  }
310 }
311 
312 // find restart time from Restart.txt
314 {
315  if (param->current_time != 0.0) {
316  FILE *fp = fopen(restartInfo.c_str(), "r");
317  if (fp == NULL) {
318  std::cerr << "Rocstar: Error: READ_RESTART: Failed to read file " << restartInfo << std::endl;
319  MPI_Abort( MPI_COMM_WORLD, -1);
320  }
321  int curStep;
322  double initialTime;
323  while (!feof(fp)) {
324  fscanf(fp, "%d %le", &curStep, &initialTime);
325  }
326  fclose(fp);
327  if (comm_rank == 0)
328  MAN_DEBUG(1,("Rocstar: This run is a restart continued at iteration %d with initial time %f.",curStep, initialTime));
329  param->update_start_time(curStep - 1, initialTime); // subtle - it starts from 0
330  }
331  else {
332  if (comm_rank == 0)
333  MAN_DEBUG(2,("Rocstar: This run is not a restart.\n"));
334  }
335 }
336 
337 void Coupling::write_restart_info(double CurrentTime, int iStep)
338 {
339  FILE *fp;
340  if ( comm_rank == 0 ) {
341  if ( CurrentTime == 0.0)
342  fp = fopen(restartInfo.c_str(), "w");
343  else
344  fp = fopen(restartInfo.c_str(), "a");
345  if (fp == NULL) {
346  std::cerr << "Rocstar: Error: Failed to open restart info file, "
347  << restartInfo << "." << std::endl;
348  MPI_Abort( MPI_COMM_WORLD, -1);
349  }
350  fprintf( fp, "%d %.20le \n", iStep, CurrentTime);
351  fclose( fp);
352  }
353 }
354 
355 void Coupling::initialize(int reinit)
356 {
357  // invoke input of coupling object (Input of initial data of physics modules)
359 
360  // invoke initialization of coupling object, load modules
361  init( param->current_time, param->time_step, reinit);
362 
363  // reset rocface if restart
364  if (reinit)
366 
367  // initialize each modules by executing init schedulers
369 }
370 
371 // experimental code
372 void Coupling::restart_at_time(double t, int step)
373 {
374  int i, n;
375 
376  MAN_DEBUG(3, ("Rocstar: Coupling::restart_at_time with t: %f step:%d.\n", t, step));
377 
378 #if 0
379  // HACK
380  system("rm RocburnAPN/Rocout/*");
381  if (comm_rank == 0) {
382  system("rm RocburnAPN/Rocout/*");
383  }
384  MPI_Barrier(get_control_param()->communicator);
385 #endif
386 
387  restarting = 1;
388 
389  // reset windows and buffers
390  finalize();
391 
392  // unload modules, only call unload to zero out data, skip dlclose
393  for ( i=0, n=agents.size(); i<n; ++i) {
394  agents[i]->unload_module();
395  }
396 
397  if (COM_get_window_handle("RFC") > 0) {
398  COM_UNLOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
399  }
400  if (COM_get_window_handle("SURF") > 0) {
401  COM_UNLOAD_MODULE_STATIC_DYNAMIC( Rocsurf, "SURF");
402  }
403  if (COM_get_window_handle("PROP") > 0) {
405  }
406  if (COM_get_window_handle("PROPCON") > 0) {
408  }
409  if (COM_get_window_handle("BLAS") > 0) {
411  }
412  if (COM_get_window_handle("MAP") > 0) {
413  COM_UNLOAD_MODULE_STATIC_DYNAMIC(Rocmap,"MAP");
414  }
415  // update to given time
416  param->update_start_time( step, t);
417 
418  // load module and call physics routine
419  for ( i=0, n=agents.size(); i<n; ++i) {
420  agents[i]->load_module();
421  }
422 
423  // proceed to initialization phase
424  initialize(1); // reinit
425 
426 /*
427  // read restart data
428  for ( i=0, n=agents.size(); i<n; ++i) {
429  agents[i]->read_restart_data();
430  }
431 */
432  restarting = 0;
433 }
434 
435 // print in GDL
436 void Coupling::print(const char *fname)
437 {
438  FILE *f = fopen(fname, "w");
439 
440  fprintf(f, "graph: { title: \"Coupling\" \n\
441  display_edge_labels: yes \n\
442  layoutalgorithm: tree \n\
443  scaling: maxspect \n\
444  node.color : green \n\
445  node.textcolor : black \n\
446  node.bordercolor: black \n\
447  node.borderwidth: 1 \n\
448  edge.color : blue \n\
449  edge.arrowsize : 7 \n\
450  edge.thickness : 2 \n\
451  edge.fontname:\"helvO08\" \n\
452  node.label: \"no type\" \n");
453 
454 // scheduler.print(f, name());
455  for (unsigned int i=0; i<agents.size(); i++) {
456  agents[i]->print(f);
457  if (i>0) fprintf(f, "edge: { sourcename: \"%s\" targetname: \"%s\" label: \"\"}\n", agents[i-1]->get_agent_name().c_str(), agents[i]->get_agent_name().c_str());
458  }
459 
460  fprintf(f, "} \n");
461  fclose(f);
462 }
463 
464 std::string Coupling::normalize_modname(const char* modname)
465 {
466  std::string mod = modname;
467  if (mod == "RocfluDummy")
468  return "Rocflu";
469  if (mod == "RocfloDummy")
470  return "Rocflo";
471  if (mod == "RocfracDummy")
472  return "Rocfrac";
473  if (mod == "RocsolidDummy")
474  return "Rocsolid";
475  return mod;
476 }
477 
478 
479 // experimental code
480 void Coupling::Interrupt(int *act,const char *message)
481 {
482  int action = *act;
483  if(!param->myRank){
484  std::cout << "Rocstar::Interrupt invoked." << std::endl
485  << "Rocstar: ***************************************************"
486  << std::endl
487  << "Rocstar: " << (message ? message : "") << std::endl
488  << "Rocstar: ***************************************************"
489  << std::endl;
490  }
491  switch(action){
492  case 0:
493  // Just stop
494  if(!param->myRank)
495  std::cout << "Rocstar: Halting simulation." << std::endl;
496  finalize();
497  RocstarShutdown();
498  break;
499  case 1:
500  // Output solutions and stop.
501  if(!param->myRank)
502  std::cout << "Rocstar: Writing restart files and halting simulation."
503  << std::endl;
505  finalize();
506  RocstarShutdown();
507  break;
508  case 2:
509  //
510  // Restart from last restart dump and increase the output
511  // frequency for debugging.
512  //
513  // 0. Call warm restart function to junk current data, and
514  // re-initialize with last successful solution dump
515  // 1. Reset the max number of timesteps and output interval
516  // 2. Code will stop and dump a soln when it reaches the step just prior
517  // to this one
518  //
519  if(!param->myRank){
520  std::cout << "Rocstar: Directed to warm restart from last dump "
521  << "and increase dump frequency." << std::endl;
522  }
523  param->InterruptFlag = 2;
524  break;
525  case 3:
526  if(!param->myRank)
527  std::cout << "Rocstar: Directed to remesh and warm restart from "
528  << "(time/step): ("
529  << param->LastOutputTime << "," << param->LastOutputStep
530  << ")" << std::endl;
531  param->InterruptFlag = 3;
532  break;
533  case 4:
534  if(!param->myRank)
535  std::cout << "Rocstar: Directed to restart from "
536  << "(time/step): (" << param->LastOutputTime << ","
537  << param->LastOutputStep << ")" << std::endl;
538  if(message)
539  std::cout << "MESSAGE: " << message << std::endl;
540  param->InterruptFlag = 4;
541  break;
542  case 5:
543  if(!param->myRank)
544  std::cout << "Rocstar: Directed to dump at (time/step): ("
545  << param->current_time << "," << param->cur_step
546  << ")" << std::endl;
549  break;
550  case 6:
551  if(!param->myRank)
552  std::cout << "Rocstar: Directed to dump and restart at (time/step): ("
553  << param->current_time << "," << param->cur_step
554  << ")" << std::endl;
557  if(message)
558  std::cout << "MESSAGE: " << message << std::endl;
559  param->InterruptFlag = 4;
560  break;
561  default:
562  if(param->myRank == 0)
563  std::cout << "Rocstar: Unknown interrupt action." << std::endl;
564  MAN_DEBUG(0,("Rocstar: Coupling::Interrupt(unknown action): %s.\n",
565  message));
566  return;
567  }
568 }
569 
570 
571 int
573 {
574  int save_step = 0;
575  bool done = false;
576  int fluid_agent_index = 0;
577  int action = param->InterruptFlag;
578  param->InterruptFlag = 0;
579  if(action > 0){
580  if(param->myRank == 0)
581  std::cout << "Rocstar: Processing interrupt." << std::endl;
582  switch(action){
583  case 2:
584  save_step = param->cur_step;
586  param->maxNumTimeSteps = save_step;
587  param->outputIntervalTime /= 10.0;
588  if(!param->myRank){
589  std::cout << "Rocstar: Restarting from (time/step): ("
590  << param->current_time << "," << param->cur_step
591  << ") with output"
592  << " interval, " << param->outputIntervalTime << "."
593  << std::endl;
594  }
595  return(1);
596  break;
597  case 3:
598  for(int i = 0,n=agents.size();i<n && !done;n++){
599  std::string::size_type x = agents[i]->get_agent_name().find("lu");
600  if( x != string::npos){
601  fluid_agent_index = i;
602  done = true;
603  }
604  }
605  if(!done){
606  std::cerr << "Rocstar: Could not find fluid agent. Dying."
607  << std::endl;
608  RocstarShutdown(1);
609  }
610  // char* solver: Path to Rocout directory (i.e. blah/blah/Rocflu)
611  // double time: timestep to read
612  // bool use_parallel_transfer
613  // bool remesh_surf: true=remesh surface false=leave surface alone
614  // bool transfer_surf: true (only valid if remesh_surf = false)
615  // double scaleFactor: scale mesh granularity
616  // int fieldWidth: digits in filename partition id
617  // int fileBase: 0 is partition ids start at 0, 1 otherwise
618  // int debug: 0=off, 1 = some, more = more
619  // int ngLayers: number of ghost layers; 0-9
620  // returns 1 if success; 0 if fail
621  // Rocrem_remesh(const char* solver, double time, bool remesh_surf,
622  // bool transfer_surf, double scaleFactor, MPI_Comm myComm,
623  // int fieldWidth, int fileBase, int debug, int ngLayers)
624  //
625  // Remeshing test case
626  //
627 #ifdef ARM
628  if(!Rocrem_remesh("Rocflu","Rocout","",param->LastOutputTime,true,true,false,1.0,
629  agents[fluid_agent_index]->get_communicator(),
630  4,0,2,2)){
631  if(!param->myRank)
632  std::cerr << "Rocstar: Remeshing failed. Stopping simulation."
633  << std::endl;
634  RocstarShutdown(1);
635  }
636 #else
637  if(!param->myRank){
638  // std::ofstream Ouf;
639  // Ouf.open("needs_remesh");
640  // Ouf.close();
641  std::cerr << "Rocstar: Online remeshing not enabled. Shutting down." << std::endl;
642  }
643  RocstarShutdown(1);
644 #endif
645  MPI_Barrier(MPI_COMM_WORLD);
647  MPI_Barrier(MPI_COMM_WORLD);
648  if(!param->myRank)
649  std::cout << "Rocstar: Restarting after remesh at (time/step): ("
650  << param->current_time << "," << param->cur_step << ")"
651  << std::endl;
652  return(1);
653  break;
654  case 4:
655  MPI_Barrier(MPI_COMM_WORLD);
657  MPI_Barrier(MPI_COMM_WORLD);
658  if(!param->myRank)
659  std::cout << "Rocstar: Warm restarting at (time/step): ("
660  << param->current_time << "," << param->cur_step << ")"
661  << std::endl;
662  return(1);
663  break;
664  default:
665  if(!param->myRank)
666  std::cout << "Rocstar: Unknown interrupt action: " << action << "."
667  << std::endl;
668  return(0);
669  break;
670  }
671  }
672  return(0);
673 }
674 
675 // Compute the integrals and dump into a file.
676 void FullyCoupling::update_integrals(double currentTime)
677 {
678  int i, n, count=0;
679  for ( i=0, n=agents.size(); i<n; ++i) {
680  count += agents[i]->compute_integrals();
681  }
682 
683  if ( comm_rank == 0 && count == 2) {
684  FILE *fp;
685  if ( overwrite_integ)
686  fp = fopen(integFname.c_str(), "w");
687  else
688  fp = fopen(integFname.c_str(), "a");
689  if (fp == NULL) {
690  std::cerr << "Rocstar: Failed to open integral file, "
691  << integFname << "." << std::endl;
692  MPI_Abort( MPI_COMM_WORLD, -1);
693  }
694  MAN_DEBUG(3, ("Rocstar: FullyCoupling::update_integrals with t: %f.\n", currentTime));
695  if ( overwrite_integ) {
696  fprintf( fp, " time f-volume s-volume f-mass s-mass f-burn area s-burn area f-non-burn area s-non-burn area s-volume-undef\n");
697  overwrite_integ = 0;
698  }
699  double *f_integrals = fluid_agent->get_integrals();
700  double *s_integrals = solid_agent->get_integrals();
701  fprintf( fp, "%.18le %.18le %.18le %.18le %.18le %.18le %.18le %.18le %.18le %.18le\n",
702  currentTime,
703  f_integrals[MAN_INTEG_VOL], s_integrals[MAN_INTEG_VOL],
704  f_integrals[MAN_INTEG_MASS], s_integrals[MAN_INTEG_MASS],
705  f_integrals[MAN_INTEG_IBAREA], s_integrals[MAN_INTEG_IBAREA],
706  f_integrals[MAN_INTEG_INBAREA], s_integrals[MAN_INTEG_INBAREA],
707  f_integrals[MAN_INTEG_VOL_UND]);
708 
709  fclose( fp);
710  }
711 }
712 
713 // Compute the distances between fluid and solid meshes and dump into a file.
714 void FullyCoupling::update_distances(double currentTime)
715 {
716  double dist_max=-1, dist_min=-1, dist_nrm2=-1;
717 
719 
720  int RFC_interpolate = COM_get_function_handle("RFC.interpolate");
721  COM_call_function( RFC_interpolate, &solid_agent->y_hdl, &fluid_agent->nc_tmp_hdl);
724  COM_call_function( RocBlas::max_scalar_MPI, &fluid_agent->sq_dist_hdl, &dist_max, &communicator);
725  COM_call_function( RocBlas::min_scalar_MPI, &fluid_agent->sq_dist_hdl, &dist_min, &communicator);
726  COM_call_function( RocBlas::sum_scalar_MPI, &fluid_agent->sq_dist_hdl, &dist_nrm2, &communicator);
727 
728  if ( comm_rank == 0) {
729  FILE *fp;
730  if ( overwrite_dist)
731  fp = fopen(distFname.c_str(), "w");
732  else
733  fp = fopen(distFname.c_str(), "a");
734  if (fp == NULL) {
735  std::cerr << "Rocstar: Failed to open distance file, " << distFname
736  << "." << std::endl;
737  MPI_Abort( MPI_COMM_WORLD, -1);
738  }
739  MAN_DEBUG(3, ("Rocstar: FullyCoupling::update_distances with t: %f.\n", currentTime));
740  if ( overwrite_dist) {
741  fprintf( fp, "# time distance-min distance-max distance-norm2 \n");
742  overwrite_dist = 0;
743  }
744  fprintf( fp, "%.18le %.18le %.18le %.18le\n",
745  currentTime, sqrt(dist_min), sqrt(dist_max), sqrt(dist_nrm2));
746 
747  fclose( fp);
748  }
749 }
750 
751 void _load_rocface(FluidAgent *fagent, SolidAgent *sagent, const RocmanControl_parameters *param);
752 
754 {
756 }
757 
758 
759 
760 
761 
762 
763 
764 
int COMMPI_Comm_rank(MPI_Comm c)
Definition: commpi.h:162
void update_start_time(int step, double t)
int COM_Type
Indices for derived data types.
Definition: roccom_basic.h:122
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
int iPredCorr
Definition: Coupling.h:110
std::string distFname
Definition: Coupling.h:123
void write_restart_info(double CurrentTime, int iStep)
Definition: Coupling.C:337
AgentList agents
Definition: Coupling.h:102
double time_step
Definition: Coupling.h:55
int sq_dist_hdl
Definition: FluidAgent.h:92
virtual void schedule()
Definition: Scheduler.C:408
int init_remeshed
Definition: Coupling.h:108
double init_time
Definition: Coupling.h:53
T mod(const T &x, const T &m)
Return the modulo of a number.
Definition: CImg.h:4788
static int limit1
Definition: RocBlas.h:37
static int axpy_scalar
Definition: RocBlas.h:45
double max_timestep(double t, double dt)
Definition: Agent.C:317
int nc_hdl
Definition: FluidAgent.h:92
std::string get_agent_name() const
Definition: Agent.h:223
void RocstarShutdown(int=0)
void print(const char *fname)
Definition: Coupling.C:436
int check_convergence()
Definition: Coupling.C:284
static int min_scalar_MPI
Definition: RocBlas.h:49
static int sum_scalar_MPI
Definition: RocBlas.h:50
double tolerTract
Definition: Coupling.h:66
void input(double t)
Invoke input functions of the agents.
Definition: Coupling.C:269
static void init()
Definition: Coupling.C:87
static int axpy
Definition: RocBlas.h:41
static int copy
Definition: RocBlas.h:34
static int div
Definition: RocBlas.h:39
Agent * add_agent(Agent *)
Add new agent.
Definition: Coupling.C:174
double sqrt(double d)
Definition: double.h:73
MPI_Comm communicator
Definition: Coupling.h:51
void COM_set_object(const char *wa_str, int pane_id, Type *addr)
Definition: roccom_c++.h:144
int fclose(std::FILE *file)
Close a file, and check for possible errors.
Definition: CImg.h:5507
virtual void update_integrals(double currentTime)
Definition: Coupling.C:676
int maxPredCorr
Definition: Coupling.h:111
static int nrm2_scalar_MPI
Definition: RocBlas.h:51
FluidAgent * fluid_agent
Definition: Coupling.h:207
void output_visualization_files(double t)
Definition: Coupling.C:306
const RocmanControl_parameters * rocmanparam
Definition: Coupling.h:114
void set_alpha(double alpha)
Definition: Scheduler.h:44
std::string integFname
Definition: Coupling.h:120
void restart_at_time(double t, int step)
Definition: Coupling.C:372
static int copy_scalar
Definition: RocBlas.h:43
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
void init(double t, double dt, int reinit=0)
Invoke initialization of the actions in the scheduler and the agents.
Definition: Coupling.C:191
int ProcessInterrupt()
Definition: Coupling.C:572
void init_convergence(int iPredCorr)
Definition: Coupling.C:275
std::string normalize_modname(const char *mod)
Definition: Coupling.C:464
Control_parameters * param
Definition: Coupling.h:113
void Interrupt(int *, const char *)
Definition: Coupling.C:480
static int add
Definition: RocBlas.h:35
double LastOutputTime
Definition: Coupling.h:76
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
Definition: Agent.h:110
std::string restartInfo
Definition: Coupling.h:116
static int mul_scalar
Definition: RocBlas.h:47
double tolerVelo
Definition: Coupling.h:67
static void initHandles()
Definition: Coupling.C:64
blockLoc i
Definition: read.cpp:79
static int neg
Definition: RocBlas.h:40
void int int REAL * x
Definition: read.cpp:74
UserScheduler init_scheduler
Definition: Coupling.h:104
void _load_rocface(FluidAgent *fagent, SolidAgent *sagent, const RocmanControl_parameters *param)
static int sub_scalar
Definition: RocBlas.h:44
const NT & n
MPI_Comm communicator
Definition: Agent.h:114
Coupling(const char *coupl_name, const char *name, Control_parameters *p, const RocmanControl_parameters *mp)
Constructor. Derived class will add actions for the coupling scheme.
Definition: Coupling.C:130
static int maxof_scalar
Definition: RocBlas.h:52
void baseInit()
Definition: Coupling.C:93
void finalize_actions()
Definition: Scheduler.C:351
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void restarting(double t)
Definition: Scheduler.h:41
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
int system(const char *const command, const char *const module_name=0)
Definition: CImg.h:4491
int new_start(double t) const
Definition: Coupling.C:170
SolidAgent * solid_agent
Definition: Coupling.h:208
void(Scheduler::* Scheduler_voidfn1_t)(double)
Definition: Scheduler.h:104
int COM_get_window_handle(const char *wname)
Definition: roccom_c++.h:404
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
void callMethod(Scheduler_voidfn1_t fn, double t)
Definition: Coupling.C:217
virtual void reload_rocface(const RocmanControl_parameters *param)
Definition: Coupling.C:753
void run_initactions(double t, double dt)
Definition: Coupling.C:258
unsigned long time()
Get the value of a system timer with a millisecond precision.
Definition: CImg.h:4605
virtual void update_distances(double currentTime)
Definition: Coupling.C:714
double run(double t, double dt, int iPredCorr, double zoom)
Invoke the scheduler.
Definition: Coupling.C:238
virtual void init_module(double t, double dt)
Definition: FluidAgent.C:159
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
int comm_rank
Definition: Coupling.h:105
virtual void reload_rocface(const RocmanControl_parameters *param)
Definition: Coupling.h:190
virtual ~Coupling()
Destructor.
Definition: Coupling.C:163
int nc_tmp_hdl
Definition: FluidAgent.h:92
PhysicsAction action
Definition: Agent.h:116
static int max_scalar_MPI
Definition: RocBlas.h:48
Definition: Rocon.H:61
double * get_integrals()
Definition: Agent.h:232
static int sub
Definition: RocBlas.h:36
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
void COM_set_member_function(const char *wf_str, Member_func_ptr func, const char *wa_str, const char *intents, const COM_Type *types)
Definition: roccom_c++.h:330
const char * name()
Definition: Coupling.h:135
int overwrite_dist
Definition: Coupling.h:122
int init_started
Definition: Coupling.h:106
void finalize()
Invoke finalization of the actions in the scheduler and the agents.
Definition: Coupling.C:230
int overwrite_integ
Definition: Coupling.h:119
MPI_Comm get_communicator() const
Definition: Agent.h:220
UserScheduler scheduler
Definition: Coupling.h:103
void init_actions(double t)
Definition: Scheduler.C:324
void run_actions(double t, double dt)
Definition: Scheduler.C:339
const Control_parameters * get_control_param()
Definition: Coupling.h:183
void initialize(int reinit=0)
Definition: Coupling.C:355
static int mul
Definition: RocBlas.h:38
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
static int div_scalar
Definition: RocBlas.h:46
void read_restart_info()
Definition: Coupling.C:313
int restarting
Definition: Coupling.h:107
vector< std::string > modules
Definition: Coupling.h:101
static int nrm2
Definition: RocBlas.h:42
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116
double outputIntervalTime
Definition: Coupling.h:63