estimate.h
Go to the documentation of this file.
1 /*
2 This file is part of the Ristra portage project.
3 Please see the license file at the root of this repository, or at:
4  https://github.com/laristra/portage/blob/master/LICENSE
5 */
6 #ifndef ESTIMATE_H_INC_
7 #define ESTIMATE_H_INC_
8 
9 #include <vector>
10 #include <string>
11 #include <cassert>
12 
15 
16 namespace Portage {
17 namespace Meshfree {
18 
19 using std::string;
20 
27 template<int dim, class TargetSwarmState>
28 class Estimate {
29  public:
34  Estimate(SwarmState<dim> const& source_state):
35  source_state_(source_state)
36  {}
37 
44  void set_interpolation_variable(std::string const & interp_var_name, size_t derivative=0) {
45  var_name_ = interp_var_name;
46  derivative_ = derivative;
47  }
48 
57  double operator()(int const target_index,
58  std::vector<Weights_t> const &sources_and_mults) const
59  {
60  int nsrc = sources_and_mults.size();
61  if (nsrc > 0) assert(derivative_ < sources_and_mults[0].weights.size());
62 
63  double result = 0.;
64  for (int i = 0; i < nsrc; i++) {
65  Weights_t const& wt = sources_and_mults[i];
66  int p = wt.entityID;
67  std::vector<double> const& shape_vec = wt.weights;
68  result += source_vals_[p] * shape_vec[derivative_];
69  }
70  return result;
71  }
72 
73  void set_variable(std::string const & var_name, size_t derivin=0) {
74  var_name_ = var_name;
75  derivative_ = derivin;
76  source_vals_ = source_state_.get_field(var_name_);
77  }
78 
79  private:
80  SwarmState<dim> const& source_state_;
81  std::string var_name_;
82  size_t derivative_;
83  Portage::vector<double> source_vals_;
84 };
85 
86 }
87 }
88 
89 #endif // ESTIMATE_H_INC
std::vector< T > vector
Definition: portage.h:238
Definition: coredriver.h:42