1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

#include "ChollaMesh.hpp"
#include "CubitFacetData.hpp"
#include "CubitFacetEdgeData.hpp"
#include "CubitPointData.hpp"

ChollaMesh::ChollaMesh()
{
}

ChollaMesh::~ChollaMesh()
{
}

FacetEntity* ChollaMesh::convert_to_facet(SMD::SMDElement elem)
{
  return reinterpret_cast<FacetEntity*>(elem.mHandle);
}

CubitPoint* ChollaMesh::convert_to_point(SMD::SMDNode node)
{
  return reinterpret_cast<CubitPoint*>(node.mHandle);
}

SMD::SMDElement ChollaMesh::convert_from_facet(FacetEntity* f)
{
  SMD::SMDElement e;
  e.mHandle = reinterpret_cast<size_t>(f);
  return e;
}

SMD::SMDNode ChollaMesh::convert_from_point(CubitPoint* p)
{
  SMD::SMDNode n;
  n.mHandle = reinterpret_cast<size_t>(p);
  return n;
}


SMD::ErrorCode ChollaMesh::get_ids(size_t num, const SMD::SMDNode nodes[], int ids[])<--- The function 'get_ids' is never used.
{
  for(size_t i=0; i<num; i++)
  {
    ids[i] = convert_to_point(nodes[i])->id();
  }
  return SMD::STATUS_OK;
}

SMD::ErrorCode ChollaMesh::get_ids(size_t num, const SMD::SMDElement elems[], int ids[])
{
  CubitFacet* tri;
  CubitFacetEdge* edge;

  for(size_t i=0; i<num; i++)
  {
    FacetEntity* f = convert_to_facet(elems[i]);
    if((tri = dynamic_cast<CubitFacet*>(f)))
    {
      ids[i] = tri->id();
    }
    else if((edge = dynamic_cast<CubitFacetEdge*>(f)))
    {
      ids[i] = edge->id();
    }
    else
    {
      ids[i] = 0;
    }
  }
  return SMD::STATUS_OK;
}


SMD::ErrorCode ChollaMesh::get_node_handle(int id, SMD::SMDNode &node)<--- The function 'get_node_handle' is never used.
{
  return SMD::ERR_NOT_IMPLEMENTED;
}

SMD::ErrorCode ChollaMesh::get_element_handle(SMD::ElementType type, int id, SMD::SMDElement &node)<--- The function 'get_element_handle' is never used.
{
  return SMD::ERR_NOT_IMPLEMENTED;
}

SMD::ErrorCode ChollaMesh::get_element_types(int num_elems, const SMD::SMDElement elem_handle_array[], <--- The function 'get_element_types' is never used.
                                 SMD::ElementType type_array[], bool*)
{
  for(int i=0; i<num_elems; i++)
  {
    FacetEntity* f = convert_to_facet(elem_handle_array[i]);
    if(dynamic_cast<CubitFacet*>(f))
    {
      type_array[i] = SMD::TRI;
    }
    else if(dynamic_cast<CubitFacetEdge*>(f))
    {
      type_array[i] = SMD::EDGE;
    }
    else
    {
      type_array[i] = SMD::NO_ELEMENT_TYPE;
    }
  }
  return SMD::STATUS_OK;
}

SMD::ErrorCode ChollaMesh::get_element_dimensions(int num_elems, const SMD::SMDElement elem_handle_array[],<--- The function 'get_element_dimensions' is never used.
                                      int dimensions[])
{
  for(int i=0; i<num_elems; i++)
  {
    FacetEntity* f = convert_to_facet(elem_handle_array[i]);
    if(dynamic_cast<CubitFacet*>(f))
    {
      dimensions[i] = 2;
    }
    else if(dynamic_cast<CubitFacetEdge*>(f))
    {
      dimensions[i] = 1;
    }
    else
    {
      dimensions[i] = 0;
    }
  }
  return SMD::STATUS_OK;
}


SMD::ErrorCode ChollaMesh::get_element_length(SMD::SMDElement elem_handle, double& length)<--- The function 'get_element_length' is never used.
{
  CubitFacetEdge* f = dynamic_cast<CubitFacetEdge*>(convert_to_facet(elem_handle));
  if(!f)
  {
    return SMD::ERR_INVALID_ENTITY_HANDLE;
  }

  length = f->length();
  return SMD::STATUS_OK;
}

SMD::ErrorCode ChollaMesh::get_element_area(SMD::SMDElement elem_handle, double& area)<--- The function 'get_element_area' is never used.
{
  CubitFacet* f = dynamic_cast<CubitFacet*>(convert_to_facet(elem_handle));
  if(!f)
  {
    return SMD::ERR_INVALID_ENTITY_HANDLE;
  }

  area = f->area();
  return SMD::STATUS_OK;
}


