package ofc.generators.onetep
-import scala.collection.mutable.{HashMap,Set}
+import scala.collection.mutable.{HashMap,HashSet,Set}
import ofc.parser
import ofc.parser.Identifier
import ofc.InvalidInputException
-trait Index
-trait SpatialIndex
-trait DiscreteIndex
+trait SpatialIndex extends Index
+trait DiscreteIndex extends Index
trait DataSpace
{
- def getIndices() : Set[Index]
+ def getSpatialIndices() : List[SpatialIndex]
+ def getDiscreteIndices() : List[DiscreteIndex]
}
trait Matrix extends DataSpace
trait FunctionSet extends DataSpace
class SPAM3(name : String) extends Matrix {
- def getIndices() = Set[Index]()
+ override def toString = name
+
+ class RowIndex(parent: SPAM3) extends DiscreteIndex {
+ override def toString = parent + ".row"
+ }
+ class ColIndex(parent: SPAM3) extends DiscreteIndex {
+ override def toString = parent + ".col"
+ }
+
+ def getSpatialIndices() = Nil
+ def getDiscreteIndices() = List(new RowIndex(this), new ColIndex(this))
}
class PPDFunctionSet(basis : String, data : String) extends FunctionSet {
- def getIndices() = Set[Index]()
+ class SphereIndex(parent: PPDFunctionSet) extends DiscreteIndex
+ class PPDIndex(parent: PPDFunctionSet) extends DiscreteIndex
+ class IntraPPDIndex(parent: PPDFunctionSet, dimension: Int) extends SpatialIndex
+
+ def getSpatialIndices() = (for (dimension <- 0 to 2) yield new IntraPPDIndex(this, dimension)).toList
+ def getDiscreteIndices() = List(new SphereIndex(this), new PPDIndex(this))
}
class Restriction
class Pointwise
class Summation
-class BindingIndex(name : String)
+class BindingIndex(name : String) {
+ override def toString() = name
+}
class Dictionary {
var matrices = new HashMap[Identifier, Matrix]
class Definition(lhs: DataSpace, rhs: DataSpace)
class IndexBindings {
- var bindings = new HashMap[BindingIndex, Set[Index]]
+ val spatial = new HashMap[BindingIndex, Set[SpatialIndex]]
+ val discrete = new HashMap[BindingIndex, Set[DiscreteIndex]]
- def add(binding: BindingIndex, index: Index) = bindings(binding) += index
+ def add(binding: BindingIndex, index: SpatialIndex) = spatial.getOrElseUpdate(binding, new HashSet()) += index
+ def add(binding: BindingIndex, index: DiscreteIndex) = discrete.getOrElseUpdate(binding, new HashSet()) += index
+
+ override def toString = spatial.toString + discrete.toString
}
class TreeBuilder(dictionary : Dictionary) {
-
val indexBindings = new IndexBindings
def apply(lhs: parser.IndexedTerm, rhs: parser.Expression) {
def buildIndexedTerm(term: parser.IndexedTerm) {
val dataSpace = dictionary.getData(term.id)
val indices = for(bindingID <- term.indices) yield dictionary.getIndex(bindingID)
- print(indices)
+
+ if (indices.size != dataSpace.getDiscreteIndices.size)
+ throw new InvalidInputException("Incorrect number of indices for object "+term.id.name);
+
+ for(i <- indices zip dataSpace.getDiscreteIndices)
+ indexBindings.add(i._1, i._2)
+
+ print(indexBindings)
}
}