PairEventData DynCompression::SphereWellEvent(const IntEvent& event, const double& deltaKE, const double& d2, size_t) const { Particle& particle1 = Sim->particles[event.getParticle1ID()]; Particle& particle2 = Sim->particles[event.getParticle2ID()]; updateParticlePair(particle1, particle2); PairEventData retVal(particle1, particle2, *Sim->species[particle1], *Sim->species[particle2], event.getType()); Sim->BCs->applyBC(retVal.rij, retVal.vijold); double p1Mass = Sim->species[retVal.particle1_.getSpeciesID()]->getMass(particle1.getID()); double p2Mass = Sim->species[retVal.particle2_.getSpeciesID()]->getMass(particle2.getID()); double mu = 1.0 / ((1.0 / p1Mass) + (1.0 / p2Mass)); bool infinite_masses = (p1Mass == HUGE_VAL) && (p2Mass == HUGE_VAL); if (infinite_masses) { p1Mass = p2Mass = 1; mu = 0.5; } Vector urij = retVal.rij / retVal.rij.nrm(); retVal.rvdot = (urij | retVal.vijold); double sqrtArg = std::pow(retVal.rvdot - growthRate * sqrt(d2), 2) + (2.0 * deltaKE / mu); if ((deltaKE < 0) && (sqrtArg < 0)) { event.setType(BOUNCE); retVal.setType(BOUNCE); retVal.impulse = urij * (2.0 * mu * (retVal.rvdot - growthRate * sqrt(d2))); } else if (deltaKE==0) retVal.impulse = Vector(0,0,0); else { retVal.particle1_.setDeltaU(-0.5 * deltaKE); retVal.particle2_.setDeltaU(-0.5 * deltaKE); if (retVal.rvdot < 0) retVal.impulse = urij * (2.0 * deltaKE / (growthRate * sqrt(d2) + std::sqrt(sqrtArg) - retVal.rvdot )); else retVal.impulse = urij * (2.0 * deltaKE / (growthRate * sqrt(d2) - std::sqrt(sqrtArg) - retVal.rvdot )); ; } retVal.rvdot *= retVal.rij.nrm(); #ifdef DYNAMO_DEBUG if (std::isnan(retVal.impulse[0])) M_throw() << "A nan dp has ocurred" << "\ndeltaKE = " << deltaKE << "\ngrowthRate = " << growthRate << "\nd2 = " << d2 << "\nsqrtArg = " << sqrtArg << "\nrvdot = " << retVal.rvdot << "\nArg " << (growthRate * sqrt(d2) - std::sqrt(sqrtArg) - retVal.rvdot) ; #endif particle1.getVelocity() -= retVal.impulse / p1Mass; particle2.getVelocity() += retVal.impulse / p2Mass; retVal.impulse *= !infinite_masses; return retVal; }
IddObjectType GenericModelObject_Impl::iddObjectType() const { IddObjectType retVal(iddObject().type()); return retVal; }
PairEventData DynNewtonian::SmoothSpheresColl(const IntEvent& event, const double& e, const double&, const EEventType& eType) const { Particle& particle1 = Sim->particles[event.getParticle1ID()]; Particle& particle2 = Sim->particles[event.getParticle2ID()]; updateParticlePair(particle1, particle2); PairEventData retVal(particle1, particle2, *Sim->species[particle1], *Sim->species[particle2], eType); Sim->BCs->applyBC(retVal.rij, retVal.vijold); double p1Mass = Sim->species[retVal.particle1_.getSpeciesID()]->getMass(particle1.getID()); double p2Mass = Sim->species[retVal.particle2_.getSpeciesID()]->getMass(particle2.getID()); retVal.rvdot = (retVal.rij | retVal.vijold); //Treat special cases if one particle has infinite mass if ((p1Mass == 0) && (p2Mass != 0)) //if (!particle1.testState(Particle::DYNAMIC) && particle2.testState(Particle::DYNAMIC)) { retVal.impulse = p2Mass * retVal.rij * ((1.0 + e) * retVal.rvdot / retVal.rij.nrm2()); //This function must edit particles so it overrides the const! particle2.getVelocity() += retVal.impulse / p2Mass; } else if ((p1Mass != 0) && (p2Mass == 0)) //if (particle1.testState(Particle::DYNAMIC) && !particle2.testState(Particle::DYNAMIC)) { retVal.impulse = p1Mass * retVal.rij * ((1.0 + e) * retVal.rvdot / retVal.rij.nrm2()); //This function must edit particles so it overrides the const! particle1.getVelocity() -= retVal.impulse / p1Mass; } else { bool isInfInf = (p1Mass == 0) && (p2Mass == 0); //If both particles have infinite mass we just collide them as identical masses if (isInfInf) p1Mass = p2Mass = 1; double mu = p1Mass * p2Mass / (p1Mass + p2Mass); retVal.impulse = retVal.rij * ((1.0 + e) * mu * retVal.rvdot / retVal.rij.nrm2()); //This function must edit particles so it overrides the const! particle1.getVelocity() -= retVal.impulse / p1Mass; particle2.getVelocity() += retVal.impulse / p2Mass; //If both particles have infinite mass we pretend no momentum was transferred retVal.impulse *= !isInfInf; } retVal.particle1_.setDeltaKE(0.5 * p1Mass * (particle1.getVelocity().nrm2() - retVal.particle1_.getOldVel().nrm2())); retVal.particle2_.setDeltaKE(0.5 * p2Mass * (particle2.getVelocity().nrm2() - retVal.particle2_.getOldVel().nrm2())); lastCollParticle1 = particle1.getID(); lastCollParticle2 = particle2.getID(); lastAbsoluteClock = Sim->systemTime; return retVal; }
Real PenetrationAux::computeValue() { const Node * current_node = NULL; if (_nodal) current_node = _current_node; else current_node = _mesh.getQuadratureNode(_current_elem, _current_side, _qp); PenetrationInfo * pinfo = _penetration_locator._penetration_info[current_node->id()]; Real retVal(NotPenetrated); if (pinfo) switch (_quantity) { case PA_DISTANCE: retVal = pinfo->_distance; break; case PA_TANG_DISTANCE: retVal = pinfo->_tangential_distance; break; case PA_NORMAL_X: retVal = pinfo->_normal(0); break; case PA_NORMAL_Y: retVal = pinfo->_normal(1); break; case PA_NORMAL_Z: retVal = pinfo->_normal(2); break; case PA_CLOSEST_POINT_X: retVal = pinfo->_closest_point(0); break; case PA_CLOSEST_POINT_Y: retVal = pinfo->_closest_point(1); break; case PA_CLOSEST_POINT_Z: retVal = pinfo->_closest_point(2); break; case PA_ELEM_ID: retVal = static_cast<Real>(pinfo->_elem->id()+1); break; case PA_SIDE: retVal = static_cast<Real>(pinfo->_side_num); break; case PA_INCREMENTAL_SLIP_MAG: retVal = pinfo->isCaptured() ? pinfo->_incremental_slip.norm() : 0; break; case PA_INCREMENTAL_SLIP_X: retVal = pinfo->isCaptured() ? pinfo->_incremental_slip(0) : 0; break; case PA_INCREMENTAL_SLIP_Y: retVal = pinfo->isCaptured() ? pinfo->_incremental_slip(1) : 0; break; case PA_INCREMENTAL_SLIP_Z: retVal = pinfo->isCaptured() ? pinfo->_incremental_slip(2) : 0; break; case PA_ACCUMULATED_SLIP: retVal = pinfo->_accumulated_slip; break; case PA_FORCE_X: retVal = pinfo->_contact_force(0); break; case PA_FORCE_Y: retVal = pinfo->_contact_force(1); break; case PA_FORCE_Z: retVal = pinfo->_contact_force(2); break; case PA_NORMAL_FORCE_MAG: retVal = -pinfo->_contact_force*pinfo->_normal; break; case PA_NORMAL_FORCE_X: retVal = (pinfo->_contact_force*pinfo->_normal) * pinfo->_normal(0); break; case PA_NORMAL_FORCE_Y: retVal = (pinfo->_contact_force*pinfo->_normal) * pinfo->_normal(1); break; case PA_NORMAL_FORCE_Z: retVal = (pinfo->_contact_force*pinfo->_normal) * pinfo->_normal(2); break; case PA_TANGENTIAL_FORCE_MAG: { RealVectorValue contact_force_normal( (pinfo->_contact_force*pinfo->_normal) * pinfo->_normal ); RealVectorValue contact_force_tangential( pinfo->_contact_force - contact_force_normal ); retVal = contact_force_tangential.norm(); break; } case PA_TANGENTIAL_FORCE_X: retVal = pinfo->_contact_force(0) - (pinfo->_contact_force*pinfo->_normal) * pinfo->_normal(0); break; case PA_TANGENTIAL_FORCE_Y: retVal = pinfo->_contact_force(1) - (pinfo->_contact_force*pinfo->_normal) * pinfo->_normal(1); break; case PA_TANGENTIAL_FORCE_Z: retVal = pinfo->_contact_force(2) - (pinfo->_contact_force*pinfo->_normal) * pinfo->_normal(2); break; case PA_FRICTIONAL_ENERGY: retVal = pinfo->_frictional_energy; break; case PA_LAGRANGE_MULTIPLIER: retVal = pinfo->_lagrange_multiplier; break; case PA_MECH_STATUS: retVal = pinfo->_mech_status; break; default: mooseError("Unknown PA_ENUM"); } // switch return retVal; }
std::string CGUIDialogProgressBarHandle::Text(void) const { CSingleLock lock(m_critSection); std::string retVal(m_strText); return retVal; }
TPtrC8 CSenPropertiesElement::Type() { TPtrC8 retVal(*this->AttrValue(KSenPropertyType)); return retVal; }
/** * CStringA::CStringA * @date Modified Mar 02, 2006 */ CStringA::CStringA(const wchar_t* str) { CStringW retVal(str); (*this) = (CStringA)retVal; }
/** Create an EventWorkspace containing fake data * of single-crystal diffraction. * Instrument is MINITOPAZ * * @return EventWorkspace_sptr */ EventWorkspace_sptr createDiffractionEventWorkspace(int numEvents) { FacilityHelper::ScopedFacilities loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST"); int numPixels = 10000; int numBins = 1600; double binDelta = 10.0; EventWorkspace_sptr retVal(new EventWorkspace); retVal->initialize(numPixels,1,1); // --------- Load the instrument ----------- LoadInstrument * loadInst = new LoadInstrument(); loadInst->initialize(); loadInst->setPropertyValue("Filename", "IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml"); loadInst->setProperty<Mantid::API::MatrixWorkspace_sptr> ("Workspace", retVal); loadInst->execute(); delete loadInst; // Populate the instrument parameters in this workspace - this works around a bug retVal->populateInstrumentParameters(); DateAndTime run_start("2010-01-01T00:00:00"); for (int pix = 0; pix < numPixels; pix++) { for (int i=0; i<numEvents; i++) { retVal->getEventList(pix) += Mantid::DataObjects::TofEvent((i+0.5)*binDelta, run_start+double(i)); } retVal->getEventList(pix).addDetectorID(pix); } //Create the x-axis for histogramming. Mantid::MantidVecPtr x1; Mantid::MantidVec& xRef = x1.access(); xRef.resize(numBins); for (int i = 0; i < numBins; ++i) { xRef[i] = i*binDelta; } //Set all the histograms at once. retVal->setAllX(x1); // Default unit: TOF. retVal->getAxis(0)->setUnit("TOF"); // Give it a crystal and goniometer WorkspaceCreationHelper::SetGoniometer(retVal, 0., 0., 0.); WorkspaceCreationHelper::SetOrientedLattice(retVal, 1., 1., 1.); // Some sanity checks if (retVal->getInstrument()->getName() != "MINITOPAZ") throw std::runtime_error("MDEventsTestHelper::createDiffractionEventWorkspace(): Wrong instrument loaded."); Mantid::detid2det_map dets; retVal->getInstrument()->getDetectors(dets); if ( dets.size() != 100*100) throw std::runtime_error("MDEventsTestHelper::createDiffractionEventWorkspace(): Wrong instrument size."); return retVal; }
PairEventData DynNewtonianMCCMap::SphereWellEvent(const IntEvent& event, const double& deltaKE, const double &, size_t newstate) const { Particle& particle1 = Sim->particles[event.getParticle1ID()]; Particle& particle2 = Sim->particles[event.getParticle2ID()]; updateParticlePair(particle1, particle2); PairEventData retVal(particle1, particle2, *Sim->species[particle1], *Sim->species[particle2], event.getType()); Sim->BCs->applyBC(retVal.rij,retVal.vijold); retVal.rvdot = (retVal.rij | retVal.vijold); double p1Mass = Sim->species[retVal.particle1_.getSpeciesID()]->getMass(particle1.getID()); double p2Mass = Sim->species[retVal.particle2_.getSpeciesID()]->getMass(particle2.getID()); double mu = p1Mass * p2Mass / (p1Mass + p2Mass); double R2 = retVal.rij.nrm2(); //Calculate the deformed energy change of the system (the one used in the dynamics) double MCDeltaKE = deltaKE; //If there are entries for the current and possible future energy, then take them into account detail::CaptureMap contact_map = *_interaction; //Add the current bias potential MCDeltaKE += W(contact_map) * Sim->ensemble->getEnsembleVals()[2]; //subtract the possible bias potential in the new state contact_map[detail::CaptureMap::key_type(particle1, particle2)] = newstate; MCDeltaKE -= W(contact_map) * Sim->ensemble->getEnsembleVals()[2]; //Test if the deformed energy change allows a capture event to occur double sqrtArg = retVal.rvdot * retVal.rvdot + 2.0 * R2 * MCDeltaKE / mu; if ((MCDeltaKE < 0) && (sqrtArg < 0)) { event.setType(BOUNCE); retVal.setType(BOUNCE); retVal.impulse = retVal.rij * 2.0 * mu * retVal.rvdot / R2; } else { retVal.particle1_.setDeltaU(-0.5 * deltaKE); retVal.particle2_.setDeltaU(-0.5 * deltaKE); if (retVal.rvdot < 0) retVal.impulse = retVal.rij * (2.0 * MCDeltaKE / (std::sqrt(sqrtArg) - retVal.rvdot)); else retVal.impulse = retVal.rij * (-2.0 * MCDeltaKE / (retVal.rvdot + std::sqrt(sqrtArg))); } #ifdef DYNAMO_DEBUG if (boost::math::isnan(retVal.impulse[0])) M_throw() << "A nan dp has ocurred"; #endif //This function must edit particles so it overrides the const! particle1.getVelocity() -= retVal.impulse / p1Mass; particle2.getVelocity() += retVal.impulse / p2Mass; return retVal; }