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:
Jacques Lucke 2023-10-20 16:47:15 +02:00
parent 4997c3aae5
commit 051b02ed11
2 changed files with 6 additions and 4 deletions

View File

@ -9,6 +9,8 @@
* \ingroup bke
*/
#include <optional>
#include "BLI_buffer.h"
#include "BLI_compiler_attrs.h"
#include "BLI_map.hh"
@ -85,7 +87,7 @@ typedef struct SPHData {
ParticleSystem *psys[10];
ParticleData *pa;
float mass;
blender::Map<blender::OrderedEdge, int> eh;
std::optional<blender::Map<blender::OrderedEdge, int>> eh;
float *gravity;
float hfac;
/* Average distance to neighbors (other particles in the support domain),

View File

@ -1806,7 +1806,7 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa
SPHRangeData pfr;
SPHNeighbor *pfn;
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 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) {
/* 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) {
spring = psys[0]->fluid_springs + spring_index - 1;