Skip to content

Commit 394c2f4

Browse files
committed
Fix wrong start and end coordinates of calculation for parallel grid
1 parent 95e1ec8 commit 394c2f4

13 files changed

Lines changed: 228 additions & 248 deletions

Source/Coordinate/GridCoordinate1D.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class GridCoordinate1DTemplate
8484
{
8585
return getX () <= rhs.getX ();
8686
}
87+
88+
GridCoordinate1DTemplate CUDA_DEVICE CUDA_HOST operator- () const
89+
{
90+
return GridCoordinate1DTemplate (- getX ());
91+
}
8792
};
8893

8994
typedef GridCoordinate1DTemplate<grid_iter> GridCoordinate1D;

Source/Coordinate/GridCoordinate2D.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ class GridCoordinate2DTemplate: public GridCoordinate1DTemplate<TcoordType>
111111
TcoordType rhs_x = rhs.GridCoordinate1DTemplate<TcoordType>::getX ();
112112
return x <= rhs_x && getY () <= rhs.getY ();
113113
}
114+
115+
GridCoordinate2DTemplate CUDA_DEVICE CUDA_HOST operator- () const
116+
{
117+
TcoordType x = GridCoordinate1DTemplate<TcoordType>::getX ();
118+
return GridCoordinate2DTemplate (- x, - getY ());
119+
}
114120
};
115121

116122
typedef GridCoordinate2DTemplate<grid_iter> GridCoordinate2D;

Source/Coordinate/GridCoordinate3D.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ class GridCoordinate3DTemplate: public GridCoordinate2DTemplate<TcoordType>
150150

151151
return x <= rhs_x && y <= rhs_y && getZ () <= rhs.getZ ();
152152
}
153+
154+
GridCoordinate3DTemplate CUDA_DEVICE CUDA_HOST operator- () const
155+
{
156+
TcoordType x = GridCoordinate1DTemplate<TcoordType>::getX ();
157+
TcoordType y = GridCoordinate2DTemplate<TcoordType>::getY ();
158+
return GridCoordinate3DTemplate (- x, - y, - getZ ());
159+
}
153160
};
154161

155162
typedef GridCoordinate3DTemplate<grid_iter> GridCoordinate3D;

