Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rocprop.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: Rocprop.C,v 1.27 2008/12/06 08:45:28 mtcampbe Exp $
24 
25 #include "Rocprop.h"
26 #include "../Rocblas/include/Rocblas.h"
27 
28 #include "MarkerParticles_3.h"
29 #include "FaceOffset_3.h"
30 
32 
33 using namespace SURF;
34 
36  // Delete Window_manifold_2, Window, and Propagation_3 objects.
37  if ( _wm) { delete _wm; _wm = NULL; }
38  if ( _buf){ delete _buf; _buf = NULL; }
39 
40  if ( _prop) { delete _prop; _prop = NULL; }
41  if ( _rem && _rem_owner) { delete _rem; _rem = NULL; }
42 }
43 
44 void Rocprop::initialize( const COM::Attribute *pmesh, Rocsurf *rsurf)
45 {
46  COM_assertion_msg( validate_object()==0, "Invalid object");
47  COM_assertion_msg( pmesh, "Mesh must be present");
48 
49  _win = const_cast<COM::Window*>(pmesh->window());
50  _parent = rsurf;
51 
52  MPI_Comm comm = _win->get_communicator();
53  if ( COMMPI_Initialized()) _rank = COMMPI_Comm_rank(comm);
54  else _rank = 0;
55 
56  if ( _parent==NULL) {
57  // Initialize the superclass
58  Rocsurf::initialize( pmesh);
59  }
60  else {
61  // If has a parent, then use the Window_manifold_2 of parent
62  // and clear up this object's Window_manifold_2 if created.
63  if ( _wm) { delete _wm; _wm = NULL; }
64  COM_assertion_msg(rsurf->manifold(), "Manifold of parent must exist");
65  }
66 
67  // Delete propagation object
68  if ( _prop) { delete _prop; _prop = NULL; }
69 
70  // Create a buffer window to clone the coordinates but use nc and pconn.
71  if ( _buf) delete _buf;
72  _buf = new COM::Window( _win->name()+"-propbuffer", comm);
73  _buf->inherit( _win->attribute( COM::COM_CONN), "",
74  COM::Pane::INHERIT_USE, true, NULL, 0);
75  _buf->inherit( _win->attribute( COM::COM_NC), "",
76  COM::Pane::INHERIT_USE, true, NULL, 0);
77  _buf->inherit( _win->attribute( COM::COM_NC), "oldnc",
78  COM::Pane::INHERIT_CLONE, true, NULL, 0);
79  _buf->inherit( _win->attribute( COM::COM_PCONN), "",
80  COM::Pane::INHERIT_USE, true, NULL, 0);
81 
82  _buf->init_done();
83 }
84 
85 void Rocprop::perturb_mesh( COM::Attribute *pmesh, const double &alpha) {
86  COM_assertion_msg( validate_object()==0, "Invalid object");
87 
88  // If Rocprop is not yet initialized, call the initialization routine.
89  SURF::Window_manifold_2 *wm = manifold();
90  if ( wm == NULL)
91  { initialize( pmesh, _parent); wm = manifold(); }
92 
93  wm->perturb_mesh( alpha);
94 }
95 
96 void Rocprop::set_constraints( const COM::Attribute *cnstr_types) {
97  COM_assertion_msg( validate_object()==0, "Invalid object");
98  _cnstr_types = cnstr_types;
99 }
100 
101 void Rocprop::set_bounds( const COM::Attribute *bnd) {
102  COM_assertion_msg( validate_object()==0, "Invalid object");
103  _cnstr_bound = bnd;
104 }
105 
106 void Rocprop::propagate( const COM::Attribute *pmesh,
107  COM::Attribute *spds_io,
108  const double *dt,
109  COM::Attribute *du,
110  double *dt_elapsed,
111  int *code)
112 {
113  COM_assertion_msg( validate_object()==0, "Invalid object");
114 
115  // If Rocprop is not yet initialized, call the initialization routine.
116  SURF::Window_manifold_2 *wm = manifold();
117  if ( wm == NULL)
118  { initialize( pmesh, _parent); wm = manifold(); }
119 
120  COM_assertion_msg( pmesh->window() == _win,
121  "Rocprop was initialized for a different window");
122 
123  // If the propagation object is not yet created, create a default one.
124  if ( _prop == NULL) {
125  if ( _prop_method == PROP_FO)
126  _prop = new FaceOffset_3( wm, _buf);
127  else
128  _prop = new MarkerParticles_3( wm, _buf);
129  }
130 
131  // Save the coordinates into buffers
132  COM::Attribute *nc = _buf->attribute( COM::COM_NC);
133  COM::Attribute *oldnc = _buf->attribute( "oldnc");
134  Rocblas::copy( nc, oldnc);
135 
136  // Initialize constraints
137  _prop->set_constraints( _cnstr_types);
138  _prop->set_bounds( _cnstr_bound);
139  _prop->set_verbose(_verb);
140 
141  // Set tolerance for eigenvalues.
142  if ( _prop_method == PROP_FO) {
143  if ( _eig_thres>=0)
144  ((FaceOffset_3*)_prop)->set_eigen_threshold( _eig_thres);
145  if ( _courant>=0)
146  ((FaceOffset_3*)_prop)->set_courant_constant( _courant);
147  if ( _fangle_strong>=0)
148  ((FaceOffset_3*)_prop)->set_fangle_strong( _fangle_strong);
149  if ( _fangle_weak>=0)
150  ((FaceOffset_3*)_prop)->set_fangle_weak( _fangle_weak);
151  if ( _fangle_turn>=0)
152  ((FaceOffset_3*)_prop)->set_fangle_turn( _fangle_turn);
153  if ( _wf_expn>=0)
154  ((FaceOffset_3*)_prop)->set_wavefrontal_expansion( _wf_expn);
155  if ( _nrm_dfsn>=0)
156  ((FaceOffset_3*)_prop)->set_normal_diffusion( _nrm_dfsn);
157  if ( _feature_layer>=0)
158  ((FaceOffset_3*)_prop)->set_feature_layer( _feature_layer);
159  if ( _wght_scheme>=0)
160  ((FaceOffset_3*)_prop)->set_weighting_scheme( _wght_scheme);
161  if ( _smoother>=0)
162  ((FaceOffset_3*)_prop)->set_smoother( _smoother);
163  if ( _conserv>=0)
164  ((FaceOffset_3*)_prop)->set_conserve( _conserv);
165  }
166 
167  COM::Attribute *spd = spds_io ?
168  _buf->inherit( spds_io, "rpr_spd_buf",
169  COM::Pane::INHERIT_USE, true, NULL, 0) : NULL;
170  _buf->init_done( false);
171 
172  // Subcycle to take small time steps
173  double t = 0, t_rem = *dt;
174  while ( t_rem > 0 || *dt==0) {
175  // Time stepping
176  int smoothed=(_rediter>0);
177  double max_dt = _prop->time_stepping( spd, t_rem, du, &smoothed);
178 
179  if ( _verb && _rank==0)
180  std::cout << "Rocprop: Subcycling with time step " << max_dt << std::endl;
181 
182  t = *dt - (t_rem-max_dt);
183  t_rem = *dt - t;
184 
185  if ( t_rem > 0 && max_dt < *dt * _time_lb) {
186  // If code is present, then set it to nonzero value
187  // if time step is large.
188  if ( code) {
189  *code = -1;
190  std::cerr << "Rocprop: Given time step could not be reached" << std::endl;
191  break;
192  }
193  else if ( dt_elapsed==NULL) {
194  std::cerr << "Rocprop: Time step is smaller than the lower bound "
195  << *dt*_time_lb << '=' << *dt << '*' << _time_lb
196  << "\nMesh is too distorted. Stopping..." << std::endl;
197  COM_assertion( max_dt >= *dt * _time_lb); abort();
198  }
199  }
200  if ( code) *code = 0;
201 
202  // Add the dispments to the current coordinates
203  Rocblas::add( nc, du, nc);
204 
205  // Reset the speed function
206  if ( _cnstr_bound && spd && spd->is_elemental())
207  _prop->bound_facial_speed( spd);
208 
209  // If propagation method is face offsetting, then perform mesh smoothing
210  // by face offsetting with time step equal to 0.
211  if ( _prop_method == PROP_FO) {
212  for ( int i=smoothed; i<_rediter; ++i) {
213  if ( _verb && _rank==0)
214  std::cout << "Rocprop: Perform additional mesh smoothing" << std::endl;
215  _prop->time_stepping( NULL, 0, du, NULL);
216  Rocblas::add( nc, du, nc);
217  }
218  }
219 
220  // If user request for elapsed time, then do not subcycle.
221  if ( dt_elapsed) { *dt_elapsed = t; break; }
222  else if ( *dt==0) break;
223  }
224 
225  // Compute displacements and recover the original coordinates
226  Rocblas::sub( nc, oldnc, du);
227  Rocblas::copy( oldnc, nc);
228 
229  // Deallocate spds_buf
230  if ( spd) _buf->delete_attribute( spd->name());
231  _buf->init_done( false);
232 }
233 
234 void Rocprop::set_option( const char *opt, const char *val)
235 {
236  COM_assertion_msg( validate_object()==0, "Invalid object");
237 
238  std::string option;
239  if ( opt) option = opt;
240 
241  if ( option == "method") {
242  std::string value(val);
243  int old_method = _prop_method;
244 
245  if ( value == "fo") // Face offsetting
246  _prop_method = PROP_FO;
247  else
248  _prop_method = PROP_MP; // Marker particle
249 
250  // Remove old object if method is changed.
251  if ( _prop_method != old_method && _prop)
252  { delete _prop; _prop=NULL; }
253  }
254  else if ( option == "eigthres") {
255  _eig_thres = std::atof( val);
256  }
257  else if ( option == "smoother") {
258  std::string value(val);
259  if ( value == "none")
260  _smoother = SMOOTHER_NONE;
261  else if ( value == "centroid")
263  else if ( value == "anisotropic")
264  _smoother = SMOOTHER_ANISOTROPIC;
265  else {
266  COM_assertion( value == "Laplacian" || value == "laplacian");
267  _smoother = SMOOTHER_LAPLACIAN;
268  }
269  }
270  else if ( option == "rediter") {
271  _rediter = std::atoi( val);
272  }
273  else if ( option == "conserv") {
274  _conserv = std::atoi( val);
275  }
276  else if ( option == "courant") {
277  _courant = std::atof( val);
278  }
279  else if ( option == "wavefrontal") {
280  _wf_expn = std::atoi( val);
281  }
282  else if ( option == "weight") {
283  _wght_scheme = std::atoi( val);
284  }
285  else if ( option == "normaldif") {
286  _nrm_dfsn = std::atoi( val);
287  }
288  else if ( option == "feature_layer") {
289  _feature_layer = std::atoi( val);
290  }
291  else if ( option == "sangle" || option == "fangle_strong") {
292  _fangle_strong = std::atof( val);
293  }
294  else if ( option == "fangle" || option=="fangle_weak") {
295  _fangle_weak = std::atof( val);
296  }
297  else if ( option == "tangle" || option == "fangle_tun") {
298  _fangle_turn = std::atof( val);
299  }
300  else if ( option == "verbose")
301  _verb = atoi( val);
302  else
303  COM_assertion_msg( false, (std::string("Unknown option ")+option).c_str());
304 }
305 
306 void Rocprop::
307 remesh_serial( COM::Attribute *mesh_out, double *lave, double *fangle) {
309 
310  if ( _rem) {
311  double l = lave?*lave:0.;
312  if ( l==0) compute_edge_lengths( &l, NULL, NULL);
313 
314  _rem->remesh_serial( _wm, mesh_out, l, fangle?*fangle:0.);
315  }
316  else {
318  std::cerr << "No remesher was registered" << std::endl;
319  }
320 }
321 
322 void Rocprop::load( const std::string &mname) {
323  Rocprop *rp = new Rocprop();
324 
325  COM_new_window( mname.c_str());
326 
327  std::string glb=mname+".global";
328 
329  COM_new_attribute( glb.c_str(), 'w', COM_VOID, 1, "");
330  COM_set_object( glb.c_str(), 0, rp);
331 
332  COM_Type types[7];
333  types[0] = types[2] = COM_RAWDATA; types[1] = COM_METADATA;
334  COM_set_member_function( (mname+".initialize").c_str(),
335  (Member_func_ptr)(&Rocprop::initialize),
336  glb.c_str(), "biB", types);
337 
338  COM_set_member_function( (mname+".set_constraints").c_str(),
339  (Member_func_ptr)(&Rocprop::set_constraints),
340  glb.c_str(), "bi", types);
341 
342  COM_set_member_function( (mname+".set_bounds").c_str(),
343  (Member_func_ptr)(&Rocprop::set_bounds),
344  glb.c_str(), "bi", types);
345 
346  types[2] = COM_DOUBLE;
347  COM_set_member_function( (mname+".perturb_mesh").c_str(),
348  (Member_func_ptr)(&Rocprop::perturb_mesh),
349  glb.c_str(), "bbi", types);
350 
351  types[2] = types[4] = COM_METADATA; types[3] = types[5] = COM_DOUBLE;
352  types[6]=COM_INT;
353  COM_set_member_function( (mname+".propagate").c_str(),
354  (Member_func_ptr)(&Rocprop::propagate),
355  glb.c_str(), "bibioOO", types);
356 
357  types[1] = types[2] = COM_STRING;
358  COM_set_member_function( (mname+".set_option").c_str(),
359  (Member_func_ptr)(&Rocprop::set_option),
360  glb.c_str(), "bii", types);
361 
362  types[1] = COM_METADATA; types[2] = types[3] = COM_DOUBLE;
363  COM_set_member_function( (mname+".remesh_serial").c_str(),
364  (Member_func_ptr)(&Rocprop::remesh_serial),
365  glb.c_str(), "boII", types);
366 
367  types[1] = COM_VOID; types[2] = COM_INT;
368  COM_set_member_function( (mname+".set_remesher").c_str(),
369  (Member_func_ptr)(&Rocprop::set_remesher),
370  glb.c_str(), "biI", types);
371 
372  // Register inherited member functions from Rocsurf.
373  std::string glb_surf=mname+".global_surf";
374  Rocsurf *surf = rp;
375  COM_new_attribute( glb_surf.c_str(), 'w', COM_VOID, 1, "");
376  COM_set_object( glb_surf.c_str(), 0, surf);
377 
378  types[1] = types[2] = types[3] = COM_DOUBLE;
379  COM_set_member_function( (mname+".compute_edge_lengths").c_str(),
380  (Member_func_ptr)(&Rocsurf::compute_edge_lengths),
381  glb_surf.c_str(), "boOO", types);
382 
383  COM_window_init_done( mname.c_str());
384 }
385 
386 void Rocprop::unload( const std::string &mname) {
387  Rocprop *rp;
388  std::string glb=mname+".global";
389 
390  COM_get_object( glb.c_str(), 0, &rp);
391 
392  COM_assertion_msg( rp->validate_object()==0, "Invalid object");
393 
394  delete rp;
395  COM_delete_window( mname.c_str());
396 }
397 
398 // C/C++ binding
399 extern "C" void Rocprop_load_module( const char *name)
400 { Rocprop::load( std::string(name)); }
401 extern "C" void Rocprop_unload_module( const char *name)
402 { Rocprop::unload( std::string(name)); }
403 
404 // Fortran binding
405 extern "C" void rocprop_load_module( const char *name, long int length)
406 { Rocprop::load( std::string(name, length)); }
407 extern "C" void rocprop_unload_module( const char *name, long int length)
408 { Rocprop::unload( std::string(name, length)); }
409 
410 extern "C" void ROCPROP_LOAD_MODULE( const char *name, long int length)
411 { Rocprop::load( std::string(name, length)); }
412 extern "C" void ROCPROP_UNLOAD_MODULE( const char *name, long int length)
413 { Rocprop::unload( std::string(name, length)); }
414 
415 extern "C" void rocprop_load_module_( const char *name, long int length)
416 { Rocprop::load( std::string(name, length)); }
417 extern "C" void rocprop_unload_module_( const char *name, long int length)
418 { Rocprop::unload( std::string(name, length)); }
419 
420 extern "C" void ROCPROP_LOAD_MODULE_( const char *name, long int length)
421 { Rocprop::load( std::string(name, length)); }
422 extern "C" void ROCPROP_UNLOAD_MODULE_( const char *name, long int length)
423 { Rocprop::unload( std::string(name, length)); }
424 
426 
427 
428 
429 
430 
431 
int COMMPI_Comm_rank(MPI_Comm c)
Definition: commpi.h:162
static void sub(const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for subtraction.
Definition: op3args.C:237
void set_bounds(const COM::Attribute *bnd)
Set the bounds Propagation_3::set_bounds.
Definition: Rocprop.C:101
int COM_Type
Indices for derived data types.
Definition: roccom_basic.h:122
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
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
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 code(though may enhance!portability between Crays and other systems)!INTEGER MPI_TAG_UB
#define PROP_END_NAMESPACE
Definition: propbasic.h:29
const char * option(const char *const name, const int argc, const char *const *const argv, const char *defaut, const char *const usage=0)
Definition: CImg.h:5604
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
void perturb_mesh(COM::Attribute *pmesh, const double &alpha)
Perturb the given mesh by alpha times shortest edge length.
Definition: Rocprop.C:85
#define PROP_BEGIN_NAMESPACE
Definition: propbasic.h:28
#define COM_assertion_msg(EX, msg)
void set_constraints(const COM::Attribute *cnstr_types)
Set the types and directions of constraints Propagation_3::set_constraints.
Definition: Rocprop.C:96
void COM_set_object(const char *wa_str, int pane_id, Type *addr)
Definition: roccom_c++.h:144
virtual ~Rocprop()
Definition: Rocprop.C:35
void propagate(const COM::Attribute *pmesh, COM::Attribute *vel, const double *dt, COM::Attribute *du, double *dt_elapsed=NULL, int *code=NULL)
Propagates the interface.
Definition: Rocprop.C:106
void ROCPROP_LOAD_MODULE(const char *name, long int length)
Definition: Rocprop.C:410
void rocprop_load_module(const char *name, long int length)
Definition: Rocprop.C:405
float atof(const char *const str)
Read a float number from a C-string.
Definition: CImg.h:4905
double length(Vector3D *const v, int n)
void COM_get_object(const char *wa_str, int pane_id, Type **addr)
Definition: roccom_c++.h:152
void ROCPROP_UNLOAD_MODULE(const char *name, long int length)
Definition: Rocprop.C:412
static void add(const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for addition.
Definition: op3args.C:221
void initialize(const COM::Attribute *pmesh)
Constructs the communication patterns of a distributed mesh.
Definition: Rocsurf.C:35
static void unload(const std::string &mname)
Definition: Rocprop.C:386
blockLoc i
Definition: read.cpp:79
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void ROCPROP_UNLOAD_MODULE_(const char *name, long int length)
Definition: Rocprop.C:422
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void ROCPROP_LOAD_MODULE_(const char *name, long int length)
Definition: Rocprop.C:420
void remesh_serial(COM::Attribute *mesh_out, double *lave=NULL, double *fangle=NULL)
Invoke serial remeshing.
Definition: Rocprop.C:307
void rocprop_unload_module_(const char *name, long int length)
Definition: Rocprop.C:417
void set_option(const char *opt, const char *val)
Set options for propagation.
Definition: Rocprop.C:234
void rocprop_unload_module(const char *name, long int length)
Definition: Rocprop.C:407
static void copy(const Attribute *x, Attribute *y)
Wrapper for copy.
Definition: op2args.C:333
void compute_edge_lengths(double *lave, double *lmin, double *lmax)
Computes edge lengths of a given window.
Definition: Rocsurf.C:87
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
int COMMPI_Initialized()
Definition: commpi.h:168
void Rocprop_load_module(const char *name)
Definition: Rocprop.C:399
int validate_object() const
Definition: Rocprop.h:123
void set_remesher(void *rem, int *owner=0)
Register remesher. Rocprop does not own the remesher.
Definition: Rocprop.h:89
static void load(const std::string &mname)
Definition: Rocprop.C:322
void Rocprop_unload_module(const char *name)
Definition: Rocprop.C:401
void initialize(const COM::Attribute *pmesh, SURF::Rocsurf *rsurf=NULL)
Initialize Rocprop with given mesh.
Definition: Rocprop.C:44
void rocprop_load_module_(const char *name, long int length)
Definition: Rocprop.C:415