package ofc.codegen
+import ofc.LogicError
object Expression {
implicit def fromInt(i: Int) : Expression[IntType] = new IntegerLiteral(i)
}
class ArrayRead[E <: Type](expression: Expression[ArrayType[E]], index: Seq[Expression[IntType]]) extends Expression[E] {
+ if (index.size != expression.getType.getRank)
+ throw new LogicError("Array of rank "+expression.getType.getRank+" indexed with rank "+index.size+" index.")
+
def foreach[U](f: Expression[_] => U) = (index :+ expression).foreach(f)
def getArrayExpression = expression
def getIndexExpressions = index
def this(rank: Int)(implicit builder: TypeBuilder[ElementType]) = this(rank, builder())
def getElementType = eType
def getFortranAttributes = eType.getFortranAttributes ++ Set("allocatable", (":"*rank).mkString("dimension(",",",")"))
+ def getRank = rank
}
final case class PointerType[TargetType <: Type](tType: TargetType) extends Type {
new FieldSymbol[PointerType[ArrayType[IntType]]]("n_ppds_sphere", fieldType)
}
- val ppdList = {
- val fieldType = new PointerType[ArrayType[IntType]](new ArrayType[IntType](1))
- new FieldSymbol[PointerType[ArrayType[IntType]]]("ppd_list", fieldType)
- }
-
val num = new FieldSymbol[IntType]("num")
val tightBoxes = {
new FieldSymbol[PointerType[ArrayType[StructType]]]("tight_boxes", fieldType)
}
+ val spheres = {
+ val fieldType = new PointerType[ArrayType[StructType]](new ArrayType[StructType](1, Sphere))
+ new FieldSymbol[PointerType[ArrayType[StructType]]]("spheres", fieldType)
+ }
+
def getFortranAttributes = Set("type(FUNC_BASIS)")
}
+ object Sphere extends StructType {
+ val ppdList = {
+ val fieldType = new PointerType[ArrayType[IntType]](new ArrayType[IntType](2))
+ new FieldSymbol[PointerType[ArrayType[IntType]]]("ppd_list", fieldType)
+ }
+
+ def getFortranAttributes = Set("type(SPHERE)")
+ }
+
object CellInfo extends StructType {
val ppdWidth = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("n_pt"+dim)}.toSeq
val numPPDs = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("n_ppds_a"+dim)}.toSeq
object TightBox extends StructType {
val startPts = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("start_pts"+dim)}.toSeq
val finishPts = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("finish_pts"+dim)}.toSeq
- val startPPD = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("start_ppd"+dim)}.toSeq
- val finishPPD = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("finish_ppd"+dim)}.toSeq
+ val startPPD = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("start_ppds"+dim)}.toSeq
+ val finishPPD = {for (dim <- 1 to 3) yield new FieldSymbol[IntType]("finish_ppds"+dim)}.toSeq
def getFortranAttributes = Set("type(FUNCTION_TIGHT_BOX)")
}
}
val sphereIndex = producer.addIteration("sphere_index", 1, numSpheres)
val numPPDs = (~(basis % FunctionBasis.numPPDsInSphere)).readAt(sphereIndex)
val ppdIndex = producer.addIteration("ppd_index", 1, numPPDs)
- val ppdGlobalCount = (~(basis % FunctionBasis.ppdList)).readAt(ppdIndex, 1) - 1
+ val ppdGlobalCount = (~((~(basis % FunctionBasis.spheres)).readAt(sphereIndex) % Sphere.ppdList)).readAt(ppdIndex, 1) - 1
// The integer co-ordinates of the PPD (0-based)
val a3pos = producer.addExpression("ppd_pos1", ppdGlobalCount / (cellWidthInPPDs(0)*cellWidthInPPDs(1)))