TEST(TransferParticlesToPointCloudBehaviorTests, UpdateTest) { auto runtime = std::make_shared<Framework::Runtime>(); runtime->addManager(std::make_shared<Framework::BehaviorManager>()); runtime->addManager(std::make_shared<Physics::PhysicsManager>()); auto sceneElement = std::make_shared<Framework::BasicSceneElement>("Element"); auto particles = std::make_shared<Particles::SphRepresentation>("Particles"); particles->setMaxParticles(10); particles->setMassPerParticle(1.0); particles->setDensity(1.0); particles->setGasStiffness(1.0); particles->setKernelSupport(1.0); for (size_t particleId = 0; particleId < 10; particleId++) { particles->addParticle(Vector3d(static_cast<double>(particleId), 0.0, 0.0), Vector3d::Zero(), 100000); } sceneElement->addComponent(particles); auto pointCloud = std::make_shared<Graphics::OsgPointCloudRepresentation>("Graphics"); sceneElement->addComponent(pointCloud); auto behavior = std::make_shared<TransferParticlesToPointCloudBehavior>("Behavior"); behavior->setSource(particles); behavior->setTarget(pointCloud); sceneElement->addComponent(behavior); auto scene = runtime->getScene(); scene->addSceneElement(sceneElement); particles->update(0.1); behavior->update(0.1); auto sourceVertices = particles->getParticles().safeGet()->getVertices(); auto targetVertices = pointCloud->getVertices()->getVertices(); ASSERT_EQ(sourceVertices.size(), targetVertices.size()); auto sourceVertex = sourceVertices.begin(); auto targetVertex = targetVertices.begin(); for (; sourceVertex != sourceVertices.end(); ++sourceVertex, ++targetVertex) { EXPECT_TRUE(sourceVertex->position.isApprox(targetVertex->position)); } particles->removeParticle(0); particles->removeParticle(1); particles->update(0.1); behavior->update(0.1); sourceVertices = particles->getParticles().safeGet()->getVertices(); targetVertices = pointCloud->getVertices()->getVertices(); ASSERT_EQ(sourceVertices.size(), targetVertices.size()); sourceVertex = sourceVertices.begin(); targetVertex = targetVertices.begin(); for (; sourceVertex != sourceVertices.end(); ++sourceVertex, ++targetVertex) { EXPECT_TRUE(sourceVertex->position.isApprox(targetVertex->position)); } }
int main(int argc, char *argv[]) { // Problem setup Tutorial7 problem; // instantiate an object of class Tutorial 6 problem.setName("Tutorial7"); problem.setSystemDimensions(2); problem.setGravity(Vec3D(0.0,0.0,0.0)); problem.setXMax(1); problem.setYMax(0.5); problem.setTimeMax(5.0); //! [T7:speciesProp] // The normal spring stiffness and normal dissipation is computed and set as // For collision time tc=0.005 and restitution coefficeint rc=1.0, auto species = problem.speciesHandler.copyAndAddObject(LinearViscoelasticSpecies()); species->setDensity(2500.0); // sets the species type-0 density species->setStiffness(258.5);// sets the spring stiffness species->setDissipation(0.0);// sets the dissipation //! [T7:speciesProp] problem.setSaveCount(10); problem.dataFile.setFileType(FileType::ONE_FILE); problem.restartFile.setFileType(FileType::ONE_FILE); problem.fStatFile.setFileType(FileType::NO_FILE); problem.eneFile.setFileType(FileType::NO_FILE); problem.setXBallsAdditionalArguments("-solidf -v0 -s .85"); problem.setTimeStep(0.005/50.0);// (collision time)/50.0 problem.solve(argc, argv); return 0; }
void cCritterViewer::resetAndMatchMoveBox(cGame *pgame) { _proportionofworldtoshow = cCritterViewer::PROPORTIONOFWORLDTOSHOW; _aspect = 4.0/3.0; _fieldofviewangle = cCritterViewer::STARTFIELDOFVIEWANGLE; _trackplayer = FALSE; _perspective = FALSE; //Will be reset by setViewpoint, _foveaproportion = cCritterViewer::FOVEAPROPORTION; _wrapflag = cCritter::CLAMP; /* I had WRAP, which was a big mistake, as sometimes I'd back way up above the world and then suddenly be under it. */ _dragbox = _movebox = cRealBox(pgame->border().center(), MOVEBOXTOGAMEBORDERRATIO * pgame->border().maxsize()); /* Put the viewer in a cube (or square in the 2D case) whose edge is a multiple of the world's largest dimension. */ //We will set _znear and _zfar in the cCritterViewer::setZClipPlanes call. setViewpoint(); /* Default viewpoint is up the z axis looking down at the origin. This call also initializes some of the remaining vairables. */ zoom(1.0); //Matches _fieldofviewangle to _proportionofworldtoshow /* Don't bother to set a listener, as the various cGame::initializeView will do that indirectly via a setGraphicsClass call, and then possibly with a direct call to change the listener again. */ setDensity(0.0); //so you don't move things you bump into. setAbsorberflag(TRUE); //So you don't bounce when you bump things. psprite()->setRadius(0.1); /* Although this guy is invisible, it seems to be good to have a radius of 1.0 for use in the COLLIDEVIEWER code. */ }
bool MasslessOpaqueMaterial_Impl::setDensity(const Quantity& density) { OptionalDouble value = getDoubleFromQuantity(OS_MaterialFields::Density,density); if (!value) { return false; } return setDensity(value.get()); }
void MineralEQ3::initThermoXML(XML_Node& phaseNode, const std::string& id_) { /* * Find the Thermo XML node */ if (!phaseNode.hasChild("thermo")) { throw CanteraError("HMWSoln::initThermoXML", "no thermo XML node"); } std::vector<const XML_Node*> xspecies = speciesData(); const XML_Node* xsp = xspecies[0]; XML_Node* aStandardState = 0; if (xsp->hasChild("standardState")) { aStandardState = &xsp->child("standardState"); } else { throw CanteraError("MineralEQ3::initThermoXML", "no standard state mode"); } doublereal volVal = 0.0; string smodel = (*aStandardState)["model"]; if (smodel != "constantVolume") { throw CanteraError("MineralEQ3::initThermoXML", "wrong standard state mode"); } if (aStandardState->hasChild("V0_Pr_Tr")) { XML_Node& aV = aStandardState->child("V0_Pr_Tr"); string Aunits = ""; double Afactor = toSI("cm3/gmol"); if (aV.hasAttrib("units")) { Aunits = aV.attrib("units"); Afactor = toSI(Aunits); } volVal = ctml::getFloat(*aStandardState, "V0_Pr_Tr"); m_V0_pr_tr= volVal; volVal *= Afactor; m_speciesSize[0] = volVal; } else { throw CanteraError("MineralEQ3::initThermoXML", "wrong standard state mode"); } doublereal rho = molecularWeight(0) / volVal; setDensity(rho); const XML_Node& sThermo = xsp->child("thermo"); const XML_Node& MinEQ3node = sThermo.child("MinEQ3"); m_deltaG_formation_pr_tr = ctml::getFloatDefaultUnits(MinEQ3node, "DG0_f_Pr_Tr", "cal/gmol", "actEnergy"); m_deltaH_formation_pr_tr = ctml::getFloatDefaultUnits(MinEQ3node, "DH0_f_Pr_Tr", "cal/gmol", "actEnergy"); m_Entrop_pr_tr = ctml::getFloatDefaultUnits(MinEQ3node, "S0_Pr_Tr", "cal/gmol/K"); m_a = ctml::getFloatDefaultUnits(MinEQ3node, "a", "cal/gmol/K"); m_b = ctml::getFloatDefaultUnits(MinEQ3node, "b", "cal/gmol/K2"); m_c = ctml::getFloatDefaultUnits(MinEQ3node, "c", "cal-K/gmol"); convertDGFormation(); }
/** * void mrc_to_gd(MRC *mrc, int ** tpixels, int pmin, int pmax) { */ void mrc_to_gd(MRC *mrc, gdImagePtr im, int pmin, int pmax) { float *data_array; float fmin=mrc->header.amin, fmax=mrc->header.amax, scale = fmax - fmin, nmin, nmax, nscale, f_val; int w=mrc->header.nx, h=mrc->header.ny, i,j; int densitymax = DENSITY_MAX; long n=w*h, ij; data_array = (float *)mrc->pbyData; nmin = fmin + pmin * scale / densitymax; nmax = fmin + pmax * scale / densitymax; nscale = nmax - nmin; if (nscale != 0) for (j = 0; j < h; ++j) { for (i = 0; i < w; ++i) { ij = i + j*w; f_val = data_array[ij]; f_val = (f_val-nmin)*densitymax/nscale; gdImageSetPixel (im, i, j, setDensity(f_val)); } } }
FORCEINLINE void TVoxelData::initializeDensity() { const int s = voxel_num * voxel_num * voxel_num; density_data = new unsigned char[s]; for (auto x = 0; x < voxel_num; x++) { for (auto y = 0; y < voxel_num; y++) { for (auto z = 0; z < voxel_num; z++) { if (density_state == TVoxelDataFillState::FULL) { setDensity(x, y, z, 1); } if (density_state == TVoxelDataFillState::ZERO) { setDensity(x, y, z, 0); } } } } }
CRigidBox::CRigidBox(S32 parent, CSceneObject *so, const CVector3 &d ) : CRigidBody(parent, so) { if(parent == 0) parent = (S32)space; mGeomID = dCreateBox((dSpaceID)parent, TO_PHYSICS(d.x), TO_PHYSICS(d.y), TO_PHYSICS(d.z)); mBodyID = dBodyCreate(world); dGeomSetBody(mGeomID, mBodyID); dGeomSetData(mGeomID, static_cast<void *>(this)); mDimentions = d; setDensity(0.0001); }
void SingleSpeciesTP::setState_SV(doublereal s, doublereal v, doublereal tol) { doublereal dt; if (v == 0.0) { setDensity(1.0E100); } else { setDensity(1.0/v); } for (int n = 0; n < 50; n++) { dt = clip((s - entropy_mass())*temperature()/cv_mass(), -100.0, 100.0); setTemperature(temperature() + dt); if (fabs(dt) < tol) { return; } } throw CanteraError("setState_SV","no convergence. dt = " + fp2str(dt)); }
/* * Reads an xml data block for the parameters needed by this * routine. eosdata is a reference to the xml thermo block, and looks * like this: * * <phase id="stoichsolid" > * <thermo model="StoichSubstance"> * <density units="g/cm3">3.52</density> * </thermo> * </phase> */ void StoichSubstanceSSTP::setParametersFromXML(const XML_Node& eosdata) { std::string model = eosdata["model"]; if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { throw CanteraError("StoichSubstanceSSTP::setParametersFromXML", "thermo model attribute must be StoichSubstance"); } doublereal rho = getFloat(eosdata, "density", "toSI"); setDensity(rho); }
void f2CircleShape::init(float32 density) { setDensity(density); setOrient(0.0f); type = e_circle; position.zero(); }
/** Initializes a new power-up object with the supplied position and index. */ bool Powerup::init(const Vec2& pos, const PowerupType& t, int i) { if (CapsuleObstacle::init(pos)) { _type = t; _index = i; setDensity(0.0f); setFriction(0.0f); setFixedRotation(true); return true; } return false; };
//private void TilemapDemoState::buildScene() { if (m_tilemap.load("assets/maps/platform.tmx")) { auto entity = xy::Entity::create(m_messageBus); const auto& layers = m_tilemap.getLayers(); for (const auto& l : layers) { if (l->getType() == xy::tmx::Layer::Type::Object) { xy::Logger::log("found object layer - attempting to create physics components", xy::Logger::Type::Info); auto rb = m_tilemap.createRigidBody(m_messageBus, *l); entity->addComponent(rb); } else { auto drawable = m_tilemap.getDrawable(m_messageBus, *l, m_textureResource, m_shaderResource); if (drawable) { xy::Logger::log("created layer drawable, adding to scene..."); entity->addComponent(drawable); } } } m_scene.addEntity(entity, xy::Scene::Layer::BackFront); static const float radius = 30.f; auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic); auto cs = xy::Physics::CollisionCircleShape(radius); cs.setDensity(0.9f); cs.setRestitution(1.f); body->addCollisionShape(cs); auto drawable = xy::Component::create<xy::SfDrawableComponent<sf::CircleShape>>(m_messageBus); drawable->getDrawable().setRadius(radius); drawable->getDrawable().setOrigin({ radius, radius }); drawable->getDrawable().setFillColor({ 255, 255, 255, 200 }); drawable->getDrawable().setOutlineThickness(2.f); auto cam = xy::Component::create<xy::Camera>(m_messageBus, getContext().defaultView); cam->lockTransform(xy::Camera::TransformLock::Rotation, true); cam->lockBounds(m_tilemap.getBounds()); entity = xy::Entity::create(m_messageBus); entity->setPosition(800.f, 400.f); entity->addComponent(body); entity->addComponent(drawable); auto camPtr = entity->addComponent(cam); ent = m_scene.addEntity(entity, xy::Scene::Layer::FrontFront); m_scene.setActiveCamera(camPtr); } }
void SingleSpeciesTP::setState_UV(doublereal u, doublereal v, doublereal tol) { doublereal dt; if (v == 0.0) { setDensity(1.0E100); } else { setDensity(1.0/v); } for (int n = 0; n < 50; n++) { dt = clip((u - intEnergy_mass())/cv_mass(), -100.0, 100.0); setTemperature(temperature() + dt); if (fabs(dt) < tol) { return; } } throw CanteraError("setState_UV", "no convergence. dt = " + fp2str(dt)+"\n" +"u = "+fp2str(u)+" v = "+fp2str(v)+"\n"); }
void Phase::restoreState(size_t lenstate, const doublereal* state) { if (lenstate >= nSpecies() + 2) { setMassFractions_NoNorm(state + 2); setTemperature(state[0]); setDensity(state[1]); } else { throw ArraySizeError("Phase::restoreState", lenstate,nSpecies()+2); } }
GroundFog::~GroundFog() { // Disable passes. setDensity(0); mDomeNode->detachObject(mDomeEntity); mScene->destroyEntity(mDomeEntity); mDomeEntity = 0; static_cast<Ogre::SceneNode*>(mDomeNode->getParent())->removeAndDestroyChild(mDomeNode->getName()); mDomeNode = 0; mScene = 0; Ogre::MaterialManager::getSingletonPtr()->remove(mDomeMaterial->getHandle()); }
void MetalSHEelectrons::setParametersFromXML(const XML_Node& eosdata) { if ( eosdata["model"] != "MetalSHEelectrons") { throw CanteraError("MetalSHEelectrons::setParametersFromXML", "thermo model attribute must be MetalSHEelectrons"); } doublereal rho = 2.65E3; if (eosdata.hasChild("density")) { rho = getFloat(eosdata, "density", "toSI"); } setDensity(rho); }
void IconSprite::setIcon(const Icon &icon) { if (icon != _icon) { _icon = icon; if (icon) { setTexture(_icon.getTexture()); setTextureRect(_icon.getTextureRect()); setDensity(_icon.getDensity()); } else { setTexture(nullptr); } } }
void StoichSubstanceSSTP::initThermoXML(XML_Node& phaseNode, std::string id) { /* * Find the Thermo XML node */ if (!phaseNode.hasChild("thermo")) { throw CanteraError("StoichSubstanceSSTP::initThermoXML", "no thermo XML node"); } XML_Node &tnode = phaseNode.child("thermo"); double dens = getFloatDefaultUnits(tnode, "density", "kg/m3"); setDensity(dens); SingleSpeciesTP::initThermoXML(phaseNode, id); }
void MineralEQ3::initThermoXML(XML_Node& phaseNode, const std::string& id_) { // Find the Thermo XML node if (!phaseNode.hasChild("thermo")) { throw CanteraError("HMWSoln::initThermoXML", "no thermo XML node"); } const XML_Node* xsp = speciesData()[0]; XML_Node* aStandardState = 0; if (xsp->hasChild("standardState")) { aStandardState = &xsp->child("standardState"); } else { throw CanteraError("MineralEQ3::initThermoXML", "no standard state mode"); } doublereal volVal = 0.0; if (aStandardState->attrib("model") != "constantVolume") { throw CanteraError("MineralEQ3::initThermoXML", "wrong standard state mode"); } if (aStandardState->hasChild("V0_Pr_Tr")) { XML_Node& aV = aStandardState->child("V0_Pr_Tr"); double Afactor = toSI("cm3/gmol"); if (aV.hasAttrib("units")) { Afactor = toSI(aV.attrib("units")); } volVal = getFloat(*aStandardState, "V0_Pr_Tr"); m_V0_pr_tr= volVal; volVal *= Afactor; } else { throw CanteraError("MineralEQ3::initThermoXML", "wrong standard state mode"); } setDensity(molecularWeight(0) / volVal); const XML_Node& MinEQ3node = xsp->child("thermo").child("MinEQ3"); m_deltaG_formation_pr_tr = getFloat(MinEQ3node, "DG0_f_Pr_Tr", "actEnergy") / actEnergyToSI("cal/gmol"); m_deltaH_formation_pr_tr = getFloat(MinEQ3node, "DH0_f_Pr_Tr", "actEnergy") / actEnergyToSI("cal/gmol"); m_Entrop_pr_tr = getFloat(MinEQ3node, "S0_Pr_Tr", "toSI") / toSI("cal/gmol/K"); m_a = getFloat(MinEQ3node, "a", "toSI") / toSI("cal/gmol/K"); m_b = getFloat(MinEQ3node, "b", "toSI") / toSI("cal/gmol/K2"); m_c = getFloat(MinEQ3node, "c", "toSI") / toSI("cal-K/gmol"); convertDGFormation(); }
DrawProfiler::DrawProfiler() : mType(kNone) , mDensity(0) , mData(NULL) , mDataSize(0) , mCurrentFrame(-1) , mPreviousTime(0) , mVerticalUnit(0) , mHorizontalUnit(0) , mThresholdStroke(0) , mShowDirtyRegions(false) , mFlashToggle(false) { setDensity(1); }
void TrussMaterial::loadFromXML ( const QDomElement& materialElem ) /*throw (LoadException)*/ { XMLSerializableObject::loadFromXML( materialElem ); /** * Set name **************/ if ( ! materialElem.hasAttribute( "name" ) ) throw LoadException(); QString name = materialElem.attribute( "name" ); setMaterialName( name ); /** * Set working stress ***************************/ if ( ! materialElem.hasAttribute( "workingStress" ) ) throw LoadException(); bool ok; double stress = materialElem.attribute( "workingStress" ).toDouble( &ok ); if ( !ok ) throw LoadException(); setWorkingStress( stress ); /** * Set elasticity module ***************************/ if ( ! materialElem.hasAttribute( "elasticityModule" ) ) throw LoadException(); double elast = materialElem.attribute( "elasticityModule" ).toDouble( &ok ); if ( !ok ) throw LoadException(); setElasticityModule( elast ); /** * Set density ******************/ if ( ! materialElem.hasAttribute( "density" ) ) throw LoadException(); double dens = materialElem.attribute( "density" ).toDouble( &ok ); if ( !ok ) throw LoadException(); setDensity( dens ); }
void MetalSHEelectrons::initThermoXML(XML_Node& phaseNode, const std::string& id_) { // Find the Thermo XML node if (!phaseNode.hasChild("thermo")) { throw CanteraError("MetalSHEelectrons::initThermoXML", "no thermo XML node"); } XML_Node& tnode = phaseNode.child("thermo"); doublereal dens = 2.65E3; if (tnode.hasChild("density")) { dens = getFloat(tnode, "density", "toSI"); } setDensity(dens); SingleSpeciesTP::initThermoXML(phaseNode, id_); }
void SingleSpeciesTP::setState_SV(doublereal s, doublereal v, doublereal tol) { doublereal dt; setDensity(1.0/v); for (int n = 0; n < 50; n++) { dt = (s - entropy_mass())*temperature()/cv_mass(); if (dt > 100.0) dt = 100.0; else if (dt < -100.0) dt = -100.0; setTemperature(temperature() + dt); if (fabs(dt) < tol) { return; } } throw CanteraError("setState_SV","no convergence. dt = " + fp2str(dt)); }
int GOPlate::methodsBridge(lua_State* luaVM) { if (isCurrentMethod("setTexture")) { setTexture(lua_tostring(luaVM, 1)); return 0; } if (isCurrentMethod("setDensity")) { setDensity(lua_tonumber(luaVM, 1)); return 0; } if (isCurrentMethod("setSize")) { setSize(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3))); return 0; } return GameObject::methodsBridge(luaVM); }
void WaterSSTP::setPressure(doublereal p) { double T = temperature(); double dens = density(); int waterState = WATER_GAS; double rc = m_sub.Rhocrit(); if (dens > rc) { waterState = WATER_LIQUID; } doublereal dd = m_sub.density(T, p, waterState, dens); if (dd <= 0.0) { throw CanteraError("setPressure", "error"); } setDensity(dd); }
void Phase::setConcentrationsNoNorm(const double* const conc) { doublereal sum = 0.0, norm = 0.0; for (size_t k = 0; k != m_kk; ++k) { sum += conc[k] * m_molwts[k]; norm += conc[k]; } m_mmw = sum/norm; setDensity(sum); doublereal rsum = 1.0/sum; for (size_t k = 0; k != m_kk; ++k) { m_ym[k] = conc[k] * rsum; m_y[k] = m_ym[k] * m_molwts[k]; } m_stateNum++; }
void StoichSubstance::initThermoXML(XML_Node& phaseNode, const std::string& id_) { // Find the Thermo XML node if (!phaseNode.hasChild("thermo")) { throw CanteraError("StoichSubstance::initThermoXML", "no thermo XML node"); } XML_Node& tnode = phaseNode.child("thermo"); std::string model = tnode["model"]; if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { throw CanteraError("StoichSubstance::initThermoXML", "thermo model attribute must be StoichSubstance"); } double dens = getFloat(tnode, "density", "toSI"); setDensity(dens); SingleSpeciesTP::initThermoXML(phaseNode, id_); }
void State::setConcentrations(const doublereal* const conc) { doublereal sum = 0.0, norm = 0.0; for (size_t k = 0; k != m_kk; ++k) { sum += conc[k]*m_molwts[k]; norm += conc[k]; } m_mmw = sum/norm; setDensity(sum); doublereal rsum = 1.0/sum; for (size_t k = 0; k != m_kk; ++k) { m_ym[k] = conc[k] * rsum; m_y[k] = m_ym[k] * m_molwts[k]; } // Call a routine to determine whether state has changed. stateMFChangeCalc(); }
void SingleSpeciesTP::setState_UV(doublereal u, doublereal v, doublereal tol) { doublereal dt; setDensity(1.0/v); for (int n = 0; n < 50; n++) { dt = (u - intEnergy_mass())/cv_mass(); if (dt > 100.0) dt = 100.0; else if (dt < -100.0) dt = -100.0; setTemperature(temperature() + dt); if (fabs(dt) < tol) { return; } } throw CanteraError("setState_UV", "no convergence. dt = " + fp2str(dt)+"\n" +"u = "+fp2str(u)+" v = "+fp2str(v)+"\n"); }