/// <summary> /// Converts the given <paramref name="numberString"/> to its /// <see cref="TimestepNumber"/> equivalent. /// </summary> /// <param name="numberString"> /// The string, which should be converted. /// </param> /// <param name="Timestep"> /// The return value, if the conversion was successful. /// </param> /// <returns> /// Indicates, whether the conversion was successful. /// </returns> public static bool TryParse(string numberString, out TimestepNumber Timestep) { bool IsTimestepNumber = true; try { Timestep = new TimestepNumber(numberString); } catch (ArgumentException) { Timestep = null; IsTimestepNumber = false; } return(IsTimestepNumber); }
/// <summary> /// Compares two time-steps based on each individual number (cf. /// <see cref="TimestepNumber"/>) in order of their /// significance. /// </summary> /// <param name="other"> /// The time-step to be compared to /// </param> /// <returns> /// The result of the integer comparison of the sub-number with the /// highest significance for which the result is not zero. /// </returns> public int CompareTo(TimestepNumber other) { int length = Math.Min(this.numbers.Length, other.numbers.Length); // Decision based on existing entries for (int i = 0; i < length; i++) { int result = this.numbers[i].CompareTo(other.numbers[i]); if (result != 0) { return(result); } } // Still undecided? -> More indices = larger return(this.numbers.Length.CompareTo(other.numbers.Length)); }
/// <summary> /// Constructs information about a time-step with given /// <paramref name="fields"/>. /// </summary> /// <param name="physTime"> /// The physical time represented by this object /// </param> /// <param name="session"> /// The session this time-step belongs to /// </param> /// <param name="TimestepNo"> /// The number of the represented time-step /// </param> /// <param name="fields"> /// The fields associated with this time-step. /// </param> /// <param name="storageID"> /// <see cref="Guid"/> of the storage vector containing the serialized /// information stored in this object. /// </param> public TimestepInfo( double physTime, ISessionInfo session, TimestepNumber TimestepNo, IEnumerable <DGField> fields) { // check & set grid this.m_GridGuid = fields.Count() > 0 ? fields.First().Basis.GridDat.GridID : Guid.Empty; if (fields.Where(f => !f.Basis.GridDat.GridID.Equals(this.m_GridGuid)).Count() > 0) { throw new ArgumentException("all fields must be associated to the same grid."); } // check validity of identifications: { List <DGField> _Fields = new List <DGField>(); FlattenHierarchy(_Fields, fields); HashSet <string> allIdentifications = new HashSet <string>(new ilPSP.FuncEqualityComparer <string>((a, b) => a.Equals(b), a => a.GetHashCode())); foreach (var f in _Fields) { if (f.Identification == null || f.Identification.Length <= 0) { throw new ArgumentException("Creating timesteps from fields without an identification is not supported."); } if (allIdentifications.Contains(f.Identification)) { throw new ArgumentException("Within a Timestep, the Identification of each field must be unique: found at least two fields named '" + f.Identification + "'"); } allIdentifications.Add(f.Identification); } } // set members: ID = Guid.Empty; this.m_StorageID = Guid.Empty; DGField[] _fields = fields.ToArray(); m_Fields = new Lazy <IEnumerable <DGField> >(() => _fields); this.m_TimestepNumber = TimestepNo; this.PhysicalTime = physTime; this.Session = session; this.m_FieldInitializers = fields.Select(f => f.Initializer).ToArray(); CreationTime = DateTime.Now; }
/// <summary> /// Compares two time-steps based on each individual number (cf. /// <see cref="TimestepNumber"/>) in order of their /// significance. /// </summary> /// <param name="other"> /// The time-step to be compared to /// </param> /// <returns> /// The result of the integer comparison of the sub-number with the /// highest significance for which the result is not zero. /// </returns> public int CompareTo(TimestepNumber other) { bool thisIsNix = (this.save_numbers == null || this.save_numbers.Length <= 0); bool othrIsNix = (other.save_numbers == null || other.save_numbers.Length <= 0); if (thisIsNix && othrIsNix) { // both unspecified -> equal return(0); } if (thisIsNix && !othrIsNix) { return(-1); } if (thisIsNix && !othrIsNix) { return(+1); } Debug.Assert(!thisIsNix && !othrIsNix); int length = Math.Min(this.save_numbers.Length, other.save_numbers.Length); // Decision based on existing entries for (int i = 0; i < length; i++) { int result = this.save_numbers[i].CompareTo(other.save_numbers[i]); if (result != 0) { return(result); } } // Still undecided? -> More indices = larger return(this.save_numbers.Length.CompareTo(other.save_numbers.Length)); }
/// <summary> /// See <see cref="T:int[].Equals"/> /// </summary> /// <param name="other"></param> /// <returns></returns> public bool Equals(TimestepNumber other) { return(ArrayTools.ListEquals(numbers, other.numbers)); }