def getValue = value
def getType = new FloatType
}
+
+class CharLiteral(value: Char) extends Expression[CharType] with LeafExpression {
+ def getValue = value
+ def getType = new CharType
+}
expression match {
case (i : IntegerLiteral) => ExpHolder(maxPrec, i.getValue.toString)
case (i : FloatLiteral) => ExpHolder(maxPrec, i.getValue.toString)
+ case (i : CharLiteral) => ExpHolder(maxPrec, "'%s'".format(i.getValue.toString))
case (a : FieldAccess[_]) => ExpHolder(maxPrec, "%s%%%s".format(buildExpression(a.getStructExpression), a.getField.getName))
case (r : VarRef[_]) => r.getSymbol match {
case (s: NamedUnboundVarSymbol[_]) => ExpHolder(maxPrec, s.getName)
def getFortranAttributes = throw new LogicError("void type does not exist in Fortran.")
}
+final case class CharType() extends PrimitiveType {
+ def getFortranAttributes = Set("character")
+}
+
+final case class ComplexType() extends PrimitiveType {
+ def getFortranAttributes = Set("complex(kind=DP)")
+}
+
final case class ArrayType[ElementType <: Type](rank: Int, eType: ElementType) extends Type {
def this(rank: Int)(implicit builder: TypeBuilder[ElementType]) = this(rank, builder())
def getElementType = eType
}
object TypeBuilder {
+ implicit val charBuilder = new TypeBuilder[CharType] { def apply() = new CharType }
implicit val intBuilder = new TypeBuilder[IntType] { def apply() = new IntType }
implicit val floatBuilder = new TypeBuilder[FloatType] { def apply() = new FloatType }
+ implicit val complexBuilder = new TypeBuilder[ComplexType] { def apply() = new ComplexType }
implicit val boolBuilder = new TypeBuilder[BoolType] { def apply() = new BoolType }
}
implicit val intNumeric = new HasProperty[IntType, Numeric]()
implicit val floatNumeric = new HasProperty[FloatType, Numeric]()
}
-
-
("n1", new IntType),
("n2", new IntType),
("n3", new IntType)))
+
+ val fourier_apply_box_pair = new FortranSubroutineSignature("fourier_apply_box_pair",
+ Seq(("grid", new CharType),
+ ("dir", new CharType),
+ ("rspc1", new ArrayType[FloatType](3)),
+ ("rspc2", new ArrayType[FloatType](3)),
+ ("gspc", new ArrayType[ComplexType](3))))
}
val tightbox = (~(basis % FunctionBasis.tightBoxes)).readAt(sphereIndex)
val sphere = (~(basis % FunctionBasis.spheres)).readAt(sphereIndex)
val fftboxOffset = for(dim <- 0 to 2) yield new DeclaredVarSymbol[IntType]("fftbox_offset"+(dim+1))
+ val reciprocalBox = new DeclaredVarSymbol[ArrayType[ComplexType]]("reciprocal_box", new ArrayType[ComplexType](3))
def setup(context: GenerationContext) {
import OnetepTypes.FFTBoxInfo
context.addDeclaration(fftbox)
+ context.addDeclaration(reciprocalBox)
fftboxOffset.map(context.addDeclaration(_))
val fftboxSize : Seq[Expression[IntType]] = for (dim <- 0 to 2) yield FFTBoxInfo.public % FFTBoxInfo.totalPts(dim)
context += new AllocateStatement(fftbox, fftboxSize)
+ context += new AllocateStatement(reciprocalBox, fftboxSize)
context += new FunctionCallStatement(new FunctionCall(OnetepFunctions.basis_ket_start_wrt_fftbox,
fftboxOffset.map(new VarRef[IntType](_)) ++ fftboxSize))
basisCopyParams :+= sphere
context += new FunctionCallStatement(new FunctionCall(OnetepFunctions.basis_copy_function_to_fftbox, basisCopyParams))
+
+ val fourierParams : Seq[Expression[_]] = Seq(new CharLiteral('C'), new CharLiteral('F'), fftbox, fftbox, reciprocalBox)
+ context += new FunctionCallStatement(new FunctionCall(OnetepFunctions.fourier_apply_box_pair, fourierParams))
+
+ context += new DeallocateStatement(fftbox)
}
def teardown(context: GenerationContext) {
- context += new DeallocateStatement(fftbox)
+ context += new DeallocateStatement(reciprocalBox)
}
}