Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rocmop_2.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_2.h,v 1.4 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 
51 
56 public:
57 
60  _eig_thres(1.e-12),_dir_thres(.1), _saliency_crn(.1),
61  _rediter(1), _cnstr_types(NULL), _cnstr_dirs(NULL),
62  _usr_window(NULL), _buf_window(NULL), _is_pmesh(false),
64  _niter(1), _ctol(.99), _ncycle(1),
66  _maxdisp(0.0), _smoothfreq(1),
67  _disp_thresh(0.0)
68  {;}
69 
71  virtual ~Rocmop();
72  //\}
73 
78 public:
79 
81  static void load( const std::string &mname);
82 
84  static void unload( const std::string &mname);
85  //\}
86 
87  void read_config_file(const std::string &);
92 public:
93 
95 
105  void smooth(const COM::Attribute *pmesh,
106  COM::Attribute *disp,
107  double* timestep = NULL);
108 
109 protected:
110 
112 
117  void smoother_specific_init();
118 
120 
126  void perform_smoothing();
127 
129 
135 
138 
140 
144  void update_buf_real_nc();
145 
147 
151  int check_input_pconn();
152 
154 
159  void get_usr_disp(const COM::Attribute *pmesh,
160  COM::Attribute *disp,
161  double* timestep);
162 
163  //\}
164 
169 public:
170 
172 
203  void set_value(const char* opt, const void* val);
204 
206  void determine_pane_border();
207 
209  void determine_physical_border(COM::Attribute* w_is_surface);
210 
213 
216 
218  void mark_elems_from_nodes(std::vector<std::vector<bool> > &marked_nodes,
219  std::vector<std::vector<bool> > &marked_elems);
220 
221 protected:
223  virtual SURF::Window_manifold_2 *manifold()
224  { return _wm;}
225 
227  int validate_object() const {
228  if ( _cookie != MOP_COOKIE) return -1;
229  else return COM_Object::validate_object();
230  }
231 
233  void invert_elements(int conn_type);
234 
238 protected:
240  static void reduce_sum_on_shared_nodes(COM::Attribute *att);
241 
243 
247  void agree_int(int& val, MPI_Op op){
248  if(COMMPI_Initialized()){
249  int temp = val;
250  MPI_Allreduce(&val, &temp, 1, MPI_INT, op,
251  _usr_window->get_communicator());
252  val = temp;
253  }
254  }
255 
257 
261  void agree_double(double& val, MPI_Op op){
262  if(COMMPI_Initialized()){
263  double temp = val;
264  MPI_Allreduce(&val, &temp, 1, MPI_DOUBLE, op,
265  _usr_window->get_communicator());
266  val = temp;
267  }
268  }
269  //\}
270 
275 protected:
276 
278 
287  void smooth_vol_mesq_wg();
288 
290 
299  ;
300  }
301 
303  void smooth_surf_medial();
304 
305  void smooth_boeing(COM::Attribute* att, int* niter);
306 
308 
314  void smooth_mesquite(std::vector<COM::Pane*> &allpanes,
315  int ghost_level=0);
316  //\}
317 
322 protected:
323 
325 
329  double check_marked_elem_quality(std::vector<std::vector<bool> > &marked_elems,
330  std::vector<COM::Pane*> &allpanes);
331 
333 
336  double check_all_elem_quality(std::vector<const COM::Pane*> &allpanes,
337  bool with_ghost = false);
338 
340 
343  double check_all_elem_quality(std::vector<COM::Pane*> &allpanes,
344  bool with_ghosts = false);
345 
347  void print_legible(int verb, const char* msg);
348 
350  void constrain_displacements(COM::Attribute * w_disp);
351 
353  void obtain_extremal_dihedrals(const COM::Attribute* att, double *min, double *max);
354 
356  void print_extremal_dihedrals(COM::Window * window);
357 
359  void print_quality(std::string &s,const std::string &s2);
360 
362  void print_mquality(std::string &s,std::vector<std::vector<bool> > &to_check);
363  //\}
364 
366  void perturb_stationary();
367 
368  // Check and tally displacements for triggering smoothing
369  bool check_displacements(COM::Attribute *disp);
370 
371  // Zero displacement array
372  void zero_displacements(COM::Attribute *disp);
373 
374 public:
375 
376  // Add aspect ratio measures to the users mesh.
377  void add_aspect_ratios(COM::Attribute *usr_att,
378  COM::Attribute *buf_att =NULL);
379 
384  protected:
385 
389  static void get_constraint_directions( int type, const Vector_3<double> &dir,
390  int &ndirs, Vector_3<double> dirs[2]);
391 
393  void evaluate_face_normals();
394 
396  void identify_ridge_edges();
397 
400 
403 
405  void compute_medial_quadric();
406 
407  // Solve the minimization problem (x^T)Ax+2b^Tx with eigen-decomposition
408  // at a vertex, return the codimension of the vertex, and save mean
409  // normal in x_nz.
411  Vector_3<double> *nrm_nz, double angle_defect);
412 
413  void get_redist_safe_factor( COM::Attribute *c_attr, COM::Attribute *w_attr,
414  int rank);
415 
416  // Compute eigenvalues and eigenvectors of a squared matrix A of order 3.
417  // At output, the eigenvalues are saved in lambdas in decending order,
418  // and A is replaced by the orthonormal eigenvectors.
419  static void compute_eigenvectors( Vector_3<double> A[3],
420  Vector_3<double> &lambdas);
421 
422  // Compute eigenvalues and eigenvectors of a squared matrix A of order 2.
423  // At output, the eigenvalues are saved in lambdas in decending order,
424  // and A is replaced by the orthonormal eigenvectors.
425  static void compute_eigenvectors( Vector_2<double> A[2],
426  Vector_2<double> &lambdas);
427 
428  // Helpers for linear solvers for 2x2 and 3x3 equations.
429  template <class FT>
430  static void solve (const FT &a1, const FT &a2,
431  const FT &b1, const FT &b2,
432  const FT &c1, const FT &c2,
433  FT &x, FT &y)
434  {
435  FT denom = a1*b2-b1*a2;
436 
437  x = - (b1*c2-c1*b2)/denom;
438 
439  y = (a1*c2-c1*a2)/denom;
440  }
441 
442  template <class FT>
443  static void solve (const FT &a1, const FT &a2, const FT &a3,
444  const FT &b1, const FT &b2, const FT &b3,
445  const FT &c1, const FT &c2, const FT &c3,
446  const FT &d1, const FT &d2, const FT &d3,
447  FT &x, FT &y, FT &z)
448  {
449  FT denom = b2*c1*a3-b1*c2*a3+c3*b1*a2+b3*c2*a1-c1*b3*a2-b2*c3*a1;
450 
451  x = - (b2*c3*d1-b2*c1*d3+c1*b3*d2+b1*c2*d3-c3*b1*d2-b3*c2*d1)/denom;
452 
453  z = (b2*d1*a3-b2*a1*d3+b1*a2*d3-b1*d2*a3-d1*b3*a2+a1*b3*d2)/denom;
454 
455  y = (a2*c3*d1-a2*c1*d3-c2*d1*a3+c2*a1*d3+d2*c1*a3-d2*c3*a1)/denom;
456  }
457 
458  // Wrapper for solving 3x3 equations
459  static void solve ( const Vector_3<double> A[3],
460  const Vector_3<double> &q,
461  Vector_3<double> &x) {
462  solve( A[0][0], A[0][1], A[0][2], A[1][0], A[1][1], A[1][2],
463  A[2][0], A[2][1], A[2][2], q[0], q[1], q[2],
464  x[0], x[1], x[2]);
465  }
466  //\}
467 
468  protected: // Variables specific to medial quadric smoothing
469 
470  bool _reorthog;
471  char _wght_scheme;
472  double _eig_thres;
473  double _dir_thres;
474  double _saliency_crn;
475  int _rediter;
476  const COM::Attribute *_cnstr_types;
477  COM::Attribute *_cnstr_dirs;
478  std::vector<std::set< Edge_ID> > _edges;
479 
480 protected: // Variables not currently modifiable via set_option
481 
482  //std::vector<std::vector<bool> > _elems_to_check; ///< Check quality of these.
483  std::vector<std::vector<bool> > _is_shared_node;
484  std::vector<std::vector<bool> > _is_shared_elem;
485  std::vector<std::vector<bool> > _is_phys_bnd_node;
486  std::vector<std::vector<bool> > _is_phys_bnd_elem;
487  std::vector<std::vector<bool> > _is_pane_bnd_node;
488  std::vector<std::vector<bool> > _is_pane_bnd_elem;
489 
490  const COM::Window *_usr_window;
491  COM::Window *_buf_window;
492 
493  std::vector<MAP::Pane_dual_connectivity*> _dcs; // Pane dual connectivities
494 
495  bool _is_pmesh;
496 
497  protected: // Variables which can be modified via set option.
498 
499  enum { MOP_COOKIE=762667};
500 
501  int _method;
502  // 0 == mesquite
503  // 1 == mesquite, no ghosts
504  // 2 == medial_quadric
505  // 3 == error (default)
506 
507  int _wrapper;
508  // 0 == ShapeImprovement Wrapper (Feasible Newton)
509  // 1 == CGWrapper (Conjugate Gradient)
510 
511  int _verb;
512  // 0 = no debugging info
513  // 1 = routine entries
514  // 2 = routine entries and exits
515  // 3 = highest level in routine info
516  // 4 = low level in routine info
517  // 5 = 4 + high level MesqPane info
518  // 6 = 5 + low level MesqPane info
519 
520  int _lazy;
521 
522  float _tol;
523  // Smoother loops until either
524  // worst element quality > tol
525  // OR _niter iterations reached
526 
527  int _niter;
528 
529  float _ctol;
530  // Parallel mesquite subcycles for convergence until either
531  // (post communication quality)/(pre communication quality) > _tol
532  // OR _ncycle cycles performed.
533  // In this context, quality refers to worst quality of all real elements
534  // containing shared nodes.
535  // _ctol should be set to a value between 0 and 1
536 
537  int _ncycle;
538 
539  int _cookie;
540 
542 
544 
545  float _maxdisp;
546 
547  int _smoothfreq;
548 
549  float _disp_thresh; // Threshold for smoothing trigger
550 };
551 
553 
554 #endif
555 
556 
557 
558 
559 
560 
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_2.h:227
void determine_physical_border()
Determine which nodes and elements are on the physical border.
Definition: Rocmop.C:677
void obtain_extremal_dihedrals(const COM::Attribute *att, double *min, double *max)
Obtain the min and max dihedral angles.
Definition: Rocmop_2.C:1991
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
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 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.
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
void smooth_boeing(COM::Attribute *att, int *niter)
Definition: Rocmop_2.C:1471
void get_usr_disp(const COM::Attribute *pmesh, COM::Attribute *disp, double *timestep)
Get displacement in _usr_window based on nc in _buf_window.
Definition: Rocmop_2.C:1001
static void solve(const Vector_3< double > A[3], const Vector_3< double > &q, Vector_3< double > &x)
Definition: Rocmop_2.h:459
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 update_buf_real_nc()
Update real nodal coordinates of _buf_window from _usr_window.
Definition: Rocmop_2.C:824
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_2.h:443
int _wrapper
Choice of Mesquite Smoothing Wrappers.
Definition: Rocmop_2.h:507
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_2.h:298
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
void invert_elements(int conn_type)
Repair inverted tets or hexes.
Definition: Rocmop_2.C:1713
Contains declarations of MPI subroutines used in Roccom.
void determine_shared_border()
Determine which nodes and elements are shared.
Definition: Rocmop.C:631
int _invert_tets
If true (default false), then invert tets.
Definition: Rocmop_2.h:541
int check_input_pconn()
Check pconn block 3 of the input mesh.
Definition: Rocmop_2.C:886
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
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_2.h:223
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
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
void agree_double(double &val, MPI_Op op)
Agree on a double value across all panes.
Definition: Rocmop_2.h:261
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_2.h:430
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_2.h:247
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_2.h:59
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 COMMPI_Initialized()
Definition: commpi.h:168
std::vector< std::vector< bool > > _is_shared_elem
Does the element contain shared nodes?
Definition: Rocmop.h:432
int _invert_hexes
If true (default false), then invert hexes.
Definition: Rocmop_2.h:543
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