Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaSPHFluid] Add option in ParticleSource to add/remove random values in the particles generation. Remove noise for CI scenes #4316

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Sph Plugin ###
SofaSphFluid/examples/SPHFluidForceField.scn 100 1e-4 1 1
SofaSphFluid/examples/SPHFluidForceField_benchmarks.scn 100 1e-4 1 1
SofaSphFluid/examples/SPHFluidSurfaceMapping.scn 100 1e-4 1 1
SofaSphFluid/examples/SPHParticleSink.scn 100 1e-4 1 1
SofaSphFluid/examples/SPHParticleSource.scn 100 1e-4 1 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Node name="Particles">
<EulerExplicitSolver symplectic="1" />
<MechanicalObject name="MModel" />
<ParticleSource name="Source" translation="0 10 0" radius="0.01 0.1 0.01" velocity="0 -10 0" delay="0.02" start="-0.1" stop="4" printLog="0"
<ParticleSource name="Source" translation="0 10 0" radius="0.01 0.1 0.01" velocity="0 -10 0" delay="0.02" start="-0.1" stop="4" addNoise="0"
center="-0.375 0 -0.75
0.0 0.0 -0.75
0.375 0.0 -0.75
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Node name="Particles">
<EulerExplicitSolver symplectic="1" />
<MechanicalObject name="MModel" />
<ParticleSource name="Source" translation="0 10 0" radius="0.01 0.1 0.01" velocity="0 -10 0" delay="0.02" start="-0.1" stop="4" printLog="0"
<ParticleSource name="Source" translation="0 10 0" radius="0.01 0.1 0.01" velocity="0 -10 0" delay="0.02" start="-0.1" stop="4" addNoise="0"
center="-0.375 0 -0.75
0.0 0.0 -0.75
0.375 0.0 -0.75
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ParticleSource : public core::behavior::ProjectiveConstraintSet<DataTypes>
Data< Real > d_delay; ///< Delay between particles creation
Data< Real > d_start; ///< Source starting time
Data< Real > d_stop; ///< Source stopping time
Data< bool > d_canHaveEmptyVector;
Data< bool > d_addNoise; ///< Will add random value to the radius of new created particles

protected:
size_t m_numberParticles; ///< Number particles given by the initial particles size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ParticleSource<DataTypes>::ParticleSource()
, d_delay(initData(&d_delay, (Real)0.01, "delay", "Delay between particles creation"))
, d_start(initData(&d_start, (Real)0, "start", "Source starting time"))
, d_stop(initData(&d_stop, (Real)1e10, "stop", "Source stopping time"))
, d_addNoise(initData(&d_addNoise, (bool)true, "addNoise", "Will add random value to the radius of new created particles"))
, m_numberParticles(0)
, m_lastparticles(initData(&m_lastparticles, "lastparticles", "lastparticles indices"))
{
Expand Down Expand Up @@ -231,18 +232,26 @@ void ParticleSource<DataTypes>::animateBegin(double /*dt*/, double time)

newX.reserve(nbParticlesToCreate * m_numberParticles);
newV.reserve(nbParticlesToCreate * m_numberParticles);
const Deriv v0 = d_velocity.getValue();
const Deriv& v0 = d_velocity.getValue();
const Real& delay = d_delay.getValue();

const type::vector<Coord>& center = d_center.getValue();
const Real& scale = d_scale.getValue();
const Coord& translation = d_translation.getValue();
const Coord& radius = d_radius.getValue();
bool addNoise = d_addNoise.getValue();

for (size_t i = 0; i < nbParticlesToCreate; i++)
{
m_lastTime += d_delay.getValue();
m_maxdist += d_delay.getValue() * d_velocity.getValue().norm() / d_scale.getValue();
m_lastTime += delay;
m_maxdist += delay * v0.norm() / scale;

//int lastparticle = i0 + i * N;
size_t lp0 = _lastparticles.empty() ? 0 : _lastparticles.size() / 2;
if (lp0 > 0)
{
size_t shift = _lastparticles.size() - lp0;
Deriv dpos = v0 * d_delay.getValue();
Deriv dpos = v0 * delay;
for (size_t s = 0; s < lp0; s++)
{
_lastparticles[s] = _lastparticles[s + shift];
Expand All @@ -255,10 +264,17 @@ void ParticleSource<DataTypes>::animateBegin(double /*dt*/, double time)

for (size_t s = 0; s < m_numberParticles; s++)
{
Coord p = d_center.getValue()[s] * d_scale.getValue() + d_translation.getValue();
Coord p = center[s] * scale + translation;

for (unsigned int c = 0; c < p.size(); c++)
p[c] += d_radius.getValue()[c] * rrand();
if (addNoise)
{
for (unsigned int c = 0; c < p.size(); c++)
p[c] += radius[c] * rrand();
}
else
{
p += radius;
}

m_lastpos.push_back(p);
_lastparticles.push_back((Index)(i0 + newX.size()));
Expand Down
Loading