Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rocmop.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.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 
39 
41 class Rocmop : public SURF::Rocsurf {
42 public:
43 
47 
52 public:
53 
56  _eig_thres(1.e-12),_dir_thres(.1), _saliency_crn(.1),
57  _rediter(1), _cnstr_types(NULL), _cnstr_dirs(NULL),
58  _usr_window(NULL), _wrk_window(NULL), _is_pmesh(false),
59  _method(SMOOTH_NONE), _verb(0), _lazy(0), _tol(0.0),
60  _niter(1), _ctol(.99), _ncycle(1), _monotone(0), _cookie(MOP_COOKIE),
61  _invert(0)
62  {;}
63 
65  virtual ~Rocmop();
66  //\}
67 
72 public:
73 
75  static void load( const std::string &mname);
76 
78  static void unload( const std::string &mname);
79  //\}
80 
85 public:
86 
88 
96  void smooth(const COM::Attribute *pmesh,
97  COM::Attribute *disp);
98 
100 
105  void smooth_in_place(COM::Attribute *pmesh);
106 
107 protected:
108 
110 
115  void smoother_specific_init();
116 
118 
126  void perform_smoothing(double pre_quality);
127 
129 
136  void perform_iterative_smoothing(double pre_quality);
137 
138 
141 
142  //\}
143 
148 public:
149 
151 
182  void set_value(const char* opt, const void* val);
183 
185  void determine_pane_border();
186 
188  void determine_physical_border(COM::Attribute* w_is_surface);
189 
192 
195 
197  void mark_elems_from_nodes(std::vector<std::vector<bool> > &marked_nodes,
198  std::vector<std::vector<bool> > &marked_elems);
199 
200 protected:
202  virtual SURF::Window_manifold_2 *manifold()
203  { return _wm;}
204 
206  int validate_object() const {
207  if ( _cookie != MOP_COOKIE) return -1;
208  else return COM_Object::validate_object();
209  }
210 
212  void invert_tets();
213 
217 protected:
219  static void reduce_sum_on_shared_nodes(COM::Attribute *att);
220 
222 
226  void agree_int(int& val, MPI_Op op){
227  if(COMMPI_Initialized()){
228  int temp = val;
229  MPI_Allreduce(&val, &temp, 1, MPI_INT, op,
230  _usr_window->get_communicator());
231  val = temp;
232  }
233  }
234 
236 
240  void agree_double(double& val, MPI_Op op){
241  if(COMMPI_Initialized()){
242  double temp = val;
243  MPI_Allreduce(&val, &temp, 1, MPI_DOUBLE, op,
244  _usr_window->get_communicator());
245  val = temp;
246  }
247  }
248  //\}
249 
254 protected:
255 
257 
266  void smooth_vol_mesq_wg(double pre_quality);
267 
269 
277  void smooth_vol_mesq_ng(double pre_quality);
278 
280  void smooth_surf_medial();
281 
283 
289  void smooth_mesquite(std::vector<COM::Pane*> &allpanes,
290  int ghost_level=0);
291  //\}
292 
297 protected:
298 
300 
304  double check_marked_elem_quality(std::vector<std::vector<bool> > &marked_elems,
305  std::vector<COM::Pane*> &allpanes);
306 
308 
311  double check_all_elem_quality(std::vector<const COM::Pane*> &allpanes,
312  bool with_ghost = false);
313 
315 
318  double check_all_elem_quality(std::vector<COM::Pane*> &allpanes,
319  bool with_ghosts = false);
320 
322  void print_quality(std::string &s);
323 
325  void print_mquality(std::string &s,std::vector<std::vector<bool> > &to_check);
326  //\}
327 
332  protected:
333 
337  static void get_constraint_directions( int type, const Vector_3<double> &dir,
338  int &ndirs, Vector_3<double> dirs[2]);
339 
341  void evaluate_face_normals();
342 
344  void identify_ridge_edges();
345 
348 
351 
353  void compute_medial_quadric();
354 
355  // Solve the minimization problem (x^T)Ax+2b^Tx with eigen-decomposition
356  // at a vertex, return the codimension of the vertex, and save mean
357  // normal in x_nz.
359  Vector_3<double> *nrm_nz, double angle_defect);
360 
361  void get_redist_safe_factor( COM::Attribute *c_attr, COM::Attribute *w_attr,
362  int rank);
363 
364  // Compute eigenvalues and eigenvectors of a squared matrix A of order 3.
365  // At output, the eigenvalues are saved in lambdas in decending order,
366  // and A is replaced by the orthonormal eigenvectors.
367  static void compute_eigenvectors( Vector_3<double> A[3],
368  Vector_3<double> &lambdas);
369 
370  // Compute eigenvalues and eigenvectors of a squared matrix A of order 2.
371  // At output, the eigenvalues are saved in lambdas in decending order,
372  // and A is replaced by the orthonormal eigenvectors.
373  static void compute_eigenvectors( Vector_2<double> A[2],
374  Vector_2<double> &lambdas);
375 
376  // Helpers for linear solvers for 2x2 and 3x3 equations.
377  template <class FT>
378  static void solve (const FT &a1, const FT &a2,
379  const FT &b1, const FT &b2,
380  const FT &c1, const FT &c2,
381  FT &x, FT &y)
382  {
383  FT denom = a1*b2-b1*a2;
384 
385  x = - (b1*c2-c1*b2)/denom;
386 
387  y = (a1*c2-c1*a2)/denom;
388  }
389 
390  template <class FT>
391  static void solve (const FT &a1, const FT &a2, const FT &a3,
392  const FT &b1, const FT &b2, const FT &b3,
393  const FT &c1, const FT &c2, const FT &c3,
394  const FT &d1, const FT &d2, const FT &d3,
395  FT &x, FT &y, FT &z)
396  {
397  FT denom = b2*c1*a3-b1*c2*a3+c3*b1*a2+b3*c2*a1-c1*b3*a2-b2*c3*a1;
398 
399  x = - (b2*c3*d1-b2*c1*d3+c1*b3*d2+b1*c2*d3-c3*b1*d2-b3*c2*d1)/denom;
400 
401  z = (b2*d1*a3-b2*a1*d3+b1*a2*d3-b1*d2*a3-d1*b3*a2+a1*b3*d2)/denom;
402 
403  y = (a2*c3*d1-a2*c1*d3-c2*d1*a3+c2*a1*d3+d2*c1*a3-d2*c3*a1)/denom;
404  }
405 
406  // Wrapper for solving 3x3 equations
407  static void solve ( const Vector_3<double> A[3],
408  const Vector_3<double> &q,
409  Vector_3<double> &x) {
410  solve( A[0][0], A[0][1], A[0][2], A[1][0], A[1][1], A[1][2],
411  A[2][0], A[2][1], A[2][2], q[0], q[1], q[2],
412  x[0], x[1], x[2]);
413  }
414  //\}
415 
416  protected: // Variables specific to medial quadric smoothing
417 
418  bool _reorthog;
420  double _eig_thres;
421  double _dir_thres;
423  int _rediter;
424  const COM::Attribute *_cnstr_types;
425  COM::Attribute *_cnstr_dirs;
426  std::vector<std::set< Edge_ID> > _edges;
427 
428 protected: // Variables not currently modifiable via set_option
429 
430  //std::vector<std::vector<bool> > _elems_to_check; ///< Check quality of these.
431  std::vector<std::vector<bool> > _is_shared_node;
432  std::vector<std::vector<bool> > _is_shared_elem;
433  std::vector<std::vector<bool> > _is_phys_bnd_node;
434  std::vector<std::vector<bool> > _is_phys_bnd_elem;
435  std::vector<std::vector<bool> > _is_pane_bnd_node;
436  std::vector<std::vector<bool> > _is_pane_bnd_elem;
437 
438  const COM::Window *_usr_window;
439  COM::Window *_wrk_window;
440 
441  bool _is_pmesh;
442 
443  protected: // Variables which can be modified via set option.
444 
445  enum { MOP_COOKIE=762667};
446 
447  int _method;
448  // 0 == mesquite
449  // 1 == mesquite, no ghosts
450  // 2 == medial_quadric
451  // 3 == error (default)
452 
453  int _verb;
454  // 0 = no debugging info
455  // 1 = routine entries
456  // 2 = routine entries and exits
457  // 3 = highest level in routine info
458  // 4 = low level in routine info
459  // 5 = 4 + high level MesqPane info
460  // 6 = 5 + low level MesqPane info
461 
462  int _lazy;
463 
464  float _tol;
465  // Smoother loops until either
466  // worst element quality > tol
467  // OR _niter iterations reached
468 
469  int _niter;
470 
471  float _ctol;
472  // Parallel mesquite subcycles for convergence until either
473  // (post communication quality)/(pre communication quality) > _tol
474  // OR _ncycle cycles performed.
475  // In this context, quality refers to worst quality of all real elements
476  // containing shared nodes.
477  // _ctol should be set to a value between 0 and 1
478 
479  int _ncycle;
480 
481  int _monotone;
482  // If true (default is false) and smoothing in place,
483  // will warn if final quality is worse than original quality
484  // If true and not smoothing in place,
485  // will return 0 displacement if final quality is worse than original quality
486 
487  int _cookie;
488 
489  int _invert;
490 };
491 
493 
494 #endif
495 
496 
497 
498 
499 
500 
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.h:206
void determine_physical_border()
Determine which nodes and elements are on the physical border.
Definition: Rocmop.C:677
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
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
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.h:407
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 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.h:391
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
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
COM::Window * _wrk_window
The working window.
Definition: Rocmop.h:439
#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
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 _monotone
Impose non-decreasing quality?
Definition: Rocmop.h:481
int _verb
Verbose level.
Definition: Rocmop.h:453
virtual SURF::Window_manifold_2 * manifold()
Obtain a reference to the manifold.
Definition: Rocmop.h:202
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.h:240
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.h:378
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.h:226
const COM::Attribute * _cnstr_types
Stores types of nodal constraints.
Definition: Rocmop.h:424
#define MOP_BEGIN_NAMESPACE
Definition: mopbasic.h:28
static int rank
Definition: advectest.C:66
Rocmop()
Default Constructor.
Definition: Rocmop.h:55
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
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
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
std::vector< std::set< Edge_ID > > _edges
ridge edges
Definition: Rocmop.h:426