6 #ifndef ACCUMULATE_H_INC_ 7 #define ACCUMULATE_H_INC_ 21 #include "wonton/support/Matrix.h" 23 namespace Portage {
namespace Meshfree {
71 Accumulate(SourceSwarm
const& source, TargetSwarm
const& target,
72 EstimateType estimate, WeightCenter center,
84 geometries_(geometries),
85 smoothing_(smoothing),
87 operator_spec_(operator_spec),
88 operator_domain_(operator_domain),
89 operator_data_(operator_data)
93 size_t n_particles = (center == Gather ? target_.num_owned_particles()
94 : source_.num_particles());
96 assert(n_particles == kernels_.size());
97 assert(n_particles == geometries_.size());
98 assert(n_particles == smoothing_.size());
100 unsigned const num_target_particles = target_.num_owned_particles();
101 assert(operator_data_.size() == num_target_particles);
102 assert(operator_domain_.size() == num_target_particles);
115 double weight(
const size_t particleA,
const size_t particleB) {
117 Wonton::Point<dim> x = target_.get_particle_coordinates(particleA);
118 Wonton::Point<dim> y = source_.get_particle_coordinates(particleB);
119 if (center_ == Gather) {
120 result = Weight::eval<dim>(geometries_[particleA],
123 smoothing_[particleA]);
124 }
else if (center_ == Scatter) {
125 result = Weight::eval<dim>(geometries_[particleB],
128 smoothing_[particleB]);
142 std::vector<Weights_t>
143 operator() (
size_t const particleA, std::vector<int>
const& source_particles) {
144 std::vector<Weights_t> result;
145 result.reserve(source_particles.size());
148 case KernelDensity: {
149 for (
auto const& particleB : source_particles) {
150 double weight_val = weight(particleA, particleB);
151 std::vector<double> pair_result(1, weight_val);
152 result.emplace_back(particleB, pair_result);
156 case OperatorRegression:
157 case LocalRegression: {
158 size_t nbasis = basis::function_size<dim>(basis_);
159 Wonton::Point<dim> x = target_.get_particle_coordinates(particleA);
162 bool zilchit =
false;
163 if (source_particles.size() < nbasis) {
168 std::vector<double> weight_val(source_particles.size());
169 Wonton::Matrix moment(nbasis,nbasis,0.);
172 for (
auto const& particleB : source_particles) {
173 weight_val[iB] = weight(particleA, particleB);
174 Wonton::Point<dim> y = source_.get_particle_coordinates(particleB);
175 auto basis = basis::shift<dim>(basis_, x, y);
176 for (
size_t i=0; i<nbasis; i++) {
177 for (
size_t j=0; j<nbasis; j++) {
178 moment[i][j] += basis[i]*basis[j]*weight_val[iB];
188 for (
auto const& particleB : source_particles) {
189 std::vector<double> pair_result(nbasis);
190 Wonton::Point<dim> y = source_.get_particle_coordinates(particleB);
191 std::vector<double> basis = basis::shift<dim>(basis_, x, y);
194 Wonton::Matrix basis_matrix(nbasis,1);
195 for (
size_t i=0; i<nbasis; i++) basis_matrix[i][0] = basis[i];
199 std::string error=
"check";
201 Wonton::Matrix pair_result_matrix = moment.solve(basis_matrix,
"lapack-sytr", error);
203 Wonton::Matrix pair_result_matrix = moment.solve(basis_matrix,
"inverse", error);
205 for (
size_t i=0; i<nbasis; i++)
206 pair_result[i] = pair_result_matrix[i][0]*weight_val[iB];
212 for (
size_t i=0; i<nbasis; i++)
217 if (estimate_ == OperatorRegression) {
218 auto ijet = basis::inverse_jet<dim>(basis_, x);
219 std::vector<std::vector<double>> basisop;
220 oper::apply<dim>(operator_spec_, basis_,
221 operator_domain_[particleA],
222 operator_data_[particleA], basisop);
223 int const num_basis = nbasis;
225 operator_domain_[particleA])[0];
226 std::vector<double> operator_result(opsize, 0.);
228 for (
int j = 0; j < opsize; j++) {
229 for (
int k = 0; k < num_basis; k++) {
230 for (
int m = 0; m < num_basis; m++) {
231 operator_result[j] += pair_result[k]*ijet[k][m]*basisop[m][j];
235 for (
int j = 0; j < num_basis; j++)
236 pair_result[j] = operator_result[j];
238 result.emplace_back(particleB, pair_result);
250 SourceSwarm
const& source_;
251 TargetSwarm
const& target_;
252 EstimateType estimate_;
253 WeightCenter center_;
265 #endif // ACCUMULATE_H_INC std::vector< T > vector
Definition: portage.h:238
Definition: operator.h:30
Type
Definition: basis.h:20
Type
Definition: operator.h:30
Definition: coredriver.h:42
std::array< size_t, 3 > size_info(Type type, basis::Type basis, Domain domain)
Definition: operator.h:513