Skip to content

Commit

Permalink
Added Rogers Ratios algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
code-recipes committed Aug 11, 2017
1 parent 515c911 commit bca1780
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 11 deletions.
Binary file modified Distribution/xDGA Sample.xlsx
Binary file not shown.
Binary file modified Distribution/xDGA.ADDIN.xll
Binary file not shown.
Binary file modified Distribution/xDGA.ADDIN64.xll
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,41 @@ So far, **xDGA** implements the following guidelines and algorithms:

* IEC 60599 ed.3 2015.
* Duval Triangles for Transformers, Reactors, Cables and On-Load Tap Changers
* Duval Pentagons

## Usage

The add-in is activated by opening the **xDGA.ADDIN64.xll** or **xDGA.ADDIN.xll** file, depending on your architecture. Both files are in the **Distribution** folder and they are stand-alone (i.e. don't need other files or libraries to run).

The formulas can then be applied to any Excel spreadsheet with DGA data.

At the moment the following functions are implemented.
The following Excel functions are implemented.

* SERIALIZEDGA()
* IEC_60599()
* DUVALTRIANGLES()
* DUVALTRIANGLES_OLTC()
* DUVALPENTAGONS()
* ROGERSRATIOS()

The SERIALIZEDGA() function accepts the date and the nine gases that constitute one DGA instance. The function produces a string with the JSON serialised version of the data.

<p align="center">
<img src="Distribution/SERIALIZEDGA.PNG" alt="SERIALIZEDGA()" width="70%" />
<img src="Images/SERIALIZEDGA.PNG" alt="SERIALIZEDGA()" width="70%" />
</p>

This is a helper function that prepares the date that can then be fed into any of the funcitons that require DGA data.

For example, the IEC_60599() function takes in the Current and the Previous DGA as well as a boolean value indicating whether the transformer has an On-Load Tap Changer (OLTC) and the volume of oil in the tank in litres.

<p align="center">
<img src="Distribution/IEC_60599.PNG" alt="IEC_60599()" width="70%" />
<img src="Images/IEC_60599.PNG" alt="IEC_60599()" width="70%" />
</p>

The IEC_60599() function returns a string with all the outputs and results of running the rules outlined in the guideline.

<p align="center">
<img src="Distribution/IEC_60599-Output.PNG" alt="IEC_60599-Output" width="95%" />
<img src="Images/IEC_60599-Output.PNG" alt="IEC_60599-Output" width="95%" />
</p>

Explore the example file to get a better understanding of how these two functions work together.
Expand Down
9 changes: 9 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# xDGA

## Version 0.4
### August 2017

#### xDGA.CORE
* Added Rogers Ratios algorithm

#### xDGA.ADDIN
* Added ROGERSRATIOS() funciton

## Version 0.3
### August 2017

Expand Down
25 changes: 25 additions & 0 deletions xDGA.ADDIN/AlgorithmFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,30 @@ public class AlgorithmFunctions
return ex.Message;
}
}

