Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Remesher_Simmetrix.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Remesher_Simmetrix.C,v 1.6 2008/12/06 08:45:28 mtcampbe Exp $
24 
28 #include "Remesher_Simmetrix.h"
29 #include "MeshSim.h"
30 #include "SimModel.h"
31 #include "SimDiscrete.h"
32 
34 
36 
40  : _size_type(0), _size_val(0.), _fangle(0), _shrtRatio(5) {
41 
42  if ( logfile) Sim_logOn( logfile);
43 
44  if ( instances == 0) {
45  MS_init(); // start up MeshSim
46  Sim_registerKey("cen002 surface 20060331 0 mTcaTqnWjLIUId26P29r3w=="); // for surface
47  Sim_registerKey("cen002 discrete 20060331 0 8VnUzbSAnldsPdfPbpWFVw=="); // for discrete
48 
49  SimDiscrete_start(0);
50  }
51  ++instances;
52 }
53 
57  --instances;
58 
59  if ( instances==0) {
60  SimDiscrete_stop(0);
61  MS_exit();
62  Sim_logOff();
63  Sim_unregisterAllKeys();
64  }
65 }
66 
68 window_to_simmesh( const COM::Window *outwin) {
69  // Obtain the list of panes
70  std::vector<const COM::Pane*> panes;
71  outwin->panes(panes);
72  COM_assertion_msg( panes.size() == 1, "Window must be a serial one");
73 
74  // Get the sizes
75  int numVerts = panes[0]->size_of_nodes();
76  int numElems = panes[0]->size_of_elements();
77 
78  // Get the pointers to
79  std::vector<const COM::Connectivity*> elems;
80  panes[0]->elements( elems);
81  COM_assertion_msg( elems.size() == 1 &&
82  elems[0]->element_type()==COM::Connectivity::TRI3,
83  "Window must be a serial one");
84 
85  pMesh mesh = M_new(0,0);
86  // Initialize pMesh.
87  std::vector<int> elemTypes(numElems, 5 /* Triangles */);
88  /* offset nodal IDs to start from 0 */
89  int *tris = const_cast<int*>(elems[0]->pointer());
90  std::vector<int> tris_vec( numElems*3,0);
91  for ( int i=0; i<numElems*3; ++i)
92  tris_vec[i] = tris[i]-1;
93 
94  double *coors = const_cast<double*>(panes[0]->coordinates());
95  M_importFromData( mesh, numVerts, coors, numElems, &elemTypes[0],
96  &tris_vec[0], NULL, NULL);
97 
98  return mesh;
99 }
100 
102 simmesh_to_window( void *m, COM::Window *outwin) {
103  pMesh mesh = (pMesh)m;
104 
105  // Obtain the panes
106  std::vector<COM::Pane*> panes;
107  outwin->panes(panes);
108  COM_assertion_msg( panes.size() == 1, "Window must be a serial one");
109  int pid = panes[0]->id();
110 
111  // Obtain coordinates
112  COM::Attribute *coor = panes[0]->attribute( COM::COM_NC);
113  outwin->set_size( coor->name(), pid, M_numVertices(mesh));
114 
115  double *coors;
116  outwin->resize_array( coor, (void**)&coors);
117 
118  VIter vIter = M_vertexIter(mesh);
119  pVertex vertex;
120 
121  for (int i=0; (vertex=VIter_next(vIter)); ++i) {
122  EN_setID((pEntity)vertex, i+1);
123  V_coord(vertex, &coors[3*i]);
124  }
125  VIter_delete(vIter);
126 
127  // Obtain connectivity
128  std::vector<COM::Connectivity*> elems;
129  panes[0]->elements( elems);
130 
131  outwin->set_size( elems[0]->name(), pid, M_numFaces(mesh));
132 
133  int *tris;
134  outwin->resize_array( elems[0], (void**)&tris);
135 
136  FIter fIter = M_faceIter(mesh);
137  pFace face;
138  for (int i=0; (face = FIter_next(fIter)); ++i){
139  pPList fVerts = F_vertices(face,1);
140  int j;
141  for(j=0; j < 3; j++){
142  vertex = (pVertex)PList_item( fVerts, j);
143  tris[3*i+j] = EN_id((pEntity)vertex);
144  }
145  }
146  FIter_delete(fIter);
147 }
148 
150 remesh_serial( Manifold *wm, COM::Attribute *mesh_out,
151  double lave, double fangle) {
152 
153  std::cout << "Setting average edge length to " << lave << std::endl;
154  std::cout << "Setting feature angle to " << fangle << std::endl;
155 
156  // Set options
157  set_global_mesh_size( 1, lave);
158  set_fangle( fangle);
159  set_short_ratio( 5);
160 
161 
162  COM::Window *outwin = mesh_out->window();
163 
164  // Serialize input mesh and put into output mesh
165  wm->serialize_window( outwin);
166 
167  pMesh mesh = (pMesh)window_to_simmesh( outwin);
168  pDiscreteModel model = DM_createFromMesh( mesh, true);
169 
170  if ( _fangle>0) {
171  // Perform feature detection
172  double angleRadian = _fangle/180*3.14159265358979;
173 
174  DM_findEdgesByFaceNormals( model, angleRadian);
175  DM_eliminateDanglingEdges( model);
176  }
177  DM_completeTopology( model);
178 
179  // Obtain a new copy of the mesh for alteration
180  pMesh newMesh = DM_getMeshCopy( model);
181  pACase newCase = MS_newMeshCase(model);
182 
183  // set the desired mesh size
184  if ( _size_type != 0)
185  {
186  pModelMember mdomain = GM_domain(model);
187  MS_setMeshSize(newCase,mdomain, _size_type, _size_val,0);
188  }
189 
190  // Modify the surface mesh so that it conforms to the new size
191  DM_modifySurfaceMesh( newMesh, newCase ,0,0,0,0, /* swap, split, min, and max angles*/
192  0, 0, /* Collapes face and edge angles */
193  0, _shrtRatio, 0);
194 
195  simmesh_to_window( newMesh, outwin);
196 
197  M_release(newMesh);
198  GM_release((SGModel *) model);
199 }
200 
202 
203 
204 
205 
206 
207 
#define PROP_END_NAMESPACE
Definition: propbasic.h:29
#define PROP_BEGIN_NAMESPACE
Definition: propbasic.h:28
#define COM_assertion_msg(EX, msg)
void set_fangle(double fangle)
static int instances
This file provides a wrapper to invoke GeomSim from Simmetrix to remesh a surface mesh...
Remesher_Simmetrix(const char *logfile=NULL)
Initialize the remesher.
virtual void remesh_serial(Manifold *wm, COM::Attribute *mesh_out, double lave, double fangle)
SURF::Window_manifold_2 Manifold
Definition: propbasic.h:46
blockLoc i
Definition: read.cpp:79
void set_global_mesh_size(int type, double val)
static T_VertexSet * face
Definition: vinci_lass.c:79
j indices j
Definition: Indexing.h:6
virtual ~Remesher_Simmetrix()
Finalize the remesher.
void set_short_ratio(double r)
void simmesh_to_window(void *mesh, COM::Window *outwin)
void * window_to_simmesh(const COM::Window *outwin)