Back to index

salome-med  6.5.0
Public Member Functions | Private Member Functions | Private Attributes
MEDMEM::ASCII_FIELD_DRIVER< T > Class Template Reference

#include <MEDMEM_AsciiFieldDriver.hxx>

Collaboration diagram for MEDMEM::ASCII_FIELD_DRIVER< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

template<class INTERLACING_TAG >
 ASCII_FIELD_DRIVER ()
template<class INTERLACING_TAG >
 ASCII_FIELD_DRIVER (const string &fileName, FIELD< T, INTERLACING_TAG > *ptrField, MED_EN::med_sort_direc direction=MED_EN::ASCENDING, const char *priority="")
 ASCII_FIELD_DRIVER (const ASCII_FIELD_DRIVER< T > &other)
void open () throw (MEDEXCEPTION)
void close ()
void read (void) throw (MEDEXCEPTION)
void write (void) const throw (MEDEXCEPTION)
GENDRIVER * copy () const

Private Member Functions

void buildIntroduction () const
template<int SPACEDIMENSION, unsigned int SORTSTRATEGY>
void sortAndWrite () const

Private Attributes

MESH * _mesh
SUPPORT * _support
FIELD< T > * _ptrField
std::string _fileName
ofstream _file
unsigned int _code
MED_EN::med_sort_direc _direc
int _nbComponents
int _spaceDimension

Detailed Description

template<class T>
class MEDMEM::ASCII_FIELD_DRIVER< T >

Definition at line 89 of file MEDMEM_AsciiFieldDriver.hxx.


Constructor & Destructor Documentation

template<class T>
template<class INTERLACING_TAG >
MEDMEM::ASCII_FIELD_DRIVER< T >::ASCII_FIELD_DRIVER ( ) [inline]

Definition at line 105 of file MEDMEM_AsciiFieldDriver.hxx.

                        :GENDRIVER(ASCII_DRIVER),
                         _ptrField((FIELD<T>)MED_NULL),
                         _fileName("") {}
template<class T >
template<class INTERLACING_TAG >
MEDMEM::ASCII_FIELD_DRIVER< T >::ASCII_FIELD_DRIVER ( const string &  fileName,
FIELD< T, INTERLACING_TAG > *  ptrField,
MED_EN::med_sort_direc  direction = MED_EN::ASCENDING,
const char *  priority = "" 
)

Definition at line 177 of file MEDMEM_AsciiFieldDriver.hxx.

    :GENDRIVER(fileName, MED_EN::WRONLY, ASCII_DRIVER),
     _ptrField((FIELD<T>*)ptrField),
     _fileName(fileName),
     _direc(direction)
    {
      _nbComponents=_ptrField->getNumberOfComponents();
      if(_nbComponents<=0)
        throw MEDEXCEPTION("ASCII_FIELD_DRIVER : No components in FIELD<T>");
      _support=(SUPPORT *)_ptrField->getSupport();
      _mesh=(MESH *)_support->getMesh();
      _spaceDimension=_mesh->getSpaceDimension();
      _code=3;
      int i;
      if(priority[0]=='\0')
        for(i=_spaceDimension-1;i>=0;i--)
          {
            _code<<=2;
            _code+=i;
          }
      else
        {
          if(_spaceDimension != (int)strlen(priority))
            throw MEDEXCEPTION("ASCII_FIELD_DRIVER : Coordinate priority invalid with spaceDim");
          for(i=_spaceDimension-1;i>=0;i--)
            {
              char c=toupper(priority[i]);
              if(int(c-'X')>(_spaceDimension-1) || int(c-'X')<0)
                throw MEDEXCEPTION("ASCII_FIELD_DRIVER : Invalid priority definition");
              _code<<=2;
              _code+=c-'X';
            }
        }
    }
template<class T >
MEDMEM::ASCII_FIELD_DRIVER< T >::ASCII_FIELD_DRIVER ( const ASCII_FIELD_DRIVER< T > &  other)

