ESyS-Particle  2.3.4
GaussianGridder.h
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
12 
13 #ifndef ESYS_LSMGAUSSIANGRIDDER_H
14 #define ESYS_LSMGAUSSIANGRIDDER_H
15 
16 #include "Foundation/vec3.h"
17 
18 #include <math.h>
19 
20 namespace esys
21 {
22  namespace lsm
23  {
25  {
26  public:
27  GaussianGridder(double stdDeviation)
28  : m_stdDeviation(stdDeviation)
29  {
30  }
31 
32  static const double SQRT_2PI;
33 
34  double getWeight(const Vec3 &regPos, const Vec3 &irrPos) const
35  {
36  return exp( - ((irrPos-regPos).norm2())/(2.0*m_stdDeviation*m_stdDeviation))/(SQRT_2PI*m_stdDeviation);
37  }
38 
39  template <typename TmplCartesianGrid>
40  void transform(const TmplCartesianGrid &irregular, TmplCartesianGrid &regular) const
41  {
42  typename TmplCartesianGrid::CellIterator regIt = regular.getCellIterator();
43  const double radius = 3.99*m_stdDeviation;
44  while (regIt.hasNext())
45  {
46  const typename TmplCartesianGrid::Cell &regCell = regIt.next();
47  typename TmplCartesianGrid::CellConstIterator irrIt = irregular.getCellIterator(regCell.getPos(), radius);
48  typename TmplCartesianGrid::value_type value;
49  value *= 0.0;
50  double weightSum = 0.0;
51  while (irrIt.hasNext())
52  {
53  typename TmplCartesianGrid::Cell::ConstIterator pairIt = irrIt.next().getIterator();
54  while (pairIt.hasNext())
55  {
56  const typename TmplCartesianGrid::Cell::PosValuePair &pair = pairIt.next();
57  const double weight = getWeight(regCell.getPos(), pair.getPos());
58  weightSum += weight;
59  value += (pair.getValue()*weight);
60  }
61  }
62  if (weightSum != 0) {
63  value /= weightSum;
64  }
65  regular.insert(regCell.getPos(), value);
66  }
67  }
68 
69  private:
71  };
72  }
73 }
74 
75 #endif
esys::lsm::GaussianGridder::transform
void transform(const TmplCartesianGrid &irregular, TmplCartesianGrid &regular) const
Definition: GaussianGridder.h:40
esys::lsm::GaussianGridder::getWeight
double getWeight(const Vec3 &regPos, const Vec3 &irrPos) const
Definition: GaussianGridder.h:34
esys::lsm::GaussianGridder
Definition: GaussianGridder.h:25
esys
Definition: CheckPointable.cpp:17
esys::lsm::GaussianGridder::SQRT_2PI
static const double SQRT_2PI
Definition: GaussianGridder.h:32
esys::lsm::GaussianGridder::m_stdDeviation
double m_stdDeviation
Definition: GaussianGridder.h:70
Vec3
Definition: vec3.h:47
vec3.h
GaussianGridder.h
esys::lsm::GaussianGridder::GaussianGridder
GaussianGridder(double stdDeviation)
Definition: GaussianGridder.h:27