private void CheckHaltingConditions(DynamicSettings settings) { var staticSettings = ConvertDynSettingsToStatic(settings); var toRemove = new List <Particle>(); for (int i = 0; i < particles.Count; i++) { var p = particles[i]; var add = false; var outBasis = new Basis(p.Current.Point, p.Current.Vector); if (!Algos.CheckHaltingConditions(p.Current.Point, p.Start, outBasis, p.Current.Vector.Value, out add, staticSettings) || add == false) { toRemove.Add(p); } else { p.Current.Point = outBasis.Point; } } foreach (var remove in toRemove) { particles.Remove(remove); } }
protected override void SolveInstance(IGH_DataAccess DA) { // inputs var points = new List <GH_Point>(); var planes = new List <GH_Plane>(); var vectors = new List <GH_Vector>(); var traveller = new GH_Point(); var settings = new GH_ObjectWrapper(); var dynamicsWrapped = new List <GH_ObjectWrapper>(); var dynamics = new List <IDynamic>(); // outputs var linePoints = new List <GH_Point>(); var lineVecs = new List <GH_Vector>(); // gather and validate inputs if (DA.GetDataList(0, points) && points == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid points list. Operation canceled."); return; } if (DA.GetData(2, ref traveller) && traveller == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid travelling point. Operation canceled."); return; } if (DA.GetDataList(3, dynamicsWrapped) && dynamicsWrapped == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid dynamics list. Operation canceled."); return; } dynamics = (from d in dynamicsWrapped select d.Value as IDynamic).ToList(); Algos.SortDynamicsByPriority(dynamics); // spm parameters component is optional, we use its defaults if it is not available StaticSettings spm_settings = new StaticSettings(); if (DA.GetData(4, ref settings)) { // if getdata succeeded but the settings var is null we had bad input if (settings == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid settings input. Operation canceled."); return; } // otherwise cast from gh_objectwrapper and continue spm_settings = (StaticSettings)settings.Value; } var bases = new List <Basis>(); var basesWrapper = new List <GH_ObjectWrapper>(); // we need to get the vector field information after settings, for tensor settings if (spm_settings.tensor && (spm_settings.tensorDir >= 0 && spm_settings.tensorDir <= 2)) { if (DA.GetDataList(1, basesWrapper) && basesWrapper == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid tensor field. Operation canceled."); return; } for (int i = 0; i < basesWrapper.Count; i++) { Basis b = basesWrapper[i].Value as Basis; bases.Add(new Basis(points[i], b.Vectors)); bases[i].Axes = spm_settings.tensorAxes; } } else { if (DA.GetDataList(1, vectors) && vectors == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid vector list. Operation canceled."); return; } if (vectors.Count != points.Count && vectors.Count != 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Vector list size mismatch with points list, they must be equal in length (or empty if you wish to integrate using just dynamics). Operation canceled."); return; } // if vectors list is empty we'll populate it with empty vectors to match each point if (vectors.Count == 0) { foreach (var i in Enumerable.Range(0, points.Count)) { vectors.Add(new GH_Vector()); } } for (int i = 0; i < points.Count; i++) { bases.Add(new Basis(points[i], vectors[i])); } } int steps = spm_settings.steps; if (steps == 0) { steps = MAX_ITERATIONS; } var startBasis = new Basis(traveller); var vecLast = new GH_Vector(); double xy = 0; double yz = 0; double xz = 0; // add start point to output linePoints.Add(startBasis.Point); Algos.ClearDynamics(dynamics); // find each next point based on an averaging formula and iterate for (int i = 0; i < steps; i++) { bool add = false; var outBasis = new Basis(); if (points.Count != 0 && !Algos.SampleForNextPoint(bases, traveller.Value, startBasis, vecLast, spm_settings, out outBasis)) { break; } if (dynamics.Count > 0) { traveller = Algos.GetPointModifiedByDynamics(traveller, outBasis, dynamics, spm_settings); outBasis.Point = traveller; } else { traveller = outBasis.Point; } // this step must be done oustide of the regular halting checks as we must store the axes rotations if (spm_settings.windAngle != 0.0d && !vecLast.Value.IsZero && Algos.IsWoundPast(outBasis.Vector.Value, vecLast.Value, spm_settings.windAngle, ref xy, ref yz, ref xz)) { break; } var working = Algos.CheckHaltingConditions(traveller, startBasis, outBasis, vecLast.Value, out add, spm_settings); traveller = outBasis.Point; vecLast = outBasis.Vector; // cache the vector between start and start+1 if (i == 0 && working) { startBasis.Vector.Value = traveller.Value - startBasis.Point.Value; } if (add) { linePoints.Add(traveller); lineVecs.Add(vecLast); } if (!working) { break; } } DA.SetDataList(0, linePoints); DA.SetDataList(1, lineVecs); }