Definition at line 217 of file MEDMEM_AsciiFieldDriver.hxx.

                                                                             :
    GENDRIVER(ASCII_DRIVER),
    _mesh(other._mesh),
    _support(other._support),
    _ptrField(other._ptrField),
    _fileName(other._fileName),
    _code(other._code),
    _direc(other._direc),
    _nbComponents(other._nbComponents),
    _spaceDimension(other._spaceDimension)
  {
  }

Member Function Documentation

template<class T >
void MEDMEM::ASCII_FIELD_DRIVER< T >::buildIntroduction ( ) const [private]

Definition at line 334 of file MEDMEM_AsciiFieldDriver.hxx.

  {

    int i;
    _file  << setiosflags(ios::scientific);
    _file << "#TITLE: table " << _ptrField->getName() << " TIME: " << _ptrField->getTime() << " IT: " << _ptrField->getIterationNumber() << endl;
    _file << "#COLUMN_TITLES: ";
    for(i=0;i<_spaceDimension;i++)
      _file << char('X'+i) << " | ";
    const std::string *compoNames=_ptrField->getComponentsNames();
    for(i=0;i<_nbComponents;i++)
      {
        if(!compoNames)
          _file << compoNames[i];
        else
          _file << "None";
        if(i<_nbComponents-1)
          _file << " | ";
      }
    _file << endl;
    _file << "#COLUMN_UNITS: ";
    compoNames=_mesh->getCoordinateptr()->getCoordinatesUnits();
    for(i=0;i<_spaceDimension;i++)
      {
        if(!compoNames)
          _file << compoNames[i];
        else
          _file << "None";
        _file << " | ";
      }
    const UNIT *compoUnits=_ptrField->getComponentsUnits();
    for(i=0;i<_nbComponents;i++)
      {
        if(!compoUnits)
          _file << compoUnits[i].getName();
        else
          _file << "None";
        if(i<_nbComponents-1)
          _file << " | ";
      }
    _file << endl;
  }
template<class T >
void MEDMEM::ASCII_FIELD_DRIVER< T >::close ( )

Definition at line 243 of file MEDMEM_AsciiFieldDriver.hxx.

  {
    _file.close();
    _status = MED_CLOSED;
  }
template<class T >
GENDRIVER * MEDMEM::ASCII_FIELD_DRIVER< T >::copy ( ) const

Definition at line 256 of file MEDMEM_AsciiFieldDriver.hxx.

  {
    return new ASCII_FIELD_DRIVER<T>(*this);
  }
template<class T >
void MEDMEM::ASCII_FIELD_DRIVER< T >::open ( ) throw (MEDEXCEPTION)

Definition at line 231 of file MEDMEM_AsciiFieldDriver.hxx.

  {
                if (_file.is_open())
                        throw MEDEXCEPTION("ASCII_FIELD_DRIVER::open() : file is already open !");
    _file.open(_fileName.c_str(),ofstream::out | ofstream::app);
    // for MEDMEMTest_AsciiFieldDriver.cxx:208 :
    // must throw because the file is opened
    //CPPUNIT_ASSERT_MED_THROW(aDriver1->setFileName("anyfile2"), MEDEXCEPTION);
    _status = _file.is_open() ? MED_OPENED : MED_INVALID;
  }
template<class T >
void MEDMEM::ASCII_FIELD_DRIVER< T >::read ( void  ) throw (MEDEXCEPTION)

Definition at line 250 of file MEDMEM_AsciiFieldDriver.hxx.

  {
    throw MEDEXCEPTION("ASCII_FIELD_DRIVER::read : Can't read with a WRONLY driver !");
  }
template<class T >
template<int SPACEDIMENSION, unsigned int SORTSTRATEGY>
void MEDMEM::ASCII_FIELD_DRIVER< T >::sortAndWrite ( ) const [private]