[ExcelFunction(Description = "Using the supplied DGA data it calculates the Rogers Ratios.")]
public static object ROGERSRATIOS(
[ExcelArgument(Description = "The Dissolved Gas Analysis that will be assessed.")]
string dga)
{
try
{
var algo = new RogersRatiosAlgorithm(dga);
algo.Execute();

var output = new StringBuilder();

foreach (var item in algo.Outputs)
{
output.AppendLine($"[ {item.Name} => {item.Description} ]");
}

return output.ToString();
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
66 changes: 66 additions & 0 deletions xDGA.CORE/Algorithms/RogersRatios/RogersRatiosAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// The MIT License (MIT)
//
// Copyright (c) 2017 Carlos Gamez
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using xDGA.CORE.Models;

namespace xDGA.CORE.Algorithms
{
public class RogersRatiosAlgorithm : AbstractAlgorithm
{
public override string Version => "Rogers Ratios as described in IEEE C57.104";

/// <summary>
/// The Dissolved Gas Analysis that will be used in the assessment.
/// </summary>
public DissolvedGasAnalysis DGA { get; internal set; }

/// <summary>
/// Creates a new RogersRatioAlgorithm instance.
/// </summary>
/// <param name="dga">The JSON serialsed DGA data.</param>
public RogersRatiosAlgorithm(string dga)
{
DGA = new DissolvedGasAnalysis(dga);
}

public override void Execute()
{
var dga = DGA;
DissolvedGasAnalysis prevDga = null;
var outputs = Outputs;

Rules.Add(new ApplyDetectionLimitsRule());
Rules.Add(new RogersRatiosRule());

// Create a Title output
outputs.Add(new Output() { Name = "Title", Description = $"Interpretation of Dissolved Gas Analysis as per {Version}" });

foreach (var rule in Rules)
{
rule.Execute(ref dga, ref prevDga, ref outputs);
}

Outputs = outputs;
}
}
}
78 changes: 78 additions & 0 deletions xDGA.CORE/Algorithms/RogersRatios/RogersRatiosRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// The MIT License (MIT)
//
// Copyright (c) 2017 Carlos Gamez
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using xDGA.CORE.Interfaces;
using xDGA.CORE.Models;
using Helper = xDGA.CORE.Algorithms.AlgorithmHelperCalculations;
using Ratio = xDGA.CORE.Models.GasRatios.Ratio;

namespace xDGA.CORE.Algorithms
{
public class RogersRatiosRule : IRule
{
private Dictionary<Ratio, double> _Ratios { get; set; } = new Dictionary<Ratio, double>();
public FailureType.Code FailureCode { get; set; } = FailureType.Code.NA;

public void Execute(ref DissolvedGasAnalysis currentDga, ref DissolvedGasAnalysis previousDga, ref List<IOutput> outputs)
{
CalculateRatios(currentDga);
FailureCode = CalculateFailureCode();
outputs.Add(new Output() { Name = GasRatios.Description[Ratio.AcetyleneToEthylene], Description = _Ratios[Ratio.AcetyleneToEthylene].ToString("0.000") });
outputs.Add(new Output() { Name = GasRatios.Description[Ratio.MethaneToHydrogen], Description = _Ratios[Ratio.MethaneToHydrogen].ToString("0.000") });
outputs.Add(new Output() { Name = GasRatios.Description[Ratio.EthyleneToEthane], Description = _Ratios[Ratio.EthyleneToEthane].ToString("0.000") });
outputs.Add(new Output() { Name = "Rogers Ratio Failure Code", Description = FailureType.Description[FailureCode] });
}

public bool IsApplicable(DissolvedGasAnalysis currentDga, DissolvedGasAnalysis previousDga, List<IOutput> outputs)
{
return currentDga != null && currentDga.Ethylene != null && currentDga.Hydrogen != null && currentDga.Methane != null && currentDga.Ethane != null && currentDga.Acetylene != null;
}

private void CalculateRatios(DissolvedGasAnalysis dga)
{
_Ratios.Clear();
_Ratios.Add(Ratio.AcetyleneToEthylene, (double)Helper.GasRatio(dga.Acetylene, dga.Ethylene));
_Ratios.Add(Ratio.MethaneToHydrogen, (double)Helper.GasRatio(dga.Methane, dga.Hydrogen));
_Ratios.Add(Ratio.EthyleneToEthane, (double)Helper.GasRatio(dga.Ethylene, dga.Ethane));
}

private FailureType.Code CalculateFailureCode()
{
var code = FailureType.Code.NA;

if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] > 0.1 && _Ratios[Ratio.MethaneToHydrogen] < 1.0 && _Ratios[Ratio.EthyleneToEthane] < 1.0) code = FailureType.Code.N;

if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] < 0.1 && _Ratios[Ratio.EthyleneToEthane] < 1.0) code = FailureType.Code.PD;

if (_Ratios[Ratio.AcetyleneToEthylene] >= 0.1 && _Ratios[Ratio.AcetyleneToEthylene] <= 3.0 && _Ratios[Ratio.MethaneToHydrogen] >= 0.1 && _Ratios[Ratio.MethaneToHydrogen] <= 1.0 && _Ratios[Ratio.EthyleneToEthane] > 3.0) code = FailureType.Code.D2;

if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] > 0.1 && _Ratios[Ratio.MethaneToHydrogen] < 1.0 && _Ratios[Ratio.EthyleneToEthane] >= 1.0 && _Ratios[Ratio.EthyleneToEthane] <= 3.0) code = FailureType.Code.T1;

if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] > 0.1 && _Ratios[Ratio.EthyleneToEthane] >= 1.0 && _Ratios[Ratio.EthyleneToEthane] <= 3.0) code = FailureType.Code.T2;

if (_Ratios[Ratio.AcetyleneToEthylene] < 0.1 && _Ratios[Ratio.MethaneToHydrogen] > 0.1 && _Ratios[Ratio.EthyleneToEthane] >= 3.0) code = FailureType.Code.T3;

