1010using namespace SPH ;
1111
1212Emitter::Emitter (FluidModel* model, const unsigned int width, const unsigned int height, const Vector3r& pos,
13- const Matrix3r& rotation, const Real velocity, const unsigned int type, const bool useBoundary)
13+ const Matrix3r& rotation, const Real velocity, const unsigned int type, const bool useBoundary,
14+ const unsigned int velocityProfile)
1415 : m_model(model), m_width(width), m_x(pos), m_rotation(rotation), m_velocity(velocity), m_type(type),
15- m_useBoundary(useBoundary)
16+ m_useBoundary(useBoundary), m_velocityProfile(velocityProfile)
1617{
1718 Simulation* sim = Simulation::getCurrent ();
1819 m_depth = getDepth ();
@@ -101,7 +102,7 @@ void Emitter::emitParticles(std::vector<unsigned int>& reusedParticles, unsigned
101102 const Vector3r axisDepth = m_rotation.col (0 );
102103 const Vector3r axisHeight = m_rotation.col (1 );
103104 const Vector3r axisWidth = m_rotation.col (2 );
104- Vector3r emitVel = m_velocity * axisDepth;
105+ Vector3r bulkEmitVel = m_velocity * axisDepth;
105106 Simulation* sim = Simulation::getCurrent ();
106107 const Real particleRadius = sim->getParticleRadius ();
107108 const Real particleDiameter = static_cast <Real>(2.0 ) * particleRadius;
@@ -128,7 +129,6 @@ void Emitter::emitParticles(std::vector<unsigned int>& reusedParticles, unsigned
128129 {
129130 m_model->setPosition (indexNextNewParticle, spawnPos);
130131 m_model->setParticleState (indexNextNewParticle, ParticleState::AnimatedByEmitter);
131- m_model->setVelocity (indexNextNewParticle, emitVel);
132132 m_model->setObjectId (indexNextNewParticle, m_objectId);
133133
134134 indexNextNewParticle++;
@@ -149,9 +149,24 @@ void Emitter::emitParticles(std::vector<unsigned int>& reusedParticles, unsigned
149149
150150 if (insideEmitter) {
151151 // Advect ALL particles inside the emitter.
152- // TODO: Doesn't get all particles within the boundary. Perhaps use getSizeExtraMargin()?
153- m_model->setPosition (i, tempPos + timeStepSize * emitVel);
154- m_model->setVelocity (i, emitVel);
152+ //
153+ // TODO: Doesn't get all particles within the rigid body. Perhaps use getSizeExtraMargin()?
154+ Vector3r localEmitVel;
155+ if (m_type == 1 && m_velocityProfile != 0 ) {
156+ // different velocity profiles for circular emitters
157+ const Vector3r localPos = tempPos - m_x;
158+ const Real r = sqrt (pow (axisWidth.dot (localPos), 2.0 ) + (pow (axisHeight.dot (localPos), 2.0 )));
159+ const Vector3r maxEmitVel =
160+ (1.0 / (1.0 - (2.0 / (static_cast <Real>(m_velocityProfile) + 2.0 )))) * bulkEmitVel;
161+ const Real relativeRadius = r / (m_size[1 ] / 2.0 );
162+ localEmitVel = maxEmitVel * (1.0 - pow (relativeRadius, static_cast <Real>(m_velocityProfile)));
163+ }
164+ else {// box shaped emitter or uniform velocity profile
165+ localEmitVel = bulkEmitVel;
166+ }
167+
168+ m_model->setPosition (i, tempPos + timeStepSize * localEmitVel);
169+ m_model->setVelocity (i, localEmitVel);
155170 }
156171 if (!insideEmitter && m_model->getParticleState (i) == ParticleState::AnimatedByEmitter
157172 && m_model->getObjectId (i) == m_objectId)
@@ -164,15 +179,14 @@ void Emitter::emitParticles(std::vector<unsigned int>& reusedParticles, unsigned
164179 // reuse a particle
165180 m_model->setPosition (reusedParticles[indexReuse], tempPos - axisDepth * particleDiameter * m_depth);
166181 m_model->setParticleState (reusedParticles[indexReuse], ParticleState::AnimatedByEmitter);
167- m_model->setVelocity (reusedParticles[indexReuse], emitVel );
182+ m_model->setVelocity (reusedParticles[indexReuse], bulkEmitVel );
168183 m_model->setObjectId (reusedParticles[indexReuse], m_objectId);
169184 indexReuse++;
170185 }
171186 else if (m_model->numActiveParticles () < m_model->numParticles ()) {
172187 // spawn a new particle
173188 m_model->setPosition (indexNextNewParticle, tempPos - axisDepth * particleDiameter * m_depth);
174189 m_model->setParticleState (indexNextNewParticle, ParticleState::AnimatedByEmitter);
175- m_model->setVelocity (indexNextNewParticle, emitVel);
176190 m_model->setObjectId (indexNextNewParticle, m_objectId);
177191
178192 indexNextNewParticle++;
0 commit comments