/// <summary> /// See <see cref="IIndexable2D.Equals(IIndexable2D, double)"/>. /// </summary> public bool Equals(IIndexable2D other, double tolerance = 1e-13) { if ((this.NumRows != other.NumRows) || (this.NumColumns != other.NumColumns)) { return(false); } var comparer = new ValueComparer(1e-13); for (int j = 0; j < NumColumns; ++j) { int colStart = colOffsets[j]; // Inclusive int colEnd = colOffsets[j + 1]; // Exclusive int previousRow = 0; for (int k = colStart; k < colEnd; ++k) { int row = rowIndices[k]; for (int i = previousRow; i < row; ++i) // Zero entries between the stored ones { if (!comparer.AreEqual(0.0, other[i, j])) { return(false); } } if (!comparer.AreEqual(values[k], other[row, j])) { return(false); // Non zero entry } previousRow = row + 1; } } return(true); // At this point all entries have been checked and are equal }
public int Compare(CartesianPoint point1, CartesianPoint point2) { if (valueComparer.AreEqual(point1.X, point2.X)) { if (valueComparer.AreEqual(point1.Y, point2.Y)) { return(0); } else if (point1.Y < point2.Y) { return(-1); } else { return(1); } } else if (point1.X < point2.X) { return(-1); } else { return(1); } }
/// <summary> /// Returns true if this[i] - <paramref name="other"/>[i] is within the acceptable <paramref name="tolerance"/> for all /// 0 <= i < 3. /// </summary> /// <param name="other">The other vector that this <see cref="Vector3"/> instance will be compared to.</param> /// <param name="tolerance">The entries at index i of the two vectors will be considered equal, if /// (<paramref name="other"/>[i] - this[i]) / this[i] <= <paramref name="tolerance"/>. Setting /// <paramref name="tolerance"/> = 0, will check if these entries are exactly the same.</param> public bool Equals(Vector3 other, double tolerance = 1e-13) { var comparer = new ValueComparer(tolerance); return(comparer.AreEqual(this.data[0], other.data[0]) && comparer.AreEqual(this.data[1], other.data[1]) && comparer.AreEqual(this.data[2], other.data[2])); }
/// <summary> /// See <see cref="IIndexable1D.Equals(IIndexable1D, double)"/>. /// </summary> public bool Equals(IIndexable1D other, double tolerance = 1e-13) { if (this.Length != other.Length) { return(false); } var comparer = new ValueComparer(tolerance); int previousIndex = 0; for (int i = 0; i < indices.Length; ++i) { int index = indices[i]; for (int j = previousIndex; j < index; ++j) // zero entries between the stored ones { if (!comparer.AreEqual(0.0, other[j])) { return(false); } } if (!comparer.AreEqual(values[i], other[index])) { return(false); // Non zero entry } previousIndex = index + 1; } return(true); }
/// <summary> /// See <see cref="IIndexable1D.Equals(IIndexable1D, double)"/>. /// </summary> bool IIndexable1D.Equals(IIndexable1D other, double tolerance) { if (other.Length != 2) { return(false); } else { var comparer = new ValueComparer(tolerance); return(comparer.AreEqual(this.data[0], other[0]) && comparer.AreEqual(this.data[1], other[1])); } }
private static bool CompareResults(IVectorView solution) { var comparer = new ValueComparer(2E-2); // dofs: 1, 2, 4, 5, 7, 8 var expectedSolution = Vector.CreateFromArray(new double[] { 0.999035307401193, 0.997371094382290, 0.993518945712248, 0.985437312426501, 0.970000503922635, 0.943065362762755, 0.900046845798943, 0.837421108911808, 0.753470801649483, 0.488434721438016 }); int numFreeDofs = 10; if (solution.Length != 10) { return(false); } for (int i = 0; i < numFreeDofs; ++i) { if (!comparer.AreEqual(expectedSolution[i], solution[i])) { return(false); } } return(true); }
static void Main(string[] args) { var cat1 = new Cat() { Head = "head", Tail = "tail" }; var cat2 = new Cat() { Head = "head", Tail = "tail" }; var result = ValueComparer.AreEqual(cat1, cat2); }
public static bool AreDisplacementsSame(int[] expectedValues, int[] computedValues) { var comparer = new ValueComparer(1E-14); for (int i1 = 0; i1 < expectedValues.GetLength(0); i1++) { if (!comparer.AreEqual(expectedValues[i1], computedValues[i1])) { return(false); } } return(true); }
private static bool AreDisplacementsSame(double[] expectedDisplacements, double[] computedDisplacements) { var comparer = new ValueComparer(1E-3); for (int i = 0; i < expectedDisplacements.Length; i++) { if (!comparer.AreEqual(expectedDisplacements[i], computedDisplacements[i])) { return(false); } } return(true); }
private static bool AreDisplacementsSame(IReadOnlyList <Dictionary <int, double> > expectedDisplacements, TotalDisplacementsPerIterationLog computedDisplacements) { var comparer = new ValueComparer(1E-13); for (int iter = 0; iter < expectedDisplacements.Count; ++iter) { foreach (int dof in expectedDisplacements[iter].Keys) { if (!comparer.AreEqual(expectedDisplacements[iter][dof], computedDisplacements.GetTotalDisplacement(iter, subdomainID, dof))) { return(false); } } } return(true); }
public static bool AreDisplacementsSame(double[,] expectedValues, double[,] computedValues) { var comparer = new ValueComparer(1E-8); for (int i1 = 0; i1 < expectedValues.GetLength(0); i1++) { for (int i2 = 0; i2 < expectedValues.GetLength(1); i2++) { if (!comparer.AreEqual(expectedValues[i1, i2], computedValues[i1, i2])) { return(false); } } } return(true); }
/// <summary> /// See <see cref="IIndexable2D.Equals(IIndexable2D, double)"/>. /// </summary> public bool Equals(IIndexable2D other, double tolerance = 1e-13) { var comparer = new ValueComparer(1e-13); if (other is Matrix2by2 casted) { return(comparer.AreEqual(this.data[0, 0], casted.data[0, 0]) && comparer.AreEqual(this.data[0, 1], casted.data[0, 1]) && comparer.AreEqual(this.data[1, 0], casted.data[1, 0]) && comparer.AreEqual(this.data[1, 1], casted.data[1, 1])); } else { return(comparer.AreEqual(this.data[0, 0], other[0, 0]) && comparer.AreEqual(this.data[0, 1], other[0, 1]) && comparer.AreEqual(this.data[1, 0], other[1, 0]) && comparer.AreEqual(this.data[1, 1], other[1, 1])); } }
private static bool AreDisplacementsSame(IReadOnlyList <Dictionary <int, double> > expectedDisplacements, TotalDisplacementsPerIterationLog computedDisplacements) { var comparer = new ValueComparer(1E-10); // for node major dof order and skyline solver //var comparer = new ValueComparer(1E-3); // for other solvers. It may require adjusting after visual inspection for (int iter = 0; iter < expectedDisplacements.Count; ++iter) { foreach (int dof in expectedDisplacements[iter].Keys) { if (!comparer.AreEqual(expectedDisplacements[iter][dof], computedDisplacements.GetTotalDisplacement(iter, subdomainID, dof))) { return(false); } } } return(true); }
private static bool CompareResults(IVectorView solution) { var comparer = new ValueComparer(1E-5); var expectedSolution = Vector.CreateFromArray(new double[] { 150, 200, 150, 200, 150, 200 }); int numFreeDofs = 6; if (solution.Length != 6) { return(false); } for (int i = 0; i < numFreeDofs; ++i) { if (!comparer.AreEqual(expectedSolution[i], solution[i])) { return(false); } } return(true); }
/// <summary> /// Returns true if <paramref name="matrix"/>[i, j] and <paramref name="matrix"/>[j, i] are equal or at least within the /// specified <paramref name="tolerance"/> for all 0 <= i < numRows, 0 <= j < numColumns. /// </summary> /// <param name="matrix">The matrix that will be checked for symmetry.</param> /// <param name="tolerance">The entries at (i, j), (j, i) the matrix will be considered equal, if /// (<paramref name="matrix"/>[i, j] - <paramref name="matrix"/>[i, j]) / <paramref name="matrix"/>[i, j] /// <= <paramref name="tolerance"/>. /// Setting <paramref name="tolerance"/> = 0, will check if these entries are exactly the same.</param> public static bool IsSymmetric(this double[,] matrix, double tolerance = double.Epsilon) //TODO: Move this to the array extensions file. { var comparer = new ValueComparer(tolerance); if (matrix.GetLength(0) != matrix.GetLength(1)) { return(false); } for (int i = 0; i < matrix.GetLength(0); ++i) { for (int j = 0; j < i; ++j) { if (!comparer.AreEqual(matrix[i, j], matrix[j, i])) { return(false); } } } return(true); }
private static bool CompareResults(IVectorView solution) { var comparer = new ValueComparer(1E-3); // dofs: 4, 5, 6, 7, 8, 9, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 26, 27 var expectedSolution = Vector.CreateFromArray(new double[] { 135.054, 158.824, 135.054, 469.004, 147.059, 159.327, 178.178, 147.299, 139.469, 147.059, 191.717, 147.059, 135.054, 158.824, 135.054, 469.004, 147.059, 159.327 }); int numFreeDofs = 18; if (solution.Length != 18) { return(false); } for (int i = 0; i < numFreeDofs; ++i) { if (!comparer.AreEqual(expectedSolution[i], solution[i])) { return(false); } } return(true); // original element node ordering solution //135.05402160864347 //158.8235294117647 //135.05402160864347 //469.00437594392588 //147.05882352941177 //159.32695658908725 //178.17836812144211 //147.29891956782711 //139.46869070208729 //147.05882352941174 //191.71668667466983 //147.05882352941177 //135.05402160864344 //158.82352941176467 //135.05402160864344 //469.00437594392588 //147.05882352941174 //159.32695658908719 }
private static bool CompareResults(IVectorView solution) { var comparer = new ValueComparer(1E-3); // dofs: 4, 5, 6, 7, 8, 9, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 26, 27 var expectedSolution = Vector.CreateFromArray(new double[] { 135.054, 158.824, 135.054, 469.004, 147.059, 159.327, 178.178, 147.299, 139.469, 147.059, 191.717, 147.059, 135.054, 158.824, 135.054, 469.004, 147.059, 159.327 }); int numFreeDofs = 18; if (solution.Length != 18) { return(false); } for (int i = 0; i < numFreeDofs; ++i) { if (!comparer.AreEqual(expectedSolution[i], solution[i])) { return(false); } } return(true); }
private static void RunAnalysisAndCheck(CantileverBeam benchmark, ISolver solver) { // Structural problem provider var provider = new ProblemStructural(benchmark.Model, solver); // Linear static analysis var childAnalyzer = new LinearAnalyzer(benchmark.Model, solver, provider); var parentAnalyzer = new StaticAnalyzer(benchmark.Model, solver, provider, childAnalyzer); // Run the analysis parentAnalyzer.Initialize(); parentAnalyzer.Solve(); // Check output double endDeflectionExpected = benchmark.CalculateEndDeflectionWithEulerBeamTheory(); double endDeflectionComputed = benchmark.CalculateAverageEndDeflectionFromSolution(solver.LinearSystems.First().Value.Solution); var comparer = new ValueComparer(1E-2); Assert.True(comparer.AreEqual(endDeflectionExpected, endDeflectionComputed)); }
/// <summary> /// See <see cref="IIndexable1D.Equals(IIndexable1D, double)"/>. /// </summary> public bool Equals(IIndexable1D other, double tolerance = 1e-13) { if (other is Vector casted) { if (this.Length != other.Length) { return(false); } var comparer = new ValueComparer(tolerance); for (int i = 0; i < Length; ++i) { if (!comparer.AreEqual(this.data[i], casted.data[i])) { return(false); } } return(true); } else { return(other.Equals(this, tolerance)); // To avoid accessing zero entries } }
private static bool Coincide(NaturalPoint point1, NaturalPoint point2) => comparer.AreEqual(point1.Xi, point2.Xi) && comparer.AreEqual(point1.Eta, point2.Eta);
internal bool AreEqual(double a, double b) => valueComparer.AreEqual(a, b);