Skip to content

Commit 37012e1

Browse files
committed
critical bug fixed
1 parent 37b5af5 commit 37012e1

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/kernels.cu

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void sim(const simulation_parameters *param, const float *pFieldMap, const uint8
9494
// tissue type
9595
uint8_t ts, ts_old;
9696
auto indx = sub2ind(xyz1[0]*param->scale2grid[0], xyz1[1]*param->scale2grid[1], xyz1[2]*param->scale2grid[2], param->fieldmap_size[0], param->fieldmap_size[1], param->fieldmap_size[2]);
97-
ts_old = pMask[indx];
97+
ts = ts_old = pMask[indx];
9898
double diffusivity_scale = param->diffusivity[ts_old];
9999

100100
bool is_lastscan = false;
@@ -122,10 +122,9 @@ void sim(const simulation_parameters *param, const float *pFieldMap, const uint8
122122
while (current_timepoint < param->n_timepoints) // param->n_timepoints is the total number of timepoints (= TR/dwelltime)
123123
{
124124
// ------ generate random walks and wrap around the boundries ------
125-
double rnd_wlk;
126125
for (uint8_t i=0; i<3; i++)
127126
{
128-
rnd_wlk = dist_random_walk_xyz(gen_r) * diffusivity_scale;
127+
double rnd_wlk = dist_random_walk_xyz(gen_r) * diffusivity_scale;
129128
xyz_new[i] = xyz_old[i] + rnd_wlk; // new spin position after random-walk
130129
if (xyz_new[i] < 0)
131130
xyz_new[i] += (param->enCrossFOV ? param->fov[i] : 2*std::abs(rnd_wlk)); // rnd_wlk is negative here
@@ -144,8 +143,9 @@ void sim(const simulation_parameters *param, const float *pFieldMap, const uint8
144143
if(ind != ind_old) // fewer access to the global memory which is slow. Helpful for large samples!
145144
{
146145
// cross-tissue diffusion
147-
ts = pMask[ind];
146+
ts = pMask[ind];
148147
if (ts != ts_old)
148+
{
149149
if (dist_cross_tissue(gen_u) >= param->pXY[ts_old*param->n_tissue_type + ts])
150150
{
151151
if(itr++ > param->max_iterations)
@@ -155,16 +155,18 @@ void sim(const simulation_parameters *param, const float *pFieldMap, const uint8
155155
}
156156
continue;
157157
}
158-
else
159-
ts_old = ts;
160-
itr = 0;
161-
field = pFieldMap != nullptr ? pFieldMap[ind_old = ind]:0.f;
162-
ind = pMask[ind]; // the index of the tissue type
163-
T1 = param->T1_ms[ind] * 1e-3; // ms -> s
164-
T2 = param->T2_ms[ind] * 1e-3; // ms -> s
165-
diffusivity_scale = param->diffusivity[ind];
166-
}
158+
ts_old = ts;
159+
}
160+
161+
ind_old = ind;
162+
field = pFieldMap != nullptr ? pFieldMap[ind]:0.f;
163+
T1 = param->T1_ms[ts_old] * 1e-3; // ms -> s
164+
T2 = param->T2_ms[ts_old] * 1e-3; // ms -> s
165+
diffusivity_scale = param->diffusivity[ts_old];
166+
}
167+
167168
accumulated_phase += field;
169+
itr = 0;
168170

169171
// ------ apply ideal dephasing if there is any ------
170172
if(counter_dephasing < param->n_dephasing && param->dephasing_us[counter_dephasing] == current_timepoint)
@@ -203,7 +205,7 @@ void sim(const simulation_parameters *param, const float *pFieldMap, const uint8
203205
// save echo and copy m1 to m0 for the next iteration
204206
for (uint32_t i=0, shift=3*param->n_TE*spin_no + 3*current_te; i<3; i++)
205207
M1[shift + i] = m0[i] = m1[i];
206-
T[spin_no*param->n_TE + current_te] = ts;
208+
T[spin_no*param->n_TE + current_te] = ts_old;
207209

208210
accumulated_phase = 0; // reset phase since we have applied it in the previous step
209211
old_timepoint = current_timepoint;

src/spinwalk.cu

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ bool run(simulation_parameters param, std::map<std::string, std::vector<std::str
159159
#endif
160160
// ========== run ==========
161161
auto start_sim = std::chrono::high_resolution_clock::now();
162-
ProgressBar bar{option::ShowPercentage{true}, option::Start{"["}, option::Fill{"="}, option::Lead{">"}, option::End{"]"}};
162+
// ProgressBar bar{option::ShowPercentage{true}, option::Start{"["}, option::Fill{"="}, option::Lead{">"}, option::End{"]"}};
163163
simulation_parameters param_local;
164164
memcpy(&param_local, &param, sizeof(simulation_parameters));
165165
std::vector<uint32_t> v(param_local.n_spins);
@@ -221,8 +221,7 @@ bool run(simulation_parameters param, std::map<std::string, std::vector<std::str
221221
thrust::copy(d_T.begin(), d_T.end(), T.begin() + shift);
222222
}
223223
#endif
224-
// bar.progress(sl, param.n_fov_scale);
225-
bar.set_progress(100 * (sl+1)/float(param.n_fov_scale));
224+
// bar.set_progress(100 * (sl+1)/float(param.n_fov_scale));
226225
}
227226

228227
auto end_config = std::chrono::high_resolution_clock::now();

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#define SPINWALK_VERSION_MAJOR 1
88
#define SPINWALK_VERSION_MINOR 13
9-
#define SPINWALK_VERSION_PATCH 11
9+
#define SPINWALK_VERSION_PATCH 12
1010

1111
//---------------------------------------------------------------------------------------------
1212
//

0 commit comments

Comments
 (0)