All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.ninecode.model.StandardModels.scala Maven / Gradle / Ivy

There is a newer version: 2.12-3.0.1-5.1.1
Show newest version
package ch.ninecode.model

import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.Serializer
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import org.apache.spark.sql.Row

import ch.ninecode.cim.CIMClassInfo
import ch.ninecode.cim.CIMContext
import ch.ninecode.cim.CIMParseable

import ch.ninecode.cim.CIMSerializer

/**
 * Abstract parent class for all Dynamics function blocks.
 *
 * @param IdentifiedObject [[ch.ninecode.model.IdentifiedObject IdentifiedObject]] Reference to the superclass object.
 * @param enabled Function block used indicator.
 *        true = use of function block is enabled
 *        false = use of function block is disabled.
 * @group StandardModels
 * @groupname StandardModels Package StandardModels
 * @groupdesc StandardModels This subclause contains standard dynamic model specifications grouped into packages by standard function block (type of equipment being modelled).
In the CIM, standard dynamic models are expressed by means of a class named with the standard model name and attributes reflecting each of the parameters necessary to describe the behaviour of an instance of the standard model.
 */
final case class DynamicsFunctionBlock
(
    IdentifiedObject: IdentifiedObject = null,
    enabled: Boolean = false
)
extends
    Element
{
    /**
     * Return the superclass object.
     *
     * @return The typed superclass nested object.
     * @group Hierarchy
     * @groupname Hierarchy Class Hierarchy Related
     * @groupdesc Hierarchy Members related to the nested hierarchy of CIM classes.
     */
    override def sup: IdentifiedObject = IdentifiedObject

    //
    // Row overrides
    //

    /**
     * Return a copy of this object as a Row.
     *
     * Creates a clone of this object for use in Row manipulations.
     *
     * @return The copy of the object.
     * @group Row
     * @groupname Row SQL Row Implementation
     * @groupdesc Row Members related to implementing the SQL Row interface
     */
    override def copy (): Row = { clone ().asInstanceOf[Row] }

    override def export_fields: String =
    {
        implicit val s: StringBuilder = new StringBuilder (sup.export_fields)
        implicit val clz: String = DynamicsFunctionBlock.cls
        def emitelem (position: Int, value: Any): Unit = if (mask (position)) emit_element (DynamicsFunctionBlock.fields (position), value)
        emitelem (0, enabled)
        s.toString
    }
    override def export: String =
    {
        "\t\n%s\t".format (id, export_fields)
    }
}

object DynamicsFunctionBlock
extends
    CIMParseable[DynamicsFunctionBlock]
{
    override val fields: Array[String] = Array[String] (
        "enabled"
    )
    val enabled: Fielder = parse_element (element (cls, fields(0)))

    def parse (context: CIMContext): DynamicsFunctionBlock =
    {
        implicit val ctx: CIMContext = context
        implicit val bitfields: Array[Int] = Array(0)
        val ret = DynamicsFunctionBlock (
            IdentifiedObject.parse (context),
            toBoolean (mask (enabled (), 0))
        )
        ret.bitfields = bitfields
        ret
    }

    def serializer: Serializer[DynamicsFunctionBlock] = DynamicsFunctionBlockSerializer
}

object DynamicsFunctionBlockSerializer extends CIMSerializer[DynamicsFunctionBlock]
{
    def write (kryo: Kryo, output: Output, obj: DynamicsFunctionBlock): Unit =
    {
        val toSerialize: Array[() => Unit] = Array (
            () => output.writeBoolean (obj.enabled)
        )
        IdentifiedObjectSerializer.write (kryo, output, obj.sup)
        implicit val bitfields: Array[Int] = obj.bitfields
        writeBitfields (output)
        writeFields (toSerialize)
    }

    def read (kryo: Kryo, input: Input, cls: Class[DynamicsFunctionBlock]): DynamicsFunctionBlock =
    {
        val parent = IdentifiedObjectSerializer.read (kryo, input, classOf[IdentifiedObject])
        implicit val bitfields: Array[Int] = readBitfields (input)
        val obj = DynamicsFunctionBlock (
            parent,
            if (isSet (0)) input.readBoolean else false
        )
        obj.bitfields = bitfields
        obj
    }
}

/**
 * Abstract parent class for all synchronous and asynchronous machine standard models.
 *
 * @param DynamicsFunctionBlock [[ch.ninecode.model.DynamicsFunctionBlock DynamicsFunctionBlock]] Reference to the superclass object.
 * @param damping Damping torque coefficient (D) (>= 0).
 *        A proportionality constant that, when multiplied by the angular velocity of the rotor poles with respect to the magnetic field (frequency), results in the damping torque.  This value is often zero when the sources of damping torques (generator damper windings, load damping effects, etc.) are modelled in detail.  Typical value = 0.
 * @param inertia Inertia constant of generator or motor and mechanical load (H) (> 0).
 *        This is the specification for the stored energy in the rotating mass when operating at rated speed.  For a generator, this includes the generator plus all other elements (turbine, exciter) on the same shaft and has units of MW x s.  For a motor, it includes the motor plus its mechanical load. Conventional units are PU on the generator MVA base, usually expressed as MW x s / MVA or just s. This value is used in the accelerating power reference frame for operator training simulator solutions.  Typical value = 3.
 * @param saturationFactor Saturation factor at rated terminal voltage (S1) (>= 0).
 *        Not used by simplified model.  Defined by defined by S(E1) in the SynchronousMachineSaturationParameters diagram.  Typical value = 0,02.
 * @param saturationFactor120 Saturation factor at 120% of rated terminal voltage (S12) (>= RotatingMachineDynamics.saturationFactor).
 *        Not used by the simplified model, defined by S(E2) in the SynchronousMachineSaturationParameters diagram.  Typical value = 0,12.
 * @param statorLeakageReactance Stator leakage reactance (Xl) (>= 0).
 *        Typical value = 0,15.
 * @param statorResistance Stator (armature) resistance (Rs) (>= 0).
 *        Typical value = 0,005.
 * @group StandardModels
 * @groupname StandardModels Package StandardModels
 * @groupdesc StandardModels This subclause contains standard dynamic model specifications grouped into packages by standard function block (type of equipment being modelled).
In the CIM, standard dynamic models are expressed by means of a class named with the standard model name and attributes reflecting each of the parameters necessary to describe the behaviour of an instance of the standard model.
 */
