Changeset f003a9 for src/units/particle/interpolation.cpp
- Timestamp:
- May 8, 2012, 2:54:17 PM (14 years ago)
- Children:
- 6f05224
- Parents:
- 4e8206
- File:
-
- 1 moved
-
src/units/particle/interpolation.cpp (moved) (moved from src/base/interpolate_polynomial.cpp ) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/units/particle/interpolation.cpp
r4e8206 rf003a9 7 7 #include "base/helper.hpp" 8 8 #include "base/index.hpp" 9 #include "base/interpolate_polynomial.hpp"10 9 #include "base/vector.hpp" 11 10 #include "grid/grid.hpp" 11 #include "units/particle/interpolation.hpp" 12 #include "units/particle/particle.hpp" 12 13 13 14 using namespace VMG; 14 15 15 InterpolatePolynomial::InterpolatePolynomial(const unsigned int& degree) :16 Particle::Interpolation::Interpolation(const unsigned int& degree) : 16 17 deg(degree), 17 18 deg_1(degree+1), … … 25 26 } 26 27 27 InterpolatePolynomial::~InterpolatePolynomial()28 Particle::Interpolation::~Interpolation() 28 29 { 29 30 delete [] coeff; … … 31 32 } 32 33 33 void InterpolatePolynomial::ComputeCoefficients(const Grid& grid, const Index& index)34 void Particle::Interpolation::ComputeCoefficients(const Grid& grid, const Index& index) 34 35 { 35 36 Index i; … … 63 64 } 64 65 65 void InterpolatePolynomial::_compute_coefficients_1d(const Index& index, const unsigned int& direction)66 void Particle::Interpolation::_compute_coefficients_1d(const Index& index, const unsigned int& direction) 66 67 { 67 68 vmg_float power = 1.0; … … 84 85 } 85 86 86 vmg_float InterpolatePolynomial::Evaluate(const Vector& pos) 87 { 88 vmg_float result = 0.0; 89 Vector prod, offset; 90 Index i; 91 92 prod[0] = 1.0; 93 offset[0] = pos[0] - pos_begin[0]; 94 for (i[0]=0; i[0]<deg_1; ++i[0]) { 95 prod[1] = prod[0]; 96 offset[1] = pos[1] - pos_begin[1]; 97 for (i[1]=0; i[1]<deg_1; ++i[1]) { 98 prod[2] = prod[1]; 99 offset[2] = pos[2] - pos_begin[2]; 100 for (i[2]=0; i[2]<deg_1; ++i[2]) { 101 result += _access_coeff(i) * prod[2]; 102 prod[2] *= offset[2]; 103 offset[2] -= h[2]; 104 } 105 prod[1] *= offset[1]; 106 offset[1] -= h[1]; 107 } 108 prod[0] *= offset[0]; 109 offset[0] -= h[0]; 110 } 111 112 return result; 113 } 114 115 void InterpolatePolynomial::Evaluate(const Vector& pos, vmg_float& pot, Vector& field) 87 void Particle::Interpolation::Evaluate(Particle& p) 116 88 { 117 89 Vector offset; 90 91 const Vector& pos = p.Pos(); 92 vmg_float& pot = p.Pot(); 93 Vector& field = p.Field(); 118 94 119 95 pot = 0.0; … … 154 130 } 155 131 156 Vector InterpolatePolynomial::EvaluateNegGradient(const Vector& pos)132 vmg_float Particle::Interpolation::EvaluatePotentialLR(const Particle& p) 157 133 { 158 Vector offset, result; 134 vmg_float result = 0.0; 135 Vector prod, offset; 136 Index i; 159 137 160 buffer[0] = 1.0; 161 offset = pos - pos_begin; 162 for (int i=1; i<deg_1; ++i) { 163 buffer[i] = buffer[i-1] * offset; 164 offset -= h; 138 const Vector& pos = p.Pos(); 139 140 prod[0] = 1.0; 141 offset[0] = pos[0] - pos_begin[0]; 142 for (i[0]=0; i[0]<deg_1; ++i[0]) { 143 prod[1] = prod[0]; 144 offset[1] = pos[1] - pos_begin[1]; 145 for (i[1]=0; i[1]<deg_1; ++i[1]) { 146 prod[2] = prod[1]; 147 offset[2] = pos[2] - pos_begin[2]; 148 for (i[2]=0; i[2]<deg_1; ++i[2]) { 149 result += _access_coeff(i) * prod[2]; 150 prod[2] *= offset[2]; 151 offset[2] -= h[2]; 152 } 153 prod[1] *= offset[1]; 154 offset[1] -= h[1]; 155 } 156 prod[0] *= offset[0]; 157 offset[0] -= h[0]; 165 158 } 166 167 offset = pos - pos_begin;168 for (int i=0; i<deg; ++i) {169 for (int j=0; j<i; ++j)170 buffer_diff[i][j] = buffer_diff[i-1][j] * offset;171 buffer_diff[i][i] = buffer[i];172 offset -= h;173 }174 175 for (int i=1; i<deg; ++i)176 for (int j=1; j<=i; ++j)177 buffer_diff[i][0] += buffer_diff[i][j];178 179 for (int i=0; i<deg_1; ++i)180 for (int j=0; j<deg_1; ++j)181 for (int k=0; k<deg; ++k) {182 result[0] -= _access_coeff(k+1, i, j) * buffer[i][1] * buffer[j][2] * buffer_diff[k][0][0];183 result[1] -= _access_coeff(i, k+1, j) * buffer[i][0] * buffer[j][2] * buffer_diff[k][0][1];184 result[2] -= _access_coeff(i, j, k+1) * buffer[i][0] * buffer[j][1] * buffer_diff[k][0][2];185 }186 159 187 160 return result;
Note:
See TracChangeset
for help on using the changeset viewer.
