$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_MESH_SMOOTHER_VSMOOTHER_H 00021 #define LIBMESH_MESH_SMOOTHER_VSMOOTHER_H 00022 00023 #include "libmesh/libmesh_config.h" 00024 #ifdef LIBMESH_ENABLE_VSMOOTHER 00025 00026 // Local Includes ----------------------------------- 00027 #include "libmesh/mesh_smoother.h" 00028 #include "libmesh/unstructured_mesh.h" 00029 00030 // C++ Includes ----------------------------------- 00031 #include <cstddef> 00032 #include <vector> 00033 #include <map> 00034 #include <fstream> 00035 00036 namespace libMesh 00037 { 00038 00060 class VariationalMeshSmoother : public MeshSmoother 00061 { 00062 public: 00063 00067 VariationalMeshSmoother(UnstructuredMesh& mesh, 00068 double theta=0.5, 00069 unsigned miniter=2, 00070 unsigned maxiter=5, 00071 unsigned miniterBC=5); 00072 00076 VariationalMeshSmoother(UnstructuredMesh& mesh, 00077 std::vector<float>* adapt_data, 00078 double theta=0.5, 00079 unsigned miniter=2, 00080 unsigned maxiter=5, 00081 unsigned miniterBC=5, 00082 double percent_to_move=1); 00083 00088 VariationalMeshSmoother(UnstructuredMesh& mesh, 00089 const UnstructuredMesh* area_of_interest, 00090 std::vector<float>* adapt_data, 00091 double theta=0.5, 00092 unsigned miniter=2, 00093 unsigned maxiter=5, 00094 unsigned miniterBC=5, 00095 double percent_to_move=1); 00096 00097 enum MetricType 00098 { 00099 UNIFORM = 1, 00100 VOLUMETRIC = 2, 00101 DIRECTIONAL = 3 00102 }; 00103 00104 enum AdaptType 00105 { 00106 CELL = -1, 00107 NONE = 0, 00108 NODE = 1 00109 }; 00110 00114 virtual ~VariationalMeshSmoother() {} 00115 00122 virtual void smooth() { _distance = this->smooth(1); } 00123 00129 double smooth(unsigned int n_iterations); 00130 00134 double distance_moved() const { return _distance; } 00135 00139 void set_generate_data(bool b) { _generate_data = b; } 00140 00144 void set_metric(MetricType t) { _metric = t; } 00145 00146 private: 00147 00151 double _distance; 00152 00156 const double _percent_to_move; 00157 00161 double _dist_norm; 00162 00166 std::map<dof_id_type, std::vector<dof_id_type> > _hanging_nodes; 00167 00171 std::vector<float> * _adapt_data; 00172 00176 const unsigned _dim; 00177 const unsigned _miniter; 00178 const unsigned _maxiter; 00179 const unsigned _miniterBC; 00180 MetricType _metric; 00181 AdaptType _adaptive_func; 00182 const double _theta; 00183 bool _generate_data; 00184 00190 dof_id_type _n_nodes; 00191 00197 dof_id_type _n_cells; 00198 00204 dof_id_type _n_hanging_edges; 00205 00209 std::ofstream _logfile; 00210 00214 const UnstructuredMesh * _area_of_interest; 00215 00216 void adjust_adapt_data(); 00217 float adapt_minimum() const; 00218 00222 template <typename T> 00223 struct Array2D 00224 { 00225 Array2D(unsigned nx, unsigned ny) : 00226 _data(nx, std::vector<T>(ny)) {} 00227 00228 // Accessors 00229 std::vector<T>& operator[](unsigned i) {return _data[i];} 00230 const std::vector<T>& operator[](unsigned i) const {return _data[i];} 00231 00232 private: 00233 std::vector<std::vector<T> > _data; 00234 }; 00235 00236 00237 00241 template <typename T> 00242 struct Array3D 00243 { 00244 Array3D(unsigned nx, unsigned ny, unsigned nz) 00245 { 00246 _data.resize(nx, Array2D<T>(ny,nz)); 00247 } 00248 00249 // Accessors 00250 Array2D<T>& operator[](unsigned i) {return _data[i];} 00251 const Array2D<T>& operator[](unsigned i) const {return _data[i];} 00252 00253 private: 00254 std::vector<Array2D<T> > _data; 00255 }; 00256 00257 00258 int writegr(const Array2D<double>& R); 00259 00260 int readgr(Array2D<double>& R, 00261 std::vector<int>& mask, 00262 Array2D<int>& cells, 00263 std::vector<int>& mcells, 00264 std::vector<int>& edges, 00265 std::vector<int>& hnodes); 00266 00267 int readmetr(std::string name, 00268 Array3D<double>& H); 00269 00270 int read_adp(std::vector<double>& afun); 00271 00272 double jac3(double x1, double y1, double z1, 00273 double x2, double y2, double z2, 00274 double x3, double y3, double z3); 00275 00276 double jac2(double x1, double y1, 00277 double x2, double y2); 00278 00279 int basisA(Array2D<double>& Q, 00280 int nvert, 00281 const std::vector<double>& K, 00282 const Array2D<double>& H, 00283 int me); 00284 00285 void adp_renew(const Array2D<double>& R, 00286 const Array2D<int>& cells, 00287 std::vector<double>& afun, 00288 int adp); 00289 00290 void full_smooth(Array2D<double>& R, 00291 const std::vector<int>& mask, 00292 const Array2D<int>& cells, 00293 const std::vector<int>& mcells, 00294 const std::vector<int>& edges, 00295 const std::vector<int>& hnodes, 00296 double w, 00297 const std::vector<int>& iter, 00298 int me, 00299 const Array3D<double>& H, 00300 int adp, 00301 int gr); 00302 00303 double maxE(Array2D<double>& R, 00304 const Array2D<int>& cells, 00305 const std::vector<int>& mcells, 00306 int me, 00307 const Array3D<double>& H, 00308 double v, 00309 double epsilon, 00310 double w, 00311 std::vector<double>& Gamma, 00312 double& qmin); 00313 00314 double minq(const Array2D<double>& R, 00315 const Array2D<int>& cells, 00316 const std::vector<int>& mcells, 00317 int me, 00318 const Array3D<double>& H, 00319 double& vol, 00320 double& Vmin); 00321 00322 double minJ(Array2D<double>& R, 00323 const std::vector<int>& mask, 00324 const Array2D<int>& cells, 00325 const std::vector<int>& mcells, 00326 double epsilon, 00327 double w, 00328 int me, 00329 const Array3D<double>& H, 00330 double vol, 00331 const std::vector<int>& edges, 00332 const std::vector<int>& hnodes, 00333 int msglev, 00334 double& Vmin, 00335 double& emax, 00336 double& qmin, 00337 int adp, 00338 const std::vector<double>& afun); 00339 00340 double minJ_BC(Array2D<double>& R, 00341 const std::vector<int>& mask, 00342 const Array2D<int>& cells, 00343 const std::vector<int>& mcells, 00344 double epsilon, 00345 double w, 00346 int me, 00347 const Array3D<double>& H, 00348 double vol, 00349 int msglev, 00350 double& Vmin, 00351 double& emax, 00352 double& qmin, 00353 int adp, 00354 const std::vector<double>& afun, 00355 int NCN); 00356 00357 double localP(Array3D<double>& W, 00358 Array2D<double>& F, 00359 Array2D<double>& R, 00360 const std::vector<int>& cell_in, 00361 const std::vector<int>& mask, 00362 double epsilon, 00363 double w, 00364 int nvert, 00365 const Array2D<double>& H, 00366 int me, 00367 double vol, 00368 int f, 00369 double& Vmin, 00370 double& qmin, 00371 int adp, 00372 const std::vector<double>& afun, 00373 std::vector<double>& Gloc); 00374 00375 double avertex(const std::vector<double>& afun, 00376 std::vector<double>& G, 00377 const Array2D<double>& R, 00378 const std::vector<int>& cell_in, 00379 int nvert, 00380 int adp); 00381 00382 double vertex(Array3D<double>& W, 00383 Array2D<double>& F, 00384 const Array2D<double>& R, 00385 const std::vector<int>& cell_in, 00386 double epsilon, 00387 double w, 00388 int nvert, 00389 const std::vector<double>& K, 00390 const Array2D<double>& H, 00391 int me, 00392 double vol, 00393 int f, 00394 double& Vmin, 00395 int adp, 00396 const std::vector<double>& g, 00397 double sigma); 00398 00399 void metr_data_gen(std::string grid, 00400 std::string metr, 00401 int me); 00402 00403 int solver(int n, 00404 const std::vector<int>& ia, 00405 const std::vector<int>& ja, 00406 const std::vector<double>& a, 00407 std::vector<double>& x, 00408 const std::vector<double>& b, 00409 double eps, 00410 int maxite, 00411 int msglev); 00412 00413 int pcg_ic0(int n, 00414 const std::vector<int>& ia, 00415 const std::vector<int>& ja, 00416 const std::vector<double>& a, 00417 const std::vector<double>& u, 00418 std::vector<double>& x, 00419 const std::vector<double>& b, 00420 std::vector<double>& r, 00421 std::vector<double>& p, 00422 std::vector<double>& z, 00423 double eps, 00424 int maxite, 00425 int msglev); 00426 00427 int pcg_par_check(int n, 00428 const std::vector<int>& ia, 00429 const std::vector<int>& ja, 00430 const std::vector<double>& a, 00431 double eps, 00432 int maxite, 00433 int msglev); 00434 00435 void gener(char grid[], int n); 00436 }; 00437 00438 } // namespace libMesh 00439 00440 #endif // LIBMESH_ENABLE_VSMOOTHER 00441 00442 #endif // LIBMESH_MESH_SMOOTHER_VSMOOTHER_H