SMD::ErrorCode ChollaMesh::get_element_normal(SMD::SMDElement elem_handle, double normal_vector[3])<--- The function 'get_element_normal' is never used.
{
  CubitFacet* f = dynamic_cast<CubitFacet*>(convert_to_facet(elem_handle));
  if(!f)
  {
    return SMD::ERR_INVALID_ENTITY_HANDLE;
  }

  CubitVector n = f->normal();
  normal_vector[0] = n.x();
  normal_vector[1] = n.y();
  normal_vector[2] = n.z();
  return SMD::STATUS_OK;
}

SMD::ErrorCode ChollaMesh::get_element_centroid(SMD::SMDElement elem_handle, double centroid[3])<--- The function 'get_element_centroid' is never used.
{
  CubitFacet* f = dynamic_cast<CubitFacet*>(convert_to_facet(elem_handle));
  if(!f)
  {
    return SMD::ERR_INVALID_ENTITY_HANDLE;
  }

  CubitVector c = f->center();
  centroid[0] = c.x();
  centroid[1] = c.y();
  centroid[2] = c.z();
  return SMD::STATUS_OK;
}

SMD::ErrorCode ChollaMesh::get_coords(int num_nodes, const SMD::SMDNode node_handle_array[], float coords[][3])<--- The function 'get_coords' is never used.
{
  for(int i=0; i<num_nodes; i++)
  {
    CubitPoint* p = convert_to_point(node_handle_array[i]);
    coords[i][0] = p->x();
    coords[i][1] = p->y();
    coords[i][2] = p->z();
  }
  return SMD::STATUS_OK;
}

SMD::ErrorCode ChollaMesh::get_coords(int num_nodes, const SMD::SMDNode node_handle_array[], double coords[][3])
{
  for(int i=0; i<num_nodes; i++)
  {
    CubitPoint* p = convert_to_point(node_handle_array[i]);
    coords[i][0] = p->x();
    coords[i][1] = p->y();
    coords[i][2] = p->z();
  }
  return SMD::STATUS_OK;
}

SMD::ErrorCode ChollaMesh::get_coords(int num_nodes, const SMD::SMDNode node_handle_array[], 
                          SMD::Real x_coords[], SMD::Real y_coords[], SMD::Real z_coords[])
{
  for(int i=0; i<num_nodes; i++)
  {
    CubitPoint* p = convert_to_point(node_handle_array[i]);
    x_coords[i] = p->x();
    y_coords[i] = p->y();
    z_coords[i] = p->z();
  }
  return SMD::STATUS_OK;
}

SMD::ErrorCode ChollaMesh::get_connectivity(
  int num_elems,
  const SMD::SMDElement elements[],
  int& node_array_size,
  SMD::SMDNode node_handles[])
{
  CubitFacet* tri;
  CubitFacetEdge* edge;

  int offset = 0;
  for(int i=0; i<num_elems; i++)
  {
    FacetEntity* f = convert_to_facet(elements[i]);
    if((tri = dynamic_cast<CubitFacet*>(f)))
    {
      if(offset + 3 > node_array_size)
      {
        return SMD::ERR_ARRAY_TOO_SMALL;
      }

      node_handles[offset++] = convert_from_point(tri->point(0));
      node_handles[offset++] = convert_from_point(tri->point(1));
      node_handles[offset++] = convert_from_point(tri->point(2));
    }
    else if((edge = dynamic_cast<CubitFacetEdge*>(f)))
    {
      if(offset + 2 > node_array_size)
      {
        return SMD::ERR_ARRAY_TOO_SMALL;
      }
      node_handles[offset++] = convert_from_point(edge->point(0));
      node_handles[offset++] = convert_from_point(edge->point(1));
    }
    else
    {
      return SMD::ERR_INVALID_ENTITY_HANDLE;
    }
  }
  node_array_size = offset;
  return SMD::STATUS_OK;
}


SMD::ErrorCode ChollaMesh::get_expanded_connectivity(<--- The function 'get_expanded_connectivity' is never used.
  int num_elems,
  const SMD::SMDElement elements[],
  unsigned int nodes_per_elem,
  int node_array_size,
  SMD::SMDNode node_handles[])
{
  return SMD::ERR_NOT_IMPLEMENTED;
}

SMD::ErrorCode ChollaMesh::get_expanded_connectivity(
  SMD::SMDElement element,
  unsigned int& nodes_per_elem,
  int node_array_size,
  SMD::SMDNode node_handles[])
{
  SMD::ErrorCode ret = get_connectivity(1, &element, node_array_size, node_handles);
  nodes_per_elem = node_array_size;
  return ret;
}

