/// <summary> /// checks if any field contains NaN's or Inf's and throws an exception if this is the case. /// </summary> public bool CheckForNanOrInf() { int bool_FoundNanOrInf_local = 0; int bool_FoundNanOrInf_global = 0; Type myT = this.GetType(); FieldInfo[] flds = myT.GetFields(); string ErrMsg = ""; bool Err = false; foreach (FieldInfo fi in flds) { if (fi.FieldType == typeof(SinglePhaseField)) { DGField f = (DGField)fi.GetValue(this); if (f != null) { try { if (f.CheckForNanOrInf(true, true, false) >= 0) { bool_FoundNanOrInf_local = 1; } } catch (ArithmeticException ae) { ErrMsg += ae.Message + "\n"; Err = true; } } } if (fi.FieldType == typeof(VectorField <SinglePhaseField>)) { VectorField <SinglePhaseField> vf = (VectorField <SinglePhaseField>)fi.GetValue(this); if (vf != null) { try { if (vf.CheckForNanOrInf(true, true, false) >= 0) { bool_FoundNanOrInf_local = 1; } } catch (ArithmeticException ae) { ErrMsg += ae.Message + "\n"; Err = true; } } } } if (Err) { throw new ArithmeticException(ErrMsg); } unsafe { csMPI.Raw.Allreduce((IntPtr)(&bool_FoundNanOrInf_local), (IntPtr)(&bool_FoundNanOrInf_global), 1, csMPI.Raw._DATATYPE.INT, csMPI.Raw._OP.MAX, csMPI.Raw._COMM.WORLD); } bool FoundNanOrInf_global = (bool_FoundNanOrInf_global > 0) ? true : false; return(FoundNanOrInf_global); }