Definition at line 384 of file MEDMEM_AsciiFieldDriver.hxx.

  {
    typedef typename MEDMEM_ArrayInterface<double,NoInterlace,NoGauss>::Array    ArrayDoubleNo;
    typedef typename MEDMEM_ArrayInterface<double,FullInterlace,NoGauss>::Array  ArrayDoubleFull;
    typedef typename MEDMEM_ArrayInterface<T,NoInterlace,NoGauss>::Array         ArrayNo;
    typedef typename MEDMEM_ArrayInterface<T,NoInterlaceByType,NoGauss>::Array   ArrayNoByType;
    typedef typename MEDMEM_ArrayInterface<T,FullInterlace,NoGauss>::Array       ArrayFull;

    int i,j;
    int numberOfValues=_ptrField->getNumberOfValues();
    std::list< SDForSorting<T,SPACEDIMENSION,SORTSTRATEGY > > li;
    const double * coord;
    FIELD<double,FullInterlace> * barycenterField=0;
    ArrayDoubleNo * baryArrayTmp = NULL;
    double * xyz[SPACEDIMENSION];
    bool deallocateXyz=false;

    if(_support->getEntity()==MED_EN::MED_NODE) {
      if (_support->isOnAllElements()) {

        coord=_mesh->getCoordinates(MED_EN::MED_NO_INTERLACE);
        for(i=0; i<SPACEDIMENSION; i++)
          xyz[i]=(double *)coord+i*numberOfValues;

      } else {

        coord = _mesh->getCoordinates(MED_EN::MED_FULL_INTERLACE);
        const int * nodesNumber=_support->getNumber(MED_EN::MED_ALL_ELEMENTS);
        for(i=0; i<SPACEDIMENSION; i++)
          xyz[i]=new double[numberOfValues];
            deallocateXyz=true;
            for(i=0;i<numberOfValues;i++) {
              for(j=0;j<SPACEDIMENSION;j++)
                xyz[j][i]=coord[(nodesNumber[i]-1)*SPACEDIMENSION+j];
            }
      }
    } else {

      barycenterField = _mesh->getBarycenter(_support);
      baryArrayTmp = ArrayConvert
        ( *( static_cast<ArrayDoubleFull*>(barycenterField->getArray()) ) );
      coord = baryArrayTmp->getPtr();
      for(i=0; i<SPACEDIMENSION; i++)
        xyz[i]=(double *)(coord+i*numberOfValues);
    }

    const T * valsToSet;
    ArrayFull * tmpArray = NULL;
    if ( _ptrField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE )
      valsToSet= _ptrField->getValue();
    else if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) {
      tmpArray = ArrayConvert
        ( *( static_cast<ArrayNoByType*>(_ptrField->getArray()) ) );
      valsToSet= tmpArray->getPtr();
    }
    else {
      tmpArray = ArrayConvert
        ( *( static_cast<ArrayNo*>(_ptrField->getArray()) ) );
      valsToSet= tmpArray->getPtr();
    }
    double temp[SPACEDIMENSION];
    for(i=0;i<numberOfValues;i++) {
      for(j=0;j<SPACEDIMENSION;j++)
        temp[j]=xyz[j][i];
      li.push_back(SDForSorting<T,SPACEDIMENSION,SORTSTRATEGY>(temp,valsToSet+i*_nbComponents,_nbComponents));
    }

    if (barycenterField) barycenterField->removeReference();
    if (baryArrayTmp)    delete baryArrayTmp;
    if (tmpArray)        delete tmpArray;

    if(deallocateXyz)
      for(j=0;j<SPACEDIMENSION;j++)
        delete [] xyz[j];

    li.sort();
    _file << setprecision(PRECISION_IN_ASCII_FILE);
    if(_direc==MED_EN::ASCENDING) {
      typename std::list< SDForSorting<T,SPACEDIMENSION,SORTSTRATEGY > >::iterator iter;
      for(iter=li.begin();iter!=li.end();iter++)
        (*iter).writeLine(_file);
      _file << endl;
    } else if (_direc==MED_EN::DESCENDING) {

      typename std::list< SDForSorting<T,SPACEDIMENSION,SORTSTRATEGY > >::reverse_iterator iter;
      for(iter=li.rbegin();iter!=li.rend();iter++)
        (*iter).writeLine(_file);
      _file << endl;
    } else
      MEDEXCEPTION("ASCII_FIELD_DRIVER : Invalid sort direction");
  }

