From dca30beba3e30c13093d4c82e388eb0f11a892f8 Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Sat, 19 May 2012 20:42:56 +0100 Subject: [PATCH] Apply Laplacian to negative frequencies correctly. --- src/ofc/generators/onetep/Laplacian.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ofc/generators/onetep/Laplacian.scala b/src/ofc/generators/onetep/Laplacian.scala index e70a165..46c6632 100644 --- a/src/ofc/generators/onetep/Laplacian.scala +++ b/src/ofc/generators/onetep/Laplacian.scala @@ -21,6 +21,16 @@ class Laplacian(op: Field) extends Field { // 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) @@ -35,7 +45,7 @@ class Laplacian(op: Field) extends Field { 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) } -- 2.47.3