Source/Cuda/CudaInterface.cu

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -159,27 +159,27 @@ void cudaExecute2DTMzSteps (CudaExitStatus *retval,
159159
cudaCheckErrorCmd (cudaMemcpy (mu_cuda, tmp_mu, sizeMuRaw, cudaMemcpyHostToDevice));
160160

161161
#if not defined (PARALLEL_GRID)
162-
GridCoordinate3D EzStart = yeeLayout.getEzStart (Ez.getComputationStart ());
163-
GridCoordinate3D EzEnd = yeeLayout.getEzEnd (Ez.getComputationEnd ());
162+
GridCoordinate3D EzStart = Ez.getComputationStart (yeeLayout->getEzStartDiff ());
163+
GridCoordinate3D EzEnd = Ez.getComputationEnd (yeeLayout->getEzEndDiff ());
164164

165-
GridCoordinate3D HxStart = yeeLayout.getHxStart (Hx.getComputationStart ());
166-
GridCoordinate3D HxEnd = yeeLayout.getHxEnd (Hx.getComputationEnd ());
165+
GridCoordinate3D HxStart = Hx.getComputationStart (yeeLayout->getHxStartDiff ());
166+
GridCoordinate3D HxEnd = Hx.getComputationEnd (yeeLayout->getHxEndDiff ());
167167

168-
GridCoordinate3D HyStart = yeeLayout.getHyStart (Hy.getComputationStart ());
169-
GridCoordinate3D HyEnd = yeeLayout.getHyEnd (Hy.getComputationEnd ());
168+
GridCoordinate3D HyStart = Hy.getComputationStart (yeeLayout->getHyStartDiff ());
169+
GridCoordinate3D HyEnd = Hy.getComputationEnd (yeeLayout->getHyEndDiff ());
170170
#endif
171171

172172
for (time_step stepEnd = t + shareStep; t < stepEnd; ++t)
173173
{
174174
#if defined (PARALLEL_GRID)
175-
GridCoordinate3D EzStart = yeeLayout.getEzStart (Ez.getComputationStart ());
176-
GridCoordinate3D EzEnd = yeeLayout.getEzEnd (Ez.getComputationEnd ());
175+
GridCoordinate3D EzStart = Ez.getComputationStart (yeeLayout->getEzStartDiff ());
176+
GridCoordinate3D EzEnd = Ez.getComputationEnd (yeeLayout->getEzEndDiff ());
177177

178-
GridCoordinate3D HxStart = yeeLayout.getHxStart (Hx.getComputationStart ());
179-
GridCoordinate3D HxEnd = yeeLayout.getHxEnd (Hx.getComputationEnd ());
178+
GridCoordinate3D HxStart = Hx.getComputationStart (yeeLayout->getHxStartDiff ());
179+
GridCoordinate3D HxEnd = Hx.getComputationEnd (yeeLayout->getHxEndDiff ());
180180

181-
GridCoordinate3D HyStart = yeeLayout.getHyStart (Hy.getComputationStart ());
182-
GridCoordinate3D HyEnd = yeeLayout.getHyEnd (Hy.getComputationEnd ());
181+
GridCoordinate3D HyStart = Hy.getComputationStart (yeeLayout->getHyStartDiff ());
182+
GridCoordinate3D HyEnd = Hy.getComputationEnd (yeeLayout->getHyEndDiff ());
183183
#endif
184184

185185
cudaCheckExitStatus (cudaCalculateTMzEzStep <<< blocksEz, threadsEz >>> (exitStatusCuda,
@@ -561,45 +561,45 @@ void cudaExecute3DSteps (CudaExitStatus *retval,
561561
cudaCheckErrorCmd (cudaMemcpy (mu_cuda, tmp_mu, sizeMuRaw, cudaMemcpyHostToDevice));
562562

563563
#if not defined (PARALLEL_GRID)
564-
GridCoordinate3D ExStart = yeeLayout.getExStart (Ex.getComputationStart ());
565-
GridCoordinate3D ExEnd = yeeLayout.getExEnd (Ex.getSize ());
564+
GridCoordinate3D ExStart = Ex.getComputationStart (yeeLayout->getExStartDiff ());
565+
GridCoordinate3D ExEnd = Ex.getComputationEnd (yeeLayout->getExEndDiff ());
566566

567-
GridCoordinate3D EyStart = yeeLayout.getEyStart (Ey.getComputationStart ());
568-
GridCoordinate3D EyEnd = yeeLayout.getEyEnd (Ey.getSize ());
567+
GridCoordinate3D EyStart = Ey.getComputationStart (yeeLayout->getEyStartDiff ());
568+
GridCoordinate3D EyEnd = Ey.getComputationEnd (yeeLayout->getEyEndDiff ());
569569

570-
GridCoordinate3D EzStart = yeeLayout.getEzStart (Ez.getComputationStart ());
571-
GridCoordinate3D EzEnd = yeeLayout.getEzEnd (Ez.getSize ());
570+
GridCoordinate3D EzStart = Ez.getComputationStart (yeeLayout->getEzStartDiff ());
571+
GridCoordinate3D EzEnd = Ez.getComputationEnd (yeeLayout->getEzEndDiff ());
572572

573-
GridCoordinate3D HxStart = yeeLayout.getHxStart (Hx.getComputationStart ());
574-
GridCoordinate3D HxEnd = yeeLayout.getHxEnd (Hx.getSize ());
573+
GridCoordinate3D HxStart = Hx.getComputationStart (yeeLayout->getHxStartDiff ());
574+
GridCoordinate3D HxEnd = Hx.getComputationEnd (yeeLayout->getHxEndDiff ());
575575

576-
GridCoordinate3D HyStart = yeeLayout.getHyStart (Hy.getComputationStart ());
577-
GridCoordinate3D HyEnd = yeeLayout.getHyEnd (Hy.getSize ());
576+
GridCoordinate3D HyStart = Hy.getComputationStart (yeeLayout->getHyStartDiff ());
577+
GridCoordinate3D HyEnd = Hy.getComputationEnd (yeeLayout->getHyEndDiff ());
578578

579-
GridCoordinate3D HzStart = yeeLayout.getHzStart (Hz.getComputationStart ());
580-
GridCoordinate3D HzEnd = yeeLayout.getHzEnd (Hz.getSize ());
579+
GridCoordinate3D HzStart = Hz.getComputationStart (yeeLayout->getHzStartDiff ());
580+
GridCoordinate3D HzEnd = Hz.getComputationEnd (yeeLayout->getHzEndDiff ());
581581
#endif
582582

583583
for (time_step stepEnd = t + shareStep; t < stepEnd; ++t)
584584
{
585585
#if defined (PARALLEL_GRID)
586-
GridCoordinate3D ExStart = yeeLayout.getExStart (Ex.getComputationStart ());
587-
GridCoordinate3D ExEnd = yeeLayout.getExEnd (Ex.getSize ());
586+
GridCoordinate3D ExStart = Ex.getComputationStart (yeeLayout->getExStartDiff ());
587+
GridCoordinate3D ExEnd = Ex.getComputationEnd (yeeLayout->getExEndDiff ());
588588

589-
GridCoordinate3D EyStart = yeeLayout.getEyStart (Ey.getComputationStart ());
590-
GridCoordinate3D EyEnd = yeeLayout.getEyEnd (Ey.getSize ());
589+
GridCoordinate3D EyStart = Ey.getComputationStart (yeeLayout->getEyStartDiff ());
590+
GridCoordinate3D EyEnd = Ey.getComputationEnd (yeeLayout->getEyEndDiff ());
591591

592-
GridCoordinate3D EzStart = yeeLayout.getEzStart (Ez.getComputationStart ());
593-
GridCoordinate3D EzEnd = yeeLayout.getEzEnd (Ez.getSize ());
592+
GridCoordinate3D EzStart = Ez.getComputationStart (yeeLayout->getEzStartDiff ());
593+
GridCoordinate3D EzEnd = Ez.getComputationEnd (yeeLayout->getEzEndDiff ());
594594

595-
GridCoordinate3D HxStart = yeeLayout.getHxStart (Hx.getComputationStart ());
596-
GridCoordinate3D HxEnd = yeeLayout.getHxEnd (Hx.getSize ());
595+
GridCoordinate3D HxStart = Hx.getComputationStart (yeeLayout->getHxStartDiff ());
596+
GridCoordinate3D HxEnd = Hx.getComputationEnd (yeeLayout->getHxEndDiff ());
597597

598-
GridCoordinate3D HyStart = yeeLayout.getHyStart (Hy.getComputationStart ());
599-
GridCoordinate3D HyEnd = yeeLayout.getHyEnd (Hy.getSize ());
598+
GridCoordinate3D HyStart = Hy.getComputationStart (yeeLayout->getHyStartDiff ());
599+
GridCoordinate3D HyEnd = Hy.getComputationEnd (yeeLayout->getHyEndDiff ());
600600

601-
GridCoordinate3D HzStart = yeeLayout.getHzStart (Hz.getComputationStart ());
602-
GridCoordinate3D HzEnd = yeeLayout.getHzEnd (Hz.getSize ());
601+
GridCoordinate3D HzStart = Hz.getComputationStart (yeeLayout->getHzStartDiff ());
602+
GridCoordinate3D HzEnd = Hz.getComputationEnd (yeeLayout->getHzEndDiff ());
603603
#endif
604604

605605
cudaCheckExitStatus (cudaCalculate3DExStep <<< blocksEx, threadsEx >>> (exitStatusCuda,

Source/Grid/Grid.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ class Grid
6868
TCoord getTotalSize () const;
6969
TCoord getRelativePosition (TCoord) const;
7070

71-
virtual TCoord getComputationStart () const;
72-
virtual TCoord getComputationEnd () const;
71+
virtual TCoord getComputationStart (TCoord) const;
72+
virtual TCoord getComputationEnd (TCoord) const;
7373
TCoord calculatePositionFromIndex (grid_iter) const;
7474

7575
void setFieldPointValue (FieldPointValue *, const TCoord &);
7676
virtual FieldPointValue *getFieldPointValue (const TCoord &);
7777
virtual FieldPointValue *getFieldPointValue (grid_iter);
7878

79-
virtual FieldPointValue *getFieldPointValueByRelativePos (const TCoord &);
79+
virtual FieldPointValue *getFieldPointValueByAbsolutePos (const TCoord &);
8080

8181
virtual void nextTimeStep ();
8282
}; /* Grid */
@@ -219,9 +219,9 @@ Grid<TCoord>::getSize () const
219219
*/
220220
template <class TCoord>
221221
TCoord
222-
Grid<TCoord>::getComputationStart () const
222+
Grid<TCoord>::getComputationStart (TCoord diffPosStart) const
223223
{
224-
return TCoord (0);
224+
return TCoord (0) + diffPosStart;
225225
} /* Grid<TCoord>::getComputationStart */
226226

227227
/**
@@ -231,9 +231,9 @@ Grid<TCoord>::getComputationStart () const
231231
*/
232232
template <class TCoord>
233233
TCoord
234-
Grid<TCoord>::getComputationEnd () const
234+
Grid<TCoord>::getComputationEnd (TCoord diffPosEnd) const
235235
{
236-
return getSize ();
236+
return getSize () - diffPosEnd;
237237
} /* Grid<TCoord>::getComputationEnd () */
238238

239239
/**
@@ -295,10 +295,10 @@ Grid<TCoord>::getFieldPointValue (grid_iter coord) /**< index in grid */
295295
*/
296296
template <class TCoord>
297297
FieldPointValue *
298-
Grid<TCoord>::getFieldPointValueByRelativePos (const TCoord &relPosition) /**< relative coordinate in grid */
298+
Grid<TCoord>::getFieldPointValueByAbsolutePos (const TCoord &relPosition) /**< relative coordinate in grid */
299299
{
300300
return getFieldPointValue (relPosition);
301-
} /* Grid<TCoord>::getFieldPointValueByRelativePos */
301+
} /* Grid<TCoord>::getFieldPointValueByAbsolutePos */
302302

303303
/**
304304
* Switch to next time step

0 commit comments

Comments
 (0)