Skip to content

Commit

Permalink
Added Duval Pentagons Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
code-recipes committed Aug 10, 2017
1 parent d5ecf98 commit d7291ff
Show file tree
Hide file tree
Showing 29 changed files with 1,437 additions and 3 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.
15 changes: 14 additions & 1 deletion VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# xDGA

## Version 0.1
### July 2017

* First version released
* Includes two functions: SERIALIZEDGA() and IEC_60599()
* Uses [ExcelDna](https://excel-dna.net/) and [Json.NET](http://www.newtonsoft.com/json)

## Version 0.2
### July 2017

* Added Duval Triangles for Transformers, Reactors, Cables and On-Load Tap Changers
* Refactored some functions
* Added Failure Types (Codes and Descriptions) for OLTCs
* Added Failure Types (Codes and Descriptions) for OLTCs

## Version 0.3
### August 2017

#### xDGA.CORE
* Implemented Pentagonal coordinate systems and transformation functions
* Implemented tests for every Duval Triangle and Pentagone Zone
* Added Duval Pentagons algorithm

#### xDGA.ADDIN
* Added DUVALPENTAGONS() function
25 changes: 25 additions & 0 deletions xDGA.ADDIN/AlgorithmFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,30 @@ public static object DUVALTRIANGLES_OLTC(
return ex.Message;
}
}

[ExcelFunction(Description = "Using the supplied DGA data it calculates the outputs (zones) of the two Duval Pentagons.")]
public static object DUVALPENTAGONS(
[ExcelArgument(Description = "The Dissolved Gas Analysis that will be assessed.")]
string dga)
{
try
{
var algo = new DuvalPentagonsAlgorithm(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;
}
}
}
}
113 changes: 113 additions & 0 deletions xDGA.CORE/Algorithms/DuvalPentagons/AbstractDuvalPentagonRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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 System.Collections.Generic;
using System.Linq;
using xDGA.CORE.Interfaces;
using xDGA.CORE.Models;
using xDGA.CORE.Units;

namespace xDGA.CORE.Algorithms
{
public abstract class AbstractDuvalPentagonRule : IRule
{
internal string PentagonName { get; set; }
internal EquilateralPentagon Pentagon { get; set; }
internal Dictionary<Gas, IMeasurement> GasMeasurements { get; set; } = new Dictionary<Gas, IMeasurement>();
internal Dictionary<Gas, double> GasPercentages { get; set; } = new Dictionary<Gas, double>();

public FailureType.Code FailureCode { get; set; } = FailureType.Code.NA;

/// <summary>
/// Creates a new instance of a Duval Pentagon.
/// Specify gases in counter clock-wise order starting at 12 o'oclock position.
/// </summary>
public AbstractDuvalPentagonRule(string name, Gas hydrogen, Gas ethane, Gas methane, Gas ethylene, Gas acetylene)
{
PentagonName = name;

Pentagon = new EquilateralPentagon(
new PolygonalAxis(hydrogen.ToString(), new Measurement() { Value = 90.0, Unit = new AngleUnits.Degrees() }),
new PolygonalAxis(ethane.ToString(), new Measurement() { Value = 162.0, Unit = new AngleUnits.Degrees() }),
new PolygonalAxis(methane.ToString(), new Measurement() { Value = 234.0, Unit = new AngleUnits.Degrees() }),
new PolygonalAxis(ethylene.ToString(), new Measurement() { Value = 306.0, Unit = new AngleUnits.Degrees() }),
new PolygonalAxis(acetylene.ToString(), new Measurement() { Value = 18.0, Unit = new AngleUnits.Degrees() }));

GasMeasurements.Add(hydrogen, null);
GasMeasurements.Add(ethane, null);
GasMeasurements.Add(methane, null);
GasMeasurements.Add(ethylene, null);
GasMeasurements.Add(acetylene, null);

GasPercentages.Add(hydrogen, 0.0);
GasPercentages.Add(ethane, 0.0);
GasPercentages.Add(methane, 0.0);
GasPercentages.Add(ethylene, 0.0);
GasPercentages.Add(acetylene, 0.0);
}

public virtual void Execute(ref DissolvedGasAnalysis currentDga, ref DissolvedGasAnalysis previousDga, ref List<IOutput> outputs)
{
FindGases(currentDga);

CalculatePercentages(currentDga);

var coordinate = Pentagon.AddDataPoint(GasPercentages[Gas.Hydrogen], GasPercentages[Gas.Ethane], GasPercentages[Gas.Methane], GasPercentages[Gas.Ethylene], GasPercentages[Gas.Acetylene]);

FailureCode = Pentagon.GetFaultCodeForDataPoint(coordinate);

outputs.Add(new Output() { Name = PentagonName, Description = FailureType.Description[FailureCode] });
}

public virtual bool IsApplicable(DissolvedGasAnalysis currentDga, DissolvedGasAnalysis previousDga, List<IOutput> outputs)
{
FindGases(currentDga);
return GasMeasurements.All(g => g.Value != null);
}

public double TotalGases()
{
return GasMeasurements.Sum(g => { return g.Value.Value; });
}

internal void FindGases(DissolvedGasAnalysis dga)
{
foreach (var gas in GasPercentages)
{
GasMeasurements[gas.Key] = (IMeasurement)dga.GetType().GetProperty(gas.Key.ToString()).GetValue(dga);
}
}

internal void CalculatePercentages(DissolvedGasAnalysis dga)
{
double total = TotalGases();
double gasPercentage = 0.0;

foreach (var gas in GasMeasurements)
{
gasPercentage = (GasMeasurements[gas.Key].Value * 100.0) / total;
GasPercentages[gas.Key] = gasPercentage;
}
}
}
}
113 changes: 113 additions & 0 deletions xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonOneRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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 xDGA.CORE.Models;

