//----------------------------------------------------------------------- void OperatorManager::addOperator(Operator* op) { assert(op); // Setup timestamp op->setTimestamp(++mTimestamp); const String& groupName = op->getGroupName(); // Erase all operator that has same group name from global redo list OperatorList::iterator it = mRedoList.begin(); while (it != mRedoList.end()) { if ((*it)->getGroupName() == groupName) mRedoList.erase(it++); else ++it; } // Add to global undo list mUndoList.push_front(op); // Find or create the group by group name Group* group = findGroup(groupName); if (!group) { group = new Group; std::pair<GroupMap::iterator, bool> inserted = mGroups.insert(GroupMap::value_type(groupName, group)); assert(inserted.second); } // Add to the group group->add(op); }
//----------------------------------------------------------------------- const OperatorManager::OperatorList& OperatorManager::getRedoOperators(const String& groupName) const { const Group* group = findGroup(groupName); if (!group) return nullOperatorList; return group->getRedoOperators(); }
void addNodeItem(ML *E,char nombre[],char boleta[],char grupo[]) { if(!findSingleGroup(*E,grupo)) { printf("\nEse grupo no existe.\n"); return; } MR *group_pointer; MD *newNode,*current; group_pointer = findGroup(*E,grupo); newNode = makeItem(nombre,boleta); if(group_pointer->listDown == NULL) { group_pointer->listDown = newNode; return; } /*Si la lista no esta vacía. Insertamos el nodo en la posición según el orden ascendente en la lista */ current = group_pointer->listDown; /*Agregamos nodo al principio de la lista no vacia*/ if(current == group_pointer->listDown) { newNode->nextDown = group_pointer->listDown; // NULL group_pointer->listDown = newNode; } }
void RosterBox::addContact( QString jid ) { QString group = roster_manager->getContactGroup( jid ); if( group.isEmpty() ) group = tr( "General" ); QListViewItem *groupItem = findGroup( group ); if( !groupItem ) { addGroup( group, isGroupOpen( group ) ); groupItem = findGroup( group ); } (void)new RosterBoxItem( jid, "item", groupItem ); }
bool ObjectCache::findGroup(Id group_id, Group& group) { Group* object = findGroup(group_id); if (object == NULL) return false; group = *object; return true; }
void GCUserView::removeEntry(const QString &nick) { GCUserViewItem *lvi = (GCUserViewItem *)findEntry(nick); if(lvi) { GCUserViewGroupItem* gr = findGroup(lvi->s.mucItem().role()); delete lvi; gr->updateText(); } }
void Database::deleteGroup(Group* group) { int position=findGroup(group->getID()); delete groupVector[position]; if(position!=-1) swapGroups(position, groupVector.size()-1); groupVector.pop_back(); sort (groupVector.begin(), groupVector.end(), Database::compareGroups); }
void DrMain::removeGroupGlobally(DrGroup *grp) { DrGroup *parent(0); if(findGroup(grp, &parent) && parent) { parent->removeGroup(grp); if(parent->isEmpty() && parent != this) removeGroupGlobally(parent); } }
//same group: return 1; different group: return 0 int findGroup(Degree* indegree, int x, int y) { Node* ptr = (indegree+y)->head; int ret = 0; while(ptr != NULL && ret != 1) { if (x == ptr->start_point) return 1; ret |= findGroup(indegree, x, ptr->start_point); ptr = ptr->next; } return ret; }
bool SymbolTable::addGroup(const DefinedAtom &da) { StringRef name = da.name(); assert(!name.empty()); const Atom *existing = findGroup(name); if (existing == nullptr) { _groupTable[name] = &da; return true; } _replacedAtoms[&da] = existing; return false; }
void GCUserView::updateEntry(const QString &nick, const Status &s) { GCUserViewGroupItem* gr; GCUserViewItem *lvi = (GCUserViewItem *)findEntry(nick); if (lvi && lvi->s.mucItem().role() != s.mucItem().role()) { gr = findGroup(lvi->s.mucItem().role()); delete lvi; gr->updateText(); lvi = NULL; } if(!lvi) { gr = findGroup(s.mucItem().role()); lvi = new GCUserViewItem(gr); lvi->setText(0, nick); gr->updateText(); } lvi->s = s; lvi->setPixmap(0, PsiIconset::instance()->status(lvi->s).impix()); }
bool SSIManager::removeGroup( const QString &group ) { Oscar::SSI gr = findGroup( group ); if ( gr.isValid() && removeGroup( gr ) ) { return true; } else kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Group " << group << " not found." << endl; return false; }
void addLayers(const QVector<Layer> &layers, KisImageSP image, int depth) { for(int i = 0; i < layers.size(); i++) { const Layer &layer = layers[i]; if (layer.depth == depth) { KisGroupLayerSP group = (depth == 0 ? image->rootLayer() : findGroup(layers, layer, i)); image->addNode(layer.layer, group); if (layer.mask) { image->addNode(layer.mask, layer.layer); } } } }
QValueList<Oscar::SSI> SSIManager::contactsFromGroup( const QString &group ) const { QValueList<Oscar::SSI> list; Oscar::SSI gr = findGroup( group ); if ( gr.isValid() ) { QValueList<Oscar::SSI>::const_iterator it, listEnd = d->SSIList.end(); for ( it = d->SSIList.begin(); it != listEnd; ++it ) if ( ( *it ).type() == ROSTER_CONTACT && (*it ).gid() == gr.gid() ) list.append( ( *it ) ); } return list; }
// Add a new instrument group, optionally under another group. qsamplerInstrumentGroup *qsamplerInstrumentList::addGroup ( const QString& sName, qsamplerInstrumentGroup *pParentGroup ) { qsamplerInstrumentGroup *pGroup = findGroup(sName); if (pGroup == NULL) { if (pParentGroup) { pParentGroup->setOpen(true); pGroup = new qsamplerInstrumentGroup(pParentGroup, sName); } else { pGroup = new qsamplerInstrumentGroup(this, sName); } } QListView::setSelected(pGroup, true); return pGroup; }
// // will add all cells which can reach the given cell through neighbourhood // accesses to the groupvector // void SandSimulator2d::findGroup( Cell *cell, std::vector<Cell *> &group ) { // first we add the given cell cell->layer = 0; group.push_back( cell ); // now add all direct neighbours if they are not within a group for( int i=0; i<4; ++i ) if(cell->neighbours[i]) if( (cell->neighbours[i]->layer == -1)&&(cell->rigid) ) { findGroup( cell->neighbours[i], group ); } }
SafeListViewGroup *SafeListView::addGroup(const QString &group_name) { // if the group's name is empty, if(group_name.isEmpty()) return NULL; // if name has zero seperators or else { QString group_path(group_name); if(group_path.at(0) == '/') { for(int i = 0; i < group_path.length(); i++) { if(group_path.at(i) != '/') { group_path.remove(0, i); break; } } DBGOUT("Group path: " << group_path); } SafeListViewGroup *group = findGroup(group_path); if(group != NULL) { DBGOUT("Found group " << group_path); return group; } DBGOUT("adding group: " << group_path); // FIXME: doesn't divide the group's name right if GroupSeperator // is escaped QString this_group = thisGroup(group_path); QString parent_group = parentGroup(group_path); DBGOUT("this_group = " << this_group); if(parent_group.isEmpty()) { return new SafeListViewGroup(this, this_group); } else { DBGOUT("parent = " << parent_group); // search for the parent // if it doesn't exist add it SafeListViewGroup *parent = addGroup(parent_group); parent->setOpen(true); return new SafeListViewGroup(parent, this_group); } } return NULL; }
bool Database::addGroup(Group* group) { if(groupVector.size()==0) { groupVector.push_back(group); return true; } if(findGroup(group->getID()) == -1) { groupVector.push_back(group); sort (groupVector.begin(), groupVector.end(), Database::compareGroups); return true; } else return false; }
void checkOverlap(struct mdbObj *mdbObjs, struct group *groups) { int errs = 0; for(; mdbObjs; mdbObjs = mdbObjs->next) { struct mdbVar *mdbVar = hashFindVal(mdbObjs->varHash, "objType"); if (sameString(mdbVar->val, "composite")) continue; struct group *ourGroup = findGroup(mdbObjs, groups); if (ourGroup == NULL) errAbort("cannot find group for %s\n", mdbObjs->obj); mdbVar = hashFindVal(mdbObjs->varHash, "view"); if (mdbVar == NULL) errAbort("obj %s has no view", mdbObjs->obj); struct hashEl *hel; if (ourGroup->viewHash == NULL) ourGroup->viewHash = newHash(10); struct mdbVar *mdbReplicate = hashFindVal(mdbObjs->varHash, "replicate"); char buffer[10*1024]; if (mdbReplicate != NULL) { if (ourGroup->repHash == NULL) ourGroup->repHash = newHash(10); hashStore(ourGroup->repHash, mdbReplicate->val); safef(buffer, sizeof buffer, "%s-%s",mdbVar->val, mdbReplicate->val); } else safef(buffer, sizeof buffer, "%s",mdbVar->val); if ((hel = hashLookup(ourGroup->viewHash, buffer)) != NULL) { printf("two views of type %s in same group\n",buffer); printf("objects are %s and %s\n", (char *)hel->val, mdbObjs->obj); printGroup(ourGroup); errs++; } else hashAdd(ourGroup->viewHash, buffer, mdbObjs->obj); } if (errs) errAbort("aborting"); }
//----------------------------------------------------------------------- size_t OperatorManager::redo(size_t count) { size_t n = 0; while (n < count && !mRedoList.empty()) { Operator* op = mRedoList.front(); Group* group = findGroup(op->getGroupName()); assert(group); group->redo(); mUndoList.push_front(op); mRedoList.pop_front(); ++n; } return n; }
bool SSIManager::newGroup( const Oscar::SSI& group ) { //trying to find the group by its ID QValueList<Oscar::SSI>::iterator it, listEnd = d->SSIList.end(); if ( findGroup( group.name() ).isValid() ) return false; if ( !group.name().isEmpty() ) //avoid the group with gid 0 and bid 0 { // the group is really new kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Adding group '" << group.name() << "' to SSI list" << endl; d->SSIList.append( group ); addID( group ); emit groupAdded( group ); return true; } return false; }
void Preference::Load(const QString &file) { // Read the input PVL preference file Isis::Pvl pvl; if(Isis::FileName(file).fileExists()) { pvl.read(file); } // Override parameters each time load is called for(int i = 0; i < pvl.groups(); i++) { Isis::PvlGroup &inGroup = pvl.group(i); if(this->hasGroup(inGroup.name())) { Isis::PvlGroup &outGroup = this->findGroup(inGroup.name()); for(int k = 0; k < inGroup.keywords(); k++) { Isis::PvlKeyword &inKey = inGroup[k]; while(outGroup.hasKeyword(inKey.name())) { outGroup.deleteKeyword(inKey.name()); } outGroup += inKey; } } else { this->addGroup(inGroup); } } // Configure Isis to use the user performance preferences where // appropriate. if (hasGroup("Performance")) { PvlGroup &performance = findGroup("Performance"); if (performance.hasKeyword("GlobalThreads")) { IString threadsPreference = performance["GlobalThreads"][0]; if (threadsPreference.DownCase() != "optimized") { // We need a no-iException conversion here int threads = threadsPreference.ToQt().toInt(); if (threads > 0) { QThreadPool::globalInstance()->setMaxThreadCount(threads); } } } } }
bool AsGroupsDlg::getItem(tstring& name, bool checkSel) { { CEdit wnd; wnd.Attach(GetDlgItem(IDC_NAME)); name = WinUtil::getEditText(wnd); wnd.Detach(); if (name.empty()) { MessageBox(_T("You must enter a group name!"), CTSTRING(MANAGE_GROUPS), MB_ICONERROR); return false; } else { int32_t pos = findGroup(name.c_str()); if (pos != -1 && (checkSel == false || pos != ctrlGroups.GetSelectedIndex())) { MessageBox(_T("Item already exists!"), CTSTRING(MANAGE_GROUPS), MB_ICONERROR); return false; } } } return true; }
Oscar::SSI SSIManager::findContact( const QString &contact, const QString &group ) const { if ( contact.isNull() || group.isNull() ) { kdWarning(OSCAR_RAW_DEBUG) << k_funcinfo << "Passed NULL name or group string, aborting!" << endl; return m_dummyItem; } Oscar::SSI gr = findGroup( group ); // find the parent group if ( gr.isValid() ) { kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "gr->name= " << gr.name() << ", gr->gid= " << gr.gid() << ", gr->bid= " << gr.bid() << ", gr->type= " << gr.type() << endl; QValueList<Oscar::SSI>::const_iterator it, listEnd = d->SSIList.end(); for ( it = d->SSIList.begin(); it != listEnd; ++it ) { if ( ( *it ).type() == ROSTER_CONTACT && (*it ).name() == contact && (*it ).gid() == gr.gid() ) { //we have found our contact kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Found contact " << contact << " in SSI data" << endl; return ( *it ); } } } else { kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "ERROR: Group '" << group << "' not found!" << endl; } return m_dummyItem; }
//----------------------------------------------------------------------- size_t OperatorManager::redo(const String& groupName, size_t count) { size_t n = 0; Group* group = findGroup(groupName); if (group) { n = group->redo(count); // Move all redo'ed operator from redo list to undo list size_t m = 0; OperatorList::iterator itRedo = mRedoList.begin(); OperatorList::iterator itUndo = mUndoList.begin(); while (m < n && itRedo != mRedoList.end()) { Operator* op = *itRedo; if (op->getGroupName() == groupName) { // Find the correct insert place, undo list is sort descend by timestamp size_t timestamp = op->getTimestamp(); while (itUndo != mUndoList.end() && timestamp < (*itUndo)->getTimestamp()) { ++itUndo; } mUndoList.insert(itUndo, op); mRedoList.erase(itRedo++); ++m; } else { ++itRedo; } } assert(m == n); } return n; }
bool SSIManager::updateGroup( const Oscar::SSI& group ) { Oscar::SSI oldGroup = findGroup( group.name() ); if ( oldGroup.isValid() ) { removeID( oldGroup ); d->SSIList.remove( oldGroup ); } if ( d->SSIList.findIndex( group ) != -1 ) { kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "New group is already in list." << endl; return false; } kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Updating group '" << group.name() << "' in SSI list" << endl; d->SSIList.append( group ); addID( group ); emit groupUpdated( group ); return true; }
DataObject* ObjectCache::find(Id object_id, bool cacheOnly) { if (object_id == INVALID_ID) return NULL; if (_objects.find(object_id) != _objects.end()) return _objects[object_id]; if (cacheOnly) return NULL; DataObject object; if (!_db->lookup(object_id, object)) return NULL; switch (object.dataType()) { case DataObject::ACCOUNT: return findAccount(object_id); case DataObject::ADJUST_REASON: return findAdjustReason(object_id); case DataObject::CARD_ADJUST: return findCardAdjust(object_id); case DataObject::CHARGE: return findCharge(object_id); case DataObject::CHEQUE: return findCheque(object_id); case DataObject::CLAIM: return findReceive(object_id); case DataObject::COMPANY: return findCompany(object_id); case DataObject::COUNT: return findCount(object_id); case DataObject::CUSTOMER: return findCustomer(object_id); case DataObject::CUST_TYPE: return findCustomerType(object_id); case DataObject::DEPT: return findDept(object_id); case DataObject::DISCOUNT: return findDiscount(object_id); case DataObject::EMPLOYEE: return findEmployee(object_id); case DataObject::EXPENSE: return findExpense(object_id); case DataObject::EXTRA: return findExtra(object_id); case DataObject::GENERAL: return findGeneral(object_id); case DataObject::GROUP: return findGroup(object_id); case DataObject::INVOICE: return findInvoice(object_id); case DataObject::ITEM: return findItem(object_id); case DataObject::ITEM_ADJUST: return findItemAdjust(object_id); case DataObject::ITEM_PRICE: return findItemPrice(object_id); case DataObject::LABEL_BATCH: return findLabelBatch(object_id); case DataObject::LOCATION: return findLocation(object_id); case DataObject::NOSALE: return findNosale(object_id); case DataObject::ORDER: return findOrder(object_id); case DataObject::PO_TEMPLATE: return findOrderTemplate(object_id); case DataObject::PAT_GROUP: return findPatGroup(object_id); case DataObject::PAT_WS: return findPatWorksheet(object_id); case DataObject::PAYOUT: return findPayout(object_id); case DataObject::PERSONAL: return findPersonal(object_id); case DataObject::PLU: assert("Invalid data type: PLU"); case DataObject::PRICE_BATCH: return findPriceBatch(object_id); case DataObject::PROMO_BATCH: return findPromoBatch(object_id); case DataObject::QUOTE: return findQuote(object_id); case DataObject::RECEIPT: return findReceipt(object_id); case DataObject::RECEIVE: return findReceive(object_id); case DataObject::RECONCILE: return findReconcile(object_id); case DataObject::RECURRING: return findRecurring(object_id); case DataObject::REPORT: assert("Invalid data type: REPORT"); case DataObject::RETURN: return findInvoice(object_id); case DataObject::SECURITY_TYPE: return findSecurityType(object_id); case DataObject::SHIFT: return findShift(object_id); case DataObject::SLIP: return findSlip(object_id); case DataObject::STATION: return findStation(object_id); case DataObject::STORE: return findStore(object_id); case DataObject::SUBDEPT: return findSubdept(object_id); case DataObject::TAX: return findTax(object_id); case DataObject::TENDER: return findTender(object_id); case DataObject::TEND_COUNT: return findTenderCount(object_id); case DataObject::TEND_ADJUST: return findTenderAdjust(object_id); case DataObject::TERM: return findTerm(object_id); case DataObject::TODO: return findTodo(object_id); case DataObject::USER: return findUser(object_id); case DataObject::VENDOR: return findVendor(object_id); case DataObject::WITHDRAW: return findWithdraw(object_id); } qWarning("Unknown object type: " + object.dataTypeName()); return NULL; }
// // takes the coloumb friction into account and evaluates // the mohr-coloumb yield-condition to change the fluid // velocity so that it behaves like sand // void SandSimulator2d::applySandModel( float dt ) { // prepare cells ------------------------------------------------------- for( stdext::hash_map<Cell::Coordinate, Cell, hash_compare>::iterator it = gridCells.begin(); it != gridCells.end(); ++it ) { (*it).second.rigid = false; (*it).second.layer = -1; // used to find groups of connected rigid cells (*it).second.strainTensor = math::Matrix22f::Zero(); (*it).second.vonMisesEquivalentStress = 0.0f; (*it).second.center = math::Vec2f( (*it).first.i*cellSize + cellSize*0.5f, (*it).first.j*cellSize + cellSize*0.5f ); } // check yield-condition for every fluid cell -------------------------- for( stdext::hash_map<Cell::Coordinate, Cell, hash_compare>::iterator it = gridCells.begin(); it != gridCells.end(); ++it ) { // get reference to current cell Cell *cell = &((*it).second); if( cell->type != Cell::Fluid ) continue; //if( !(cell->xNeighboursFluid || cell->yNeighboursFluid) ) // continue; // compute strain rate D from strain rate tensor D and the frobenius norm of D math::Matrix22f D; // strain rate tensor math::Matrix22f sigma_f; // friction stress tensor in yielding area (dynamic friction) math::Matrix22f sigma_rigid; // friction stress tensor in rigid areas (static friction) D = math::Matrix22f::Zero(); sigma_f = math::Matrix22f::Zero(); sigma_rigid = math::Matrix22f::Zero(); // compute the rate of strain tensor D D = computeStrainRateTensor( cell ); // compute frobenius norm of sigma_rigid float frobD = math::frobeniusNorm( D ); // frobenius Norm of the rate of strain tensor D //float frictionCoefficient = 100.6f; //float frictionCoefficient = 60.6f; float frictionCoefficient = .8f; // compute sigma_f from D if( frobD > 0.0f ) sigma_f = frictionCoefficient*cell->pressure*(1.0f/(sqrt(1.0f/2.0f)*frobD))*D; //sigma_f = -frictionCoefficient*cell->pressure*(D*cellSize*cellSize)/frobD; //sigma_f = -frictionCoefficient*cell->pressure*D*cellSize; //sigma_f = frictionCoefficient*cell->pressure*D*cellSize; //sigma_f = -frictionCoefficient*dt*D; else sigma_f = math::Matrix22f::Zero(); // compute sigma_rigid from D sigma_rigid = -(D*cellSize*cellSize)/dt; float cohesion = 0.0001f; //cohesion = 0.01f; //cohesion = 0.005f; //cohesion = 0.0045f; //cohesion = 0.00001f; cell->meanStress = cell->pressure; //cell->shearStress = sqrt(3.0f/2.0f)*frobD; // zhou cell->shearStress = sqrt(3.0f/2.0f)*math::frobeniusNorm( sigma_rigid ); // zhou? //cell->shearStress = frobD; // zhou //cell->shearStress = frobD; // zhou //cell->shearStress = sqrt( 3.0f*(D.m[0][0]*D.m[1][1] - D.m[0][1]*D.m[0][1]) ); // wiki -> problem: root from negative value //cell->shearStress = sqrt( D.m[0][0]*D.m[0][0] + D.m[1][1]*D.m[1][1] - D.m[0][0]*D.m[1][1] + 1*D.m[0][1] ); // ... //cell->shearStress = sqrt( D.m[0][0]*D.m[0][0] + D.m[1][1]*D.m[1][1] - D.m[0][0]*D.m[1][1] + 3*D.m[0][1] ); // ... //float t = sigma2.m[0][0]*sigma2.m[0][0] + sigma2.m[1][1]*sigma2.m[1][1] - sigma2.m[0][0]*sigma2.m[1][1] + 3*sigma2.m[0][1]; //if( t < 0.0f ) // printf( "----> " ); //cell->shearStress = sqrt( sigma2.m[0][0]*sigma2.m[0][0] + sigma2.m[1][1]*sigma2.m[1][1] - sigma2.m[0][0]*sigma2.m[1][1] + 3*sigma2.m[0][1] ); // ... //printf( "%f %f\n", cell->shearStress, cell->meanStress ); // use sigma_rigid to check for yield-condition //if( math::frobeniusNorm( D ) < frictionCoefficient*sqrt(cell->pressure*cell->pressure*2.0f) ) //if( math::frobeniusNorm( D ) < frictionCoefficient*sqrt(cell->pressure*cell->pressure*2.0f) ) //if( sqrt(3.0f)*math::frobeniusNorm( D )/sqrt(2.0f) < frictionCoefficient*cell->pressure ) //if( math::frobeniusNorm( D )/sqrt(2.0f) < 10.0*cell->pressure ) //if( sqrt(3.0f)*frobSigma_rigid/sqrt(2.0f) < frictionCoefficient*cell->pressure ) //printf( "%f < %f \n", frobSigma_rigid/sqrt(2.0f), frictionCoefficient*cell->pressure + cohesion ); //if( sqrt(3.0f)*frobSigma_rigid/sqrt(2.0f) < frictionCoefficient*cell->pressure + cohesion ) //if( sqrt(3.0f)*frobD/sqrt(2.0f) < frictionCoefficient*cell->pressure*cell->pressure*2.0f ) //if( frobSigma_rigid < frictionCoefficient*cell->pressure*cell->pressure*3.0f ) //if( sqrt(3.0f)*frobSigma_rigid/sqrt(2.0f) < frictionCoefficient*cell->pressure*cell->pressure*2.0f + cohesion ) //if( sqrt(3.0f)*frobSigma_rigid/sqrt(2.0f) < frictionCoefficient*cell->pressure + cohesion ) //* //if( frobSigma_rigid < frictionCoefficient*cell->pressure ) //if( sqrt(3.0f)*math::frobeniusNorm( sigma2 )/sqrt(2.0f) < frictionCoefficient*cell->pressure ) // ** //if( sqrt(3.0f)*math::frobeniusNorm( sigma2 )/sqrt(2.0f) < frictionCoefficient*cell->pressure + cohesion ) // ** //if( frobSigma_rigid < frictionCoefficient*sqrt(cell->pressure*cell->pressure*2.0f) ) //if( frictionCoefficient*sqrt(3.0f)*math::frobeniusNorm( testm )/sqrt(2.0f) < frictionCoefficient*cell->pressure + cohesion ) //if( sigma_v < frictionCoefficient*cell->pressure + cohesion ) //if( cell->shearStress < 35.0f*cell->meanStress ) if( cell->shearStress < frictionCoefficient*cell->meanStress + cohesion ) // sand //if( (cell->pressure < 3.0f) && ( cell->shearStress < frictionCoefficient*cell->meanStress + cohesion ) ) // galcier-test { // cell is rigid cell->rigid = true; // store stress tensor cell->strainTensor = sigma_rigid; }else // cell is not rigid -> there is flow cell->strainTensor = sigma_f; // store equivalent stress cell->vonMisesEquivalentStress = cell->shearStress; } // rigidify all chunks/groups of connected rigid fluid cells ----------- std::vector< std::vector<Cell *> > groups; // list of cellgroups - the cellgroups are chuncks of connected rigid cells // find all groups for( stdext::hash_map<Cell::Coordinate, Cell, hash_compare>::iterator it = gridCells.begin(); it != gridCells.end(); ++it ) { // get reference to current cell Cell *cell = &((*it).second); if( cell->rigid ) { // we have found a rigid cell // is the cell is not already within a group if( cell->layer == -1 ) { // we will add a new group... groups.push_back( std::vector<Cell *>() ); // ...and find all cells which belong to this group through region growing findGroup( cell, groups[groups.size()-1] ); } } } // rigidify all groups for( size_t i=0; i<groups.size(); ++i ) rigidify( groups[i] ); // apply friction force (sigma_f) to all non-rigid fluid cells ------------------- for( stdext::hash_map<Cell::Coordinate, Cell, hash_compare>::iterator it = gridCells.begin(); it != gridCells.end(); ++it ) { // get reference to current cell Cell *cell = &((*it).second); if( !(cell->xNeighboursFluid || cell->yNeighboursFluid) ) continue; //if( (!cell->rigid)||(cell->rigid && cell->neighbours[0]->type == Cell::Air)||(cell->rigid && cell->neighbours[2]->type == Cell::Air) ) if( !cell->rigid ) { // non-rigid fluid cell -> apply internal coloumb friction // compute divergence of the stress tensor which is stored at the cell // tensor E ist a matrix which consists of 3 column vectors c1, c2 ,c3 // the divergence of tensor E is the vector of the gradients of these // column vectors divE = (divc1, divc2, divc3) // we approximate the gradient using standard central differences of neighbouring cells // note: thats why we have stored sigma_rigid with each cell math::Vec2f divE = computeDivE( cell ); // apply euler step if( cell->xNeighboursFluid ) cell->velocity.x += dt*divE.x; if( cell->yNeighboursFluid ) cell->velocity.y += dt*divE.y; } } }
int main () { int T; scanf("%d", &T); while(T--) { int n, m; scanf("%d%d", &n, &m); //Initialize the map matrix for fast search weight //int* map = (int* )calloc(n*n, sizeof(int)); //Initialize the edges array for sort Edges* all_edges = (Edges* )malloc(sizeof(Edges) * m); //Initialize the indegree tree Degree* indegree = (Degree* )malloc(sizeof(Degree) * n); for (int i = 0; i < n; i++) { (indegree+i)->head = NULL; (indegree+i)->tail = NULL; } //Read (a, b), c into map matrix and edges array for (int i = 0; i < m; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); //swap // if (a > b) // a ^= b ^= a ^= b; a--; b--; (all_edges+i)->x = a; (all_edges+i)->y = b; (all_edges+i)->weight = c; // if (*(map+a*n+b) == 0) // *(map+a*n+b) = c; // else { // if (*(map+a*n+b) > c) // *(map+a*n+b) = c; // } } //Initialize the Result ret Result ret; ret.total_number = 0; ret.total_weight = 0; //Initialize the group == make_set(n) // int* group = (int* )malloc(sizeof(int) * n); // for (int i = 0; i < n; i++) // *(group+i) = i; //Sort qsort(all_edges, m, sizeof(Edges), cmp); //Handle all edges for (int i = 0; i < m; i++) { Edges tmp = *(all_edges+i); int isSameGroup_1 = findGroup(indegree, tmp.x, tmp.y); int isSameGroup_2 = findGroup(indegree, tmp.y, tmp.x); printf("(%d, %d, %d) same group:%d\n", tmp.x+1, tmp.y+1, tmp.weight, isSameGroup_1 || isSameGroup_2); if ((isSameGroup_1 || isSameGroup_2) == 0) { ret.total_number++; ret.total_weight += tmp.weight; //update the indegree simultaneously Node* insert_node = (Node* )malloc(sizeof(Node)); insert_node->start_point = tmp.x; insert_node->edge_value = tmp.weight; insert_node->prev = NULL; insert_node->next = NULL; insertNode(indegree, tmp.y, insert_node); //printf("Hi, %d, %d\n", ret.total_number, ret.total_weight); } else { if (isSameGroup_1) { //printf("Oh_1\n"); checkRepeat(indegree, tmp.x, tmp.y, &ret, tmp.weight); } else { //printf("Oh_2\n"); checkRepeat(indegree, tmp.y, tmp.x, &ret, tmp.weight); } } printf("<%d, %d>\n", ret.total_number, ret.total_weight); } /* for (int i = 0; i < m; i++) printf("(%d, %d, %d) -> %d\n", ((all_edges+i)->x)+1, ((all_edges+i)->y)+1, (all_edges+i)->weight, *(map+((all_edges+i)->x)*n+((all_edges+i)->y))); */ printf("%d %d\n", ret.total_number, ret.total_weight); //Clean up //free(map); free(all_edges); free(indegree); //free(group); } return 0; }
/*--------------------------------------------------------------*/ int NXVvalidateGroup(pNXVcontext self, hid_t groupID, xmlNodePtr groupNode) { hash_table namesSeen, baseNames; xmlNodePtr cur = NULL; xmlChar *name = NULL, *myClass = NULL; xmlChar *target = NULL; hid_t childID; char fName[256], childName[512], nxdlChildPath[512], childPath[512]; char mynxdlPath[512]; char *savedNXDLPath, *pPtr; SecondPassData spd; hsize_t idx = 0; /* manage nxdlPath, xmlGetNodePath does not work */ savedNXDLPath = self->nxdlPath; myClass = xmlGetProp(groupNode,(xmlChar *)"type"); if(self->nxdlPath == NULL) { snprintf(mynxdlPath,sizeof(mynxdlPath),"/%s", (char *) myClass); } else { snprintf(mynxdlPath,sizeof(mynxdlPath),"%s/%s", self->nxdlPath, (char *) myClass); } self->nxdlPath = mynxdlPath; /* tell what we are doing */ H5Iget_name(groupID,fName,sizeof(fName)); NXVsetLog(self,"sev","debug"); NXVsetLog(self,"message","Validating group"); NXVsetLog(self,"nxdlPath",self->nxdlPath); NXVsetLog(self,"dataPath",fName); NXVlog(self); validateGroupAttributes(self, groupID, groupNode); hash_construct_table(&namesSeen,100); /* first pass */ cur = groupNode->xmlChildrenNode; while(cur != NULL){ if(xmlStrcmp(cur->name,(xmlChar *) "group") == 0){ childID = findGroup(self, groupID, cur); if(childID >= 0){ H5Iget_name(childID, childName,sizeof(childName)); /* we have to get at the HDF5 name. There may be no name in the NXDL, but a suitable group has been found by NXclass. */ pPtr = strrchr(childName,'/'); if(pPtr != NULL){ hash_insert(pPtr+1,strdup(""),&namesSeen); } else { hash_insert(childName,strdup(""),&namesSeen); } NXVvalidateGroup(self,childID,cur); } else { name = xmlGetProp(cur,(xmlChar *)"type"); snprintf(nxdlChildPath,sizeof(nxdlChildPath),"%s/%s", self->nxdlPath, (char *)name); xmlFree(name); NXVsetLog(self,"dataPath",fName); NXVsetLog(self,"nxdlPath", nxdlChildPath); if(!isOptional(cur)){ NXVsetLog(self,"sev","error"); NXVsetLog(self,"message","Required group missing"); NXVlog(self); self->errCount++; } else { NXVsetLog(self,"sev","warnopt"); NXVsetLog(self,"message","Optional group missing"); NXVlog(self); } } } if(xmlStrcmp(cur->name,(xmlChar *) "field") == 0){ name = xmlGetProp(cur,(xmlChar *)"name"); if(H5LTfind_dataset(groupID,(char *)name) ) { childID = H5Dopen(groupID,(char *)name,H5P_DEFAULT); } else { childID = -1; } snprintf(childPath,sizeof(childPath),"%s/%s", fName,name); if(childID < 0){ NXVsetLog(self,"dataPath",childPath); snprintf(nxdlChildPath,sizeof(nxdlChildPath), "%s/%s", self->nxdlPath, name); NXVsetLog(self,"nxdlPath", nxdlChildPath); if(!isOptional(cur)){ NXVsetLog(self,"sev","error"); NXVsetLog(self,"message","Required field missing"); NXVlog(self); self->errCount++; } else { NXVsetLog(self,"sev","warnopt"); NXVsetLog(self,"message","Optional field missing"); NXVlog(self); } } else { if(xmlStrcmp(name,(xmlChar *)"depends_on") == 0){ /* This must b validated from the field level. As it might point to fields which are not in the application definition */ validateDependsOn(self,groupID,childID); } else { NXVvalidateField(self,childID, cur); } hash_insert((char *)name,strdup(""),&namesSeen); } xmlFree(name); } if(xmlStrcmp(cur->name,(xmlChar *) "link") == 0){ name = xmlGetProp(cur,(xmlChar *)"name"); target = xmlGetProp(cur,(xmlChar *)"target"); hash_insert((char *)name,strdup(""),&namesSeen); validateLink(self,groupID,name, target); xmlFree(name); xmlFree(target); } cur = cur->next; } /* Second pass: search the HDF5 group for additional stuff which have not checked yet. Most of the hard work is in the SecondPassIterator. */ hash_construct_table(&baseNames,100); NXVloadBaseClass(self,&baseNames,(char *)myClass); spd.baseNames = &baseNames; spd.namesSeen = &namesSeen; spd.self = self; NXVsetLog(self,"nxdlPath", mynxdlPath); H5Literate(groupID, H5_INDEX_NAME, H5_ITER_INC, &idx, SecondPassIterator, &spd); /* clean up */ hash_free_table(&namesSeen,free); hash_free_table(&baseNames,free); xmlFree(myClass); /* restore my paths... */ self->nxdlPath = savedNXDLPath; return 0; }