From: Francis Russell Date: Thu, 19 Jan 2012 20:00:11 +0000 (+0000) Subject: Some work on object indices. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=5645efe73528af5bcc0c72d8253fe21f7f1a2d4d;p=francis%2Fofc.git Some work on object indices. --- diff --git a/src/ofc/generators/onetep/Tree.scala b/src/ofc/generators/onetep/Tree.scala index 849bfc6..c0b3ed8 100644 --- a/src/ofc/generators/onetep/Tree.scala +++ b/src/ofc/generators/onetep/Tree.scala @@ -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) } }