Fix #113851: viscoelastic springs do not work
Caused by 425b871607
.
The root issue was that these two states of the hash table were
mixed up in 425b871607: (1) the hash table exists and (2) the hash
table is empty.
The use of `std::optional` restores these two different states again.
This commit is contained in:
parent
4997c3aae5
commit
051b02ed11
|
@ -9,6 +9,8 @@
|
||||||
* \ingroup bke
|
* \ingroup bke
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "BLI_buffer.h"
|
#include "BLI_buffer.h"
|
||||||
#include "BLI_compiler_attrs.h"
|
#include "BLI_compiler_attrs.h"
|
||||||
#include "BLI_map.hh"
|
#include "BLI_map.hh"
|
||||||
|
@ -85,7 +87,7 @@ typedef struct SPHData {
|
||||||
ParticleSystem *psys[10];
|
ParticleSystem *psys[10];
|
||||||
ParticleData *pa;
|
ParticleData *pa;
|
||||||
float mass;
|
float mass;
|
||||||
blender::Map<blender::OrderedEdge, int> eh;
|
std::optional<blender::Map<blender::OrderedEdge, int>> eh;
|
||||||
float *gravity;
|
float *gravity;
|
||||||
float hfac;
|
float hfac;
|
||||||
/* Average distance to neighbors (other particles in the support domain),
|
/* Average distance to neighbors (other particles in the support domain),
|
||||||
|
|
|
@ -1806,7 +1806,7 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa
|
||||||
SPHRangeData pfr;
|
SPHRangeData pfr;
|
||||||
SPHNeighbor *pfn;
|
SPHNeighbor *pfn;
|
||||||
float *gravity = sphdata->gravity;
|
float *gravity = sphdata->gravity;
|
||||||
const blender::Map<blender::OrderedEdge, int> &springhash = sphdata->eh;
|
const std::optional<blender::Map<blender::OrderedEdge, int>> &springhash = sphdata->eh;
|
||||||
|
|
||||||
float q, u, rij, dv[3];
|
float q, u, rij, dv[3];
|
||||||
float pressure, near_pressure;
|
float pressure, near_pressure;
|
||||||
|
@ -1890,9 +1890,9 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa
|
||||||
|
|
||||||
if (spring_constant > 0.0f) {
|
if (spring_constant > 0.0f) {
|
||||||
/* Viscoelastic spring force */
|
/* Viscoelastic spring force */
|
||||||
if (pfn->psys == psys[0] && fluid->flag & SPH_VISCOELASTIC_SPRINGS && !springhash.is_empty())
|
if (pfn->psys == psys[0] && fluid->flag & SPH_VISCOELASTIC_SPRINGS && springhash.has_value())
|
||||||
{
|
{
|
||||||
spring_index = springhash.lookup({index, pfn->index});
|
spring_index = springhash->lookup_default({index, pfn->index}, 0);
|
||||||
|
|
||||||
if (spring_index) {
|
if (spring_index) {
|
||||||
spring = psys[0]->fluid_springs + spring_index - 1;
|
spring = psys[0]->fluid_springs + spring_index - 1;
|
||||||
|
|
Loading…
Reference in New Issue