Changeset ef94e7 for src


Ignore:
Timestamp:
Jul 4, 2012, 6:10:39 PM (13 years ago)
Author:
Julian Iseringhausen <isering@…>
Children:
0260d3
Parents:
290aa3
Message:

vmg: Fix force calculation.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1900 5161e1c8-67bf-11de-9fd5-51895aff932f

Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/base/vector.hpp

    r290aa3 ref94e7  
    106106  }
    107107
     108  bool IsInBounds(const Vector& begin, const Vector& end) const
     109  {
     110    return this->IsComponentwiseGreaterOrEqual(begin) &&
     111           this->IsComponentwiseLessOrEqual(end);
     112  }
    108113
    109114  Vector MaxComponentwise(const Vector& rhs) const
  • src/comm/comm.hpp

    r290aa3 ref94e7  
    7373  virtual void Barrier() {}
    7474
    75   virtual vmg_float GlobalSum(const vmg_float& value) {return value;}
    76   virtual vmg_float GlobalSumRoot(const vmg_float& value) {return value;}
     75  virtual vmg_float GlobalSum(vmg_float value) {return value;}
     76  virtual vmg_float GlobalSumRoot(vmg_float value) {return value;}
    7777  virtual void GlobalSumArray(vmg_float* array, const vmg_int& size) {}
    78   virtual vmg_float GlobalMax(const vmg_float& value) {return value;}
    79   virtual vmg_float GlobalMaxRoot(const vmg_float& value) {return value;}
     78  virtual vmg_float GlobalMax(vmg_float value) {return value;}
     79  virtual vmg_float GlobalMaxRoot(vmg_float value) {return value;}
    8080  virtual void GlobalMaxArray(vmg_float* array, const vmg_int& size) {}
    8181  virtual void GlobalBroadcast(vmg_float& value) {}
    8282  virtual void GlobalGather(vmg_float& value, vmg_float* array) {array[0] = value;}
    8383
    84   virtual vmg_int GlobalSum(const vmg_int& value) {return value;}
    85   virtual vmg_int GlobalSumRoot(const vmg_int& value) {return value;}
     84  virtual vmg_int GlobalSum(vmg_int value) {return value;}
     85  virtual vmg_int GlobalSumRoot(vmg_int value) {return value;}
    8686  virtual void GlobalSumArray(vmg_int* array, const vmg_int& size) {}
    87   virtual vmg_int GlobalMax(const vmg_int& value) {return value;}
    88   virtual vmg_int GlobalMaxRoot(const vmg_int& value) {return value;}
     87  virtual vmg_int GlobalMax(vmg_int value) {return value;}
     88  virtual vmg_int GlobalMaxRoot(vmg_int value) {return value;}
    8989  virtual void GlobalMaxArray(vmg_int* array, const vmg_int& size) {}
    9090  virtual void GlobalBroadcast(vmg_int& value) {}
     
    9393  virtual void GlobalBroadcast(char* str) {}
    9494
    95   virtual vmg_float LevelSum(const Grid& grid, const vmg_float& value) {return value;}
    96   virtual vmg_float LevelSumRoot(const Grid& grid, const vmg_float& value) {return value;}
     95  virtual vmg_float LevelSum(const Grid& grid, vmg_float value) {return value;}
     96  virtual vmg_float LevelSumRoot(const Grid& grid, vmg_float value) {return value;}
    9797  virtual void LevelSumArray(const Grid& grid,  vmg_float* array, const vmg_int& size) {}
    9898
    99   virtual vmg_int LevelSum(const Grid& grid, const vmg_int& value) {return value;}
    100   virtual vmg_int LevelSumRoot(const Grid& grid, const vmg_int& value) {return value;}
     99  virtual vmg_int LevelSum(const Grid& grid, vmg_int value) {return value;}
     100  virtual vmg_int LevelSumRoot(const Grid& grid, vmg_int value) {return value;}
    101101  virtual void LevelSumArray(const Grid& grid, vmg_int* array, const vmg_int& size) {}
    102102
  • src/comm/comm_mpi.cpp

    r290aa3 ref94e7  
    191191}
    192192
    193 vmg_float CommMPI::GlobalSum(const vmg_float& value)
    194 {
    195   vmg_float result = value;
    196   MPI_Allreduce(MPI_IN_PLACE, &result, 1, MPI_DOUBLE, MPI_SUM, comm_global);
    197   return result;
    198 }
    199 
    200 vmg_float CommMPI::GlobalSumRoot(const vmg_float& value)
    201 {
    202   vmg_float recv_buffer = value;
    203   vmg_float send_buffer = value;
    204   MPI_Reduce(&send_buffer, &recv_buffer, 1, MPI_DOUBLE, MPI_SUM, 0, comm_global);
    205   return recv_buffer;
     193vmg_float CommMPI::GlobalSum(vmg_float value)
     194{
     195  vmg_float result = 0;
     196  MPI_Allreduce(&value, &result, 1, MPI_DOUBLE, MPI_SUM, comm_global);
     197  return result;
     198}
     199
     200vmg_float CommMPI::GlobalSumRoot(vmg_float value)
     201{
     202  vmg_float result = 0;
     203  MPI_Reduce(&value, &result, 1, MPI_DOUBLE, MPI_SUM, 0, comm_global);
     204  return result;
    206205}
    207206
     
    221220}
    222221
    223 vmg_int CommMPI::GlobalSum(const vmg_int& value)
    224 {
    225   vmg_int result = value;
    226   MPI_Allreduce(MPI_IN_PLACE, &result, 1, MPI_INT, MPI_SUM, comm_global);
    227   return result;
    228 }
    229 
    230 vmg_int CommMPI::GlobalSumRoot(const vmg_int& value)
    231 {
    232   vmg_int recv_buffer = value;
    233   vmg_int send_buffer = value;
    234   MPI_Reduce(&send_buffer, &recv_buffer, 1, MPI_INT, MPI_SUM, 0, comm_global);
    235   return recv_buffer;
     222vmg_int CommMPI::GlobalSum(vmg_int value)
     223{
     224  vmg_int result = 0;
     225  MPI_Allreduce(&value, &result, 1, MPI_INT, MPI_SUM, comm_global);
     226  return result;
     227}
     228
     229vmg_int CommMPI::GlobalSumRoot(vmg_int value)
     230{
     231  vmg_int result = 0;
     232  MPI_Reduce(&value, &result, 1, MPI_INT, MPI_SUM, 0, comm_global);
     233  return result;
    236234}
    237235
     
    241239}
    242240
    243 vmg_float CommMPI::GlobalMax(const vmg_float& value)
    244 {
    245   vmg_float result = value;
    246   MPI_Allreduce(MPI_IN_PLACE, &result, 1, MPI_DOUBLE, MPI_MAX, comm_global);
    247   return result;
    248 }
    249 
    250 vmg_float CommMPI::GlobalMaxRoot(const vmg_float& value)
    251 {
    252   vmg_float recv_buffer = value;
    253   vmg_float send_buffer = value;
    254   MPI_Reduce(&send_buffer, &recv_buffer, 1, MPI_DOUBLE, MPI_MAX, 0, comm_global);
    255   return recv_buffer;
     241vmg_float CommMPI::GlobalMax(vmg_float value)
     242{
     243  vmg_float result = 0.0;
     244  MPI_Allreduce(&value, &result, 1, MPI_DOUBLE, MPI_MAX, comm_global);
     245  return result;
     246}
     247
     248vmg_float CommMPI::GlobalMaxRoot(vmg_float value)
     249{
     250  vmg_float result = 0.0;
     251  MPI_Reduce(&value, &result, 1, MPI_DOUBLE, MPI_MAX, 0, comm_global);
     252  return result;
    256253}
    257254
     
    261258}
    262259
    263 vmg_int CommMPI::GlobalMax(const vmg_int& value)
    264 {
    265   vmg_int result = value;
    266   MPI_Allreduce(MPI_IN_PLACE, &result, 1, MPI_INT, MPI_MAX, comm_global);
    267   return result;
    268 }
    269 
    270 vmg_int CommMPI::GlobalMaxRoot(const vmg_int& value)
    271 {
    272   vmg_int recv_buffer = value;
    273   vmg_int send_buffer = value;
    274   MPI_Reduce(&send_buffer, &recv_buffer, 1, MPI_INT, MPI_MAX, 0, comm_global);
    275   return recv_buffer;
     260vmg_int CommMPI::GlobalMax(vmg_int value)
     261{
     262  vmg_int result = 0;
     263  MPI_Allreduce(&value, &result, 1, MPI_INT, MPI_MAX, comm_global);
     264  return result;
     265}
     266
     267vmg_int CommMPI::GlobalMaxRoot(vmg_int value)
     268{
     269  vmg_int result = 0;
     270  MPI_Reduce(&value, &result, 1, MPI_INT, MPI_MAX, 0, comm_global);
     271  return result;
    276272}
    277273
     
    298294}
    299295
    300 vmg_float CommMPI::LevelSum(const Grid& grid, const vmg_float& value)
    301 {
    302   vmg_float result = value;
     296vmg_float CommMPI::LevelSum(const Grid& grid, vmg_float value)
     297{
     298  vmg_float result = 0.0;
    303299  MPI_Comm comm = settings.CommunicatorLocal(grid);
    304300  assert(comm != MPI_COMM_NULL);
    305   MPI_Allreduce(MPI_IN_PLACE, &result, 1, MPI_DOUBLE, MPI_SUM, comm);
    306   return result;
    307 }
    308 
    309 vmg_float CommMPI::LevelSumRoot(const Grid& grid, const vmg_float& value)
    310 {
    311   vmg_float recv_buffer = value;
    312   vmg_float send_buffer = value;
     301  MPI_Allreduce(&value, &result, 1, MPI_DOUBLE, MPI_SUM, comm);
     302  return result;
     303}
     304
     305vmg_float CommMPI::LevelSumRoot(const Grid& grid, vmg_float value)
     306{
     307  vmg_float result = 0.0;
    313308  MPI_Comm comm = settings.CommunicatorLocal(grid);
    314309  assert(comm != MPI_COMM_NULL);
    315   MPI_Reduce(&send_buffer, &recv_buffer, 1, MPI_DOUBLE, MPI_SUM, 0, comm);
    316   return recv_buffer;
     310  MPI_Reduce(&value, &result, 1, MPI_DOUBLE, MPI_SUM, 0, comm);
     311  return result;
    317312}
    318313
     
    324319}
    325320
    326 vmg_int CommMPI::LevelSum(const Grid& grid, const vmg_int& value)
    327 {
    328   vmg_int result = value;
     321vmg_int CommMPI::LevelSum(const Grid& grid, vmg_int value)
     322{
     323  vmg_int result = 0;
    329324  MPI_Comm comm = settings.CommunicatorLocal(grid);
    330325  assert(comm != MPI_COMM_NULL);
    331   MPI_Allreduce(MPI_IN_PLACE, &result, 1, MPI_INT, MPI_SUM, comm);
    332   return result;
    333 }
    334 
    335 vmg_int CommMPI::LevelSumRoot(const Grid& grid, const vmg_int& value)
    336 {
    337   vmg_int recv_buffer = value;
    338   vmg_int send_buffer = value;
     326  MPI_Allreduce(&value, &result, 1, MPI_INT, MPI_SUM, comm);
     327  return result;
     328}
     329
     330vmg_int CommMPI::LevelSumRoot(const Grid& grid, vmg_int value)
     331{
     332  vmg_int result = 0;
    339333  MPI_Comm comm = settings.CommunicatorLocal(grid);
    340334  assert(comm != MPI_COMM_NULL);
    341   MPI_Reduce(&send_buffer, &recv_buffer, 1, MPI_INT, MPI_SUM, 0, comm);
    342   return recv_buffer;
     335  MPI_Reduce(&value, &result, 1, MPI_INT, MPI_SUM, 0, comm);
     336  return result;
    343337}
    344338
  • src/comm/comm_mpi.hpp

    r290aa3 ref94e7  
    8989  void Barrier();
    9090
    91   vmg_float GlobalSum(const vmg_float& value);
    92   vmg_float GlobalSumRoot(const vmg_float& value);
     91  vmg_float GlobalSum(vmg_float value);
     92  vmg_float GlobalSumRoot(vmg_float value);
    9393  void GlobalSumArray(vmg_float* array, const vmg_int& size);
    94   vmg_float GlobalMax(const vmg_float& value);
    95   vmg_float GlobalMaxRoot(const vmg_float& value);
     94  vmg_float GlobalMax(vmg_float value);
     95  vmg_float GlobalMaxRoot(vmg_float value);
    9696  void GlobalMaxArray(vmg_float* array, const vmg_int& size);
    9797  void GlobalBroadcast(vmg_float& value);
    9898  void GlobalGather(vmg_float& value, vmg_float* array);
    9999
    100   vmg_int GlobalSum(const vmg_int& value);
    101   vmg_int GlobalSumRoot(const vmg_int& value);
     100  vmg_int GlobalSum(vmg_int value);
     101  vmg_int GlobalSumRoot(vmg_int value);
    102102  void GlobalSumArray(vmg_int* array, const vmg_int& size);
    103   vmg_int GlobalMax(const vmg_int& value);
    104   vmg_int GlobalMaxRoot(const vmg_int& value);
     103  vmg_int GlobalMax(vmg_int value);
     104  vmg_int GlobalMaxRoot(vmg_int value);
    105105  void GlobalMaxArray(vmg_int* array, const vmg_int& size);
    106106  void GlobalBroadcast(vmg_int& value);
     
    109109  void GlobalBroadcast(char* str);
    110110
    111   vmg_float LevelSum(const Grid& grid, const vmg_float& value);
    112   vmg_float LevelSumRoot(const Grid& grid, const vmg_float& value);
     111  vmg_float LevelSum(const Grid& grid, vmg_float value);
     112  vmg_float LevelSumRoot(const Grid& grid, vmg_float value);
    113113  void LevelSumArray(const Grid& grid,  vmg_float* array, const vmg_int& size);
    114114
    115   vmg_int LevelSum(const Grid& grid, const vmg_int& value);
    116   vmg_int LevelSumRoot(const Grid& grid, const vmg_int& value);
     115  vmg_int LevelSum(const Grid& grid, vmg_int value);
     116  vmg_int LevelSumRoot(const Grid& grid, vmg_int value);
    117117  void LevelSumArray(const Grid& grid,  vmg_int* array, const vmg_int& size);
    118118
  • src/grid/grid.cpp

    r290aa3 ref94e7  
    269269  bool consistent = true;
    270270
    271   for (Grid::iterator iter=Iterators().CompleteGrid().Begin(); iter!=Iterators().CompleteGrid().End(); ++iter)
     271  for (Grid::iterator iter=Iterators().Local().Begin(); iter!=Iterators().Local().End(); ++iter)
    272272    consistent &= Helper::CheckNumber(GetVal(*iter));
    273273
  • src/units/particle/comm_mpi_particle.cpp

    r290aa3 ref94e7  
    218218    for (vmg_int j=0; j<size_receive[i]; ++j) {
    219219      p[recv_buffer_index[i][j]] = recv_buffer_float[i][4*j];
    220       std::memcpy(&f[recv_buffer_index[i][j]], &recv_buffer_float[i][4*j+1], 3*sizeof(vmg_float));
     220      std::memcpy(&f[3*recv_buffer_index[i][j]], &recv_buffer_float[i][4*j+1], 3*sizeof(vmg_float));
    221221    }
    222222#endif
  • src/units/particle/interface_fcs.cpp

    r290aa3 ref94e7  
    221221  const Grid& grid = multigrid(multigrid.MaxLevel());
    222222
    223   int error_code;
     223  int error_code = 0;
    224224
    225225  if (!grid.Global().LocalSize().IsComponentwiseGreater(near_field_cells))
    226226    error_code = 1;
    227   else
    228     error_code = 0;
    229 
    230   error_code = MG::GetComm()->GlobalMax(error_code);
    231 
    232   return error_code;
     227
     228  return MG::GetComm()->GlobalMax(error_code);
    233229}
    234230
  • src/units/particle/interface_particles.cpp

    r290aa3 ref94e7  
    179179        for (p1=lc(i,j,k).begin(); p1!=lc(i,j,k).end(); ++p1) {
    180180
     181          // Interpolate long-range part of potential and electric field
    181182          ip.Evaluate(**p1);
     183
     184          // Subtract self-induced potential
    182185          (*p1)->Pot() -= (*p1)->Charge() * spl.GetAntiDerivativeAtZero();
    183           (*p1)->Field() *= 0.5;
    184186
    185187#ifdef DEBUG_OUTPUT
  • src/units/particle/interpolation.cpp

    r290aa3 ref94e7  
    3030#include "units/particle/particle.hpp"
    3131
     32#include "mg.hpp"
     33#include "comm/comm.hpp"
     34
    3235using namespace VMG;
    3336
     
    5457  Index i;
    5558
    56   const Index begin = index - deg/2 - 1;
     59  const Index begin = index - deg/2;
    5760
    5861  h = grid.Extent().MeshWidth();
     
    105108void Particle::Interpolation::Evaluate(Particle& p)
    106109{
    107  Vector offset;
     110  const Vector& pos = p.Pos();
     111  vmg_float& pot = p.Pot();
     112  Vector& field = p.Field();
    108113
    109  const Vector& pos = p.Pos();
    110  vmg_float& pot = p.Pot();
    111  Vector& field = p.Field();
     114  pot = 0.0;
     115  field = 0.0;
    112116
    113  pot = 0.0;
    114  field = 0.0;
    115 
     117  Vector offset = pos - pos_begin;
    116118  buffer[0] = 1.0;
    117   offset = pos - pos_begin;
    118   for (int i=1; i<deg_1; ++i) {
    119     buffer[i] = buffer[i-1] * offset;
    120     offset -= h;
    121   }
    122 
    123   offset = pos - pos_begin;
    124119  for (int i=0; i<deg; ++i) {
     120    buffer[i+1] = buffer[i] * offset;
    125121    for (int j=0; j<i; ++j)
    126122      buffer_diff[i][j] = buffer_diff[i-1][j] * offset;
     
    145141        field[2] -= _access_coeff(i, j, k+1) * buffer[i][0] * buffer[j][1] * buffer_diff[k][0][2];
    146142      }
    147 
    148143}
    149144
  • src/units/particle/particle.hpp

    r290aa3 ref94e7  
    4040{
    4141public:
     42  Particle() :
     43    x_(0.0),
     44    f_(0.0),
     45    q_(0.0),
     46    p_(0.0),
     47    rank_(-1),
     48    index_(-1)
     49  {}
     50
    4251  Particle(const vmg_float* x, const vmg_float& q) :
    4352    x_(x),
Note: See TracChangeset for help on using the changeset viewer.