]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Some work on object indices.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 19 Jan 2012 20:00:11 +0000 (20:00 +0000)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 19 Jan 2012 20:00:11 +0000 (20:00 +0000)
src/ofc/generators/onetep/Tree.scala

index 849bfc6d935b6809b03d1728614ef74abdeb2698..c0b3ed85c65bcadf5dcece0775fa480ec6a6ce43 100644 (file)
@@ -1,28 +1,43 @@
 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
@@ -30,7 +45,9 @@ class Reciprocal
 class Pointwise
 class Summation
 
-class BindingIndex(name : String)
+class BindingIndex(name : String) {
+  override def toString()  = name
+}
 
 class Dictionary {
   var matrices = new HashMap[Identifier, Matrix]
@@ -56,13 +73,16 @@ class Dictionary {
 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) {
@@ -72,6 +92,13 @@ class TreeBuilder(dictionary : Dictionary) {
   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)
   }
 }