TupleList SimpleQueryLinker::make_tuples( const std::vector<std::string>& variables) { TupleList result; std::string first_qvar = *variables.begin(); if(!is_initialized(first_qvar)) { throw QueryLinkerError(); } for(ConditionSet::iterator cit = _qvar_table[first_qvar].begin(); cit != _qvar_table[first_qvar].end(); ++cit) { TupleList tuples = make_tuples(first_qvar, *cit, ++variables.begin(), variables.end()); for(TupleList::iterator tit = tuples.begin(); tit != tuples.end(); ++tit) { result.insert(*tit); } } return result; }
void SimpleQueryLinker::merge_tuples(const ConditionPtr& target_condition, const TupleList& tuples, TupleList& result) { for(TupleList::const_iterator tit = tuples.begin(); tit != tuples.end(); ++tit) { result.insert(ConditionTuplePtr( new SimpleConditionTuple(target_condition, *tit))); } }
//Simple quick sort to real void ParallelMergeMesh::SortTuplesByReal(TupleList &tup, double eps) { bool canWrite = tup.get_writeEnabled(); if(!canWrite) tup.enableWriteAccess(); uint mi, ml, mul, mr; tup.getTupleSize(mi,ml,mul,mr); PerformRealSort(tup, 0, tup.get_n(), eps, mr); if(!canWrite) tup.disableWriteAccess(); }
TupleList SimpleQueryLinker::make_tuples( const std::string& current_qvar, const ConditionPtr& current_condition, std::vector<std::string>::const_iterator next_qit, std::vector<std::string>::const_iterator end) { if(!is_initialized(current_qvar)) { throw QueryLinkerError(); } TupleList result; if(next_qit == end) { result.insert(ConditionTuplePtr( new SimpleConditionTuple(current_condition))); } else { std::string next_qvar = *next_qit++; if(has_link(current_qvar, next_qvar)) { ConditionSet linked_conditions = get_linked_conditions( current_qvar, next_qvar, current_condition); for(ConditionSet::iterator cit = linked_conditions.begin(); cit != linked_conditions.end(); ++cit) { merge_tuples(current_condition, make_tuples(next_qvar, *cit, next_qit, end), result); } } else if(has_indirect_links(current_qvar, next_qvar)) { ConditionSet linked_conditions = get_indirect_links( current_qvar, next_qvar, current_condition); for(ConditionSet::iterator cit = linked_conditions.begin(); cit != linked_conditions.end(); ++cit) { merge_tuples(current_condition, make_tuples(next_qvar, *cit, next_qit, end), result); } } else { for(ConditionSet::iterator cit = _qvar_table[next_qvar].begin(); cit != _qvar_table[next_qvar].end(); ++cit) { merge_tuples(current_condition, make_tuples(next_qvar, *cit, next_qit, end), result); } } } return result; }
/** Merge two DiscreteDBFs as if there we executed sequentially * @remarks This can also be achived on-the-fly using SequentialDBF */ DiscreteDBF DiscreteDBF::sequentialMerge(const DiscreteDBF& dbf1, const DiscreteDBF& dbf2){ DiscreteDBF retval; const TupleList& t1 = dbf1._tuples, t2 = dbf2._tuples; TupleList& tr = retval._tuples; ConstTupleIterator i1 = t1.begin(), i2 = t2.begin(); int max = 0; // While we have stuff to merge from both t1 and t2 while(i1 != t1.end() && i2 != t2.end()){ int time = -1; if(i1->time() <= i2->time()){ if(max < i1->wcet()){ max = i1->wcet(); time = i1->time(); assert(time != -1); } i1++; }else if(i1->time() >= i2->time()){ if(max < i2->wcet()){ max = i2->wcet(); time = i2->time(); assert(time != -1); } i2++; } if(time != -1) tr.push_back(DemandTuple(max, time)); } // Now one of them might contains something... while(i1 != t1.end()){ if(max < i1->wcet()){ max = i1->wcet(); tr.push_back(DemandTuple(max, i1->time())); } i1++; } while(i2 != t2.end()){ if(max < i2->wcet()){ max = i2->wcet(); tr.push_back(DemandTuple(max, i2->time())); } i2++; } return retval; }
void DomUtil::writeTupleListEntry(QDomDocument &doc, const QString &path, const QString &tag, const QStringList &attrList, const TupleList &value) { QDomElement el = createElementByPath(doc, path); TupleList::ConstIterator it; for (it = value.begin(); it != value.end(); ++it) { QDomElement subEl = doc.createElement(tag); int i=0; for(QValueListConstIterator<QString> iter = attrList.begin(); iter != attrList.end(); ++iter) { subEl.setAttribute(*iter,(*it)[i++]); } el.appendChild(subEl); } }
ErrorCode ReadCCMIO::make_faces(int *farray, TupleList &vert_map, std::vector<EntityHandle> &new_faces, int num_faces) { std::vector<EntityHandle> verts; ErrorCode tmp_rval = MB_SUCCESS, rval = MB_SUCCESS; for (int i = 0; i < num_faces; i++) { int num_verts = *farray++; verts.resize(num_verts); // fill in connectivity by looking up by gid in vert tuple_list for (int j = 0; j < num_verts; j++) { #ifdef TUPLE_LIST int tindex = vert_map.find(1, farray[j]); if (-1 == tindex) { tmp_rval = MB_FAILURE; break; } verts[j] = vert_map.get_ulong(tindex, 0); #else verts[j] = (vert_map[farray[j]])[0]; #endif } farray += num_verts; if (MB_SUCCESS == tmp_rval) { // make face EntityType ftype = (3 == num_verts ? MBTRI : (4 == num_verts ? MBQUAD : MBPOLYGON)); EntityHandle faceh; tmp_rval = mbImpl->create_element(ftype, &verts[0], num_verts, faceh); if (faceh) new_faces.push_back(faceh); } if (MB_SUCCESS != tmp_rval) rval = tmp_rval; } return rval; }
ErrorCode ReadCCMIO::read_all_faces(CCMIOID topologyID, TupleList &vert_map, TupleList &face_map #ifndef TUPLE_LIST ,SenseList &sense_map #endif , Range *new_faces) { CCMIOSize_t index = CCMIOSIZEC(0); CCMIOID faceID; ErrorCode rval; // get total # internal/bdy faces, size the face map accordingly int nint_faces = 0, nbdy_faces = 0; CCMIOSize_t nf; CCMIOError error = kCCMIONoErr; while (kCCMIONoErr == CCMIONextEntity(NULL, topologyID, kCCMIOBoundaryFaces, &index, &faceID)) { CCMIOEntitySize(&error, faceID, &nf, NULL); nbdy_faces = nbdy_faces + nf; } CCMIOGetEntity(&error, topologyID, kCCMIOInternalFaces, 0, &faceID); CCMIOEntitySize(&error, faceID, &nf, NULL); nint_faces = nint_faces + nf; #ifdef TUPLE_LIST face_map.resize(2*nint_faces + nbdy_faces); #endif // get multiple blocks of bdy faces index = CCMIOSIZEC(0); while (kCCMIONoErr == CCMIONextEntity(NULL, topologyID, kCCMIOBoundaryFaces, &index, &faceID)) { rval = read_faces(faceID, kCCMIOBoundaryFaces, vert_map, face_map #ifndef TUPLE_LIST , sense_map #endif , new_faces); CHKERR(rval, "Trouble reading boundary faces."); } // now get internal faces CCMIOGetEntity(&error, topologyID, kCCMIOInternalFaces, 0, &faceID); rval = read_faces(faceID, kCCMIOInternalFaces, vert_map,face_map #ifndef TUPLE_LIST , sense_map #endif , new_faces); CHKERR(rval, "Trouble reading internal faces."); return rval; }
TupleList MBConnection::getBigramCount(const std::string& word1, const std::string& word2) { MYSQL_BIND param[2]; memset(param, 0, 2 * sizeof(MYSQL_BIND)); setBindValue<0>(param, word1); setBindValue<1>(param, word2); long nameId; long lineCount; MYSQL_BIND result[2]; memset(result, 0, 2 * sizeof(MYSQL_BIND)); setBindValue<0>(result, nameId); setBindValue<1>(result, lineCount); if (mysql_stmt_bind_param(this->_getBigramCountStatement, param)) { std::cout << "Binding parameters to prepared statement failed" << std::endl; throw 0; } if (mysql_stmt_bind_result(this->_getBigramCountStatement, result)) { std::cout << "Binding result to prepared statement failed" << std::endl; throw 0; } if (mysql_stmt_execute(this->_getBigramCountStatement)) { std::cout << "Executing select from bigram count failed" << mysql_stmt_error(this->_getBigramCountStatement) << std::endl; throw 0; } mysql_stmt_store_result(this->_getBigramCountStatement); TupleList resultSet; while (!mysql_stmt_fetch(this->_getBigramCountStatement)) resultSet.push_back(make_tuple(static_cast<int>(nameId), static_cast<int>(lineCount))); return resultSet; }
//Swap around tuples void ParallelMergeMesh::SwapTuples(TupleList &tup, unsigned long a, unsigned long b) { if(a==b) return; uint mi, ml, mul, mr; tup.getTupleSize(mi, ml, mul, mr); //Swap mi unsigned long a_val = a*mi, b_val=b*mi; for(unsigned long i=0; i< mi;i++){ sint t =tup.vi_rd[a_val]; tup.vi_wr[a_val] = tup.vi_rd[b_val]; tup.vi_wr[b_val] = t; a_val++; b_val++; } //Swap ml a_val = a*ml; b_val = b*ml; for(unsigned long i=0; i< ml;i++){ slong t =tup.vl_rd[a_val]; tup.vl_wr[a_val] = tup.vl_rd[b_val]; tup.vl_wr[b_val] = t; a_val++; b_val++; } //Swap mul a_val = a*mul; b_val = b*mul; for(unsigned long i=0; i< mul;i++){ Ulong t =tup.vul_rd[a_val]; tup.vul_wr[a_val] = tup.vul_rd[b_val]; tup.vul_wr[b_val] = t; a_val++; b_val++; } //Swap mr a_val = a*mr; b_val = b*mr; for(unsigned long i=0; i< mr;i++){ realType t =tup.vr_rd[a_val]; tup.vr_wr[a_val] = tup.vr_rd[b_val]; tup.vr_wr[b_val] = t; a_val++; b_val++; } }
void sendStaticFile(TCPSocket* sock, TupleList& headers, const Path& file) { int64_t beg = -1; int64_t end = -1; std::string range = headers.get("range"); if (range.compare(0, 6, "bytes=") == 0) { std::vector<std::string> parts; String::split(range.substr(6), "-", parts); std::istringstream p0(parts[0]); p0 >> beg; std::istringstream p1(parts[1]); p1 >> end; }
void TupleCache::add_emit_tuple(sp_int32 _task_id, const proto::system::AckTuple& _tuple) { if (total_size_ >= drain_threshold_bytes_) drain_impl(); TupleList* l = get(_task_id); return l->add_emit_tuple(_tuple, &total_size_); }
sp_int64 TupleCache::add_data_tuple(sp_int32 _task_id, const proto::api::StreamId& _streamid, proto::system::HeronDataTuple* _tuple) { if (total_size_ >= drain_threshold_bytes_) drain_impl(); TupleList* l = get(_task_id); return l->add_data_tuple(_streamid, _tuple, &total_size_, &tuples_cache_max_tuple_size_); }
ErrorCode ReadCCMIO::read_vertices(CCMIOSize_t /* proc */, CCMIOID /* processorID */, CCMIOID verticesID, CCMIOID /* topologyID */, Range *verts, TupleList &vert_map) { CCMIOError error = kCCMIONoErr; // pre-read the number of vertices, so we can pre-allocate & read directly in CCMIOSize_t nverts = CCMIOSIZEC(0); CCMIOEntitySize(&error, verticesID, &nverts, NULL); CHKCCMERR(error, "Couldn't get number of vertices."); // get # dimensions CCMIOSize_t dims; float scale; CCMIOReadVerticesf(&error, verticesID, &dims, NULL, NULL, NULL, CCMIOINDEXC(0), CCMIOINDEXC(1)); CHKCCMERR(error, "Couldn't get number of dimensions."); // allocate vertex space EntityHandle node_handle = 0; std::vector<double*> arrays; readMeshIface->get_node_coords(3, GETINT32(nverts), MB_START_ID, node_handle, arrays); // read vertex coords CCMIOID mapID; std::vector<double> tmp_coords(GETINT32(dims)*GETINT32(nverts)); CCMIOReadVerticesd(&error, verticesID, &dims, &scale, &mapID, &tmp_coords[0], CCMIOINDEXC(0), CCMIOINDEXC(0+nverts)); CHKCCMERR(error, "Trouble reading vertex coordinates."); // copy interleaved coords into moab blocked coordinate space int i = 0, threei = 0; for (; i < nverts; i++) { arrays[0][i] = tmp_coords[threei++]; arrays[1][i] = tmp_coords[threei++]; if (3 == GETINT32(dims)) arrays[2][i] = tmp_coords[threei++]; else arrays[2][i] = 0.0; } // scale, if necessary if (1.0 != scale) { for(i = 0; i < nverts; i++) { arrays[0][i] *= scale; arrays[1][i] *= scale; if (3 == GETINT32(dims)) arrays[2][i] *= scale; } } // read gids for vertices std::vector<int> gids(GETINT32(nverts)); CCMIOReadMap(&error, mapID, &gids[0], CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd)); CHKCCMERR(error, "Trouble reading vertex global ids."); // put new vertex handles into range, and set gids for them Range new_verts(node_handle, node_handle+nverts-1); ErrorCode rval = mbImpl->tag_set_data(mGlobalIdTag, new_verts, &gids[0]); CHKERR(rval, "Couldn't set gids on vertices."); // pack vert_map with global ids and handles for these vertices #ifdef TUPLE_LIST vert_map.resize(GETINT32(nverts)); for (i = 0; i < GETINT32(nverts); i++) { vert_map.push_back(NULL, &gids[i], &node_handle, NULL); #else for (i = 0; i < GETINT32(nverts); i++) { (vert_map[gids[i]]).push_back(node_handle); #endif node_handle += 1; } if (verts) verts->merge(new_verts); return MB_SUCCESS; } ErrorCode ReadCCMIO::get_processors(CCMIOID stateID, CCMIOID &processorID, CCMIOID &verticesID, CCMIOID &topologyID, CCMIOID &solutionID, std::vector<CCMIOSize_t> &procs, bool & /* has_solution */) { CCMIOSize_t proc = CCMIOSIZEC(0); CCMIOError error = kCCMIONoErr; CCMIONextEntity(&error, stateID, kCCMIOProcessor, &proc, &processorID); CHKCCMERR(error, NULL); if (CCMIOReadProcessor(NULL, processorID, &verticesID, &topologyID, NULL, &solutionID) != kCCMIONoErr) { // Maybe no solution; try again CCMIOReadProcessor(&error, processorID, &verticesID, &topologyID, NULL, NULL); hasSolution = false; } CHKCCMERR(error, NULL); procs.push_back(proc); return MB_SUCCESS; }
/** Create DiscreteStepIterator */ DiscreteDBF::DiscreteStepIterator::DiscreteStepIterator(const TupleList& tuples){ _next = tuples.begin(); _end = tuples.end(); }
ErrorCode ReadCCMIO::construct_cells(TupleList &face_map, #ifndef TUPLE_LIST SenseList &sense_map, #endif TupleList & /* vert_map */, std::map<int,int> &cell_topo_types, std::vector<EntityHandle> &new_cells) { std::vector<EntityHandle> facehs; std::vector<int> senses; EntityHandle cell; ErrorCode tmp_rval, rval = MB_SUCCESS; EntityType this_type = MBMAXTYPE; bool has_mid_nodes = false; #ifdef TUPLE_LIST unsigned int i = 0; while (i < face_map.n) { // pull out face handles bounding the same cell facehs.clear(); int this_id = face_map.get_int(i); unsigned int inext = i; while (face_map.get_int(inext) == this_id && inext <= face_map.n) { inext++; EntityHandle face = face_map.get_ulong(inext); facehs.push_back(face); senses.push_back(face_map.get_short(inext)); } this_type = MBMAXTYPE; has_mid_nodes = false; #else std::map<int,std::vector<EntityHandle> >::iterator fmit; std::map<int,std::vector<int> >::iterator smit; std::map<int,int>::iterator typeit; for (fmit = face_map.begin(), smit = sense_map.begin(); fmit != face_map.end(); fmit++, smit++) { // pull out face handles bounding the same cell facehs.clear(); int this_id = (*fmit).first; facehs = (*fmit).second; senses.clear(); senses = (*smit).second; typeit = cell_topo_types.find(this_id); if (typeit != cell_topo_types.end()) { rval = ccmio_to_moab_type(typeit->second, this_type, has_mid_nodes); } else { this_type = MBMAXTYPE; has_mid_nodes = false; } #endif tmp_rval = create_cell_from_faces(facehs, senses, this_type, has_mid_nodes, cell); if (MB_SUCCESS != tmp_rval) rval = tmp_rval; else { new_cells.push_back(cell); // tag cell with global id tmp_rval = mbImpl->tag_set_data(mGlobalIdTag, &cell, 1, &this_id); if (MB_SUCCESS != tmp_rval) rval = tmp_rval; } } return rval; } ErrorCode ReadCCMIO::ccmio_to_moab_type(int ccm_type, EntityType &moab_type, bool &has_mid_nodes) { switch (ccm_type) { case 1: moab_type = MBVERTEX; break; case 2: case 28: moab_type = MBEDGE; break; case 29: moab_type = MBMAXTYPE; break; case 3: case 4: moab_type = MBQUAD; break; case 11: case 21: moab_type = MBHEX; break; case 12: case 22: moab_type = MBPRISM; break; case 13: case 23: moab_type = MBTET; break; case 14: case 24: moab_type = MBPYRAMID; break; case 255: moab_type = MBPOLYHEDRON; break; default: moab_type = MBMAXTYPE; } switch (ccm_type) { case 28: case 4: case 21: case 22: case 23: case 24: has_mid_nodes = true; break; default: break; } return MB_SUCCESS; } ErrorCode ReadCCMIO::create_cell_from_faces(std::vector<EntityHandle> &facehs, std::vector<int> &senses, EntityType this_type, bool /* has_mid_nodes */, EntityHandle &cell) { ErrorCode rval; // test up front to see if they're one type EntityType face_type = mbImpl->type_from_handle(facehs[0]); bool same_type = true; for (std::vector<EntityHandle>::iterator vit = facehs.begin(); vit != facehs.end(); vit++) { if (face_type != mbImpl->type_from_handle(*vit)) { same_type = false; break; } } std::vector<EntityHandle> verts; EntityType input_type = this_type; std::vector<EntityHandle> storage; MeshTopoUtil mtu(mbImpl); // preset this to maxtype, so we get an affirmative choice in loop this_type = MBMAXTYPE; if ((MBTET == input_type || MBMAXTYPE == input_type) && same_type && face_type == MBTRI && facehs.size() == 4) { // try to get proper connectivity for tet // get connectivity of first face, and reverse it if sense is forward, since // base face always points into entity rval = mbImpl->get_connectivity(&facehs[0], 1, verts); CHKERR(rval, "Couldn't get connectivity."); if (senses[0] > 0) std::reverse(verts.begin(), verts.end()); // get the 4th vertex through the next tri const EntityHandle *conn; int conn_size; rval = mbImpl->get_connectivity(facehs[1], conn, conn_size, true, &storage); CHKERR(rval, "Couldn't get connectivity."); int i = 0; while (std::find(verts.begin(), verts.end(), conn[i]) != verts.end() && i < conn_size) i++; // if i is not at the end of the verts, found the apex; otherwise fall back to polyhedron if (conn_size != i) { this_type = MBTET; verts.push_back(conn[i]); } } else if ((MBHEX == input_type || MBMAXTYPE == input_type) && same_type && MBQUAD == face_type && facehs.size() == 6) { // build hex from quads // algorithm: // - verts = vertices from 1st quad // - find quad q1 sharing verts[0] and verts[1] // - find quad q2 sharing other 2 verts in q1 // - find v1 = opposite vert from verts[1] in q1 , v2 = opposite from verts[0] // - get i = offset of v1 in verts2 of q2, rotate verts2 by i // - if verts2[i+1%4] != v2, flip verts2 by switching verts2[1] and verts2[3] // - append verts2 to verts // get the other vertices for this hex; need to find the quad with no common vertices Range tmp_faces, tmp_verts; // get connectivity of first face, and reverse it if sense is forward, since // base face always points into entity rval = mbImpl->get_connectivity(&facehs[0], 1, verts); CHKERR(rval, "Couldn't get connectivity."); if (senses[0] > 0) std::reverse(verts.begin(), verts.end()); // get q1, which shares 2 vertices with q0 std::copy(facehs.begin(), facehs.end(), range_inserter(tmp_faces)); rval = mbImpl->get_adjacencies(&verts[0], 2, 2, false, tmp_faces); if (MB_SUCCESS != rval || tmp_faces.size() != 2) CHKERR(MB_FAILURE, "Couldn't get adj face."); tmp_faces.erase(facehs[0]); EntityHandle q1 = *tmp_faces.begin(); // get other 2 verts of q1 rval = mbImpl->get_connectivity(&q1, 1, tmp_verts); CHKERR(rval, "Couldn't get adj verts."); tmp_verts.erase(verts[0]); tmp_verts.erase(verts[1]); // get q2 std::copy(facehs.begin(), facehs.end(), range_inserter(tmp_faces)); rval = mbImpl->get_adjacencies(tmp_verts, 2, false, tmp_faces); if (MB_SUCCESS != rval || tmp_faces.size() != 2) CHKERR(MB_FAILURE, "Couldn't get adj face."); tmp_faces.erase(q1); EntityHandle q2 = *tmp_faces.begin(); // get verts in q2 rval = mbImpl->get_connectivity(&q2, 1, storage); CHKERR(rval, "Couldn't get adj vertices."); // get verts in q1 opposite from v[1] and v[0] in q0 EntityHandle v0 = 0, v1 = 0; rval = mtu.opposite_entity(q1, verts[1], v0); rval = mtu.opposite_entity(q1, verts[0], v1); if (v0 && v1) { // offset of v0 in q2, then rotate and flip unsigned int ioff = std::find(storage.begin(), storage.end(), v0) - storage.begin(); if (4 == ioff) CHKERR(MB_FAILURE, "Trouble finding offset."); if (storage[(ioff+1)%4] != v1) { std::reverse(storage.begin(), storage.end()); ioff = std::find(storage.begin(), storage.end(), v0) - storage.begin(); } if (0 != ioff) std::rotate(storage.begin(), storage.begin()+ioff, storage.end()); // copy into verts, and make hex std::copy(storage.begin(), storage.end(), std::back_inserter(verts)); this_type = MBHEX; } } if (MBMAXTYPE == this_type && facehs.size() == 5) { // some preliminaries std::vector<EntityHandle> tris, quads; for (unsigned int i = 0; i < 5; i++) { if (MBTRI == mbImpl->type_from_handle(facehs[i])) tris.push_back(facehs[i]); else if (MBQUAD == mbImpl->type_from_handle(facehs[i])) quads.push_back(facehs[i]); } // check for prisms if (2 == tris.size() && 3 == quads.size()) { // ok, we have the right number of tris and quads; try to find the proper verts // get connectivity of first tri, and reverse if necessary int index = std::find(facehs.begin(), facehs.end(), tris[0]) - facehs.begin(); rval = mbImpl->get_connectivity(&tris[0], 1, verts); CHKERR(rval, "Couldn't get connectivity."); if (senses[index] > 0) std::reverse(verts.begin(), verts.end()); // now align vertices of other tri, through a quad, similar to how we did hexes // get q1, which shares 2 vertices with t0 Range tmp_faces, tmp_verts; std::copy(facehs.begin(), facehs.end(), range_inserter(tmp_faces)); rval = mbImpl->get_adjacencies(&verts[0], 2, 2, false, tmp_faces); if (MB_SUCCESS != rval || tmp_faces.size() != 2) CHKERR(MB_FAILURE, "Couldn't get adj face."); tmp_faces.erase(tris[0]); EntityHandle q1 = *tmp_faces.begin(); // get verts in q1 rval = mbImpl->get_connectivity(&q1, 1, storage); CHKERR(rval, "Couldn't get adj vertices."); // get verts in q1 opposite from v[1] and v[0] in q0 EntityHandle v0 = 0, v1 = 0; rval = mtu.opposite_entity(q1, verts[1], v0); rval = mtu.opposite_entity(q1, verts[0], v1); if (v0 && v1) { // offset of v0 in t2, then rotate and flip storage.clear(); rval = mbImpl->get_connectivity(&tris[1], 1, storage); CHKERR(rval, "Couldn't get connectivity."); index = std::find(facehs.begin(), facehs.end(), tris[1]) - facehs.begin(); if (senses[index] < 0) std::reverse(storage.begin(), storage.end()); unsigned int ioff = std::find(storage.begin(), storage.end(), v0) - storage.begin(); if (3 == ioff) CHKERR(MB_FAILURE, "Trouble finding offset."); for (unsigned int i = 0; i < 3; i++) verts.push_back(storage[(ioff+i)%3]); this_type = MBPRISM; } } else if (tris.size() == 4 && quads.size() == 1) { // check for pyramid // get connectivity of first tri, and reverse if necessary int index = std::find(facehs.begin(), facehs.end(), quads[0]) - facehs.begin(); rval = mbImpl->get_connectivity(&quads[0], 1, verts); CHKERR(rval, "Couldn't get connectivity."); if (senses[index] > 0) std::reverse(verts.begin(), verts.end()); // get apex node rval = mbImpl->get_connectivity(&tris[0], 1, storage); CHKERR(rval, "Couldn't get connectivity."); for (unsigned int i = 0; i < 3; i++) { if (std::find(verts.begin(), verts.end(), storage[i]) == verts.end()) { verts.push_back(storage[i]); break; } } if (5 == verts.size()) this_type = MBPYRAMID; } else { // dummy else clause to stop in debugger this_type = MBMAXTYPE; } } if (MBMAXTYPE != input_type && input_type != this_type && this_type != MBMAXTYPE) std::cerr << "Warning: types disagree (cell_topo_type = " << CN::EntityTypeName(input_type) << ", faces indicate type " << CN::EntityTypeName(this_type) << std::endl; if (MBMAXTYPE != input_type && this_type == MBMAXTYPE && input_type != MBPOLYHEDRON) std::cerr << "Warning: couldn't find proper connectivity for specified topo_type = " << CN::EntityTypeName(input_type) << std::endl; // now make the element; if we fell back to polyhedron, use faces, otherwise use verts if (MBPOLYHEDRON == this_type || MBMAXTYPE == this_type) rval = mbImpl->create_element(MBPOLYHEDRON, &facehs[0], facehs.size(), cell); else rval = mbImpl->create_element(this_type, &verts[0], verts.size(), cell); CHKERR(rval, "create_element failed."); return MB_SUCCESS; }
ErrorCode ReadCCMIO::read_faces(CCMIOID faceID, CCMIOEntity bdy_or_int, TupleList &vert_map, TupleList &face_map #ifndef TUPLE_LIST ,SenseList &sense_map #endif , Range *new_faces) { if (kCCMIOInternalFaces != bdy_or_int && kCCMIOBoundaryFaces != bdy_or_int) CHKERR(MB_FAILURE, "Face type isn't boundary or internal."); CCMIOSize_t dum_faces; CCMIOError error = kCCMIONoErr; CCMIOEntitySize(&error, faceID, &dum_faces, NULL); int num_faces = GETINT32(dum_faces); // get the size of the face connectivity array (not really a straight connect // array, has n, connect(n), ...) CCMIOSize_t farray_size = CCMIOSIZEC(0); CCMIOReadFaces(&error, faceID, bdy_or_int, NULL, &farray_size, NULL, CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd)); CHKCCMERR(error, "Trouble reading face connectivity length."); // allocate vectors for holding farray and cells for each face; use new for finer // control of de-allocation int num_sides = (kCCMIOInternalFaces == bdy_or_int ? 2 : 1); int *farray = new int[GETINT32(farray_size)]; // read farray and make the faces CCMIOID mapID; CCMIOReadFaces(&error, faceID, bdy_or_int, &mapID, NULL, farray, CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd)); CHKCCMERR(error, "Trouble reading face connectivity."); std::vector<EntityHandle> face_handles; ErrorCode rval = make_faces(farray, vert_map, face_handles, num_faces); CHKERR(rval, NULL); // read face cells and make tuples int *face_cells; if (num_sides*num_faces < farray_size) face_cells = new int[num_sides*num_faces]; else face_cells = farray; CCMIOReadFaceCells(&error, faceID, bdy_or_int, face_cells, CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd)); CHKCCMERR(error, "Trouble reading face cells."); int *tmp_ptr = face_cells; for (unsigned int i = 0; i < face_handles.size(); i++) { #ifdef TUPLE_LIST short forward = 1, reverse = -1; face_map.push_back(&forward, tmp_ptr++, &face_handles[i], NULL); if (2 == num_sides) face_map.push_back(&reverse, tmp_ptr++, &face_handles[i], NULL); #else face_map[*tmp_ptr].push_back(face_handles[i]); sense_map[*tmp_ptr++].push_back(1); if (2 == num_sides) { face_map[*tmp_ptr].push_back(face_handles[i]); sense_map[*tmp_ptr++].push_back(-1); } #endif } // now read & set face gids, reuse face_cells 'cuz we know it's big enough CCMIOReadMap(&error, mapID, face_cells, CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd)); CHKCCMERR(error, "Trouble reading face gids."); rval = mbImpl->tag_set_data(mGlobalIdTag, &face_handles[0], face_handles.size(), face_cells); CHKERR(rval, "Couldn't set face global ids."); // make a neumann set for these faces if they're all in a boundary face set if (kCCMIOBoundaryFaces == bdy_or_int) { EntityHandle neuset; rval = mbImpl->create_meshset(MESHSET_SET, neuset); CHKERR(rval, "Failed to create neumann set."); // don't trust entity index passed in int index; CCMIOGetEntityIndex(&error, faceID, &index); newNeusets[index] = neuset; rval = mbImpl->add_entities(neuset, &face_handles[0], face_handles.size()); CHKERR(rval, "Failed to add faces to neumann set."); // now tag as neumann set; will add id later int dum_val = 0; rval = mbImpl->tag_set_data(mNeumannSetTag, &neuset, 1, &dum_val); CHKERR(rval, "Failed to tag neumann set."); } if (new_faces) { std::sort(face_handles.begin(), face_handles.end()); std::copy(face_handles.rbegin(), face_handles.rend(), range_inserter(*new_faces)); } return MB_SUCCESS; }