private static ElementNeighborhood FindNeighbors(double radius, ContinuumElement2D[] allElements, int elementIdx) { //TODO: Using appropriate mesh classes, we do not have to process all elements. Instead we can focus on neighbouring // once until the radius is exceeded. var neighborIndices = new List <int>(); var weightFactors = new List <double>(); CartesianPoint thisCentroid = allElements[elementIdx].FindCentroid(); for (int f = 0; f < allElements.Length; ++f) { CartesianPoint otherCentroid = allElements[f].FindCentroid(); double distance = otherCentroid.CalculateDistanceFrom(thisCentroid); if (distance <= radius) { neighborIndices.Add(f); weightFactors.Add(radius - distance); } } return(new ElementNeighborhood(neighborIndices.ToArray(), weightFactors.ToArray())); }