/[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 3962 by jfenwick, Tue Sep 11 09:12:07 2012 UTC revision 4009 by caltinay, Tue Oct 2 05:53:37 2012 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2012 by University of Queensland  * Copyright (c) 2003-2012 by University of Queensland
5  * Earth Systems Science Computational Center (ESSCC)  * http://www.uq.edu.au
 * http://www.uq.edu.au/esscc  
6  *  *
7  * Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
8  * Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
9  * http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
10  *  *
11  *******************************************************/  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12    * Development since 2012 by School of Earth Sciences
13    *
14    *****************************************************************************/
15    
16  #include <ripley/Brick.h>  #include <ripley/Brick.h>
17  extern "C" {  extern "C" {
# Line 238  bool Brick::operator==(const AbstractDom Line 240  bool Brick::operator==(const AbstractDom
240      return false;      return false;
241  }  }
242    
243    void Brick::readBinaryGrid(escript::Data& out, string filename,
244                               const vector<int>& first,
245                               const vector<int>& numValues) const
246    {
247        // check destination function space
248        int myN0, myN1, myN2;
249        if (out.getFunctionSpace().getTypeCode() == Nodes) {
250            myN0 = m_N0;
251            myN1 = m_N1;
252            myN2 = m_N2;
253        } else if (out.getFunctionSpace().getTypeCode() == Elements ||
254                    out.getFunctionSpace().getTypeCode() == ReducedElements) {
255            myN0 = m_NE0;
256            myN1 = m_NE1;
257            myN2 = m_NE2;
258        } else
259            throw RipleyException("readBinaryGrid(): invalid function space for output data object");
260    
261        // check file existence and size
262        ifstream f(filename.c_str(), ifstream::binary);
263        if (f.fail()) {
264            throw RipleyException("readBinaryGrid(): cannot open file");
265        }
266        f.seekg(0, ios::end);
267        const int numComp = out.getDataPointSize();
268        const int filesize = f.tellg();
269        const int reqsize = numValues[0]*numValues[1]*numValues[2]*numComp*sizeof(float);
270        if (filesize < reqsize) {
271            f.close();
272            throw RipleyException("readBinaryGrid(): not enough data in file");
273        }
274    
275        // check if this rank contributes anything
276        if (first[0] >= m_offset0+myN0 || first[0]+numValues[0] <= m_offset0 ||
277                first[1] >= m_offset1+myN1 || first[1]+numValues[1] <= m_offset1 ||
278                first[2] >= m_offset2+myN2 || first[2]+numValues[2] <= m_offset2) {
279            f.close();
280            return;
281        }
282    
283        // now determine how much this rank has to write
284    
285        // first coordinates in data object to write to
286        const int first0 = max(0, first[0]-m_offset0);
287        const int first1 = max(0, first[1]-m_offset1);
288        const int first2 = max(0, first[2]-m_offset2);
289        // indices to first value in file
290        const int idx0 = max(0, m_offset0-first[0]);
291        const int idx1 = max(0, m_offset1-first[1]);
292        const int idx2 = max(0, m_offset2-first[2]);
293        // number of values to write
294        const int num0 = min(numValues[0]-idx0, myN0-first0);
295        const int num1 = min(numValues[1]-idx1, myN1-first1);
296        const int num2 = min(numValues[2]-idx2, myN2-first2);
297    
298        out.requireWrite();
299        vector<float> values(num0*numComp);
300        const int dpp = out.getNumDataPointsPerSample();
301    
302        for (index_t z=0; z<num2; z++) {
303            for (index_t y=0; y<num1; y++) {
304                const int fileofs = numComp*(idx0+(idx1+y)*numValues[0]+(idx2+z)*numValues[0]*numValues[1]);
305                f.seekg(fileofs*sizeof(float));
306                f.read((char*)&values[0], num0*numComp*sizeof(float));
307                const int dataIndex = first0+(first1+y)*myN0+(first2+z)*myN0*myN1;
308    
309                for (index_t x=0; x<num0; x++) {
310                    double* dest = out.getSampleDataRW(dataIndex+x);
311                    for (index_t c=0; c<numComp; c++) {
312                        for (index_t q=0; q<dpp; q++) {
313                            *dest++ = static_cast<double>(values[x*numComp+c]);
314                        }
315                    }
316                }
317            }
318        }
319    
320        f.close();
321    }
322    
323  void Brick::dump(const string& fileName) const  void Brick::dump(const string& fileName) const
324  {  {
325  #if USE_SILO  #if USE_SILO
# Line 1678  void Brick::dofToNodes(escript::Data& ou Line 1760  void Brick::dofToNodes(escript::Data& ou
1760                  : &buffer[(m_dofMap[i]-numDOF)*numComp]);                  : &buffer[(m_dofMap[i]-numDOF)*numComp]);
1761          copy(src, src+numComp, out.getSampleDataRW(i));          copy(src, src+numComp, out.getSampleDataRW(i));
1762      }      }
1763        Paso_Coupler_free(coupler);
1764  }  }
1765    
1766  //private  //private

Legend:
Removed from v.3962  
changed lines
  Added in v.4009

  ViewVC Help
Powered by ViewVC 1.1.26