Skip to content

Commit

Permalink
simplify dref/flux separation
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Aug 4, 2023
1 parent 50006b9 commit 82367f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
28 changes: 11 additions & 17 deletions src/mcxlab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,24 +397,18 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
float* dref = (float*)malloc(fieldlen * sizeof(float));
memcpy(dref, cfg.exportfield, fieldlen * sizeof(float));

for (int ix = 0; ix < cfg.dim.x; ix++) {
for (int iy = 0; iy < cfg.dim.y; iy++) {
for (int iz = 0; iz < cfg.dim.z; iz++) {
int voxelid = iz * (cfg.dim.x * cfg.dim.y) + iy * cfg.dim.x + ix;

if (cfg.vol[voxelid]) {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < cfg.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = 0.f;
}
} else {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < cfg.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = -dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid];
cfg.exportfield[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = 0.f;
}
for (int voxelid = 0; voxelid < voxellen; voxelid++) {
if (cfg.vol[voxelid]) {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < cfg.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = 0.f;
}
} else {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < cfg.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = -dref[(gate * voxellen + voxelid) * cfg.srcnum + srcid];
cfg.exportfield[(gate * voxellen + voxelid) * cfg.srcnum + srcid] = 0.f;
}
}
}
}

Expand Down
28 changes: 11 additions & 17 deletions src/pmcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,24 +1042,18 @@ py::dict pmcx_interface(const py::dict& user_cfg) {
auto* dref = static_cast<float*>(dref_array.mutable_data());
memcpy(dref, mcx_config.exportfield, field_len * sizeof(float));

for (int ix = 0; ix < mcx_config.dim.x; ix++) {
for (int iy = 0; iy < mcx_config.dim.y; iy++) {
for (int iz = 0; iz < mcx_config.dim.z; iz++) {
int voxelid = iz * (mcx_config.dim.x * mcx_config.dim.y) + iy * mcx_config.dim.x + ix;

if (mcx_config.vol[voxelid]) {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < mcx_config.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = 0.f;
}
} else {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < mcx_config.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = -dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid];
mcx_config.exportfield[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = 0.f;
}
for (int voxelid = 0; voxelid < voxellen; voxelid++) {
if (mcx_config.vol[voxelid]) {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < mcx_config.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = 0.f;
}
} else {
for (int gate = 0; gate < highdim; gate++)
for (int srcid = 0; srcid < mcx_config.srcnum; srcid++) {
dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = -dref[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid];
mcx_config.exportfield[(gate * voxellen + voxelid) * mcx_config.srcnum + srcid] = 0.f;
}
}
}
}

Expand Down

0 comments on commit 82367f0

Please sign in to comment.