From 5a2d4ed7051e2ba0dfb20641df9c680ac2becaa4 Mon Sep 17 00:00:00 2001 From: Jesse Carter Date: Wed, 14 Sep 2016 22:09:21 -0400 Subject: [PATCH] return closest element info in Circle UserObjects, closes #34 --- src/userobjects/CircleAverageMaterialProperty.C | 15 ++++++++++++++- src/userobjects/CircleMaxOriginalElementSize.C | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/userobjects/CircleAverageMaterialProperty.C b/src/userobjects/CircleAverageMaterialProperty.C index c82b60f0e0..7cea08cf83 100644 --- a/src/userobjects/CircleAverageMaterialProperty.C +++ b/src/userobjects/CircleAverageMaterialProperty.C @@ -78,6 +78,9 @@ CircleAverageMaterialProperty::averageValue(const Point & p, const Real & radius Real integral_sum = 0.0; Real volume_sum = 0.0; + Real min_distance = std::numeric_limits::max(); + dof_id_type closest_element; + for (std::map::const_iterator it = _centroids.begin(); it != _centroids.end(); ++it) @@ -87,6 +90,13 @@ CircleAverageMaterialProperty::averageValue(const Point & p, const Real & radius Real r = distance(p, centroid); + // save closest element in case mesh too coarse + if (r < min_distance) + { + min_distance = r; + closest_element = id; + } + // check if distance between points is less than supplied radius if (r < radius) { @@ -103,6 +113,8 @@ CircleAverageMaterialProperty::averageValue(const Point & p, const Real & radius if (volume_sum > 0.0) return integral_sum/volume_sum; + else + return _integral_values.at(closest_element)/_volume_values.at(closest_element); // return at least the information of the closest element return 0.0; } @@ -153,7 +165,8 @@ CircleAverageMaterialProperty::execute() Real r = distance(_current_elem->centroid(), _old_event_list[i].second); // check if distance between points is less than supplied radius - if (r < _radius) + // or if point is in element + if ((r < _radius) || (_current_elem->contains_point(_old_event_list[i].second))) { _integral_sum[i] += computeIntegral(); _volume_sum[i] += _current_elem_volume; diff --git a/src/userobjects/CircleMaxOriginalElementSize.C b/src/userobjects/CircleMaxOriginalElementSize.C index fe4beda23b..1684d4dce3 100644 --- a/src/userobjects/CircleMaxOriginalElementSize.C +++ b/src/userobjects/CircleMaxOriginalElementSize.C @@ -37,6 +37,10 @@ CircleMaxOriginalElementSize::value(const Point & p, const Real & radius) const { Real max_element_size = 0.0; + Real min_distance = std::numeric_limits::max(); + dof_id_type closest_element; + bool found_max = false; + // Loop over elements for (std::map::const_iterator it = _centroids.begin(); it != _centroids.end(); @@ -47,6 +51,13 @@ CircleMaxOriginalElementSize::value(const Point & p, const Real & radius) const Real r = distance(p, centroid); + // save closest element in case mesh too coarse + if (r < min_distance) + { + min_distance = r; + closest_element = id; + } + // check if distance between points is less than supplied radius if (r < radius) { @@ -60,6 +71,10 @@ CircleMaxOriginalElementSize::value(const Point & p, const Real & radius) const } } } + + if (min_distance == std::numeric_limits::max()) + return _original_element_sizes.at(closest_element); + return max_element_size; }