return code;
}
}
}
2 changes: 2 additions & 0 deletions xDGA.CORE/Models/FailureType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static class FailureType
/// </summary>
public enum Code
{
N,
PD,
D1,
D2,
Expand Down Expand Up @@ -67,6 +68,7 @@ public enum Code
{
return new Dictionary<Code, string>()
{
{ Code.N, "N => Normal Operation" },
{ Code.PD, "PD => Partial Discharges" },
{ Code.D1, "D1 => Discharges of low energy" },
{ Code.D2, "D2 => Discharges of high energy" },
Expand Down
91 changes: 91 additions & 0 deletions xDGA.CORE/Models/GasRatios.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// The MIT License (MIT)
//
// Copyright (c) 2017 Carlos Gamez
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;

namespace xDGA.CORE.Models
{
public static class GasRatios
{
public enum Ratio
{
HydrogenToMethane,
HydrogenToEthane,
HydrogenToEthylene,
HydrogenToAcetylene,
MethaneToHydrogen,
MethaneToEthane,
MethaneToEthylene,
MethaneToAcetylene,
EthaneToHydrogen,
EthaneToMethane,
EthaneToEthylene,
EthaneToAcetylene,
EthyleneToHydrogen,
EthyleneToMethane,
EthyleneToEthane,
EthyleneToAcetylene,
AcetyleneToHydrogen,
AcetyleneToMethane,
AcetyleneToEthane,
AcetyleneToEthylene,
CarbonMonoxideToCarbonDioxide,
CarbonDioxideToCarbonMonoxide,
NitrogenToOxygen,
OxygenToNitrogen
}

public static Dictionary<Ratio, string> Description
{
get
{
return new Dictionary<Ratio, string>()
{
{ Ratio.HydrogenToMethane, "H2/CH4" },
{ Ratio.HydrogenToEthane, "H2/C2H6" },
{ Ratio.HydrogenToEthylene, "H2/C2H4" },
{ Ratio.HydrogenToAcetylene, "H2/C2H2" },
{ Ratio.MethaneToHydrogen, "CH4/H2" },
{ Ratio.MethaneToEthane, "CH4/C2H6" },
{ Ratio.MethaneToEthylene, "CH4/C2H4" },
{ Ratio.MethaneToAcetylene, "CH4/C2H2" },
{ Ratio.EthaneToHydrogen, "C2H6/H2" },
{ Ratio.EthaneToMethane, "C2H6/CH4" },
{ Ratio.EthaneToEthylene, "C2H6/C2H4" },
{ Ratio.EthaneToAcetylene, "C2H6/C2H2" },
{ Ratio.EthyleneToHydrogen, "C2H4/H2" },
{ Ratio.EthyleneToMethane, "C2H4/CH4" },
{ Ratio.EthyleneToEthane, "C2H4/C2H6" },
{ Ratio.EthyleneToAcetylene, "C2H4/C2H2" },
{ Ratio.AcetyleneToHydrogen, "C2H2/H2" },
{ Ratio.AcetyleneToMethane, "C2H2/CH4" },
{ Ratio.AcetyleneToEthane, "C2H2/C2H6" },
{ Ratio.AcetyleneToEthylene, "C2H2/C2H4" },
{ Ratio.CarbonMonoxideToCarbonDioxide, "CO/CO2" },
{ Ratio.CarbonDioxideToCarbonMonoxide, "CO2/CO" },
{ Ratio.NitrogenToOxygen, "N2/O2" },
{ Ratio.OxygenToNitrogen, "O2/N2" }
};
}
}
}
}
3 changes: 3 additions & 0 deletions xDGA.CORE/xDGA.CORE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<Compile Include="Algorithms\IEC60599\OxygenToNitrogenRatioRule.cs" />
<Compile Include="Algorithms\IEC60599\RateOfChangeRule.cs" />
<Compile Include="Algorithms\IEEEC57104Algorithm.cs" />
<Compile Include="Algorithms\RogersRatios\RogersRatiosAlgorithm.cs" />
<Compile Include="Algorithms\RogersRatios\RogersRatiosRule.cs" />
<Compile Include="Interfaces\IOutput.cs" />
<Compile Include="Interfaces\IRule.cs" />
<Compile Include="Models\Area.cs" />
Expand All @@ -84,6 +86,7 @@
<Compile Include="Models\PolygonalCoordinate.cs" />
<Compile Include="Models\PolygonalOrdinate.cs" />
<Compile Include="Models\PolygonalAxis.cs" />
<Compile Include="Models\GasRatios.cs" />
<Compile Include="Models\Vector.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\ConcentrationUnitConverter.cs" />
Expand Down
6 changes: 0 additions & 6 deletions xDGA.TEST/DissolvedG.cs

This file was deleted.

0 comments on commit bca1780

Please sign in to comment.