final case class RotatingMachineDynamics
(
    DynamicsFunctionBlock: DynamicsFunctionBlock = null,
    damping: Double = 0.0,
    inertia: Double = 0.0,
    saturationFactor: Double = 0.0,
    saturationFactor120: Double = 0.0,
    statorLeakageReactance: Double = 0.0,
    statorResistance: Double = 0.0
)
extends
    Element
{
    /**
     * Return the superclass object.
     *
     * @return The typed superclass nested object.
     * @group Hierarchy
     * @groupname Hierarchy Class Hierarchy Related
     * @groupdesc Hierarchy Members related to the nested hierarchy of CIM classes.
     */
    override def sup: DynamicsFunctionBlock = DynamicsFunctionBlock

    //
    // Row overrides
    //

    /**
     * Return a copy of this object as a Row.
     *
     * Creates a clone of this object for use in Row manipulations.
     *
     * @return The copy of the object.
     * @group Row
     * @groupname Row SQL Row Implementation
     * @groupdesc Row Members related to implementing the SQL Row interface
     */
    override def copy (): Row = { clone ().asInstanceOf[Row] }

    override def export_fields: String =
    {
        implicit val s: StringBuilder = new StringBuilder (sup.export_fields)
        implicit val clz: String = RotatingMachineDynamics.cls
        def emitelem (position: Int, value: Any): Unit = if (mask (position)) emit_element (RotatingMachineDynamics.fields (position), value)
        emitelem (0, damping)
        emitelem (1, inertia)
        emitelem (2, saturationFactor)
        emitelem (3, saturationFactor120)
        emitelem (4, statorLeakageReactance)
        emitelem (5, statorResistance)
        s.toString
    }
    override def export: String =
    {
        "\t\n%s\t".format (id, export_fields)
    }
}

object RotatingMachineDynamics
extends
    CIMParseable[RotatingMachineDynamics]
{
    override val fields: Array[String] = Array[String] (
        "damping",
        "inertia",
        "saturationFactor",
        "saturationFactor120",
        "statorLeakageReactance",
        "statorResistance"
    )
    val damping: Fielder = parse_element (element (cls, fields(0)))
    val inertia: Fielder = parse_element (element (cls, fields(1)))
    val saturationFactor: Fielder = parse_element (element (cls, fields(2)))
    val saturationFactor120: Fielder = parse_element (element (cls, fields(3)))
    val statorLeakageReactance: Fielder = parse_element (element (cls, fields(4)))
    val statorResistance: Fielder = parse_element (element (cls, fields(5)))

    def parse (context: CIMContext): RotatingMachineDynamics =
    {
        implicit val ctx: CIMContext = context
        implicit val bitfields: Array[Int] = Array(0)
        val ret = RotatingMachineDynamics (
            DynamicsFunctionBlock.parse (context),
            toDouble (mask (damping (), 0)),
            toDouble (mask (inertia (), 1)),
            toDouble (mask (saturationFactor (), 2)),
            toDouble (mask (saturationFactor120 (), 3)),
            toDouble (mask (statorLeakageReactance (), 4)),
            toDouble (mask (statorResistance (), 5))
        )
        ret.bitfields = bitfields
        ret
    }

    def serializer: Serializer[RotatingMachineDynamics] = RotatingMachineDynamicsSerializer
}

object RotatingMachineDynamicsSerializer extends CIMSerializer[RotatingMachineDynamics]
{
    def write (kryo: Kryo, output: Output, obj: RotatingMachineDynamics): Unit =
    {
        val toSerialize: Array[() => Unit] = Array (
            () => output.writeDouble (obj.damping),
            () => output.writeDouble (obj.inertia),
            () => output.writeDouble (obj.saturationFactor),
            () => output.writeDouble (obj.saturationFactor120),
            () => output.writeDouble (obj.statorLeakageReactance),
            () => output.writeDouble (obj.statorResistance)
        )
        DynamicsFunctionBlockSerializer.write (kryo, output, obj.sup)
        implicit val bitfields: Array[Int] = obj.bitfields
        writeBitfields (output)
        writeFields (toSerialize)
    }

    def read (kryo: Kryo, input: Input, cls: Class[RotatingMachineDynamics]): RotatingMachineDynamics =
    {
        val parent = DynamicsFunctionBlockSerializer.read (kryo, input, classOf[DynamicsFunctionBlock])
        implicit val bitfields: Array[Int] = readBitfields (input)
        val obj = RotatingMachineDynamics (
            parent,
            if (isSet (0)) input.readDouble else 0.0,
            if (isSet (1)) input.readDouble else 0.0,
            if (isSet (2)) input.readDouble else 0.0,
            if (isSet (3)) input.readDouble else 0.0,
            if (isSet (4)) input.readDouble else 0.0,
            if (isSet (5)) input.readDouble else 0.0
        )
        obj.bitfields = bitfields
        obj
    }
}

private[ninecode] object _StandardModels
{
    def register: List[CIMClassInfo] =
    {
        List (
            DynamicsFunctionBlock.register,
            RotatingMachineDynamics.register
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy