Add possibility to have an external state
This commit is contained in:
parent
be64c7fd7a
commit
924047de22
@ -426,7 +426,7 @@ namespace CosmoTool {
|
||||
#define CTOOL_HDF5_INSERT_ELEMENT(r, STRUCT, element) \
|
||||
{ \
|
||||
::CosmoTool::get_hdf5_data_type<BOOST_PP_TUPLE_ELEM(2, 0, element)> t; \
|
||||
long position = HOFFSET(STRUCT, BOOST_PP_TUPLE_ELEM(2, 1, element)); \
|
||||
long position = offsetof(STRUCT, BOOST_PP_TUPLE_ELEM(2, 1, element)); \
|
||||
const char *field_name = BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, element)); \
|
||||
type.insertMember(field_name, position, t.type()); \
|
||||
}
|
||||
|
@ -72,7 +72,9 @@ namespace CosmoTool {
|
||||
void
|
||||
fetchNeighbours(const typename SPHTree::coords &c, SPHState *state = 0);
|
||||
|
||||
void fetchNeighbours(const typename SPHTree::coords &c, uint32_t newNsph);
|
||||
void fetchNeighbours(
|
||||
const typename SPHTree::coords &c, uint32_t newNsph,
|
||||
SPHState *state = 0);
|
||||
void fetchNeighboursOnVolume(
|
||||
const typename SPHTree::coords &c, ComputePrecision radius);
|
||||
const typename SPHTree::coords &getCurrentCenter() const {
|
||||
|
@ -35,32 +35,38 @@ namespace CosmoTool {
|
||||
|
||||
template <typename ValType, int Ndims>
|
||||
void SPHSmooth<ValType, Ndims>::fetchNeighbours(
|
||||
const typename SPHTree::coords &c, uint32_t newNngb) {
|
||||
const typename SPHTree::coords &c, uint32_t newNngb, SPHState *state) {
|
||||
ComputePrecision d2, max_dist = 0;
|
||||
uint32_t requested = newNngb;
|
||||
|
||||
if (state != 0) {
|
||||
state->distances = boost::shared_ptr<CoordType[]>(new CoordType[Nsph]);
|
||||
state->ngb = boost::shared_ptr<SPHCell *[]>(new SPHCell *[Nsph]);
|
||||
} else {
|
||||
state = &internal;
|
||||
if (requested > maxNgb) {
|
||||
maxNgb = requested;
|
||||
internal.ngb = boost::shared_ptr<P_SPHCell[]>(new P_SPHCell[maxNgb]);
|
||||
internal.distances =
|
||||
boost::shared_ptr<CoordType[]>(new CoordType[maxNgb]);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(internal.currentCenter, c, sizeof(c));
|
||||
memcpy(state->currentCenter, c, sizeof(c));
|
||||
tree->getNearestNeighbours(
|
||||
c, requested, (SPHCell **)internal.ngb.get(),
|
||||
(CoordType *)internal.distances.get());
|
||||
c, requested, (SPHCell **)state->ngb.get(),
|
||||
(CoordType *)state->distances.get());
|
||||
|
||||
internal.currentNgb = 0;
|
||||
for (uint32_t i = 0; i < requested && (internal.ngb)[i] != 0;
|
||||
i++, internal.currentNgb++) {
|
||||
internal.distances[i] = sqrt(internal.distances[i]);
|
||||
d2 = internal.distances[i];
|
||||
state->currentNgb = 0;
|
||||
for (uint32_t i = 0; i < requested && (state->ngb)[i] != 0;
|
||||
i++, state->currentNgb++) {
|
||||
state->distances[i] = sqrt(state->distances[i]);
|
||||
d2 = state->distances[i];
|
||||
if (d2 > max_dist)
|
||||
max_dist = d2;
|
||||
}
|
||||
|
||||
internal.smoothRadius = max_dist / 2;
|
||||
state->smoothRadius = max_dist / 2;
|
||||
}
|
||||
|
||||
template <typename ValType, int Ndims>
|
||||
@ -241,5 +247,4 @@ namespace CosmoTool {
|
||||
const SPHSmooth<ValType2, Ndims> &s2) {
|
||||
return (s1.getSmoothingLen() < s2.getSmoothingLen());
|
||||
}
|
||||
|
||||
}; // namespace CosmoTool
|
||||
|
Loading…
Reference in New Issue
Block a user