Skip to content

Commit

Permalink
invalidate all elements of transformer service area with special tran…
Browse files Browse the repository at this point in the history
…sformer
  • Loading branch information
Derrick Oswald committed Nov 6, 2018
1 parent 3a158df commit 62fa0c5
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1 deletion.
5 changes: 5 additions & 0 deletions GridLAB-D/src/main/scala/ch/ninecode/gl/GridLABD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ class GridLABD (
{
element match
{
case cable: ACLineSegment
if (cable.r >= 5.0) // ToDo: use PSRType_Bogus
"invalid element (%s r=%s)".format (cable.id, cable.r)
else
null
case _: PowerTransformer
// Three Winding Transformer - if there are more than 2 PowerTransformerEnd associated to the PowerTransformer
if (num_terminals > 2)
Expand Down
5 changes: 5 additions & 0 deletions GridLAB-D/src/main/scala/ch/ninecode/gl/Island.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ with Serializable
{
element match
{
case cable: ACLineSegment
if (cable.r < 5.0) // ToDo: use PSRType_Bogus
"invalid element (%s r=%s)".format (cable.id, cable.r)
else
null
case _: PowerTransformer
// Three Winding Transformer - if there are more than 2 PowerTransformerEnd associated to the PowerTransformer
if (num_terminals > 2)
Expand Down
55 changes: 55 additions & 0 deletions MaximumFeedIn/src/main/scala/ch/ninecode/mfi/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,61 @@ object Database
}
}

def invalidate_precalculation (simulation: Int, problems: RDD[(String, String)]): Unit =
{
val file = Paths.get ("simulation/results.db")
if (!Files.exists (file))
log.error ("database file " + file + " does not exist")
else
{
// load the sqlite-JDBC driver using the current class loader
Class.forName ("org.sqlite.JDBC")

var connection: Connection = null
try
{
// create a database connection
connection = DriverManager.getConnection ("jdbc:sqlite:simulation/results.db")
connection.setAutoCommit (false)

val records = problems.collect ()

val update = connection.prepareStatement ("update results set maximum=null, reason=?, details=null where simulation = ? and trafo = ?")
for (i <- records.indices)
{
val trafo_id = records(i)._1
val reason = records(i)._2
update.setString (1, reason)
update.setInt (2, simulation)
update.setString (3, trafo_id)
update.executeUpdate ()
}
update.close ()
connection.commit ()
}
catch
{
// if the error message is "out of memory",
// it probably means no database file is found
case e: SQLException log.error ("exception caught: " + e);
}
finally
{
try
{
if (connection != null)
connection.close ()
}
catch
{
// connection close failed
case e: SQLException log.error ("exception caught: " + e);
}
}
}

}

def fetchHouseMaximumsForTransformer (simulation: Int, transformer: String): Array[(String,Double)] =
{
var ret = new ArrayBuffer[(String,Double)] ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,11 @@ case class Einspeiseleistung (session: SparkSession, options: EinspeiseleistungO
else
precalc_results.has.filter (x (x.eea != null) || (x.reason == "non-radial network"))

// get a list of invalid nodes and group by transformer
val invalid = houses.filter (_.problem).keyBy (_.source_obj).groupByKey

val tl = session.sparkContext.parallelize (transformers)
val trafo_list = houses.keyBy (_.source_obj).groupByKey.join (tl.keyBy (_.transformer_name)).values.map (_._2)
val trafo_list = houses.keyBy (_.source_obj).groupByKey.subtractByKey (invalid).join (tl.keyBy (_.transformer_name)).values.map (_._2)
log.info ("" + trafo_list.count + " transformers to process")
if (log.isDebugEnabled)
trafo_list.foreach (trafo log.debug ("%s %gkVA %g:%g".format (trafo.transformer_name, trafo.power_rating / 1000, trafo.v0, trafo.v1)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ case class MaxPowerFeedingNodeEEA (
else
id_seq
}

def problem: Boolean =
reason.indexOf ("invalid element") != -1 ||
reason.indexOf ("transformer windings for edge") != -1 ||
reason.indexOf ("regulator edge") != -1 ||
reason.indexOf ("subtransmission edge") != -1
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ class PowerFeeding (session: SparkSession) extends CIMRDD with Serializable
val simulation = Database.store_precalculation ("Threshold Precalculation", Calendar.getInstance ()) (has)
log.info ("the simulation number is " + simulation)

// update each element in the transformer service area with bad value (just choose the first)
val problem_trafos = has.filter (_.problem).keyBy (_.source_obj).groupByKey.map (x (x._1, x._2.head.reason))
if (!problem_trafos.isEmpty)
Database.invalidate_precalculation (simulation, problem_trafos)

def mapGraphEdges(triplet: EdgeTriplet[PowerFeedingNode, PreEdge]): (String, PreEdge) =
{
val source = triplet.srcAttr.source_obj
Expand Down

0 comments on commit 62fa0c5

Please sign in to comment.