Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
inks/SmartLaplacianSmoother.cpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
24  pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
25 
26  ***************************************************************** */
39 #include "SmartLaplacianSmoother.hpp"
40 #include "LaplacianSmoother.hpp"
41 #include "MsqDebug.hpp"
42 #include "LInfTemplate.hpp"
43 #include "IdealWeightInverseMeanRatio.hpp"
44 
45 #ifdef MSQ_USE_OLD_STD_HEADERS
46 # include <vector.h>
47 #else
48 # include <vector>
49  using std::vector;
50 #endif
51 
52 
53 namespace Mesquite {
54 
55 
56 SmartLaplacianSmoother::SmartLaplacianSmoother(ObjectiveFunction* obj_func,
57  MsqError &err)
58  : edgeQM(0), defaultObjFunc(0)
59 {
60  this->set_name("SmartLaplacianSmoother");
61 
63  if(obj_func==NULL){
64  edgeQM = new IdealWeightInverseMeanRatio(err); MSQ_ERRRTN(err);
65  defaultObjFunc = new LInfTemplate(edgeQM);
67  }
68  else{
69  objFunc=obj_func;
70  defaultObjFunc=NULL;
71  }
72 
73 }
74 
76 {
77  delete edgeQM;
78  delete defaultObjFunc;
79 }
80 
81 void SmartLaplacianSmoother::initialize(PatchData& /*pd*/, MsqError& /*err*/)
82 {
83 
84 }
85 
87  MsqError &/*err*/)
88 {
89  // cout << "- Executing SmartLaplacianSmoother::iteration_complete()\n";
90 }
91 
98  MsqError &err)
99 {
100  //default the laplacian smoother to 3 even for 2-d elements.
101  //int dim = get_mesh_set()->space_dim();
102  size_t dim = 3;
103  MsqVertex* verts=pd.get_vertex_array(err); MSQ_ERRRTN(err);
104  //variables for the function values.
105  double orig_val=0;
106  double mod_val=0;
107  //compute the original function value and check validity
108  bool valid_flag = objFunc->evaluate(pd,orig_val,err); MSQ_ERRRTN(err);
109  // does the Laplacian smoothing
110  MsqFreeVertexIndexIterator free_iter(&pd, err); MSQ_ERRRTN(err);
111  free_iter.reset();
112  free_iter.next();
113  //m is the free vertex.
114  size_t m=free_iter.value();
115  vector<size_t> vert_indices;
116  vert_indices.reserve(25);
117  //get vertices adjacent to vertex m
118  pd.get_adjacent_vertex_indices(m,vert_indices,err); MSQ_ERRRTN(err);
119  //move vertex m
120  //save the original position of the free vertex
121  Vector3D orig_position(verts[m]);
122  //smooth the patch
123  centroid_smooth_mesh(pd, vert_indices.size(), vert_indices,
124  m, dim, err); MSQ_ERRRTN(err);
125  //snap vertex m to domain
126  pd.snap_vertex_to_domain(m,err); MSQ_ERRRTN(err);
127  //if the original function val was invalid, then we allow the move
128  //But, if it wasn valid, we need to decide.
129  if(valid_flag){
130  //compute the new value
131  valid_flag = objFunc->evaluate(pd,mod_val,err); MSQ_ERRRTN(err);
132  //if the new value is worse the original OR if the new value is not
133  //valid (we already know the original value was valid by above) then
134  //we don't allow the move.
135  if(!valid_flag || mod_val>orig_val){
136  //move the vert back to where it was.
137  verts[m]=orig_position;
138  //PRINT_INFO("\norig = %f, new = %f, new valid = %d",orig_val,mod_val,valid_flag);
139  }
140 
141  }
142 
143 }
144 
146  MsqError &/*err*/)
147 {
148  // cout << "- Executing SmartLaplacianSmoother::iteration_complete()\n";
149 }
150 
152 {
153  // cout << "- Executing SmartLaplacianSmoother::iteration_end()\n";
154 }
155 
156 
157 }
virtual void set_patch_type(PatchData::PatchType patch_type, MsqError &err, int param1=0, int param2=0)
Sets the Patch Type.
bool evaluate(PatchData &patch, double &fval, MsqError &err)
void set_name(msq_std::string name)
provides a name to the QualityImprover (use it in constructor).
NVec< 3, double > Vector3D
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.
void centroid_smooth_mesh(PatchData &pd, size_t num_adj_vtx, msq_std::vector< size_t > adj_vtx_ind, size_t free_ind, size_t dimension, MsqError &err)