namespace xDGA.CORE.Algorithms
{
public class DuvalPentagonOneRule : AbstractDuvalPentagonRule
{
public DuvalPentagonOneRule() : base("Duval Pentagon 1", Gas.Hydrogen, Gas.Ethane, Gas.Methane, Gas.Ethylene, Gas.Acetylene)
{
Pentagon.Areas.Add(new Area(FailureType.Code.PD)
{
Coordinates =
{
new CartesianCoordinate(0.0, 33.0),
new CartesianCoordinate(-1.0, 33.0),
new CartesianCoordinate(-1.0, 24.5),
new CartesianCoordinate(0.0, 24.5)
}
});

Pentagon.Areas.Add(new Area(FailureType.Code.D1)
{
Coordinates =
{
new CartesianCoordinate(0.0, 40.0),
new CartesianCoordinate(38.0, 12.0),
new CartesianCoordinate(32.0, -6.0),
new CartesianCoordinate(4.0, 16.0),
new CartesianCoordinate(0.0, 1.5)
}
});

Pentagon.Areas.Add(new Area(FailureType.Code.D2)
{
Coordinates =
{
new CartesianCoordinate(4.0, 16.0),
new CartesianCoordinate(32.0, -6.0),
new CartesianCoordinate(24.0, -30.0),
new CartesianCoordinate(-1.0, -2.0)
}
});

Pentagon.Areas.Add(new Area(FailureType.Code.T3)
{
Coordinates =
{
new CartesianCoordinate(24.0, -30.0),
new CartesianCoordinate(1.0, -32.0),
new CartesianCoordinate(-6.0, -4.0),
new CartesianCoordinate(-1.0, -2.0)
}
});

Pentagon.Areas.Add(new Area(FailureType.Code.T2)
{
Coordinates =
{
new CartesianCoordinate(1.0, -32.0),
new CartesianCoordinate(-22.5, -32.0),
new CartesianCoordinate(-6.0, -4.0)
}
});

Pentagon.Areas.Add(new Area(FailureType.Code.T1)
{
Coordinates =
{
new CartesianCoordinate(0.0, 1.5),
new CartesianCoordinate(-35.0, 3.0),
new CartesianCoordinate(-22.5, -32.0),
new CartesianCoordinate(-6.0, -4.0),
new CartesianCoordinate(-1.0, -2.0)
}
});

Pentagon.Areas.Add(new Area(FailureType.Code.S)
{
Coordinates =
{
new CartesianCoordinate(-35.0, 3.0),
new CartesianCoordinate(0.0, 1.5),
new CartesianCoordinate(0.0, 24.5),
new CartesianCoordinate(-1.0, 24.5),
new CartesianCoordinate(-1.0, 33.0),
new CartesianCoordinate(0.0, 33.0),
new CartesianCoordinate(0.0, 40.0)
}
});
}
}
}
Loading

0 comments on commit d7291ff

Please sign in to comment.