SMD::ErrorCode ChollaMesh::create_nodes(<--- The function 'create_nodes' is never used.
  unsigned int num_nodes,
  const SMD::Real coords[][3],
  SMD::SMeshOwner owner,
  SMD::SMDNode node_handles[])
{
  for(unsigned int i=0; i<num_nodes; i++)
  {
    node_handles[i] = convert_from_point(new CubitPointData(coords[i][0], coords[i][1], coords[i][2]));
  }
  return SMD::STATUS_OK;
}


SMD::ErrorCode ChollaMesh::create_elements(<--- The function 'create_elements' is never used.
  SMD::ElementType type,
  unsigned int num_nodes,
  const SMD::SMDNode node_handle_array[],
  unsigned int num_elements,
  unsigned int num_nodes_per_element,
  const unsigned int connectivity[],
  SMD::SMeshOwner new_entities_owner,
  SMD::SMDElement *created_element_handles)
{
  if(type == SMD::EDGE)
  {
    unsigned int conn_offset=0;
    for(unsigned int i=0; i<num_elements; i++, conn_offset += num_nodes_per_element)
    {
      CubitPoint* pts[2];
      pts[0] = convert_to_point(node_handle_array[connectivity[conn_offset]]);
      pts[1] = convert_to_point(node_handle_array[connectivity[conn_offset+1]]);
      created_element_handles[i] = convert_from_facet(new CubitFacetEdgeData(pts[0], pts[1]));
    }
    return SMD::STATUS_OK;
  }
  else if(type == SMD::TRI)
  {
    unsigned int conn_offset=0;
    for(unsigned int i=0; i<num_elements; i++, conn_offset += num_nodes_per_element)
    {
      CubitPoint* pts[3];
      pts[0] = convert_to_point(node_handle_array[connectivity[conn_offset]]);
      pts[1] = convert_to_point(node_handle_array[connectivity[conn_offset+1]]);
      pts[2] = convert_to_point(node_handle_array[connectivity[conn_offset+2]]);
      created_element_handles[i] = convert_from_facet(new CubitFacetData(pts[0], pts[1], pts[2]));
    }
    return SMD::STATUS_OK;
  }

  return SMD::ERR_INVALID_ENTITY_TYPE;
}


SMD::ErrorCode ChollaMesh::delete_node(SMD::SMDNode node)<--- The function 'delete_node' is never used.
{
  CubitPoint* f = convert_to_point(node);
  if(!f)
    return SMD::ERR_INVALID_ENTITY_HANDLE;

  delete f;

  return SMD::STATUS_OK;
}


SMD::ErrorCode ChollaMesh::delete_element(SMD::SMDElement element)<--- The function 'delete_element' is never used.
{
  FacetEntity* f = convert_to_facet(element);
  if(!f)
    return SMD::ERR_INVALID_ENTITY_HANDLE;

  delete f;

  return SMD::STATUS_OK;
}


SMD::ErrorCode ChollaMesh::reverse_element_connectivity(SMD::SMDElement element)<--- The function 'reverse_element_connectivity' is never used.
{
  FacetEntity* f = convert_to_facet(element);
  CubitFacet* tri;
  CubitFacetEdge* edge;

  if((tri = dynamic_cast<CubitFacet*>(f)))
  {
    tri->flip();
    return SMD::STATUS_OK;
  }
  else if((edge = dynamic_cast<CubitFacetEdge*>(f)))
  {
    edge->flip();
    return SMD::STATUS_OK;
  }
  return SMD::ERR_INVALID_ENTITY_HANDLE;
}

SMD::ErrorCode ChollaMesh::find_element(SMD::ElementType type, unsigned int num_pts, const SMD::SMDNode nodes[], <--- The function 'find_element' is never used.
                                SMD::SMDElement& found_element)
{
  if(type == SMD::EDGE && num_pts == 2)
  {
    CubitFacetEdge* edge = convert_to_point(nodes[0])->shared_edge(convert_to_point(nodes[1]));
    found_element = convert_from_facet(edge);
    return SMD::STATUS_OK;
  }
  else if(type == SMD::TRI && num_pts == 3)
  {
    DLIList<CubitFacet*> facets[3];
    convert_to_point(nodes[0])->facets(facets[0]);
    convert_to_point(nodes[1])->facets(facets[1]);
    convert_to_point(nodes[2])->facets(facets[2]);
    facets[0].intersect_unordered(facets[1]);
    facets[0].intersect_unordered(facets[2]);

    if(facets[0].size())
    {
      found_element = convert_from_facet(facets[0][0]);
    }
    return SMD::STATUS_OK;
  }
  return SMD::ERR_INVALID_ENTITY_TYPE;
}