~d-weatherley/esys-particle/2.2

« back to all changes in this revision

Viewing changes to Geometry/GeometryInfo.cpp

  • Committer: Steffen Abe
  • Date: 2012-10-31 15:48:29 UTC
  • Revision ID: s.abe@ged.rwth-aachen.de-20121031154829-hdolm11mlms2xskn
Major cleanup of the readGeometry / loadCheckPoint / setSpatialDomain functions. 
- added consistency checks for spatial domain at loading of geometry or checkpoint
- added warning messages for attempts to change spatial domain when already set
- GeometryInfo setup of snapshot & checkpoint controllers ic changed from a "push" approach when setting the spatial domain to "pull" when instatiating the snapshot / checkpoint controller. 
- added warning message if snapshot / checkpoint controller is instantiated before spatial domain is set

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
#include "Geometry/GeometryInfo.h"
15
15
 
 
16
// --- STL includes --- 
16
17
#include <stdexcept>
17
18
#include <sstream>
 
19
#include <algorithm> 
18
20
 
19
21
namespace esys
20
22
{
147
149
        << m_periodicDimensions[1] << " "
148
150
        << m_periodicDimensions[2];
149
151
 
150
 
      if (m_version == 1.2f)
 
152
      if (m_version >= 1.2f)
151
153
      {
152
154
        oStream
153
155
          << "\nDimension "
162
164
      // read and check file type marker
163
165
      std::string fileType;
164
166
      iStream >> fileType;
165
 
      if (fileType != "LSMGeometry") { // wrong file type -> bail out
166
 
        throw runtime_error("Unrecognised file type " + fileType + " expected LSMGeometry.");
 
167
      size_t ftl=std::min(fileType.size(),size_t(4));
 
168
      std::string fileTypeHead=fileType.substr(0,ftl);
 
169
      if ((fileType != "LSMGeometry") && (fileTypeHead!="ESyS")) { // wrong file type -> bail out
 
170
        throw runtime_error("Unrecognised file type " + fileType + " expected LSMGeometry or ESyS-Particle.");
167
171
      }
168
172
 
169
173
      // read and check version number
170
174
      iStream >> impl.m_version;
171
 
      if((impl.m_version != 1.1f) && (impl.m_version != 1.2f)){
 
175
      if((fileType=="LSMGeometry") && ((impl.m_version != 1.1f) && (impl.m_version != 1.2f))){
172
176
        std::stringstream msg;
173
177
        msg
174
178
          << "Can only read version 1.1 or 1.2 geometry files, this is version "
175
179
          << impl.m_version;
176
 
        // throw std::runtime_error(msg.str().c_str());
177
 
        impl.m_version=1.2; // temporary hack
 
180
        throw std::runtime_error(msg.str().c_str());
 
181
      } else if (fileTypeHead=="ESyS") {
 
182
        impl.m_version=1.2f; // temporary hack
178
183
      }
179
184
 
180
185
      // read boundary box
320
325
      m_pImpl->m_version = version;
321
326
    }
322
327
      
 
328
    /*!
 
329
        get the version of the loaded geometry
 
330
    */    
 
331
    float GeometryInfo::getLsmGeoVersion() const
 
332
    {
 
333
      return m_pImpl->m_version;
 
334
    }
 
335
    
323
336
    void GeometryInfo::read(std::istream &iStream)
324
337
    {
325
338
      m_pImpl->read(iStream);
340
353
      m_pImpl->m_bBoxMin = min;
341
354
      m_pImpl->m_bBoxMax = max;
342
355
    }
 
356
 
 
357
        /*!
 
358
         check if a model with the geometry described in the GeoInfo given in the argument
 
359
         can be loaded into a pre-existing model 
 
360
        
 
361
         \param gi the new geometry info
 
362
         */
 
363
        bool GeometryInfo::isCompatible(const GeometryInfo& gi) const
 
364
        {
 
365
                bool res=true;
 
366
                
 
367
                // check if circular dimensions agree
 
368
                res=res && (m_pImpl->m_periodicDimensions[0]==gi.m_pImpl->m_periodicDimensions[0]) 
 
369
                        && (m_pImpl->m_periodicDimensions[1]==gi.m_pImpl->m_periodicDimensions[1]) 
 
370
                        && (m_pImpl->m_periodicDimensions[2]==gi.m_pImpl->m_periodicDimensions[2]); 
 
371
                // check if min/max in circular dimensions agree and 
 
372
                // if new (argument) bounding box fits into old bbx in the non-circular dimensions
 
373
                // x
 
374
                if(m_pImpl->m_periodicDimensions[0]) {
 
375
                        res = res && (m_pImpl->m_bBoxMin[0]==gi.m_pImpl->m_bBoxMin[0])
 
376
                                && (m_pImpl->m_bBoxMax[0]==gi.m_pImpl->m_bBoxMax[0]);
 
377
                } else {
 
378
                        res = res && (m_pImpl->m_bBoxMin[0]<=gi.m_pImpl->m_bBoxMin[0])
 
379
                                && (m_pImpl->m_bBoxMax[0]>=gi.m_pImpl->m_bBoxMax[0]);
 
380
                }
 
381
                // y
 
382
                if(m_pImpl->m_periodicDimensions[1]) {
 
383
                        res = res && (m_pImpl->m_bBoxMin[1]==gi.m_pImpl->m_bBoxMin[1])
 
384
                                && (m_pImpl->m_bBoxMax[1]==gi.m_pImpl->m_bBoxMax[1]);
 
385
                } else {
 
386
                        res = res && (m_pImpl->m_bBoxMin[1]<=gi.m_pImpl->m_bBoxMin[1])
 
387
                                && (m_pImpl->m_bBoxMax[1]>=gi.m_pImpl->m_bBoxMax[1]);
 
388
                }
 
389
                // z
 
390
                if(m_pImpl->m_periodicDimensions[2]) {
 
391
                        res = res && (m_pImpl->m_bBoxMin[2]==gi.m_pImpl->m_bBoxMin[2])
 
392
                                && (m_pImpl->m_bBoxMax[2]==gi.m_pImpl->m_bBoxMax[2]);
 
393
                } else {
 
394
                        res = res && (m_pImpl->m_bBoxMin[2]<=gi.m_pImpl->m_bBoxMin[2])
 
395
                                && (m_pImpl->m_bBoxMax[2]>=gi.m_pImpl->m_bBoxMax[2]);
 
396
                }
 
397
                
 
398
                return res;
 
399
        }
 
400
 
343
401
    
 
402
        /*!
 
403
                Check if the geometrical dimensions in two GeometryInfo objects are identical
 
404
        
 
405
                \param gi the new geometry info
 
406
         */
 
407
        bool GeometryInfo::isIdenticalGeometry(const GeometryInfo& gi) const
 
408
        {
 
409
                bool res=true;
 
410
                
 
411
                // check if circular dimensions agree
 
412
                res=res && (m_pImpl->m_periodicDimensions[0]==gi.m_pImpl->m_periodicDimensions[0]) 
 
413
                        && (m_pImpl->m_periodicDimensions[1]==gi.m_pImpl->m_periodicDimensions[1]) 
 
414
                        && (m_pImpl->m_periodicDimensions[2]==gi.m_pImpl->m_periodicDimensions[2]); 
 
415
                // check if dimensions agree 
 
416
                // x
 
417
                res = res && (m_pImpl->m_bBoxMin[0]==gi.m_pImpl->m_bBoxMin[0])
 
418
                                && (m_pImpl->m_bBoxMax[0]==gi.m_pImpl->m_bBoxMax[0]);
 
419
                // y
 
420
                res = res && (m_pImpl->m_bBoxMin[1]==gi.m_pImpl->m_bBoxMin[1])
 
421
                                && (m_pImpl->m_bBoxMax[1]==gi.m_pImpl->m_bBoxMax[1]);
 
422
                // z
 
423
                res = res && (m_pImpl->m_bBoxMin[2]==gi.m_pImpl->m_bBoxMin[2])
 
424
                                && (m_pImpl->m_bBoxMax[2]==gi.m_pImpl->m_bBoxMax[2]);
 
425
                
 
426
                return res;
 
427
        }
 
428
 
 
429
        
344
430
    std::ostream &operator<<(std::ostream &oStream, const GeometryInfo &geoInfo)
345
431
    {
346
432
      geoInfo.write(oStream);