From: Francis Russell Date: Thu, 3 May 2012 00:00:21 +0000 (+0100) Subject: Add conversion from reciprocal to psinc space. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=4cde7c33407699541ca2c0afeac0cadab701ebf5;p=francis%2Fofc.git Add conversion from reciprocal to psinc space. --- diff --git a/src/ofc/generators/onetep/FieldFragment.scala b/src/ofc/generators/onetep/FieldFragment.scala index cd954d6..1ccc07c 100644 --- a/src/ofc/generators/onetep/FieldFragment.scala +++ b/src/ofc/generators/onetep/FieldFragment.scala @@ -3,9 +3,12 @@ import ofc.codegen._ trait FieldFragment extends Fragment { def toReciprocal : ReciprocalFragment + def toPsinc : PsincFragment } -trait PsincFragment extends FieldFragment +trait PsincFragment extends FieldFragment { + def toPsinc = this +} trait ReciprocalFragment extends FieldFragment { def toReciprocal = this diff --git a/src/ofc/generators/onetep/Laplacian.scala b/src/ofc/generators/onetep/Laplacian.scala index 5f771f7..f1bf392 100644 --- a/src/ofc/generators/onetep/Laplacian.scala +++ b/src/ofc/generators/onetep/Laplacian.scala @@ -63,6 +63,8 @@ class Laplacian(op: Field) extends Field { def getSize = opFragment.getSize def getBuffer = transformed + + def toPsinc = new ReciprocalToPsinc(this) } private def getOperand = op diff --git a/src/ofc/generators/onetep/PPDFunctionSet.scala b/src/ofc/generators/onetep/PPDFunctionSet.scala index 754e0e7..84267a7 100644 --- a/src/ofc/generators/onetep/PPDFunctionSet.scala +++ b/src/ofc/generators/onetep/PPDFunctionSet.scala @@ -157,6 +157,8 @@ class PPDFunctionSet(basisName: String, dataName: String, indices: Seq[NamedInde def getSize = for (dim <- 0 to 2) yield OnetepTypes.FFTBoxInfo.public % OnetepTypes.FFTBoxInfo.totalPts(dim) def getBuffer = reciprocalBox + + def toPsinc = new ReciprocalToPsinc(this) } private def getSphereIndex = indices.head diff --git a/src/ofc/generators/onetep/ReciprocalToPsinc.scala b/src/ofc/generators/onetep/ReciprocalToPsinc.scala new file mode 100644 index 0000000..52bcd6b --- /dev/null +++ b/src/ofc/generators/onetep/ReciprocalToPsinc.scala @@ -0,0 +1,27 @@ +package ofc.generators.onetep +import ofc.codegen._ + +class ReciprocalToPsinc(op: ReciprocalFragment) extends PsincFragment { + val fftbox = new DeclaredVarSymbol[ArrayType[FloatType]]("fftbox", new ArrayType[FloatType](3)) + + def toReciprocal = op + + def setup(context: GenerationContext) { + op.setup(context) + context.addDeclaration(fftbox) + + val fftboxSize : Seq[Expression[IntType]] = getSize + context += new AllocateStatement(fftbox, fftboxSize) + + val fourierParams : Seq[Expression[_]] = Seq(new CharLiteral('C'), new CharLiteral('B'), fftbox, fftbox, op.getBuffer) + context += new FunctionCallStatement(new FunctionCall(OnetepFunctions.fourier_apply_box_pair, fourierParams)) + + op.teardown(context) + } + + def teardown(context: GenerationContext) { + context += new DeallocateStatement(fftbox) + } + + def getSize = for (dim <- 0 to 2) yield OnetepTypes.FFTBoxInfo.public % OnetepTypes.FFTBoxInfo.totalPts(dim) +}