using System; using System.Collections.Generic; using Deltares.Mathematics; namespace Deltares.Stability.Calculation.Inner { public class TShearStressTable { private List distance = new List(); private int nPoints; private string shearStressTableName = String.Empty; private List sigma = new List(); //Constructor Create() public TShearStressTable() { InitShearStressTable(); } public string ShearStressTableName { get { return shearStressTableName; } set { shearStressTableName = value; } } public int NPoints { get { return nPoints; } set { nPoints = value; } } public double GetDistance(int aIndex) { double result; if (((aIndex >= 0) && (aIndex < distance.Count))) { result = distance[aIndex]; } else { result = -1; } return result; } public double GetSigma(int aIndex) { double result; if ((aIndex >= 0) && (aIndex < sigma.Count)) { result = sigma[aIndex]; } else { result = -1; } return result; } public void SetDistance(int aIndex, double aValue) { if ((aIndex >= 0) && (aIndex < distance.Count)) { distance[aIndex] = aValue; } else if ((aIndex <= distance.Count)) { nPoints = aIndex + 1; distance.Add(aValue); } } public void SetSigma(int aIndex, double aValue) { if ((aIndex >= 0) && (aIndex < sigma.Count)) { sigma[aIndex] = aValue; } else if ((aIndex <= sigma.Count)) { nPoints = aIndex + 1; sigma.Add(aValue); } } public string IsValid(bool aPseudo) { var error = string.Empty; var validSigma = true; var validSize = (sigma.Count == nPoints) && (distance.Count == nPoints); if (!validSize) { error = error + "Dimensions in shearstresstable are not equal " + '\r'; } if (Math.Abs(GetSigma(0)) >= StressTable.CDiff) { error = error + "First sigma value is not zero " + '\r'; } var counter = 1; while ((counter <= nPoints - 1)) { validSigma = validSigma && (sigma[counter] - sigma[counter - 1] > StressTable.CDiff); counter ++; } if (!validSigma) { error = error + "Values Sigma are not increasing " + '\r'; } if (nPoints == 1) { error = error + "Table has only 1 point " + '\r'; } return error; } public void Copy(TShearStressTable copy) { if (copy == null) { return; } ShearStressTableName = copy.ShearStressTableName; NPoints = copy.NPoints; sigma = new List(); distance = new List(); for (var counter = 0; counter < copy.NPoints; counter++) { SetDistance(counter, copy.GetDistance(counter)); SetSigma(counter, copy.GetSigma(counter)); } } public double RetrieveYatX(double ax) { double result = 0; if (distance.Count > 1) { int pointIndex = 1; // Find the X Value while ((pointIndex < distance.Count - 1) && (ax > distance[pointIndex])) { pointIndex++; } if (ax > distance[pointIndex]) { // Last point exceeded result = sigma[pointIndex]; } else { // Interpolation result = Routines2D.LinInpolY(distance[pointIndex - 1], sigma[pointIndex - 1], distance[pointIndex], sigma[pointIndex], ax); } } else { if (distance.Count == 1) { result = sigma[0]; } } return result; } private void InitShearStressTable() { nPoints = 0; shearStressTableName = ""; } } }