libMesh
mesh_smoother_vsmoother.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_MESH_SMOOTHER_VSMOOTHER_H
21 #define LIBMESH_MESH_SMOOTHER_VSMOOTHER_H
22 
23 #include "libmesh/libmesh_config.h"
24 #ifdef LIBMESH_ENABLE_VSMOOTHER
25 
26 // Local Includes
27 #include "libmesh/libmesh_common.h"
28 #include "libmesh/mesh_smoother.h"
29 
30 // C++ Includes
31 #include <cstddef>
32 #include <vector>
33 #include <map>
34 #include <fstream>
35 
36 namespace libMesh
37 {
38 
39 // Forward declarations
40 class UnstructuredMesh;
41 
64 {
65 public:
66 
71  double theta=0.5,
72  unsigned miniter=2,
73  unsigned maxiter=5,
74  unsigned miniterBC=5);
75 
80  std::vector<float> * adapt_data,
81  double theta=0.5,
82  unsigned miniter=2,
83  unsigned maxiter=5,
84  unsigned miniterBC=5,
85  double percent_to_move=1);
86 
92  const UnstructuredMesh * area_of_interest,
93  std::vector<float> * adapt_data,
94  double theta=0.5,
95  unsigned miniter=2,
96  unsigned maxiter=5,
97  unsigned miniterBC=5,
98  double percent_to_move=1);
99 
101  {
102  UNIFORM = 1,
105  };
106 
108  {
109  CELL = -1,
110  NONE = 0,
111  NODE = 1
112  };
113 
118 
125  virtual void smooth() libmesh_override { _distance = this->smooth(1); }
126 
132  double smooth(unsigned int n_iterations);
133 
137  double distance_moved() const { return _distance; }
138 
142  void set_generate_data(bool b) { _generate_data = b; }
143 
147  void set_metric(MetricType t) { _metric = t; }
148 
149 private:
150 
154  double _distance;
155 
159  const double _percent_to_move;
160 
164  double _dist_norm;
165 
169  std::map<dof_id_type, std::vector<dof_id_type>> _hanging_nodes;
170 
174  std::vector<float> * _adapt_data;
175 
179  const unsigned _dim;
180  const unsigned _miniter;
181  const unsigned _maxiter;
182  const unsigned _miniterBC;
185  const double _theta;
187 
194 
201 
208 
212  std::ofstream _logfile;
213 
218 
219  void adjust_adapt_data();
220  float adapt_minimum() const;
221 
225  template <typename T>
226  struct Array2D
227  {
228  Array2D(unsigned nx, unsigned ny) :
229  _data(nx, std::vector<T>(ny)) {}
230 
231  // Accessors
232  std::vector<T> & operator[](unsigned i) {return _data[i];}
233  const std::vector<T> & operator[](unsigned i) const {return _data[i];}
234 
235  private:
236  std::vector<std::vector<T>> _data;
237  };
238 
239 
240 
244  template <typename T>
245  struct Array3D
246  {
247  Array3D(unsigned nx, unsigned ny, unsigned nz)
248  {
249  _data.resize(nx, Array2D<T>(ny,nz));
250  }
251 
252  // Accessors
253  Array2D<T> & operator[](unsigned i) {return _data[i];}
254  const Array2D<T> & operator[](unsigned i) const {return _data[i];}
255 
256  private:
257  std::vector<Array2D<T>> _data;
258  };
259 
260 
261  int writegr(const Array2D<double> & R);
262 
263  int readgr(Array2D<double> & R,
264  std::vector<int> & mask,
265  Array2D<int> & cells,
266  std::vector<int> & mcells,
267  std::vector<int> & edges,
268  std::vector<int> & hnodes);
269 
270  int readmetr(std::string name,
271  Array3D<double> & H);
272 
273  int read_adp(std::vector<double> & afun);
274 
275  double jac3(double x1, double y1, double z1,
276  double x2, double y2, double z2,
277  double x3, double y3, double z3);
278 
279  double jac2(double x1, double y1,
280  double x2, double y2);
281 
282  int basisA(Array2D<double> & Q,
283  int nvert,
284  const std::vector<double> & K,
285  const Array2D<double> & H,
286  int me);
287 
288  void adp_renew(const Array2D<double> & R,
289  const Array2D<int> & cells,
290  std::vector<double> & afun,
291  int adp);
292 
293  void full_smooth(Array2D<double> & R,
294  const std::vector<int> & mask,
295  const Array2D<int> & cells,
296  const std::vector<int> & mcells,
297  const std::vector<int> & edges,
298  const std::vector<int> & hnodes,
299  double w,
300  const std::vector<int> & iter,
301  int me,
302  const Array3D<double> & H,
303  int adp,
304  int gr);
305 
306  double maxE(Array2D<double> & R,
307  const Array2D<int> & cells,
308  const std::vector<int> & mcells,
309  int me,
310  const Array3D<double> & H,
311  double v,
312  double epsilon,
313  double w,
314  std::vector<double> & Gamma,
315  double & qmin);
316 
317  double minq(const Array2D<double> & R,
318  const Array2D<int> & cells,
319  const std::vector<int> & mcells,
320  int me,
321  const Array3D<double> & H,
322  double & vol,
323  double & Vmin);
324 
325  double minJ(Array2D<double> & R,
326  const std::vector<int> & mask,
327  const Array2D<int> & cells,
328  const std::vector<int> & mcells,
329  double epsilon,
330  double w,
331  int me,
332  const Array3D<double> & H,
333  double vol,
334  const std::vector<int> & edges,
335  const std::vector<int> & hnodes,
336  int msglev,
337  double & Vmin,
338  double & emax,
339  double & qmin,
340  int adp,
341  const std::vector<double> & afun);
342 
343  double minJ_BC(Array2D<double> & R,
344  const std::vector<int> & mask,
345  const Array2D<int> & cells,
346  const std::vector<int> & mcells,
347  double epsilon,
348  double w,
349  int me,
350  const Array3D<double> & H,
351  double vol,
352  int msglev,
353  double & Vmin,
354  double & emax,
355  double & qmin,
356  int adp,
357  const std::vector<double> & afun,
358  int NCN);
359 
360  double localP(Array3D<double> & W,
361  Array2D<double> & F,
362  Array2D<double> & R,
363  const std::vector<int> & cell_in,
364  const std::vector<int> & mask,
365  double epsilon,
366  double w,
367  int nvert,
368  const Array2D<double> & H,
369  int me,
370  double vol,
371  int f,
372  double & Vmin,
373  double & qmin,
374  int adp,
375  const std::vector<double> & afun,
376  std::vector<double> & Gloc);
377 
378  double avertex(const std::vector<double> & afun,
379  std::vector<double> & G,
380  const Array2D<double> & R,
381  const std::vector<int> & cell_in,
382  int nvert,
383  int adp);
384 
385  double vertex(Array3D<double> & W,
386  Array2D<double> & F,
387  const Array2D<double> & R,
388  const std::vector<int> & cell_in,
389  double epsilon,
390  double w,
391  int nvert,
392  const std::vector<double> & K,
393  const Array2D<double> & H,
394  int me,
395  double vol,
396  int f,
397  double & Vmin,
398  int adp,
399  const std::vector<double> & g,
400  double sigma);
401 
402  void metr_data_gen(std::string grid,
403  std::string metr,
404  int me);
405 
406  int solver(int n,
407  const std::vector<int> & ia,
408  const std::vector<int> & ja,
409  const std::vector<double> & a,
410  std::vector<double> & x,
411  const std::vector<double> & b,
412  double eps,
413  int maxite,
414  int msglev);
415 
416  int pcg_ic0(int n,
417  const std::vector<int> & ia,
418  const std::vector<int> & ja,
419  const std::vector<double> & a,
420  const std::vector<double> & u,
421  std::vector<double> & x,
422  const std::vector<double> & b,
423  std::vector<double> & r,
424  std::vector<double> & p,
425  std::vector<double> & z,
426  double eps,
427  int maxite,
428  int msglev);
429 
430  int pcg_par_check(int n,
431  const std::vector<int> & ia,
432  const std::vector<int> & ja,
433  const std::vector<double> & a,
434  double eps,
435  int maxite,
436  int msglev);
437 
438  void gener(char grid[], int n);
439 };
440 
441 } // namespace libMesh
442 
443 #endif // LIBMESH_ENABLE_VSMOOTHER
444 
445 #endif // LIBMESH_MESH_SMOOTHER_VSMOOTHER_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
Array3D(unsigned nx, unsigned ny, unsigned nz)
int solver(int n, const std::vector< int > &ia, const std::vector< int > &ja, const std::vector< double > &a, std::vector< double > &x, const std::vector< double > &b, double eps, int maxite, int msglev)
std::map< dof_id_type, std::vector< dof_id_type > > _hanging_nodes
Map for hanging_nodes.
int basisA(Array2D< double > &Q, int nvert, const std::vector< double > &K, const Array2D< double > &H, int me)
void full_smooth(Array2D< double > &R, const std::vector< int > &mask, const Array2D< int > &cells, const std::vector< int > &mcells, const std::vector< int > &edges, const std::vector< int > &hnodes, double w, const std::vector< int > &iter, int me, const Array3D< double > &H, int adp, int gr)
void adp_renew(const Array2D< double > &R, const Array2D< int > &cells, std::vector< double > &afun, int adp)
double jac2(double x1, double y1, double x2, double y2)
dof_id_type _n_hanging_edges
The number of hanging node edges in the Mesh at the time of smoothing.
double minJ(Array2D< double > &R, const std::vector< int > &mask, const Array2D< int > &cells, const std::vector< int > &mcells, double epsilon, double w, int me, const Array3D< double > &H, double vol, const std::vector< int > &edges, const std::vector< int > &hnodes, int msglev, double &Vmin, double &emax, double &qmin, int adp, const std::vector< double > &afun)
void set_generate_data(bool b)
Allow user to control whether the metric is generated from the initial mesh.
double vertex(Array3D< double > &W, Array2D< double > &F, const Array2D< double > &R, const std::vector< int > &cell_in, double epsilon, double w, int nvert, const std::vector< double > &K, const Array2D< double > &H, int me, double vol, int f, double &Vmin, int adp, const std::vector< double > &g, double sigma)
MeshBase & mesh
std::ofstream _logfile
All output (including debugging) is sent to the _logfile.
The libMesh namespace provides an interface to certain functionality in the library.
double _distance
Max distance of the last set of movement.
dof_id_type _n_cells
The number of active elements in the Mesh at the time of smoothing.
virtual ~VariationalMeshSmoother()
Destructor.
const double _percent_to_move
Dampening factor.
dof_id_type _n_nodes
The number of nodes in the Mesh at the time of smoothing.
double minq(const Array2D< double > &R, const Array2D< int > &cells, const std::vector< int > &mcells, int me, const Array3D< double > &H, double &vol, double &Vmin)
int readgr(Array2D< double > &R, std::vector< int > &mask, Array2D< int > &cells, std::vector< int > &mcells, std::vector< int > &edges, std::vector< int > &hnodes)
double minJ_BC(Array2D< double > &R, const std::vector< int > &mask, const Array2D< int > &cells, const std::vector< int > &mcells, double epsilon, double w, int me, const Array3D< double > &H, double vol, int msglev, double &Vmin, double &emax, double &qmin, int adp, const std::vector< double > &afun, int NCN)
2D array type for interfacing with C APIs.
const std::vector< T > & operator[](unsigned i) const
PetscErrorCode Vec x
double localP(Array3D< double > &W, Array2D< double > &F, Array2D< double > &R, const std::vector< int > &cell_in, const std::vector< int > &mask, double epsilon, double w, int nvert, const Array2D< double > &H, int me, double vol, int f, double &Vmin, double &qmin, int adp, const std::vector< double > &afun, std::vector< double > &Gloc)
The UnstructuredMesh class is derived from the MeshBase class.
std::vector< float > * _adapt_data
Vector for holding adaptive data.
int pcg_par_check(int n, const std::vector< int > &ia, const std::vector< int > &ja, const std::vector< double > &a, double eps, int maxite, int msglev)
double jac3(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3)
int readmetr(std::string name, Array3D< double > &H)
double maxE(Array2D< double > &R, const Array2D< int > &cells, const std::vector< int > &mcells, int me, const Array3D< double > &H, double v, double epsilon, double w, std::vector< double > &Gamma, double &qmin)
int read_adp(std::vector< double > &afun)
VariationalMeshSmoother(UnstructuredMesh &mesh, double theta=0.5, unsigned miniter=2, unsigned maxiter=5, unsigned miniterBC=5)
Simple constructor to use for smoothing purposes.
const Array2D< T > & operator[](unsigned i) const
virtual void smooth() libmesh_override
Redefinition of the smooth function from the base class.
This is an implementation of Larisa Branets&#39; smoothing algorithms.
int pcg_ic0(int n, const std::vector< int > &ia, const std::vector< int > &ja, const std::vector< double > &a, const std::vector< double > &u, std::vector< double > &x, const std::vector< double > &b, std::vector< double > &r, std::vector< double > &p, std::vector< double > &z, double eps, int maxite, int msglev)
This class provides the necessary interface for mesh smoothing.
Definition: mesh_smoother.h:38
double avertex(const std::vector< double > &afun, std::vector< double > &G, const Array2D< double > &R, const std::vector< int > &cell_in, int nvert, int adp)
const UnstructuredMesh * _area_of_interest
Area of Interest Mesh.
int writegr(const Array2D< double > &R)
3D array type for interfacing with C APIs.
uint8_t dof_id_type
Definition: id_types.h:64
const unsigned _dim
Smoother control variables.
double _dist_norm
Records a relative "distance moved".
void metr_data_gen(std::string grid, std::string metr, int me)
void set_metric(MetricType t)
Allow user to control the smoothing metric used.