https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ThreadedRadialAverageLoop.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11#include "Function.h"
12
13// Make newer nanoflann API spelling compatible with older nanoflann
14// versions
15#if NANOFLANN_VERSION < 0x150
16namespace nanoflann
17{
18typedef SearchParams SearchParameters;
19
20template <typename T, typename U>
21using ResultItem = std::pair<T, U>;
22}
23#endif
24
26
27// Splitting Constructor
33
34void
36{
37 // fetch data from parent
38 const auto radius = _radavg._radius;
39 const auto & qp_data = _radavg._qp_data;
40 const auto & kd_tree = _radavg._kd_tree;
41 const auto & weights_type = _radavg._weights_type;
42
43 // tree search data structures
44 std::vector<nanoflann::ResultItem<std::size_t, Real>> ret_matches;
45 nanoflann::SearchParameters search_params;
46
47 // result map entry
48 const auto end_it = _radavg._average.end();
49 auto it = end_it;
50
51 // iterate over qp range
52 for (auto && local_qp : qpdata_range)
53 {
54 // Look up result map iterator only if we enter a new element. this saves a bunch
55 // of map lookups because same element entries are consecutive in the qp_data vector.
56 if (it == end_it || it->first != local_qp._elem_id)
57 it = _radavg._average.find(local_qp._elem_id);
58
59 // initialize result entry
60 mooseAssert(it != end_it, "Current element id not found in result set.");
61 auto & sum = it->second[local_qp._qp];
62 sum = 0.0;
63
64 ret_matches.clear();
65 std::size_t n_result =
66 kd_tree->radiusSearch(&(local_qp._q_point(0)), radius * radius, ret_matches, search_params);
67 Real total_vol = 0.0;
68 Real weight = 1.0;
69 for (std::size_t j = 0; j < n_result; ++j)
70 {
71 const auto & other_qp = qp_data[ret_matches[j].first];
72 switch (weights_type)
73 {
75 break;
76
78 weight = radius - std::sqrt(ret_matches[j].second);
79 break;
80
82 weight = std::cos(std::sqrt(ret_matches[j].second) / radius * libMesh::pi) + 1.0;
83 break;
84 }
85
86 sum += other_qp._value * other_qp._volume * weight;
87 total_vol += other_qp._volume * weight;
88 }
89 sum /= total_vol;
90 }
91}
StoredRange< std::vector< RadialAverage::QPData >::const_iterator, RadialAverage::QPData > QPDataRange
Gather and communicate a full list of all quadrature points and the values of a selected material pro...
enum RadialAverage::WeightsType _weights_type
const Real _radius
cut-off radius
std::unique_ptr< KDTreeType > _kd_tree
spatial index (nanoflann guarantees this to be threadsafe under read-only operations)
Result _average
average result
std::vector< QPData > _qp_data
gathered data
RadialAverage threaded loop.
void operator()(const QPDataRange &range)
parens operator with the code that is executed in threads
RadialAverage & _radavg
rasterizer to manage the sample data
const Real pi
std::pair< T, U > ResultItem
Definition KDTree.h:24
SearchParams SearchParameters
const Real radius