Here is the call graph for this function:

template<class T >
void MEDMEM::ASCII_FIELD_DRIVER< T >::write ( void  ) const throw (MEDEXCEPTION)

Definition at line 262 of file MEDMEM_AsciiFieldDriver.hxx.

  {
                if (!_file.is_open()) 
                        throw MEDEXCEPTION("ASCII_FIELD_DRIVER::write : can't write a file that was not opened !");
                
    buildIntroduction();
    switch(_spaceDimension)
      {
      case 2:
        {
          switch(_code)
            {
            case 52: //XY
              {
                sortAndWrite<2,52>();
                break;
              }
            case 49: //YX
              {
                sortAndWrite<2,49>();
                break;
              }
            default:
              MEDEXCEPTION("ASCII_FIELD_DRIVER : Invalid priority definition");
            }
          break;
        }
        case 3:
        {
          switch(_code)
            {
            case 228: //XYZ
              {
                sortAndWrite<3,228>();
                break;
              }
            case 216: //XZY
              {
                sortAndWrite<3,216>();
                break;
              }
            case 225://YXZ
              {
                sortAndWrite<3,225>();
                break;
              }
            case 201://YZX
              {
                sortAndWrite<3,201>();
                break;
              }
            case 210://ZXY
              {
                sortAndWrite<3,210>();
                break;
              }
            case 198://ZYX
              {
                sortAndWrite<3,198>();
                break;
              }
             default:
              MEDEXCEPTION("ASCII_FIELD_DRIVER : Invalid priority definition");
            }
          break;
          }
      default:
        MEDEXCEPTION("ASCII_FIELD_DRIVER : Invalid space dimension must be 2 or 3");
        }
  }

Member Data Documentation

template<class T>
unsigned int MEDMEM::ASCII_FIELD_DRIVER< T >::_code [private]

Definition at line 97 of file MEDMEM_AsciiFieldDriver.hxx.

template<class T>
MED_EN::med_sort_direc MEDMEM::ASCII_FIELD_DRIVER< T >::_direc [private]

Definition at line 98 of file MEDMEM_AsciiFieldDriver.hxx.

template<class T>
ofstream MEDMEM::ASCII_FIELD_DRIVER< T >::_file [mutable, private]

Definition at line 96 of file MEDMEM_AsciiFieldDriver.hxx.

template<class T>
std::string MEDMEM::ASCII_FIELD_DRIVER< T >::_fileName [private]

Definition at line 95 of file MEDMEM_AsciiFieldDriver.hxx.

template<class T>
MESH* MEDMEM::ASCII_FIELD_DRIVER< T >::_mesh [private]

Definition at line 92 of file MEDMEM_AsciiFieldDriver.hxx.

template<class T>
int MEDMEM::ASCII_FIELD_DRIVER< T >::_nbComponents [private]

Definition at line 99 of file MEDMEM_AsciiFieldDriver.hxx.

template<class T>
FIELD<T>* MEDMEM::ASCII_FIELD_DRIVER< T >::_ptrField [mutable, private]

Definition at line 94 of file MEDMEM_AsciiFieldDriver.hxx.

template<class T>
int MEDMEM::ASCII_FIELD_DRIVER< T >::_spaceDimension [private]

Definition at line 100 of file MEDMEM_AsciiFieldDriver.hxx.

template<class T>
SUPPORT* MEDMEM::ASCII_FIELD_DRIVER< T >::_support [private]

Definition at line 93 of file MEDMEM_AsciiFieldDriver.hxx.


The documentation for this class was generated from the following file: