Changeset b4e1be
- Timestamp:
- Mar 9, 2015, 4:49:20 PM (11 years ago)
- Children:
- 5c22be
- Parents:
- fb3b4c
- File:
-
- 1 edited
-
src/units/particle/bspline.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/units/particle/bspline.hpp
rfb3b4c rb4e1be 128 128 } 129 129 130 void changeGridBySelfInducedPotential(Grid& grid, Particle& p, const vmg_float &sign) const 131 { 132 assert(p.Pos().X() >= grid.Extent().Begin().X() && p.Pos().X() < grid.Extent().End().X()); 133 assert(p.Pos().Y() >= grid.Extent().Begin().Y() && p.Pos().Y() < grid.Extent().End().Y()); 134 assert(p.Pos().Z() >= grid.Extent().Begin().Z() && p.Pos().Z() < grid.Extent().End().Z()); 135 136 const int index_global_x = grid.Global().GlobalBegin().X() + std::floor((p.Pos().X() - grid.Extent().Begin().X()) / grid.Extent().MeshWidth().X()); 137 const int index_global_y = grid.Global().GlobalBegin().Y() + std::floor((p.Pos().Y() - grid.Extent().Begin().Y()) / grid.Extent().MeshWidth().Y()); 138 const int index_global_z = grid.Global().GlobalBegin().Z() + std::floor((p.Pos().Z() - grid.Extent().Begin().Z()) / grid.Extent().MeshWidth().Z()); 139 140 assert(index_global_x >= grid.Global().LocalBegin().X() && index_global_x < grid.Global().LocalEnd().X()); 141 assert(index_global_y >= grid.Global().LocalBegin().Y() && index_global_y < grid.Global().LocalEnd().Y()); 142 assert(index_global_z >= grid.Global().LocalBegin().Z() && index_global_z < grid.Global().LocalEnd().Z()); 143 144 const int index_local_x = index_global_x - grid.Global().LocalBegin().X() + grid.Local().HaloSize1().X(); 145 const int index_local_y = index_global_y - grid.Global().LocalBegin().Y() + grid.Local().HaloSize1().Y(); 146 const int index_local_z = index_global_z - grid.Global().LocalBegin().Z() + grid.Local().HaloSize1().Z(); 147 148 assert(index_local_x >= grid.Local().Begin().X() && index_local_x < grid.Local().End().X()); 149 assert(index_local_y >= grid.Local().Begin().Y() && index_local_y < grid.Local().End().Y()); 150 assert(index_local_z >= grid.Local().Begin().Z() && index_local_z < grid.Local().End().Z()); 151 152 const vmg_float pos_beg_x = grid.Extent().Begin().X() + grid.Extent().MeshWidth().X() * (index_global_x - grid.Global().GlobalBegin().X() - near_field_cells) - p.Pos().X(); 153 const vmg_float pos_beg_y = grid.Extent().Begin().Y() + grid.Extent().MeshWidth().Y() * (index_global_y - grid.Global().GlobalBegin().Y() - near_field_cells) - p.Pos().Y(); 154 const vmg_float pos_beg_z = grid.Extent().Begin().Z() + grid.Extent().MeshWidth().Z() * (index_global_z - grid.Global().GlobalBegin().Z() - near_field_cells) - p.Pos().Z(); 155 156 const vmg_float& h_x = grid.Extent().MeshWidth().X(); 157 const vmg_float& h_y = grid.Extent().MeshWidth().Y(); 158 const vmg_float& h_z = grid.Extent().MeshWidth().Z(); 159 160 vmg_float dir_x = pos_beg_x; 161 for (int i=-1*near_field_cells; i<=near_field_cells; ++i) { 162 vmg_float dir_y = pos_beg_y; 163 for (int j=-1*near_field_cells; j<=near_field_cells; ++j) { 164 vmg_float dir_z = pos_beg_z; 165 for (int k=-1*near_field_cells; k<=near_field_cells; ++k) { 166 const double length_sq = dir_x*dir_x+dir_y*dir_y+dir_z*dir_z; 167 const double length = std::sqrt(length_sq); 168 grid(index_local_x + i, 169 index_local_y + j, 170 index_local_z + k) += sign * p.Charge() * EvaluatePotential(length); 171 172 dir_z += h_z; 173 } 174 dir_y += h_y; 175 } 176 dir_x += h_x; 177 } 178 } 179 180 void SubtractSelfInducedForces(const Grid& grid, Particle& p) const 181 { 182 assert(p.Pos().X() >= grid.Extent().Begin().X() && p.Pos().X() < grid.Extent().End().X()); 183 assert(p.Pos().Y() >= grid.Extent().Begin().Y() && p.Pos().Y() < grid.Extent().End().Y()); 184 assert(p.Pos().Z() >= grid.Extent().Begin().Z() && p.Pos().Z() < grid.Extent().End().Z()); 185 186 vmg_float temp_val = 0.; 187 188 const int index_global_x = grid.Global().GlobalBegin().X() + std::floor((p.Pos().X() - grid.Extent().Begin().X()) / grid.Extent().MeshWidth().X()); 189 const int index_global_y = grid.Global().GlobalBegin().Y() + std::floor((p.Pos().Y() - grid.Extent().Begin().Y()) / grid.Extent().MeshWidth().Y()); 190 const int index_global_z = grid.Global().GlobalBegin().Z() + std::floor((p.Pos().Z() - grid.Extent().Begin().Z()) / grid.Extent().MeshWidth().Z()); 191 192 assert(index_global_x >= grid.Global().LocalBegin().X() && index_global_x < grid.Global().LocalEnd().X()); 193 assert(index_global_y >= grid.Global().LocalBegin().Y() && index_global_y < grid.Global().LocalEnd().Y()); 194 assert(index_global_z >= grid.Global().LocalBegin().Z() && index_global_z < grid.Global().LocalEnd().Z()); 195 196 const int index_local_x = index_global_x - grid.Global().LocalBegin().X() + grid.Local().HaloSize1().X(); 197 const int index_local_y = index_global_y - grid.Global().LocalBegin().Y() + grid.Local().HaloSize1().Y(); 198 const int index_local_z = index_global_z - grid.Global().LocalBegin().Z() + grid.Local().HaloSize1().Z(); 199 200 assert(index_local_x >= grid.Local().Begin().X() && index_local_x < grid.Local().End().X()); 201 assert(index_local_y >= grid.Local().Begin().Y() && index_local_y < grid.Local().End().Y()); 202 assert(index_local_z >= grid.Local().Begin().Z() && index_local_z < grid.Local().End().Z()); 203 204 const vmg_float pos_beg_x = grid.Extent().Begin().X() + grid.Extent().MeshWidth().X() * (index_global_x - grid.Global().GlobalBegin().X() - near_field_cells) - p.Pos().X(); 205 const vmg_float pos_beg_y = grid.Extent().Begin().Y() + grid.Extent().MeshWidth().Y() * (index_global_y - grid.Global().GlobalBegin().Y() - near_field_cells) - p.Pos().Y(); 206 const vmg_float pos_beg_z = grid.Extent().Begin().Z() + grid.Extent().MeshWidth().Z() * (index_global_z - grid.Global().GlobalBegin().Z() - near_field_cells) - p.Pos().Z(); 207 208 const vmg_float& h_x = grid.Extent().MeshWidth().X(); 209 const vmg_float& h_y = grid.Extent().MeshWidth().Y(); 210 const vmg_float& h_z = grid.Extent().MeshWidth().Z(); 211 212 int int_val = 0.; 213 vmg_float dir_x = pos_beg_x; 214 for (int i=-1*near_field_cells; i<=near_field_cells; ++i) { 215 vmg_float dir_y = pos_beg_y; 216 for (int j=-1*near_field_cells; j<=near_field_cells; ++j) { 217 vmg_float dir_z = pos_beg_z; 218 for (int k=-1*near_field_cells; k<=near_field_cells; ++k) { 219 220 // Compute distance from grid point to particle 221 int_val += EvaluateSpline(std::sqrt(dir_x*dir_x+dir_y*dir_y+dir_z*dir_z)); 222 223 dir_z += h_z; 224 } 225 dir_y += h_y; 226 } 227 dir_x += h_x; 228 } 229 // Reciprocal value of the numerically integrated spline 230 if (fabs(int_val) > std::numeric_limits<double>::epsilon()) 231 int_val = 1.0 / (int_val * h_x * h_y * h_z); 232 else 233 int_val = 1.0; 234 235 // Iterate over all grid points which lie in the support of the interpolating B-Spline 236 dir_x = pos_beg_x; 237 for (int i=-1*near_field_cells; i<=near_field_cells; ++i) { 238 vmg_float dir_y = pos_beg_y; 239 for (int j=-1*near_field_cells; j<=near_field_cells; ++j) { 240 vmg_float dir_z = pos_beg_z; 241 for (int k=-1*near_field_cells; k<=near_field_cells; ++k) { 242 243 // Compute distance from grid point to particle 244 const double length_sq = dir_x*dir_x+dir_y*dir_y+dir_z*dir_z; 245 if (fabs(length_sq) > std::numeric_limits<double>::epsilon()) { 246 const double length = std::sqrt(length_sq); 247 // temp_val = EvaluateField(length); 248 // p.Field()[0] -= p.Charge() * dir_x * temp_val; 249 // p.Field()[1] -= p.Charge() * dir_y * temp_val; 250 // p.Field()[2] -= p.Charge() * dir_z * temp_val; 251 temp_val = int_val * EvaluateSpline(length); 252 p.Field()[0] -= p.Charge()*p.Charge() * temp_val * temp_val * dir_x / (length_sq*length); 253 p.Field()[1] -= p.Charge()*p.Charge() * temp_val * temp_val * dir_y / (length_sq*length); 254 p.Field()[2] -= p.Charge()*p.Charge() * temp_val * temp_val * dir_z / (length_sq*length); 255 } else { 256 std::cerr << "Value very small " << length_sq << "=(" 257 << dir_x << ")^2+(" << dir_y << ")^2+(" << dir_z << ")^2 for particle at (" 258 << p.Pos().X() << "," 259 << p.Pos().Y() << "," 260 << p.Pos().Z() << ")" 261 << "\n"; 262 } 263 dir_z += h_z; 264 } 265 dir_y += h_y; 266 } 267 dir_x += h_x; 268 } 269 } 270 130 271 vmg_float EvaluatePotential(const vmg_float& val) const 131 272 {
Note:
See TracChangeset
for help on using the changeset viewer.
