/[escript]/branches/diaplayground/ripley/src/Brick.cpp
ViewVC logotype

Diff of /branches/diaplayground/ripley/src/Brick.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4615 by caltinay, Mon Jan 13 05:05:33 2014 UTC revision 4618 by caltinay, Wed Jan 15 04:35:19 2014 UTC
# Line 251  bool Brick::operator==(const AbstractDom Line 251  bool Brick::operator==(const AbstractDom
251  }  }
252    
253  void Brick::readNcGrid(escript::Data& out, string filename, string varname,  void Brick::readNcGrid(escript::Data& out, string filename, string varname,
254              const GridParameters& params) const              const ReaderParameters& params) const
255  {  {
256  #ifdef USE_NETCDF  #ifdef USE_NETCDF
257      // check destination function space      // check destination function space
# Line 323  void Brick::readNcGrid(escript::Data& ou Line 323  void Brick::readNcGrid(escript::Data& ou
323      const int first0 = max(0, params.first[0]-m_offset[0]);      const int first0 = max(0, params.first[0]-m_offset[0]);
324      const int first1 = max(0, params.first[1]-m_offset[1]);      const int first1 = max(0, params.first[1]-m_offset[1]);
325      const int first2 = max(0, params.first[2]-m_offset[2]);      const int first2 = max(0, params.first[2]-m_offset[2]);
326      // indices to first value in file      // indices to first value in file (not accounting for reverse yet)
327      const int idx0 = max(0, m_offset[0]-params.first[0]);      int idx0 = max(0, m_offset[0]-params.first[0]);
328      const int idx1 = max(0, m_offset[1]-params.first[1]);      int idx1 = max(0, m_offset[1]-params.first[1]);
329      const int idx2 = max(0, m_offset[2]-params.first[2]);      int idx2 = max(0, m_offset[2]-params.first[2]);
330      // number of values to read      // number of values to read
331      const int num0 = min(params.numValues[0]-idx0, myN0-first0);      const int num0 = min(params.numValues[0]-idx0, myN0-first0);
332      const int num1 = min(params.numValues[1]-idx1, myN1-first1);      const int num1 = min(params.numValues[1]-idx1, myN1-first1);
333      const int num2 = min(params.numValues[2]-idx2, myN2-first2);      const int num2 = min(params.numValues[2]-idx2, myN2-first2);
334    
335        // make sure we read the right block if going backwards through file
336        if (params.reverse[0])
337            idx0 = edges[dims-1]-num0-idx0;
338        if (dims>1 && params.reverse[1])
339            idx1 = edges[dims-2]-num1-idx1;
340        if (dims>2 && params.reverse[2])
341            idx2 = edges[dims-3]-num2-idx2;
342    
343    
344      vector<double> values(num0*num1*num2);      vector<double> values(num0*num1*num2);
345      if (dims==3) {      if (dims==3) {
346          var->set_cur(idx2, idx1, idx0);          var->set_cur(idx2, idx1, idx0);
# Line 347  void Brick::readNcGrid(escript::Data& ou Line 356  void Brick::readNcGrid(escript::Data& ou
356      const int dpp = out.getNumDataPointsPerSample();      const int dpp = out.getNumDataPointsPerSample();
357      out.requireWrite();      out.requireWrite();
358    
359        // helpers for reversing
360        const int x0 = (params.reverse[0] ? num0-1 : 0);
361        const int x_mult = (params.reverse[0] ? -1 : 1);
362        const int y0 = (params.reverse[1] ? num1-1 : 0);
363        const int y_mult = (params.reverse[1] ? -1 : 1);
364        const int z0 = (params.reverse[2] ? num2-1 : 0);
365        const int z_mult = (params.reverse[2] ? -1 : 1);
366    
367      for (index_t z=0; z<num2; z++) {      for (index_t z=0; z<num2; z++) {
368          for (index_t y=0; y<num1; y++) {          for (index_t y=0; y<num1; y++) {
369  #pragma omp parallel for  #pragma omp parallel for
# Line 354  void Brick::readNcGrid(escript::Data& ou Line 371  void Brick::readNcGrid(escript::Data& ou
371                  const int baseIndex = first0+x*params.multiplier[0]                  const int baseIndex = first0+x*params.multiplier[0]
372                                       +(first1+y*params.multiplier[1])*myN0                                       +(first1+y*params.multiplier[1])*myN0
373                                       +(first2+z*params.multiplier[2])*myN0*myN1;                                       +(first2+z*params.multiplier[2])*myN0*myN1;
374                  const int srcIndex=z*num1*num0+y*num0+x;                  const int srcIndex=(z0+z_mult*z)*num1*num0
375                                      +(y0+y_mult*y)*num0
376                                      +(x0+x_mult*x);
377                  if (!isnan(values[srcIndex])) {                  if (!isnan(values[srcIndex])) {
378                      for (index_t m2=0; m2<params.multiplier[2]; m2++) {                      for (index_t m2=0; m2<params.multiplier[2]; m2++) {
379                          for (index_t m1=0; m1<params.multiplier[1]; m1++) {                          for (index_t m1=0; m1<params.multiplier[1]; m1++) {
# Line 379  void Brick::readNcGrid(escript::Data& ou Line 398  void Brick::readNcGrid(escript::Data& ou
398  }  }
399    
400  void Brick::readBinaryGrid(escript::Data& out, string filename,  void Brick::readBinaryGrid(escript::Data& out, string filename,
401                             const GridParameters& params) const                             const ReaderParameters& params) const
402  {  {
403      // the mapping is not universally correct but should work on our      // the mapping is not universally correct but should work on our
404      // supported platforms      // supported platforms
# Line 400  void Brick::readBinaryGrid(escript::Data Line 419  void Brick::readBinaryGrid(escript::Data
419    
420  template<typename ValueType>  template<typename ValueType>
421  void Brick::readBinaryGridImpl(escript::Data& out, const string& filename,  void Brick::readBinaryGridImpl(escript::Data& out, const string& filename,
422                                 const GridParameters& params) const                                 const ReaderParameters& params) const
423  {  {
424      // check destination function space      // check destination function space
425      int myN0, myN1, myN2;      int myN0, myN1, myN2;

Legend:
Removed from v.4615  
changed lines
  Added in v.4618

  ViewVC Help
Powered by ViewVC 1.1.26