public static AgainstBadArgument ( string parameterName, ArgumentComparator testForFailure, string failureMessage ) : void | ||
parameterName | string | The name of the parameter within the calling method. |
testForFailure | ArgumentComparator | A comparator which returns true if this method is to throw an error |
failureMessage | string | A custom message to provide with the exception. |
return | void |
/// <summary> /// /// </summary> /// <param name="other"></param> /// <returns></returns> public KeyedVector <TKey> CrossProduct(KeyedVector <TKey> other) { Guard.AgainstNullArgument(other, "other"); Guard.AgainstBadArgument( "other", () => { return(other.Count != 3); }, "Cross product can only be carried out with a 3 dimensional vector"); Guard.AgainstInvalidState( () => { return(this.Count != 3); }, "Cross product can only be carried out with a 3 dimensional vector. Number of dimensions of this vectors are {0}", this.Count); KeyCompatibilityValidator <TKey, TKey> kcv = new KeyCompatibilityValidator <TKey, TKey>(this.Keys, other.Keys); kcv.ThrowIfInvalid(); ////TODO If the keys match but are in the wrong order, swap the other vector items and keys to match exactly IList <TKey> keyz = this.Keys; TKey key0 = keyz[0]; TKey key1 = keyz[1]; TKey key2 = keyz[2]; KeyedVector <TKey> result = new KeyedVector <TKey>(keyz); result[key0] = (this[key1] * other[key2]) - (this[key2] * other[key1]); result[key1] = (this[key2] * other[key0]) - (this[key0] * other[key2]); result[key2] = (this[key0] * other[key1]) - (this[key1] * other[key0]); return(result); }
/// <summary> /// Creates a new keyed matrix from keyed vectors representing the rows of the new matrix /// </summary> /// <param name="axis1">The vector representing the first row</param> /// <param name="axis2">The vector representing the second row</param> /// <param name="axis3">The vector representing the third row</param> /// <returns>A matrix built from the vectors</returns> protected static KeyedSquareMatrix <DegreeOfFreedom> CreateFromRows(KeyedVector <DegreeOfFreedom> axis1, KeyedVector <DegreeOfFreedom> axis2, KeyedVector <DegreeOfFreedom> axis3) { ////TODO this should be devolved to the KeyedMatrix class Guard.AgainstBadArgument( "axis1", () => { return(axis1.Count != 3); }, "All axes should be 3D, i.e. have 3 items"); Guard.AgainstBadArgument( "axis2", () => { return(axis2.Count != 3); }, "All axes should be 3D, i.e. have 3 items"); Guard.AgainstBadArgument( "axis3", () => { return(axis3.Count != 3); }, "All axes should be 3D, i.e. have 3 items"); Guard.AgainstBadArgument( "axis1", () => { return(axis1.SumMagnitudes().IsApproximatelyEqualTo(0.0)); }, string.Format( System.Globalization.CultureInfo.InvariantCulture, "Axis should not be zero: {0}", axis1)); Guard.AgainstBadArgument( "axis2", () => { return(axis2.SumMagnitudes().IsApproximatelyEqualTo(0.0)); }, string.Format( System.Globalization.CultureInfo.InvariantCulture, "Axis should not be zero: {0}", axis2)); Guard.AgainstBadArgument( "axis3", () => { return(axis3.SumMagnitudes().IsApproximatelyEqualTo(0.0)); }, string.Format( System.Globalization.CultureInfo.InvariantCulture, "Axis should not be zero: {0}", axis3)); KeyedVector <DegreeOfFreedom> axis1Norm = axis1.Normalize(2); KeyedVector <DegreeOfFreedom> axis2Norm = axis2.Normalize(2); KeyedVector <DegreeOfFreedom> axis3Norm = axis3.Normalize(2); IList <DegreeOfFreedom> dof = new List <DegreeOfFreedom>(3) { DegreeOfFreedom.X, DegreeOfFreedom.Y, DegreeOfFreedom.Z }; KeyedSquareMatrix <DegreeOfFreedom> result = new KeyedSquareMatrix <DegreeOfFreedom>(dof); result.At(DegreeOfFreedom.X, DegreeOfFreedom.X, axis1Norm[DegreeOfFreedom.X]); result.At(DegreeOfFreedom.X, DegreeOfFreedom.Y, axis1Norm[DegreeOfFreedom.Y]); result.At(DegreeOfFreedom.X, DegreeOfFreedom.Z, axis1Norm[DegreeOfFreedom.Z]); result.At(DegreeOfFreedom.Y, DegreeOfFreedom.X, axis2Norm[DegreeOfFreedom.X]); result.At(DegreeOfFreedom.Y, DegreeOfFreedom.Y, axis2Norm[DegreeOfFreedom.Y]); result.At(DegreeOfFreedom.Y, DegreeOfFreedom.Z, axis2Norm[DegreeOfFreedom.Z]); result.At(DegreeOfFreedom.Z, DegreeOfFreedom.X, axis3Norm[DegreeOfFreedom.X]); result.At(DegreeOfFreedom.Z, DegreeOfFreedom.Y, axis3Norm[DegreeOfFreedom.Y]); result.At(DegreeOfFreedom.Z, DegreeOfFreedom.Z, axis3Norm[DegreeOfFreedom.Z]); return(result); }
/// <summary> /// /// </summary> /// <param name="height"></param> /// <param name="width"></param> public GenericCrossSection(double sectionArea) : this(sectionArea, 0, 0, 0, true) { Guard.AgainstBadArgument("sectionArea", () => { return(sectionArea <= 0); }, "sectionArea has to be a positive, non-zero number"); }
/// <summary> /// Allows a force vector to be applied to a specific finite element node. /// </summary> /// <param name="forceToApply">The force vector to apply to the node</param> /// <param name="nodeToApplyTo">The node to which the force will be applied.</param> /// <exception cref="ArgumentException">The force has not previous been registered with this repository. The force needs to have been created via an instance of the ForceFactory class which was initialized with this repository as a parameter"</exception> public void ApplyForceToNode(ForceVector forceToApply, IFiniteElementNode nodeToApplyTo) { Guard.AgainstBadArgument( "forceToApply", () => { return(!this.Contains(forceToApply)); }, "The force has not previously been registered with this repository. The force needs to have been created via an instance of the ForceFactory class which was initialized with this repository as a parameter"); this.nodalForces.Add(nodeToApplyTo, forceToApply); }
/// <summary> /// Gets the key of an item /// </summary> /// <param name="item">The item for which we wish to search for the key</param> /// <returns>the key for the item</returns> public Key KeyOfValue(Value item) { Guard.AgainstBadArgument( "item", () => { return(!this.reverseIndex.ContainsKey(item)); }, "The item is not contained by any key in this UniqueIndex"); return(this.reverseIndex[item]); }
/// <summary> /// Registers a new item in the repository /// </summary> /// <param name="item">The item to register in this repository</param> public void Add(T item) { Guard.AgainstBadArgument( "item", () => { return(this.Contains(item)); }, "This repository already contains the item. Duplicate items cannot be added to a repository"); this.InternalStore.Add(item); this.AddToRepository(item); }
public GenericCrossSection(double sectionArea, double sectionSecondMomentOfAreaAroundYY) : this(sectionArea, sectionSecondMomentOfAreaAroundYY, 0, 0, true) { Guard.AgainstBadArgument("sectionArea", () => { return(sectionArea <= 0); }, "sectionArea has to be a positive, non-zero number"); Guard.AgainstBadArgument("sectionSecondMomentOfAreaAroundYY", () => { return(sectionSecondMomentOfAreaAroundYY <= 0); }, "sectionSecondMomentOfAreaAroundYY has to be a positive, non-zero number"); }
/// <summary> /// /// </summary> /// <param name="node0"></param> /// <param name="node1"></param> /// <param name="node2"></param> /// <param name="elementMaterial"></param> /// <param name="elementThickness"></param> public LinearConstantStrainTriangle(IFiniteElementNode node0, IFiniteElementNode node1, IFiniteElementNode node2, IMaterial elementMaterial, double elementThickness) { this.AddNode(node0); this.AddNode(node1); this.AddNode(node2); Guard.AgainstNullArgument(elementMaterial, "elementMaterial"); Guard.AgainstBadArgument( "elementThickness", () => { return(elementThickness <= 0); }, "thickness has to be greater than zero"); this.Material = elementMaterial; this.Thickness = elementThickness; }
/// <summary> /// /// </summary> /// <param name="node0"></param> /// <param name="node1"></param> /// <param name="node2"></param> /// <param name="node3"></param> /// <param name="mat"></param> /// <param name="elementThickness"></param> public LinearConstantStressQuadrilateral(IFiniteElementNode node0, IFiniteElementNode node1, IFiniteElementNode node2, IFiniteElementNode node3, IMaterial mat, double elementThickness) { this.AddNode(node0); this.AddNode(node1); this.AddNode(node2); this.AddNode(node3); Guard.AgainstNullArgument(mat, "mat"); Guard.AgainstBadArgument( "t", () => { return(elementThickness <= 0); }, "thickness has to be greater than zero"); this.Material = mat; this.Thickness = elementThickness; }
public GenericCrossSection(double sectionArea, double sectionSecondMomentOfAreaAroundYY, double sectionSecondMomentOfAreaAroundZZ, double sectionMomentOfInertiaInTorsion) : this(sectionArea, sectionSecondMomentOfAreaAroundYY, sectionSecondMomentOfAreaAroundZZ, sectionMomentOfInertiaInTorsion, true) { Guard.AgainstBadArgument("sectionArea", () => { return(sectionArea <= 0); }, "sectionArea has to be a positive, non-zero number"); Guard.AgainstBadArgument("sectionSecondMomentOfAreaAroundYY", () => { return(sectionSecondMomentOfAreaAroundYY <= 0); }, "sectionSecondMomentOfAreaAroundYY has to be a positive, non-zero number"); Guard.AgainstBadArgument("sectionSecondMomentOfAreaAroundZZ", () => { return(sectionSecondMomentOfAreaAroundZZ <= 0); }, "sectionSecondMomentOfAreaAroundZZ has to be a positive, non-zero number"); Guard.AgainstBadArgument("sectionMomentOfInertiaInTorsion", () => { return(sectionMomentOfInertiaInTorsion <= 0); }, "sectionMomentOfInertiaInTorsion has to be a positive, non-zero number"); }
/// <summary> /// Replaces the keys with the provided lists. /// First checks that the lists are reasonably valid (does not check for duplicate keys, however) /// </summary> /// <param name="keysForVector">The keys to replace the Keys property with</param> private void InitializeKeysAndData(IList <TKey> keysForVector, double[] values) { Guard.AgainstNullArgument(keysForVector, "keysForVector"); Guard.AgainstNullArgument(values, "values"); Guard.AgainstBadArgument( "keysForVector", () => { return(values.Length != keysForVector.Count); }, "The number of items in the keys list should match the number of value items"); this.store.Clear(); int numKeys = keysForVector.Count; for (int i = 0; i < numKeys; i++) { this.store.Add(keysForVector[i], values[i]); } }
protected KeyedRowColumnMatrix(IDictionary <TRowKey, int> rows, IDictionary <TColumnKey, int> columns, Matrix <double> dataToCopy) { Guard.AgainstNullArgument(rows, "rows"); Guard.AgainstNullArgument(columns, "columns"); Guard.AgainstNullArgument(dataToCopy, "dataToCopy"); Guard.AgainstBadArgument( "rows", () => { return(rows.Count != dataToCopy.RowCount); }, "Number of row keys does not equal the number of rows in the underlying data"); Guard.AgainstBadArgument( "columns", () => { return(columns.Count != dataToCopy.ColumnCount); }, "Number of column keys does not equal the number of columns in the underlying data"); this.keysForRows = new Dictionary <TRowKey, int>(rows); this.keysForColumns = new Dictionary <TColumnKey, int>(columns); this.underlyingMatrix = dataToCopy.Clone(); }