int MultilevelHexahedronSetTopologyContainer::getHexaChildren(const unsigned int hexaId, helper::vector<unsigned int>& children) const { std::list<Component*> compList; compList.push_back(_coarseComponents.getValue()[hexaId]); Component* comp = compList.front(); while(!comp->_children.empty()) { for(std::set<Component*>::iterator iter = comp->_children.begin(); iter != comp->_children.end(); ++iter) { compList.push_back(*iter); } compList.pop_front(); comp = compList.front(); } std::set<Component*> compSet; compSet.insert(compList.begin(), compList.end()); children.reserve(compSet.size()); for(unsigned int i=0; i<_fineComponents.getValue().size(); ++i) { if(compSet.find(_fineComponents.getValue()[i]) != compSet.end()) children.push_back(i); } return (int) children.size(); }
void MeshGmshLoader::addInGroup(helper::vector< sofa::core::loader::PrimitiveGroup>& group,int tag,int /*eid*/) { for (unsigned i=0;i<group.size();i++) { if (tag == group[i].p0) { group[i].nbp++; return; } } stringstream ss; string s; ss << tag; group.push_back(sofa::core::loader::PrimitiveGroup(tag,1,s,s,-1)); }
/// Generate discrete mass position values with variational sympletic implicit solver void generateDiscreteMassPositions (double h, double K, double m, double z0, double v0,double g, double finalTime, double rm,double rk) { int size = 0 ; // During t=finalTime if((finalTime/h) > 0) { size = int(finalTime/h); positionsArray.reserve(size); velocitiesArray.reserve(size); energiesArray.reserve(size); } // First velocity is v0 velocitiesArray.push_back(v0); // First acceleration energiesArray.push_back(m*v0); // First position is z0 positionsArray.push_back(double(z0)); // Compute totalEnergy totalEnergy = m*g*z0; // energy at initial time // Set constants double denominator = 4*m+h*h*K+4*h*(rm*m + rk*K);//4*h*(-rk*K+rm*m); double constant = -h*K; // Compute velocities, energies and positions for(int i=1;i< size+1; i++) { velocitiesArray.push_back(2*(-m*g*h+constant*(positionsArray[i-1]-z0)+2*energiesArray[i-1])/denominator); energiesArray.push_back(m*velocitiesArray[i]+h*(-K*(positionsArray[i-1]- z0+velocitiesArray[i]*h/2) -m*g)/2); positionsArray.push_back(positionsArray[i-1]+h*velocitiesArray[i]); } }
void TimerData::process() { if (records.empty()) return; ++nbIter; if (nbIter == 0) return; // do not keep stats on very first iteration ctime_t t0 = records[0].time; //ctime_t last_t = 0; int level = 0; for (unsigned int ri = 0; ri < records.size(); ++ri) { const Record& r = records[ri]; ctime_t t = r.time - t0; //last_t = r.time; if (r.type == Record::REND || r.type == Record::RSTEP_END) --level; switch (r.type) { case Record::RNONE: break; case Record::RBEGIN: case Record::RSTEP_BEGIN: case Record::RSTEP: { AdvancedTimer::IdStep id; if (r.type != Record::RBEGIN) id = AdvancedTimer::IdStep(r.id); if (stepData.find(id) == stepData.end()) steps.push_back(id); StepData& data = stepData[id]; data.level = level; if (data.lastIt != nbIter) { data.lastIt = nbIter; data.tstart += t; ++data.numIt; } data.lastTime = t; ++data.num; break; } case Record::REND: case Record::RSTEP_END: { AdvancedTimer::IdStep id; if (r.type != Record::REND) id = AdvancedTimer::IdStep(r.id); StepData& data = stepData[id]; if (data.lastIt == nbIter) { ctime_t dur = t - data.lastTime; data.ttotal += dur; data.ttotal2 += dur*dur; if (data.num == 1 || dur > data.tmax) data.tmax = dur; if (data.num == 1 || dur < data.tmin) data.tmin = dur; } break; } case Record::RVAL_SET: case Record::RVAL_ADD: { AdvancedTimer::IdVal id = AdvancedTimer::IdVal(r.id); if (valData.find(id) == valData.end()) vals.push_back(id); ValData& data = valData[id]; if (r.type == Record::RVAL_SET || (data.lastIt != nbIter)) { // update vmin and vmax if (data.num == 1 || data.vtotalIt < data.vmin) data.vmin = data.vtotalIt; if (data.num == 1 || data.vtotalIt > data.vmax) data.vmax = data.vtotalIt; } if (data.lastIt != nbIter) { data.lastIt = nbIter; data.vtotalIt = r.val; data.vtotal += r.val; data.vtotal2 += r.val*r.val; ++data.numIt; ++data.num; } else if (r.type == Record::RVAL_SET) { data.vtotalIt = r.val; data.vtotal += r.val; data.vtotal2 += r.val*r.val; ++data.num; } else { data.vtotalIt += r.val; data.vtotal += r.val; data.vtotal2 += r.val*r.val; } break; } } if (r.type == Record::RBEGIN || r.type == Record::RSTEP_BEGIN) ++level; } for (unsigned int vi=0; vi < vals.size(); ++vi) { AdvancedTimer::IdVal id = vals[vi]; ValData& data = valData[id]; if (data.num > 0) { // update vmin and vmax if (data.num == 1 || data.vtotalIt < data.vmin) data.vmin = data.vtotalIt; if (data.num == 1 || data.vtotalIt > data.vmax) data.vmax = data.vtotalIt; } } }