libMesh
mesh_smoother_vsmoother.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 #if defined(LIBMESH_ENABLE_VSMOOTHER) && LIBMESH_DIM > 1
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  Real theta=0.5,
72  unsigned miniter=2,
73  unsigned maxiter=5,
74  unsigned miniterBC=5);
75 
80  std::vector<float> * adapt_data,
81  Real theta=0.5,
82  unsigned miniter=2,
83  unsigned maxiter=5,
84  unsigned miniterBC=5,
85  Real percent_to_move=1);
86 
92  const UnstructuredMesh * area_of_interest,
93  std::vector<float> * adapt_data,
94  Real theta=0.5,
95  unsigned miniter=2,
96  unsigned maxiter=5,
97  unsigned miniterBC=5,
98  Real 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() override { _distance = this->smooth(1); }
126 
132  Real smooth(unsigned int n_iterations);
133 
137  Real 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 
155 
160 
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 Real _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<Real> & R);
262 
263  int readgr(Array2D<Real> & 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<Real> & H);
272 
273  int read_adp(std::vector<Real> & afun);
274 
275  Real jac3(Real x1, Real y1, Real z1,
276  Real x2, Real y2, Real z2,
277  Real x3, Real y3, Real z3);
278 
279  Real jac2(Real x1, Real y1,
280  Real x2, Real y2);
281 
282  int basisA(Array2D<Real> & Q,
283  int nvert,
284  const std::vector<Real> & K,
285  const Array2D<Real> & H,
286  int me);
287 
288  void adp_renew(const Array2D<Real> & R,
289  const Array2D<int> & cells,
290  std::vector<Real> & afun,
291  int adp);
292 
293  void full_smooth(Array2D<Real> & 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  Real w,
300  const std::vector<int> & iter,
301  int me,
302  const Array3D<Real> & H,
303  int adp,
304  int gr);
305 
306  Real maxE(Array2D<Real> & R,
307  const Array2D<int> & cells,
308  const std::vector<int> & mcells,
309  int me,
310  const Array3D<Real> & H,
311  Real v,
312  Real epsilon,
313  Real w,
314  std::vector<Real> & Gamma,
315  Real & qmin);
316 
317  Real minq(const Array2D<Real> & R,
318  const Array2D<int> & cells,
319  const std::vector<int> & mcells,
320  int me,
321  const Array3D<Real> & H,
322  Real & vol,
323  Real & Vmin);
324 
325  Real minJ(Array2D<Real> & R,
326  const std::vector<int> & mask,
327  const Array2D<int> & cells,
328  const std::vector<int> & mcells,
329  Real epsilon,
330  Real w,
331  int me,
332  const Array3D<Real> & H,
333  Real vol,
334  const std::vector<int> & edges,
335  const std::vector<int> & hnodes,
336  int msglev,
337  Real & Vmin,
338  Real & emax,
339  Real & qmin,
340  int adp,
341  const std::vector<Real> & afun);
342 
344  const std::vector<int> & mask,
345  const Array2D<int> & cells,
346  const std::vector<int> & mcells,
347  Real epsilon,
348  Real w,
349  int me,
350  const Array3D<Real> & H,
351  Real vol,
352  int msglev,
353  Real & Vmin,
354  Real & emax,
355  Real & qmin,
356  int adp,
357  const std::vector<Real> & afun,
358  int NCN);
359 
361  Array2D<Real> & F,
362  Array2D<Real> & R,
363  const std::vector<int> & cell_in,
364  const std::vector<int> & mask,
365  Real epsilon,
366  Real w,
367  int nvert,
368  const Array2D<Real> & H,
369  int me,
370  Real vol,
371  int f,
372  Real & Vmin,
373  Real & qmin,
374  int adp,
375  const std::vector<Real> & afun,
376  std::vector<Real> & Gloc);
377 
378  Real avertex(const std::vector<Real> & afun,
379  std::vector<Real> & G,
380  const Array2D<Real> & R,
381  const std::vector<int> & cell_in,
382  int nvert,
383  int adp);
384 
386  Array2D<Real> & F,
387  const Array2D<Real> & R,
388  const std::vector<int> & cell_in,
389  Real epsilon,
390  Real w,
391  int nvert,
392  const std::vector<Real> & K,
393  const Array2D<Real> & H,
394  int me,
395  Real vol,
396  int f,
397  Real & Vmin,
398  int adp,
399  const std::vector<Real> & g,
400  Real 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<Real> & a,
410  std::vector<Real> & x,
411  const std::vector<Real> & b,
412  Real 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<Real> & a,
420  const std::vector<Real> & u,
421  std::vector<Real> & x,
422  const std::vector<Real> & b,
423  std::vector<Real> & r,
424  std::vector<Real> & p,
425  std::vector<Real> & z,
426  Real 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<Real> & a,
434  Real eps,
435  int maxite,
436  int msglev);
437 
438  void gener(char grid[], int n);
439 };
440 
441 } // namespace libMesh
442 
443 #endif // defined(LIBMESH_ENABLE_VSMOOTHER) && LIBMESH_DIM > 1
444 
445 #endif // LIBMESH_MESH_SMOOTHER_VSMOOTHER_H
libMesh::VariationalMeshSmoother::gener
void gener(char grid[], int n)
Definition: mesh_smoother_vsmoother.C:3918
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::VariationalMeshSmoother::avertex
Real avertex(const std::vector< Real > &afun, std::vector< Real > &G, const Array2D< Real > &R, const std::vector< int > &cell_in, int nvert, int adp)
Definition: mesh_smoother_vsmoother.C:3317
libMesh::VariationalMeshSmoother::set_generate_data
void set_generate_data(bool b)
Allow user to control whether the metric is generated from the initial mesh.
Definition: mesh_smoother_vsmoother.h:142
libMesh::VariationalMeshSmoother::pcg_par_check
int pcg_par_check(int n, const std::vector< int > &ia, const std::vector< int > &ja, const std::vector< Real > &a, Real eps, int maxite, int msglev)
Definition: mesh_smoother_vsmoother.C:3664
libMesh::VariationalMeshSmoother::adp_renew
void adp_renew(const Array2D< Real > &R, const Array2D< int > &cells, std::vector< Real > &afun, int adp)
Definition: mesh_smoother_vsmoother.C:829
libMesh::VariationalMeshSmoother::_n_nodes
dof_id_type _n_nodes
The number of nodes in the Mesh at the time of smoothing.
Definition: mesh_smoother_vsmoother.h:193
libMesh::VariationalMeshSmoother::_logfile
std::ofstream _logfile
All output (including debugging) is sent to the _logfile.
Definition: mesh_smoother_vsmoother.h:212
libMesh::VariationalMeshSmoother::_area_of_interest
const UnstructuredMesh * _area_of_interest
Area of Interest Mesh.
Definition: mesh_smoother_vsmoother.h:217
libMesh::VariationalMeshSmoother::smooth
virtual void smooth() override
Redefinition of the smooth function from the base class.
Definition: mesh_smoother_vsmoother.h:125
libMesh::VariationalMeshSmoother::readmetr
int readmetr(std::string name, Array3D< Real > &H)
Definition: mesh_smoother_vsmoother.C:490
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::VariationalMeshSmoother::Array2D::operator[]
std::vector< T > & operator[](unsigned i)
Definition: mesh_smoother_vsmoother.h:232
libMesh::VariationalMeshSmoother::NONE
Definition: mesh_smoother_vsmoother.h:110
libMesh::VariationalMeshSmoother::UNIFORM
Definition: mesh_smoother_vsmoother.h:102
libMesh::VariationalMeshSmoother::Array2D::_data
std::vector< std::vector< T > > _data
Definition: mesh_smoother_vsmoother.h:236
libMesh::VariationalMeshSmoother::readgr
int readgr(Array2D< Real > &R, std::vector< int > &mask, Array2D< int > &cells, std::vector< int > &mcells, std::vector< int > &edges, std::vector< int > &hnodes)
Definition: mesh_smoother_vsmoother.C:269
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::VariationalMeshSmoother::_n_hanging_edges
dof_id_type _n_hanging_edges
The number of hanging node edges in the Mesh at the time of smoothing.
Definition: mesh_smoother_vsmoother.h:207
libMesh::VariationalMeshSmoother::writegr
int writegr(const Array2D< Real > &R)
Definition: mesh_smoother_vsmoother.C:223
libMesh::VariationalMeshSmoother::minJ
Real minJ(Array2D< Real > &R, const std::vector< int > &mask, const Array2D< int > &cells, const std::vector< int > &mcells, Real epsilon, Real w, int me, const Array3D< Real > &H, Real vol, const std::vector< int > &edges, const std::vector< int > &hnodes, int msglev, Real &Vmin, Real &emax, Real &qmin, int adp, const std::vector< Real > &afun)
Definition: mesh_smoother_vsmoother.C:1887
libMesh::VariationalMeshSmoother::_hanging_nodes
std::map< dof_id_type, std::vector< dof_id_type > > _hanging_nodes
Map for hanging_nodes.
Definition: mesh_smoother_vsmoother.h:169
libMesh::VariationalMeshSmoother::Array3D
3D array type for interfacing with C APIs.
Definition: mesh_smoother_vsmoother.h:245
libMesh::VariationalMeshSmoother::adapt_minimum
float adapt_minimum() const
Definition: mesh_smoother_vsmoother.C:512
libMesh::VariationalMeshSmoother::_adapt_data
std::vector< float > * _adapt_data
Vector for holding adaptive data.
Definition: mesh_smoother_vsmoother.h:174
libMesh::VariationalMeshSmoother::NODE
Definition: mesh_smoother_vsmoother.h:111
libMesh::VariationalMeshSmoother::Array2D::operator[]
const std::vector< T > & operator[](unsigned i) const
Definition: mesh_smoother_vsmoother.h:233
libMesh::VariationalMeshSmoother::distance_moved
Real distance_moved() const
Definition: mesh_smoother_vsmoother.h:137
libMesh::VariationalMeshSmoother::jac2
Real jac2(Real x1, Real y1, Real x2, Real y2)
Definition: mesh_smoother_vsmoother.C:610
libMesh::VariationalMeshSmoother::_generate_data
bool _generate_data
Definition: mesh_smoother_vsmoother.h:186
libMesh::VariationalMeshSmoother::vertex
Real vertex(Array3D< Real > &W, Array2D< Real > &F, const Array2D< Real > &R, const std::vector< int > &cell_in, Real epsilon, Real w, int nvert, const std::vector< Real > &K, const Array2D< Real > &H, int me, Real vol, int f, Real &Vmin, int adp, const std::vector< Real > &g, Real sigma)
Definition: mesh_smoother_vsmoother.C:3409
libMesh::VariationalMeshSmoother::VariationalMeshSmoother
VariationalMeshSmoother(UnstructuredMesh &mesh, Real theta=0.5, unsigned miniter=2, unsigned maxiter=5, unsigned miniterBC=5)
Simple constructor to use for smoothing purposes.
Definition: mesh_smoother_vsmoother.C:45
libMesh::VariationalMeshSmoother::jac3
Real jac3(Real x1, Real y1, Real z1, Real x2, Real y2, Real z2, Real x3, Real y3, Real z3)
Definition: mesh_smoother_vsmoother.C:595
libMesh::VariationalMeshSmoother::localP
Real localP(Array3D< Real > &W, Array2D< Real > &F, Array2D< Real > &R, const std::vector< int > &cell_in, const std::vector< int > &mask, Real epsilon, Real w, int nvert, const Array2D< Real > &H, int me, Real vol, int f, Real &Vmin, Real &qmin, int adp, const std::vector< Real > &afun, std::vector< Real > &Gloc)
Definition: mesh_smoother_vsmoother.C:2979
libMesh::VariationalMeshSmoother::_dist_norm
Real _dist_norm
Records a relative "distance moved".
Definition: mesh_smoother_vsmoother.h:164
libMesh::VariationalMeshSmoother::DIRECTIONAL
Definition: mesh_smoother_vsmoother.h:104
libMesh::VariationalMeshSmoother::maxE
Real maxE(Array2D< Real > &R, const Array2D< int > &cells, const std::vector< int > &mcells, int me, const Array3D< Real > &H, Real v, Real epsilon, Real w, std::vector< Real > &Gamma, Real &qmin)
Definition: mesh_smoother_vsmoother.C:1077
libMesh::VariationalMeshSmoother::minq
Real minq(const Array2D< Real > &R, const Array2D< int > &cells, const std::vector< int > &mcells, int me, const Array3D< Real > &H, Real &vol, Real &Vmin)
Definition: mesh_smoother_vsmoother.C:1484
libMesh::VariationalMeshSmoother::CELL
Definition: mesh_smoother_vsmoother.h:109
libMesh::VariationalMeshSmoother::_theta
const Real _theta
Definition: mesh_smoother_vsmoother.h:185
libMesh::VariationalMeshSmoother::VOLUMETRIC
Definition: mesh_smoother_vsmoother.h:103
libMesh::VariationalMeshSmoother::_n_cells
dof_id_type _n_cells
The number of active elements in the Mesh at the time of smoothing.
Definition: mesh_smoother_vsmoother.h:200
libMesh::VariationalMeshSmoother::adjust_adapt_data
void adjust_adapt_data()
Definition: mesh_smoother_vsmoother.C:531
libMesh::UnstructuredMesh
The UnstructuredMesh class is derived from the MeshBase class.
Definition: unstructured_mesh.h:48
libMesh::VariationalMeshSmoother::minJ_BC
Real minJ_BC(Array2D< Real > &R, const std::vector< int > &mask, const Array2D< int > &cells, const std::vector< int > &mcells, Real epsilon, Real w, int me, const Array3D< Real > &H, Real vol, int msglev, Real &Vmin, Real &emax, Real &qmin, int adp, const std::vector< Real > &afun, int NCN)
Definition: mesh_smoother_vsmoother.C:2359
libMesh::VariationalMeshSmoother::solver
int solver(int n, const std::vector< int > &ia, const std::vector< int > &ja, const std::vector< Real > &a, std::vector< Real > &x, const std::vector< Real > &b, Real eps, int maxite, int msglev)
Definition: mesh_smoother_vsmoother.C:3627
libMesh::VariationalMeshSmoother::_adaptive_func
AdaptType _adaptive_func
Definition: mesh_smoother_vsmoother.h:184
libMesh::VariationalMeshSmoother::_dim
const unsigned _dim
Smoother control variables.
Definition: mesh_smoother_vsmoother.h:179
libMesh::VariationalMeshSmoother::Array3D::operator[]
Array2D< T > & operator[](unsigned i)
Definition: mesh_smoother_vsmoother.h:253
libMesh::VariationalMeshSmoother::_miniter
const unsigned _miniter
Definition: mesh_smoother_vsmoother.h:180
libMesh::VariationalMeshSmoother::AdaptType
AdaptType
Definition: mesh_smoother_vsmoother.h:107
libMesh::VariationalMeshSmoother::Array3D::_data
std::vector< Array2D< T > > _data
Definition: mesh_smoother_vsmoother.h:257
std
Definition: float128_shims.h:27
libMesh::VariationalMeshSmoother
This is an implementation of Larisa Branets' smoothing algorithms.
Definition: mesh_smoother_vsmoother.h:63
libMesh::VariationalMeshSmoother::metr_data_gen
void metr_data_gen(std::string grid, std::string metr, int me)
Definition: mesh_smoother_vsmoother.C:3988
libMesh::VariationalMeshSmoother::Array2D
2D array type for interfacing with C APIs.
Definition: mesh_smoother_vsmoother.h:226
libMesh::VariationalMeshSmoother::Array2D::Array2D
Array2D(unsigned nx, unsigned ny)
Definition: mesh_smoother_vsmoother.h:228
libMesh::VariationalMeshSmoother::full_smooth
void full_smooth(Array2D< Real > &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, Real w, const std::vector< int > &iter, int me, const Array3D< Real > &H, int adp, int gr)
Definition: mesh_smoother_vsmoother.C:876
libMesh::VariationalMeshSmoother::~VariationalMeshSmoother
virtual ~VariationalMeshSmoother()
Destructor.
Definition: mesh_smoother_vsmoother.h:117
libMesh::VariationalMeshSmoother::set_metric
void set_metric(MetricType t)
Allow user to control the smoothing metric used.
Definition: mesh_smoother_vsmoother.h:147
libMesh::VariationalMeshSmoother::basisA
int basisA(Array2D< Real > &Q, int nvert, const std::vector< Real > &K, const Array2D< Real > &H, int me)
Definition: mesh_smoother_vsmoother.C:621
libMesh::VariationalMeshSmoother::_maxiter
const unsigned _maxiter
Definition: mesh_smoother_vsmoother.h:181
libMesh::VariationalMeshSmoother::_percent_to_move
const Real _percent_to_move
Dampening factor.
Definition: mesh_smoother_vsmoother.h:159
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::MeshSmoother
This class provides the necessary interface for mesh smoothing.
Definition: mesh_smoother.h:38
libMesh::VariationalMeshSmoother::_miniterBC
const unsigned _miniterBC
Definition: mesh_smoother_vsmoother.h:182
libMesh::VariationalMeshSmoother::read_adp
int read_adp(std::vector< Real > &afun)
Definition: mesh_smoother_vsmoother.C:573
libMesh::VariationalMeshSmoother::MetricType
MetricType
Definition: mesh_smoother_vsmoother.h:100
libMesh::VariationalMeshSmoother::_distance
Real _distance
Max distance of the last set of movement.
Definition: mesh_smoother_vsmoother.h:154
libMesh::VariationalMeshSmoother::Array3D::operator[]
const Array2D< T > & operator[](unsigned i) const
Definition: mesh_smoother_vsmoother.h:254
libMesh::VariationalMeshSmoother::Array3D::Array3D
Array3D(unsigned nx, unsigned ny, unsigned nz)
Definition: mesh_smoother_vsmoother.h:247
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::VariationalMeshSmoother::_metric
MetricType _metric
Definition: mesh_smoother_vsmoother.h:183
libMesh::VariationalMeshSmoother::pcg_ic0
int pcg_ic0(int n, const std::vector< int > &ia, const std::vector< int > &ja, const std::vector< Real > &a, const std::vector< Real > &u, std::vector< Real > &x, const std::vector< Real > &b, std::vector< Real > &r, std::vector< Real > &p, std::vector< Real > &z, Real eps, int maxite, int msglev)
Definition: mesh_smoother_vsmoother.C:3806