Index beta
# Computation
-kinet = ket[beta]
+kinet = fftbox(beta, ket[beta])
# Implementation specific
target ONETEP
val finishPPD = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("finish_ppds"+dim)}.toSeq
def getFortranAttributes = Set("type(FUNCTION_TIGHT_BOX)")
}
+
+ object FFTBoxInfo extends StructType {
+ val totalPts = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("total_pt"+dim)}.toSeq
+ def getFortranAttributes = Set("type(FFTBOX_INFO)")
+ }
}
package ofc.generators.onetep
+import ofc.codegen._
+
+object SpatialRestriction {
+ private val pubFFTBox = new NamedUnboundVarSymbol[StructType]("pub_fftbox", OnetepTypes.FFTBoxInfo)
+}
+
+class SpatialRestriction(op: IterationSpace, function: BindingIndex) extends IterationSpace {
+ def getOperands = List(op)
+ def getDiscreteIndices = Nil
+ def getSuffixFragment = new NullStatement
+ def getDataValue = op.getDataValue
+ def getReaderFragment = {
+ //TODO: Implement me!
+ new NullStatement
+ }
+
+ def getSpatialIndices = {
+ //TODO: Implement me!
+ Nil
+ }
+
/*
-class SpatialRestriction(op: IterationSpace) extends IterationSpace {
class RestrictedIndex(parent: SpatialRestriction, dimension: Int) extends SpatialIndex {
def getName = "restriction_index_" + dimension
def getDependencies = Set()
val spatialIndices = for (dimension <- 0 until op.getSpatialIndices.size) yield new RestrictedIndex(this, dimension)
- def getOperands = List(op)
def getSpatialIndices = spatialIndices.toList
def getDiscreteIndices = op.getDiscreteIndices
def getExternalIndices = Set()
})
def getTransformGenerator = None
def getProducerGenerator = None
-}
*/
+}
+
import ofc.parser.Identifier
import ofc.{InvalidInputException,UnimplementedException}
-class BindingIndex(name : String) {
+case class BindingIndex(name : String) {
override def toString() = name
}
val indexBindings = new IndexBindings
var nextBindingIndexID = 0
- def newBindingIndex() = {
+ private def newBindingIndex() = {
val index = new BindingIndex("synthetic_"+nextBindingIndexID)
nextBindingIndexID += 1
index
}
- def apply(lhs: parser.IndexedTerm, rhs: parser.Expression) = {
- val lhsTree = buildIndexedTerm(lhs)
+ def apply(lhs: parser.IndexedIdentifier, rhs: parser.Expression) = {
+ val lhsTree = buildIndexedSpace(lhs)
val rhsTree = buildExpression(rhs)
lhsTree match {
}
}
- def buildIndexedTerm(term: parser.IndexedTerm) : IterationSpace = {
+ private def buildIndexedSpace(term: parser.IndexedIdentifier) : IterationSpace = {
val dataSpace = dictionary.getData(term.id)
val indices = for(bindingID <- term.indices) yield dictionary.getIndex(bindingID)
if (indices.size != dataSpace.getDiscreteIndices.size)
- throw new InvalidInputException("Incorrect number of indices for object "+term.id.name);
+ throw new InvalidInputException("Incorrect number of indices for object "+term.id.name)
for(i <- indices zip dataSpace.getDiscreteIndices)
indexBindings.add(i._1, i._2)
}
}
- def buildExpression(term: parser.Expression) : IterationSpace = {
+ private def buildIndex(term: parser.Expression) : BindingIndex = {
+ term match {
+ case (indexedID: parser.IndexedIdentifier) => {
+ if (indexedID.indices.nonEmpty)
+ throw new InvalidInputException("Tried to parse expression "+term+" as index but it is indexed.")
+ else
+ dictionary.getIndex(indexedID.id)
+ }
+ case other => throw new InvalidInputException("Cannot parse expression "+other+" as index.")
+ }
+ }
+
+ private def buildExpression(term: parser.Expression) : IterationSpace = {
import parser._
term match {
- case (t: IndexedTerm) => buildIndexedTerm(t)
-/*
+ case (t: IndexedIdentifier) => buildIndexedSpace(t)
+ case Operator(Identifier("fftbox"), List(indexID, op)) =>
+ new SpatialRestriction(buildExpression(op), buildIndex(indexID))
+
+ /*
case ScalarConstant(s) => new Scalar(s)
case Multiplication(a, b) =>
new GeneralInnerProduct(List(buildExpression(a), buildExpression(b)), Set())
}
case Operator(Identifier("reciprocal"), List(op)) => new Reciprocal(buildExpression(op))
case Operator(Identifier("laplacian"), List(op)) => new Laplacian(buildExpression(op))
- case Operator(Identifier("fftbox"), List(op)) => new SpatialRestriction(buildExpression(op))
case Operator(Identifier(name), _) => throw new UnimplementedException("Unknown or incorrectly called operator: "+name)
-*/
+ */
}
}
}
def term: Parser[Expression] = scalarConstant ||| indexedIdentifier ||| operator
def scalarConstant : Parser[ScalarConstant] = floatingPointNumber ^^ (x => new ScalarConstant(x.toDouble))
- def indexedIdentifier: Parser[IndexedTerm] = identifier~opt("["~>repsep(identifier, ",")<~"]") ^^
- (x => new IndexedTerm(x._1, x._2 match {
+ def indexedIdentifier: Parser[IndexedIdentifier] = identifier~opt("["~>repsep(identifier, ",")<~"]") ^^
+ (x => new IndexedIdentifier(x._1, x._2 match {
case Some(list) => list
case None => Nil
}))
case class DeclarationList(oflType: OFLType, names: List[Identifier]) extends Statement {
override def toString : String = "decl("+oflType+", "+names+")"
}
-case class Definition(term: IndexedTerm, expr: Expression) extends Statement {
+case class Definition(term: IndexedIdentifier, expr: Expression) extends Statement {
override def toString : String = "define("+term+", "+expr+")"
}
case class Target(name: Identifier) extends Statement {
case class ScalarConstant(s: Double) extends Expression {
override def toString : String = s.toString
}
-case class IndexedTerm(id: Identifier, indices : List[Identifier]) extends Expression {
+case class IndexedIdentifier(id: Identifier, indices : List[Identifier]) extends Expression {
override def toString : String = id+indices.mkString("[", ", ", "]")
}
case class Operator(id: Identifier, operands : List[Expression]) extends Expression {