cgma
|
00001 00002 #include "ChollaMesh.hpp" 00003 #include "CubitFacetData.hpp" 00004 #include "CubitFacetEdgeData.hpp" 00005 #include "CubitPointData.hpp" 00006 00007 ChollaMesh::ChollaMesh() 00008 { 00009 } 00010 00011 ChollaMesh::~ChollaMesh() 00012 { 00013 } 00014 00015 FacetEntity* ChollaMesh::convert_to_facet(SMD::SMDElement elem) 00016 { 00017 return reinterpret_cast<FacetEntity*>(elem.mHandle); 00018 } 00019 00020 CubitPoint* ChollaMesh::convert_to_point(SMD::SMDNode node) 00021 { 00022 return reinterpret_cast<CubitPoint*>(node.mHandle); 00023 } 00024 00025 SMD::SMDElement ChollaMesh::convert_from_facet(FacetEntity* f) 00026 { 00027 SMD::SMDElement e; 00028 e.mHandle = reinterpret_cast<size_t>(f); 00029 return e; 00030 } 00031 00032 SMD::SMDNode ChollaMesh::convert_from_point(CubitPoint* p) 00033 { 00034 SMD::SMDNode n; 00035 n.mHandle = reinterpret_cast<size_t>(p); 00036 return n; 00037 } 00038 00039 00040 SMD::ErrorCode ChollaMesh::get_ids(size_t num, const SMD::SMDNode nodes[], int ids[]) 00041 { 00042 for(size_t i=0; i<num; i++) 00043 { 00044 ids[i] = convert_to_point(nodes[i])->id(); 00045 } 00046 return SMD::STATUS_OK; 00047 } 00048 00049 SMD::ErrorCode ChollaMesh::get_ids(size_t num, const SMD::SMDElement elems[], int ids[]) 00050 { 00051 CubitFacet* tri; 00052 CubitFacetEdge* edge; 00053 00054 for(size_t i=0; i<num; i++) 00055 { 00056 FacetEntity* f = convert_to_facet(elems[i]); 00057 if((tri = dynamic_cast<CubitFacet*>(f))) 00058 { 00059 ids[i] = tri->id(); 00060 } 00061 else if((edge = dynamic_cast<CubitFacetEdge*>(f))) 00062 { 00063 ids[i] = edge->id(); 00064 } 00065 else 00066 { 00067 ids[i] = 0; 00068 } 00069 } 00070 return SMD::STATUS_OK; 00071 } 00072 00073 00074 SMD::ErrorCode ChollaMesh::get_node_handle(int id, SMD::SMDNode &node) 00075 { 00076 return SMD::ERR_NOT_IMPLEMENTED; 00077 } 00078 00079 SMD::ErrorCode ChollaMesh::get_element_handle(SMD::ElementType type, int id, SMD::SMDElement &node) 00080 { 00081 return SMD::ERR_NOT_IMPLEMENTED; 00082 } 00083 00084 SMD::ErrorCode ChollaMesh::get_element_types(int num_elems, const SMD::SMDElement elem_handle_array[], 00085 SMD::ElementType type_array[], bool*) 00086 { 00087 for(int i=0; i<num_elems; i++) 00088 { 00089 FacetEntity* f = convert_to_facet(elem_handle_array[i]); 00090 if(dynamic_cast<CubitFacet*>(f)) 00091 { 00092 type_array[i] = SMD::TRI; 00093 } 00094 else if(dynamic_cast<CubitFacetEdge*>(f)) 00095 { 00096 type_array[i] = SMD::EDGE; 00097 } 00098 else 00099 { 00100 type_array[i] = SMD::NO_ELEMENT_TYPE; 00101 } 00102 } 00103 return SMD::STATUS_OK; 00104 } 00105 00106 SMD::ErrorCode ChollaMesh::get_element_dimensions(int num_elems, const SMD::SMDElement elem_handle_array[], 00107 int dimensions[]) 00108 { 00109 for(int i=0; i<num_elems; i++) 00110 { 00111 FacetEntity* f = convert_to_facet(elem_handle_array[i]); 00112 if(dynamic_cast<CubitFacet*>(f)) 00113 { 00114 dimensions[i] = 2; 00115 } 00116 else if(dynamic_cast<CubitFacetEdge*>(f)) 00117 { 00118 dimensions[i] = 1; 00119 } 00120 else 00121 { 00122 dimensions[i] = 0; 00123 } 00124 } 00125 return SMD::STATUS_OK; 00126 } 00127 00128 00129 SMD::ErrorCode ChollaMesh::get_element_length(SMD::SMDElement elem_handle, double& length) 00130 { 00131 CubitFacetEdge* f = dynamic_cast<CubitFacetEdge*>(convert_to_facet(elem_handle)); 00132 if(!f) 00133 { 00134 return SMD::ERR_INVALID_ENTITY_HANDLE; 00135 } 00136 00137 length = f->length(); 00138 return SMD::STATUS_OK; 00139 } 00140 00141 SMD::ErrorCode ChollaMesh::get_element_area(SMD::SMDElement elem_handle, double& area) 00142 { 00143 CubitFacet* f = dynamic_cast<CubitFacet*>(convert_to_facet(elem_handle)); 00144 if(!f) 00145 { 00146 return SMD::ERR_INVALID_ENTITY_HANDLE; 00147 } 00148 00149 area = f->area(); 00150 return SMD::STATUS_OK; 00151 } 00152 00153 00154 SMD::ErrorCode ChollaMesh::get_element_normal(SMD::SMDElement elem_handle, double normal_vector[3]) 00155 { 00156 CubitFacet* f = dynamic_cast<CubitFacet*>(convert_to_facet(elem_handle)); 00157 if(!f) 00158 { 00159 return SMD::ERR_INVALID_ENTITY_HANDLE; 00160 } 00161 00162 CubitVector n = f->normal(); 00163 normal_vector[0] = n.x(); 00164 normal_vector[1] = n.y(); 00165 normal_vector[2] = n.z(); 00166 return SMD::STATUS_OK; 00167 } 00168 00169 SMD::ErrorCode ChollaMesh::get_element_centroid(SMD::SMDElement elem_handle, double centroid[3]) 00170 { 00171 CubitFacet* f = dynamic_cast<CubitFacet*>(convert_to_facet(elem_handle)); 00172 if(!f) 00173 { 00174 return SMD::ERR_INVALID_ENTITY_HANDLE; 00175 } 00176 00177 CubitVector c = f->center(); 00178 centroid[0] = c.x(); 00179 centroid[1] = c.y(); 00180 centroid[2] = c.z(); 00181 return SMD::STATUS_OK; 00182 } 00183 00184 SMD::ErrorCode ChollaMesh::get_coords(int num_nodes, const SMD::SMDNode node_handle_array[], float coords[][3]) 00185 { 00186 for(int i=0; i<num_nodes; i++) 00187 { 00188 CubitPoint* p = convert_to_point(node_handle_array[i]); 00189 coords[i][0] = p->x(); 00190 coords[i][1] = p->y(); 00191 coords[i][2] = p->z(); 00192 } 00193 return SMD::STATUS_OK; 00194 } 00195 00196 SMD::ErrorCode ChollaMesh::get_coords(int num_nodes, const SMD::SMDNode node_handle_array[], double coords[][3]) 00197 { 00198 for(int i=0; i<num_nodes; i++) 00199 { 00200 CubitPoint* p = convert_to_point(node_handle_array[i]); 00201 coords[i][0] = p->x(); 00202 coords[i][1] = p->y(); 00203 coords[i][2] = p->z(); 00204 } 00205 return SMD::STATUS_OK; 00206 } 00207 00208 SMD::ErrorCode ChollaMesh::get_coords(int num_nodes, const SMD::SMDNode node_handle_array[], 00209 SMD::Real x_coords[], SMD::Real y_coords[], SMD::Real z_coords[]) 00210 { 00211 for(int i=0; i<num_nodes; i++) 00212 { 00213 CubitPoint* p = convert_to_point(node_handle_array[i]); 00214 x_coords[i] = p->x(); 00215 y_coords[i] = p->y(); 00216 z_coords[i] = p->z(); 00217 } 00218 return SMD::STATUS_OK; 00219 } 00220 00221 SMD::ErrorCode ChollaMesh::get_connectivity( 00222 int num_elems, 00223 const SMD::SMDElement elements[], 00224 int& node_array_size, 00225 SMD::SMDNode node_handles[]) 00226 { 00227 CubitFacet* tri; 00228 CubitFacetEdge* edge; 00229 00230 int offset = 0; 00231 for(int i=0; i<num_elems; i++) 00232 { 00233 FacetEntity* f = convert_to_facet(elements[i]); 00234 if((tri = dynamic_cast<CubitFacet*>(f))) 00235 { 00236 if(offset + 3 > node_array_size) 00237 { 00238 return SMD::ERR_ARRAY_TOO_SMALL; 00239 } 00240 00241 node_handles[offset++] = convert_from_point(tri->point(0)); 00242 node_handles[offset++] = convert_from_point(tri->point(1)); 00243 node_handles[offset++] = convert_from_point(tri->point(2)); 00244 } 00245 else if((edge = dynamic_cast<CubitFacetEdge*>(f))) 00246 { 00247 if(offset + 2 > node_array_size) 00248 { 00249 return SMD::ERR_ARRAY_TOO_SMALL; 00250 } 00251 node_handles[offset++] = convert_from_point(edge->point(0)); 00252 node_handles[offset++] = convert_from_point(edge->point(1)); 00253 } 00254 else 00255 { 00256 return SMD::ERR_INVALID_ENTITY_HANDLE; 00257 } 00258 } 00259 node_array_size = offset; 00260 return SMD::STATUS_OK; 00261 } 00262 00263 00264 SMD::ErrorCode ChollaMesh::get_expanded_connectivity( 00265 int num_elems, 00266 const SMD::SMDElement elements[], 00267 unsigned int nodes_per_elem, 00268 int node_array_size, 00269 SMD::SMDNode node_handles[]) 00270 { 00271 return SMD::ERR_NOT_IMPLEMENTED; 00272 } 00273 00274 SMD::ErrorCode ChollaMesh::get_expanded_connectivity( 00275 SMD::SMDElement element, 00276 unsigned int& nodes_per_elem, 00277 int node_array_size, 00278 SMD::SMDNode node_handles[]) 00279 { 00280 SMD::ErrorCode ret = get_connectivity(1, &element, node_array_size, node_handles); 00281 nodes_per_elem = node_array_size; 00282 return ret; 00283 } 00284 00285 SMD::ErrorCode ChollaMesh::create_nodes( 00286 unsigned int num_nodes, 00287 const SMD::Real coords[][3], 00288 SMD::SMeshOwner owner, 00289 SMD::SMDNode node_handles[]) 00290 { 00291 for(unsigned int i=0; i<num_nodes; i++) 00292 { 00293 node_handles[i] = convert_from_point(new CubitPointData(coords[i][0], coords[i][1], coords[i][2])); 00294 } 00295 return SMD::STATUS_OK; 00296 } 00297 00298 00299 SMD::ErrorCode ChollaMesh::create_elements( 00300 SMD::ElementType type, 00301 unsigned int num_nodes, 00302 const SMD::SMDNode node_handle_array[], 00303 unsigned int num_elements, 00304 unsigned int num_nodes_per_element, 00305 const unsigned int connectivity[], 00306 SMD::SMeshOwner new_entities_owner, 00307 SMD::SMDElement *created_element_handles) 00308 { 00309 if(type == SMD::EDGE) 00310 { 00311 unsigned int conn_offset=0; 00312 for(unsigned int i=0; i<num_elements; i++, conn_offset += num_nodes_per_element) 00313 { 00314 CubitPoint* pts[2]; 00315 pts[0] = convert_to_point(node_handle_array[connectivity[conn_offset]]); 00316 pts[1] = convert_to_point(node_handle_array[connectivity[conn_offset+1]]); 00317 created_element_handles[i] = convert_from_facet(new CubitFacetEdgeData(pts[0], pts[1])); 00318 } 00319 return SMD::STATUS_OK; 00320 } 00321 else if(type == SMD::TRI) 00322 { 00323 unsigned int conn_offset=0; 00324 for(unsigned int i=0; i<num_elements; i++, conn_offset += num_nodes_per_element) 00325 { 00326 CubitPoint* pts[3]; 00327 pts[0] = convert_to_point(node_handle_array[connectivity[conn_offset]]); 00328 pts[1] = convert_to_point(node_handle_array[connectivity[conn_offset+1]]); 00329 pts[2] = convert_to_point(node_handle_array[connectivity[conn_offset+2]]); 00330 created_element_handles[i] = convert_from_facet(new CubitFacetData(pts[0], pts[1], pts[2])); 00331 } 00332 return SMD::STATUS_OK; 00333 } 00334 00335 return SMD::ERR_INVALID_ENTITY_TYPE; 00336 } 00337 00338 00339 SMD::ErrorCode ChollaMesh::delete_node(SMD::SMDNode node) 00340 { 00341 CubitPoint* f = convert_to_point(node); 00342 if(!f) 00343 return SMD::ERR_INVALID_ENTITY_HANDLE; 00344 00345 delete f; 00346 00347 return SMD::STATUS_OK; 00348 } 00349 00350 00351 SMD::ErrorCode ChollaMesh::delete_element(SMD::SMDElement element) 00352 { 00353 FacetEntity* f = convert_to_facet(element); 00354 if(!f) 00355 return SMD::ERR_INVALID_ENTITY_HANDLE; 00356 00357 delete f; 00358 00359 return SMD::STATUS_OK; 00360 } 00361 00362 00363 SMD::ErrorCode ChollaMesh::reverse_element_connectivity(SMD::SMDElement element) 00364 { 00365 FacetEntity* f = convert_to_facet(element); 00366 CubitFacet* tri; 00367 CubitFacetEdge* edge; 00368 00369 if((tri = dynamic_cast<CubitFacet*>(f))) 00370 { 00371 tri->flip(); 00372 return SMD::STATUS_OK; 00373 } 00374 else if((edge = dynamic_cast<CubitFacetEdge*>(f))) 00375 { 00376 edge->flip(); 00377 return SMD::STATUS_OK; 00378 } 00379 return SMD::ERR_INVALID_ENTITY_HANDLE; 00380 } 00381 00382 SMD::ErrorCode ChollaMesh::find_element(SMD::ElementType type, unsigned int num_pts, const SMD::SMDNode nodes[], 00383 SMD::SMDElement& found_element) 00384 { 00385 if(type == SMD::EDGE && num_pts == 2) 00386 { 00387 CubitFacetEdge* edge = convert_to_point(nodes[0])->shared_edge(convert_to_point(nodes[1])); 00388 found_element = convert_from_facet(edge); 00389 return SMD::STATUS_OK; 00390 } 00391 else if(type == SMD::TRI && num_pts == 3) 00392 { 00393 DLIList<CubitFacet*> facets[3]; 00394 convert_to_point(nodes[0])->facets(facets[0]); 00395 convert_to_point(nodes[1])->facets(facets[1]); 00396 convert_to_point(nodes[2])->facets(facets[2]); 00397 facets[0].intersect_unordered(facets[1]); 00398 facets[0].intersect_unordered(facets[2]); 00399 00400 if(facets[0].size()) 00401 { 00402 found_element = convert_from_facet(facets[0][0]); 00403 } 00404 return SMD::STATUS_OK; 00405 } 00406 return SMD::ERR_INVALID_ENTITY_TYPE; 00407 } 00408