// Construct loops
val loops = for(dim <- 0 to 2) yield new ForLoop(indices(dim), 1, getSize(dim))
+ val frequencies = for(dim <- 0 to 2) yield {
+ val index = indices(dim)
+ val frequency = new DeclaredVarSymbol[IntType]("freq_"+(dim+1))
+ val halfWidth = getSize(dim)/2 + 1;
+ context.addDeclaration(frequency)
+ loops(dim) += new AssignStatement(frequency,
+ new ConditionalValue[IntType](index |>| halfWidth, index - getSize(dim) - 1, index - 1))
+ frequency
+ }
+
// Nest loops and add outer to context
for(dim <- 1 to 2) loops(dim) += loops(dim-1)
context += loops(2)
var component : Expression[FloatType] = new FloatLiteral(0.0)
for(vec <- 0 to 2) {
val vector = OnetepTypes.FFTBoxInfo.public % OnetepTypes.FFTBoxInfo.latticeReciprocal(vec)
- component = component + vector % OnetepTypes.Point.coord(dim) * new Conversion[IntType, FloatType](indices(vec) - 1)
+ component = component + vector % OnetepTypes.Point.coord(dim) * new Conversion[IntType, FloatType](frequencies(vec))
}
loops(0) += new AssignStatement(reciprocalVector(dim), component)
}