Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/Randomize.hpp
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  ***************************************************************** */
38 #ifndef Mesquite_Randomize_hpp
39 #define Mesquite_Randomize_hpp
40 
41 #include "Mesquite.hpp"
42 #include "VertexMover.hpp"
44 #include "MsqDebug.hpp"
45 #include <math.h>
46 namespace Mesquite
47 {
48 
52  class Randomize : public VertexMover
53  {
54  public:
56  Randomize();
58  Randomize(double percent);
59 
60  virtual ~Randomize() { }
61 
62  protected:
63  virtual void initialize(PatchData &pd, MsqError &err);
64  virtual void optimize_vertex_positions(PatchData &pd,
65  MsqError &err);
66  virtual void initialize_mesh_iteration(PatchData &pd, MsqError &err);
67  virtual void terminate_mesh_iteration(PatchData &pd, MsqError &err);
68  virtual void cleanup();
69  private:
71  double mPercent;
76  inline void randomize_vertex(PatchData &pd,size_t num_vtx,
77  MsqVertex &free_vtx,
78  MsqError &err);
79  };
80 
81 
83  inline void Randomize::randomize_vertex(PatchData &pd, size_t num_vtx,
84  MsqVertex &free_vtx,
85  MsqError &err)
86  {
87  size_t i;
88  short j;
89  MsqVertex* verts = pd.get_vertex_array(err); MSQ_ERRRTN(err);
90  //a scale w.r.t. the patch size
91  double scale_factor=0.0;
92  //a "random" number between -1 and 1
93  double rand_double=0.0;
94  //a "random" int
95  int rand_int=0;
96  if (num_vtx<=1){
97  MSQ_PRINT(1)("WARNING: Number of incident vertex is zero. Returning.\n");
98  return;
99  }
100 
101  size_t free_ind = pd.get_vertex_index(&(free_vtx));
102 
103 
104  for (i=0;i<num_vtx;++i){
105  if(i != free_ind)
106  scale_factor+=(verts[i]-free_vtx).length();
107  }
108  scale_factor/=( (double) num_vtx - 1.0 );
109  for (j=0;j<3;++j){
110  rand_int = rand();
111  //number between 0 and 1000
112  rand_int = rand_int%1000;
113  //number between -1 and 1
114  rand_double = (((double) rand_int)/500.0)-1.0;
115  free_vtx[j] += scale_factor*rand_double*mPercent;
116  }
117 
118  return;
119  }
120 
121 
122 }
123 
124 #endif
Randomize()
Constructor defaulting mPercent to .05.
virtual void terminate_mesh_iteration(PatchData &pd, MsqError &err)
Used to hold the error state and return it to the application.
double length(Vector3D *const v, int n)
size_t get_vertex_index(MsqVertex *vertex)
blockLoc i
Definition: read.cpp:79
virtual void initialize_mesh_iteration(PatchData &pd, MsqError &err)
const MsqVertex * get_vertex_array(MsqError &err) const
Returns a pointer to the start of the vertex array.
j indices j
Definition: Indexing.h:6
#define MSQ_PRINT(flag)
Check debug flag and print printf-style formatted output.
virtual void optimize_vertex_positions(PatchData &pd, MsqError &err)
Randomly perftubs the (un-culled) vertices.
double rand()
Return a random variable between [0,1] with respect to an uniform distribution.
Definition: CImg.h:4833
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
virtual void initialize(PatchData &pd, MsqError &err)
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.
void randomize_vertex(PatchData &pd, size_t num_vtx, MsqVertex &free_vtx, MsqError &err)
Perturbs the free vertex randomly.