Add and fix support for parallel SPH state

This commit is contained in:
Guilhem Lavaux 2022-11-15 09:02:11 +01:00
parent f03751907b
commit b538d4974d
2 changed files with 45 additions and 40 deletions

View File

@ -108,6 +108,7 @@ namespace CosmoTool
template<typename FuncT>
void runForEachNeighbour(FuncT fun, SPHState *state = 0);
void addGridSite(const typename SPHTree::coords& c, SPHState *state);
void addGridSite(const typename SPHTree::coords& c);
bool hasNeighbours() const;

View File

@ -86,7 +86,7 @@ void SPHSmooth<ValType,Ndims>::fetchNeighbours(const typename SPHTree::coords& c
state->currentNgb = 0;
for (uint32_t i = 0; i < requested && state->ngb[i] != 0; i++,state->currentNgb++)
{
d2 = internal.distances[i] = sqrt(internal.distances[i]);
d2 = state->distances[i] = sqrt(state->distances[i]);
if (d2 > max_dist)
max_dist = d2;
}
@ -179,23 +179,27 @@ void SPHSmooth<ValType,Ndims>::runForEachNeighbour(FuncT fun, SPHState *state)
}
}
template<typename ValType, int Ndims>
void SPHSmooth<ValType,Ndims>::addGridSite(const typename SPHTree::coords& c, SPHState *state)
{
ComputePrecision outputValue = 0;
ComputePrecision max_dist = 0;
ComputePrecision r3 = cube(state->smoothRadius);
for (uint32_t i = 0; i < state->currentNgb; i++)
{
ComputePrecision d = state->distances[i];
SPHCell& cell = *(state->ngb[i]);
double kernel_value = getKernel(d/state->smoothRadius) / r3;
#pragma omp atomic
cell.val.weight += kernel_value;
}
}
template<typename ValType, int Ndims>
void SPHSmooth<ValType,Ndims>::addGridSite(const typename SPHTree::coords& c)
{
ComputePrecision outputValue = 0;
ComputePrecision max_dist = 0;
ComputePrecision r3 = cube(internal.smoothRadius);
for (uint32_t i = 0; i < internal.currentNgb; i++)
{
ComputePrecision d = internal.distances[i];
SPHCell& cell = *(internal.ngb[i]);
double kernel_value = getKernel(d/internal.smoothRadius) / r3;
#pragma omp atomic
cell.val.weight += kernel_value;
}
addGridSite(c, &internal);
}
template<typename ValType, int Ndims>