Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rocmop_1.h
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: Rocmop_1.h,v 1.5 2008/12/06 08:45:24 mtcampbe Exp $
24 
28 #ifndef __ROCMOP_H_
29 #define __ROCMOP_H_
30 
31 #include "mopbasic.h"
32 #include "roccom_devel.h"
33 #include "Pane_communicator.h"
34 #include "commpi.h"
35 #include "Manifold_2.h"
36 #include "Rocsurf.h"
37 #include "Dual_connectivity.h"
38 
40 
42 class Rocmop : public SURF::Rocsurf {
43 public:
44 
48 
53 public:
54 
57  _eig_thres(1.e-12),_dir_thres(.1), _saliency_crn(.1),
58  _rediter(1), _cnstr_types(NULL), _cnstr_dirs(NULL),
59  _usr_window(NULL), _buf_window(NULL), _is_pmesh(false),
60  _method(SMOOTH_VOL_MESQ_WG), _verb(0), _lazy(0), _tol(165.0),
61  _niter(1), _ctol(.99), _ncycle(1),
63  N(-9999), disp_tally(0.0), _disp_thresh(0.0)
64  {;}
65 
67  virtual ~Rocmop();
68  //\}
69 
74 public:
75 
77  static void load( const std::string &mname);
78 
80  static void unload( const std::string &mname);
81  //\}
82 
83  void read_config_file(const std::string &);
88 public:
89 
91 
99  void smooth(const COM::Attribute *pmesh,
100  COM::Attribute *disp);
101 
103 
108  void smooth_in_place(COM::Attribute *pmesh);
109 
110 protected:
111 
113 
118  void smoother_specific_init();
119 
121 
127  void perform_smoothing();
128 
130 
136 
137 
140 
141  //\}
142 
147 public:
148 
150 
181  void set_value(const char* opt, const void* val);
182 
184  void determine_pane_border();
185 
187  void determine_physical_border(COM::Attribute* w_is_surface);
188 
191 
194 
196  void mark_elems_from_nodes(std::vector<std::vector<bool> > &marked_nodes,
197  std::vector<std::vector<bool> > &marked_elems);
198 
199 protected:
201  virtual SURF::Window_manifold_2 *manifold()
202  { return _wm;}
203 
205  int validate_object() const {
206  if ( _cookie != MOP_COOKIE) return -1;
207  else return COM_Object::validate_object();
208  }
209 
211  void invert_tets();
212 
216 protected:
218  static void reduce_sum_on_shared_nodes(COM::Attribute *att);
219 
221 
225  void agree_int(int& val, MPI_Op op){
226  if(COMMPI_Initialized()){
227  int temp = val;
228  MPI_Allreduce(&val, &temp, 1, MPI_INT, op,
229  _usr_window->get_communicator());
230  val = temp;
231  }
232  }
233 
235 
239  void agree_double(double& val, MPI_Op op){
240  if(COMMPI_Initialized()){
241  double temp = val;
242  MPI_Allreduce(&val, &temp, 1, MPI_DOUBLE, op,
243  _usr_window->get_communicator());
244  val = temp;
245  }
246  }
247  //\}
248 
253 protected:
254 
256 
265  void smooth_vol_mesq_wg();
266 
268 
277  ;
278  }
279 
281  void smooth_surf_medial();
282 
284 
290  void smooth_mesquite(std::vector<COM::Pane*> &allpanes,
291  int ghost_level=0);
292  //\}
293 
298 protected:
299 
301 
305  double check_marked_elem_quality(std::vector<std::vector<bool> > &marked_elems,
306  std::vector<COM::Pane*> &allpanes);
307 
309 
312  double check_all_elem_quality(std::vector<const COM::Pane*> &allpanes,
313  bool with_ghost = false);
314 
316 
319  double check_all_elem_quality(std::vector<COM::Pane*> &allpanes,
320  bool with_ghosts = false);
321 
323  void print_legible(int verb, const char* msg);
324 
326  void constrain_displacements(COM::Attribute * w_disp);
327 
329  void print_extremal_dihedrals(COM::Window * window);
330 
332  void print_quality(std::string &s,const std::string &s2);
333 
335  void print_mquality(std::string &s,std::vector<std::vector<bool> > &to_check);
336  //\}
337 
339  void perturb_stationary();
340 
341  // Check and tally displacements for triggering smoothing
342  bool check_displacements(COM::Attribute *disp);
343 
344  // Zero displacement array
345  void zero_displacements(COM::Attribute *disp);
346 
347 public:
348 
349  // Add aspect ratio measures to the users mesh.
350  void add_aspect_ratios(COM::Attribute *usr_att,
351  COM::Attribute *buf_att =NULL);
352 
357  protected:
358 
362  static void get_constraint_directions( int type, const Vector_3<double> &dir,
363  int &ndirs, Vector_3<double> dirs[2]);
364 
366  void evaluate_face_normals();
367 
369  void identify_ridge_edges();
370 
373 
376 
378  void compute_medial_quadric();
379 
380  // Solve the minimization problem (x^T)Ax+2b^Tx with eigen-decomposition
381  // at a vertex, return the codimension of the vertex, and save mean
382  // normal in x_nz.
384  Vector_3<double> *nrm_nz, double angle_defect);
385 
386  void get_redist_safe_factor( COM::Attribute *c_attr, COM::Attribute *w_attr,
387  int rank);
388 
389  // Compute eigenvalues and eigenvectors of a squared matrix A of order 3.
390  // At output, the eigenvalues are saved in lambdas in decending order,
391  // and A is replaced by the orthonormal eigenvectors.
392  static void compute_eigenvectors( Vector_3<double> A[3],
393  Vector_3<double> &lambdas);
394 
395  // Compute eigenvalues and eigenvectors of a squared matrix A of order 2.
396  // At output, the eigenvalues are saved in lambdas in decending order,
397  // and A is replaced by the orthonormal eigenvectors.
398  static void compute_eigenvectors( Vector_2<double> A[2],
399  Vector_2<double> &lambdas);
400 
401  // Helpers for linear solvers for 2x2 and 3x3 equations.
402  template <class FT>
403  static void solve (const FT &a1, const FT &a2,
404  const FT &b1, const FT &b2,
405  const FT &c1, const FT &c2,
406  FT &x, FT &y)
407  {
408  FT denom = a1*b2-b1*a2;
409 
410  x = - (b1*c2-c1*b2)/denom;
411 
412  y = (a1*c2-c1*a2)/denom;
413  }
414 
415  template <class FT>
416  static void solve (const FT &a1, const FT &a2, const FT &a3,
417  const FT &b1, const FT &b2, const FT &b3,
418  const FT &c1, const FT &c2, const FT &c3,
419  const FT &d1, const FT &d2, const FT &d3,
420  FT &x, FT &y, FT &z)
421  {
422  FT denom = b2*c1*a3-b1*c2*a3+c3*b1*a2+b3*c2*a1-c1*b3*a2-b2*c3*a1;
423 
424  x = - (b2*c3*d1-b2*c1*d3+c1*b3*d2+b1*c2*d3-c3*b1*d2-b3*c2*d1)/denom;
425 
426  z = (b2*d1*a3-b2*a1*d3+b1*a2*d3-b1*d2*a3-d1*b3*a2+a1*b3*d2)/denom;
427 
428  y = (a2*c3*d1-a2*c1*d3-c2*d1*a3+c2*a1*d3+d2*c1*a3-d2*c3*a1)/denom;
429  }
430 
431  // Wrapper for solving 3x3 equations
432  static void solve ( const Vector_3<double> A[3],
433  const Vector_3<double> &q,
434  Vector_3<double> &x) {
435  solve( A[0][0], A[0][1], A[0][2], A[1][0], A[1][1], A[1][2],
436  A[2][0], A[2][1], A[2][2], q[0], q[1], q[2],
437  x[0], x[1], x[2]);
438  }
439  //\}
440 
441  protected: // Variables specific to medial quadric smoothing
442 
443  bool _reorthog;
444  char _wght_scheme;
445  double _eig_thres;
446  double _dir_thres;
447  double _saliency_crn;
448  int _rediter;
449  const COM::Attribute *_cnstr_types;
450  COM::Attribute *_cnstr_dirs;
451  std::vector<std::set< Edge_ID> > _edges;
452 
453 protected: // Variables not currently modifiable via set_option
454 
455  //std::vector<std::vector<bool> > _elems_to_check; ///< Check quality of these.
456  std::vector<std::vector<bool> > _is_shared_node;
457  std::vector<std::vector<bool> > _is_shared_elem;
458  std::vector<std::vector<bool> > _is_phys_bnd_node;
459  std::vector<std::vector<bool> > _is_phys_bnd_elem;
460  std::vector<std::vector<bool> > _is_pane_bnd_node;
461  std::vector<std::vector<bool> > _is_pane_bnd_elem;
462 
463  const COM::Window *_usr_window;
464  COM::Window *_buf_window;
465 
466  std::vector<MAP::Pane_dual_connectivity*> _dcs; // Pane dual connectivities
467 
468  bool _is_pmesh;
469 
470  protected: // Variables which can be modified via set option.
471 
472  enum { MOP_COOKIE=762667};
473 
474  int _method;
475  // 0 == mesquite
476  // 1 == mesquite, no ghosts
477  // 2 == medial_quadric
478  // 3 == error (default)
479 
480  int _verb;
481  // 0 = no debugging info
482  // 1 = routine entries
483  // 2 = routine entries and exits
484  // 3 = highest level in routine info
485  // 4 = low level in routine info
486  // 5 = 4 + high level MesqPane info
487  // 6 = 5 + low level MesqPane info
488 
489  int _lazy;
490 
491  float _tol;
492  // Smoother loops until either
493  // worst element quality > tol
494  // OR _niter iterations reached
495 
496  int _niter;
497 
498  float _ctol;
499  // Parallel mesquite subcycles for convergence until either
500  // (post communication quality)/(pre communication quality) > _tol
501  // OR _ncycle cycles performed.
502  // In this context, quality refers to worst quality of all real elements
503  // containing shared nodes.
504  // _ctol should be set to a value between 0 and 1
505 
506  int _ncycle;
507 
508  int _cookie;
509 
510  int _invert;
511 
512  float _maxdisp;
513 
515 
516  int N;
517 
518  double disp_tally;
519 
520  float _disp_thresh; // Threshold for smoothing trigger
521 };
522 
524 
525 #endif
526 
527 
528 
529 
530 
531 
int eigen_analyze_vertex(Vector_3< double > A_io[3], Vector_3< double > &b_io, Vector_3< double > *nrm_nz, double angle_defect)
int validate_object() const
Check that the object is valid.
Definition: Rocmop_1.h:205
void determine_physical_border()
Determine which nodes and elements are on the physical border.
Definition: Rocmop.C:677
int _smoothfreq
Definition: Rocmop_1.h:514
std::vector< std::vector< bool > > _is_pane_bnd_node
Is the node on the pane boundary?
Definition: Rocmop.h:435
void smooth_in_place(COM::Attribute *pmesh)
Smooth a mesh in place..
Definition: Rocmop.C:204
double check_all_elem_quality(std::vector< const COM::Pane * > &allpanes, bool with_ghost=false)
Get the largest dihedral angle of all real elements.
Definition: Rocmop.C:785
std::vector< std::vector< bool > > _is_pane_bnd_elem
Does the element contain nodes on the pane boundary?
Definition: Rocmop.h:436
float _maxdisp
Maximum displacement allowed.
Definition: Rocmop_1.h:512
const COM::Window * _usr_window
The user&#39;s window.
Definition: Rocmop.h:438
void invert_tets()
Repair inverted tets.
Definition: Rocmop.C:748
void print_mquality(std::string &s, std::vector< std::vector< bool > > &to_check)
Print the quality range of marked elements, for debugging.
Definition: Rocmop.C:883
void int int REAL REAL * y
Definition: read.cpp:74
int _ncycle
Max number of subcycles for convergence.
Definition: Rocmop.h:479
void perturb_stationary()
Randomly perturn stationary nodes on pane boundary, not on phys. surface.
Definition: Rocmop_1.C:1689
char _wght_scheme
Weighting scheme.
Definition: Rocmop.h:419
void determine_pane_border()
Determine which nodes and elements are on pane borders.
Definition: Rocmop.C:603
double s
Definition: blastest.C:80
void identify_ridge_edges()
Identify ridge edges.
static void solve(const Vector_3< double > A[3], const Vector_3< double > &q, Vector_3< double > &x)
Definition: Rocmop_1.h:432
A Roccom mesh optimization module.
Definition: Rocmop.h:41
bool _reorthog
Reorthogonalize?
Definition: Rocmop.h:418
void smooth_vol_mesq_wg()
Smooth a volume via Mesquite using ghost information.
double _eig_thres
Eigenvalue thresholds.
Definition: Rocmop.h:420
void compute_medial_quadric()
Compute medial quadric for every vertex.
Handles communication of shared nodes, ghost nodes or ghost cells across panes.
static void compute_eigenvectors(Vector_3< double > A[3], Vector_3< double > &lambdas)
static void reduce_sum_on_shared_nodes(COM::Attribute *att)
Perform a sum-reduction on the shared nodes for the given attribute.
Definition: Rocmop.C:595
int _method
Choice of smoothing method.
Definition: Rocmop.h:447
std::vector< std::vector< bool > > _is_phys_bnd_node
Is the node on the physical boundary?
Definition: Rocmop.h:433
void zero_displacements(COM::Attribute *disp)
Definition: Rocmop_1.C:426
void read_config_file(const std::string &)
Definition: Rocmop_1.C:122
void evaluate_face_normals()
Evaluate face normals (copied from FaceOffset_3.[hC].
void perform_smoothing()
Perform smoothing on _buf_window.
Definition: Rocmop_1.C:776
std::vector< std::vector< bool > > _is_phys_bnd_elem
Does the element contain nodes on the phys. boundary?
Definition: Rocmop.h:434
rational * A
Definition: vinci_lass.c:67
static void solve(const FT &a1, const FT &a2, const FT &a3, const FT &b1, const FT &b2, const FT &b3, const FT &c1, const FT &c2, const FT &c3, const FT &d1, const FT &d2, const FT &d3, FT &x, FT &y, FT &z)
Definition: Rocmop_1.h:416
virtual ~Rocmop()
Destructor.
Definition: Rocmop.C:76
void redistribute_vertices_smooth()
Redistribute smooth vertices within their tangent spaces.
void smooth_vol_mesq_ng()
Smooths a volume using Mesquite with only shared node information.
Definition: Rocmop_1.h:276
void int int int REAL REAL REAL * z
Definition: write.cpp:76
int _cookie
For Roccom.
Definition: Rocmop.h:487
int _niter
Maximum number of iterations for smoothing.
Definition: Rocmop.h:469
static void get_constraint_directions(int type, const Vector_3< double > &dir, int &ndirs, Vector_3< double > dirs[2])
Get orthonormals of the constraints.
void perform_noniterative_smoothing()
Perform noniterative smoothing.
Definition: Rocmop.C:344
double check_marked_elem_quality(std::vector< std::vector< bool > > &marked_elems, std::vector< COM::Pane * > &allpanes)
Get the largest dihedral angle of marked real elements.
Definition: Rocmop.C:760
void constrain_displacements(COM::Attribute *w_disp)
Contrain displacements to _maxdisp.
Definition: Rocmop_1.C:1424
static void unload(const std::string &mname)
Unloads Rocmop from Roccom.
Definition: Rocmop.C:120
void get_redist_safe_factor(COM::Attribute *c_attr, COM::Attribute *w_attr, int rank)
void int int REAL * x
Definition: read.cpp:74
int _rediter
No.iterations for vertex redistribution.
Definition: Rocmop.h:423
Contains declarations of MPI subroutines used in Roccom.
void determine_shared_border()
Determine which nodes and elements are shared.
Definition: Rocmop.C:631
void print_legible(int verb, const char *msg)
Single process print message if given verbosity level is exceeded.
Definition: Rocmop_1.C:1408
#define MOP_END_NAMESPACE
Definition: mopbasic.h:29
void redistribute_vertices_ridge()
Redistribute ridge vertices within their tangent spaces.
double _saliency_crn
Definition: Rocmop.h:422
float _disp_thresh
originally a static in check_displacements
Definition: Rocmop_1.h:520
int _invert
If true (default false), then invert the mesh.
Definition: Rocmop.h:489
void print_quality(std::string &s)
Print the quality range of all elements, for debugging.
Definition: Rocmop.C:846
int _verb
Verbose level.
Definition: Rocmop.h:453
virtual SURF::Window_manifold_2 * manifold()
Obtain a reference to the manifold.
Definition: Rocmop_1.h:201
void smooth_surf_medial()
Smooths a surface using the medial quadric.
void smooth(const COM::Attribute *pmesh, COM::Attribute *disp)
Smooth the mesh in a Rocmop managed buffer.
Definition: Rocmop.C:132
bool _is_pmesh
pmesh or mesh ?
Definition: Rocmop.h:441
double _dir_thres
Another threshold.
Definition: Rocmop.h:421
double disp_tally
originally a static in smooth()
Definition: Rocmop_1.h:518
void agree_double(double &val, MPI_Op op)
Agree on a double value across all panes.
Definition: Rocmop_1.h:239
static void solve(const FT &a1, const FT &a2, const FT &b1, const FT &b2, const FT &c1, const FT &c2, FT &x, FT &y)
Definition: Rocmop_1.h:403
float _ctol
Subcycling tolerance.
Definition: Rocmop.h:471
void smoother_specific_init()
Perform smoother specific initialization.
Definition: Rocmop.C:364
static void load(const std::string &mname)
Loads Rocmop onto Roccom with a given module name.
Definition: Rocmop.C:88
COM::Attribute * _cnstr_dirs
Stores directions of nodal contraints.
Definition: Rocmop.h:425
NT q
int _lazy
Check quality before smoothing?
Definition: Rocmop.h:462
void agree_int(int &val, MPI_Op op)
Agree on an integer value across all panes.
Definition: Rocmop_1.h:225
const COM::Attribute * _cnstr_types
Stores types of nodal constraints.
Definition: Rocmop.h:424
#define MOP_BEGIN_NAMESPACE
Definition: mopbasic.h:28
void print_extremal_dihedrals(COM::Window *window)
Print the min and max dihedral angles along with their locations.
Definition: Rocmop_1.C:1463
static int rank
Definition: advectest.C:66
Rocmop()
Default Constructor.
Definition: Rocmop_1.h:56
void set_value(const char *opt, const void *val)
Set a Rocomp option.
Definition: Rocmop.C:529
void mark_elems_from_nodes(std::vector< std::vector< bool > > &marked_nodes, std::vector< std::vector< bool > > &marked_elems)
Mark the nodes which contain marked elems.
Definition: Rocmop.C:712
void add_aspect_ratios(COM::Attribute *usr_att, COM::Attribute *buf_att=NULL)
Definition: Rocmop_1.C:454
int N
Smooth every _smoothfreq&#39;th call.
Definition: Rocmop_1.h:516
int COMMPI_Initialized()
Definition: commpi.h:168
std::vector< std::vector< bool > > _is_shared_elem
Does the element contain shared nodes?
Definition: Rocmop.h:432
void smooth_mesquite(std::vector< COM::Pane * > &allpanes, int ghost_level=0)
Smooth the panes of the working window using MESQUITE.
Definition: Rocmop.C:570
CGAL_BEGIN_NAMESPACE void const NT NT NT NT & denom
COM::Window * _buf_window
The buffer window.
Definition: Rocmop_1.h:464
void perform_iterative_smoothing()
Perform iterative smoothing.
Definition: Rocmop_1.C:798
std::vector< std::vector< bool > > _is_shared_node
Is the node shared?
Definition: Rocmop.h:431
float _tol
Smoother iterating tolerance.
Definition: Rocmop.h:464
bool check_displacements(COM::Attribute *disp)
Definition: Rocmop_1.C:357
std::vector< std::set< Edge_ID > > _edges
ridge edges
Definition: Rocmop.h:426
std::vector< MAP::Pane_dual_connectivity * > _dcs
Definition: Rocmop_1.h:466