Skip to content

Commit

Permalink
better random positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
aghaeifar committed Oct 20, 2024
1 parent 8973a38 commit 88f47b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
14 changes: 5 additions & 9 deletions src/kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void sim(const simulation_parameters *param, const float *pFieldMap, const uint8

// update old position with the new one
if(param->enRecordTrajectory && (current_timepoint != 0 || dummy_scan != 0))
xyz1 += 3;
xyz1 += 3;
for (uint8_t i=0; i < 3; i++)
xyz1[i] = xyz_old[i] = xyz_new[i];
// increase timepoint
Expand All @@ -240,15 +240,11 @@ void sim(const simulation_parameters *param, const float *pFieldMap, const uint8
__host__
#endif
void randPosGen(float *spin_position_xyz, const simulation_parameters &param)
{
float res[3];
for (uint8_t i = 0; i < 3; i++)
res[i] = param.fov[i] / param.fieldmap_size[i];

{
std::mt19937 gen(param.seed);
std::uniform_real_distribution<float> dist_initial_x(res[0], param.fov[0] - res[0]);
std::uniform_real_distribution<float> dist_initial_y(res[1], param.fov[1] - res[1]);
std::uniform_real_distribution<float> dist_initial_z(res[2], param.fov[2] - res[2]);
std::uniform_real_distribution<float> dist_initial_x(0.01*param.fov[0], 0.99*param.fov[0]);
std::uniform_real_distribution<float> dist_initial_y(0.01*param.fov[1], 0.99*param.fov[1]);
std::uniform_real_distribution<float> dist_initial_z(0.01*param.fov[2], 0.99*param.fov[2]);

for (size_t i = 0; i < param.n_spins; i++)
{
Expand Down
17 changes: 7 additions & 10 deletions src/spinwalk.cu
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ bool run(simulation_parameters param, std::map<std::string, std::vector<std::str
// scale position to mimic the different volume size
thrust::transform(d_XYZ0.begin(), d_XYZ0.end(), thrust::make_constant_iterator(fov_scale[sl]), d_XYZ0_scaled.begin(), thrust::multiplies<float>());
gpuCheckKernelExecutionError(__FILE__, __LINE__);
cu_sim<<<numGrid, BLOCKS, 0>>>(d_param,thrust::raw_pointer_cast(d_pFieldMap.data()),
thrust::raw_pointer_cast(d_pMask.data()),
thrust::raw_pointer_cast(d_M0.data()),
thrust::raw_pointer_cast(d_XYZ0_scaled.data()),
thrust::raw_pointer_cast(d_M1.data()),
thrust::raw_pointer_cast(d_XYZ1.data()),
thrust::raw_pointer_cast(d_T.data()));
cu_sim<<<numGrid, BLOCKS, 0>>>(d_param, thrust::raw_pointer_cast(d_pFieldMap.data()),
thrust::raw_pointer_cast(d_pMask.data()),
thrust::raw_pointer_cast(d_M0.data()),
thrust::raw_pointer_cast(d_XYZ0_scaled.data()),
thrust::raw_pointer_cast(d_M1.data()),
thrust::raw_pointer_cast(d_XYZ1.data()),
thrust::raw_pointer_cast(d_T.data()));
gpuCheckKernelExecutionError(__FILE__, __LINE__);
// copy data back to CPU
size_t shift = 3*param.n_TE*param.n_spins*sl;
Expand Down Expand Up @@ -253,9 +253,6 @@ bool run(simulation_parameters param, std::map<std::string, std::vector<std::str
dims[0] = fov_scale.size(); dims[1] = 1; dims[2] = 1; dims[3] = 1;
file_utils::save_h5(f, fov_scale.data(), dims, "scales", "double");

dims[0] = fov_scale.size(); dims[1] = 1; dims[2] = 1; dims[3] = 1;
file_utils::save_h5(f, fov_scale.data(), dims, "scales", "double");

std::vector<float> TE;
for(int i=0; i<param.n_TE; i++) TE.push_back(param.TE_us[i]*param.timestep_us*1e-6);
dims[0] = TE.size(); dims[1] = 1; dims[2] = 1; dims[3] = 1;
Expand Down

0 comments on commit 88f47b7

Please sign in to comment.