diff --git a/src/field.cc b/src/field.cc index 4c14af8..d692bd6 100644 --- a/src/field.cc +++ b/src/field.cc @@ -1,70 +1,71 @@ /** * @file field.cc * * @author Guillaume Anciaux * * @date creation: Wed Dec 14 2011 * @date last modification: Thu Nov 01 2012 * * @brief implementation of the Field class * * @section LICENSE * * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * IOHelper is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * IOHelper is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with IOHelper. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "field.hh" /* -------------------------------------------------------------------------- */ __BEGIN_IOHELPER__ /* -------------------------------------------------------------------------- */ - - template <> FieldType Field::getFieldDataType(){ return REAL; } /* -------------------------------------------------------------------------- */ - template <> FieldType Field::getFieldDataType(){ return UINT; } /* -------------------------------------------------------------------------- */ - template <> FieldType Field::getFieldDataType(){ return BOOL; } /* -------------------------------------------------------------------------- */ +template <> +FieldType Field::getFieldDataType(){ + return INT; +} +/* -------------------------------------------------------------------------- */ template <> -FieldType Field::getFieldDataType(){ +FieldType Field::getFieldDataType(){ return INT; } /* -------------------------------------------------------------------------- */ __END_IOHELPER__ diff --git a/src/iohelper_common.hh b/src/iohelper_common.hh index a16afe2..2fff59f 100644 --- a/src/iohelper_common.hh +++ b/src/iohelper_common.hh @@ -1,288 +1,294 @@ /** * @file iohelper_common.hh * * @author Guillaume Anciaux * @author David Simon Kammer * @author Nicolas Richart * * @date creation: Thu Mar 11 2010 * @date last modification: Thu Oct 10 2013 * * @brief header for common types * * @section LICENSE * * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * IOHelper is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * IOHelper is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with IOHelper. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef __IOHELPER_COMMON_H__ #define __IOHELPER_COMMON_H__ /* -------------------------------------------------------------------------- */ #define USING_ZLIB #include #include #include #define __BEGIN_IOHELPER__ namespace iohelper { #define __END_IOHELPER__ } #include #include /* -------------------------------------------------------------------------- */ __BEGIN_IOHELPER__ typedef unsigned int UInt; typedef int Int; typedef double Real; /* -------------------------------------------------------------------------- */ enum DataType { _bool, _uint, _int, _float, - _double + _double, + _int64, + _uint64, }; enum IndexingMode{ C_MODE = 0, FORTRAN_MODE = 1 }; /* -------------------------------------------------------------------------- */ #if __cplusplus <= 199711L enum ElemType { #else enum ElemType : unsigned int { #endif TRIANGLE1 , TRIANGLE2 , TETRA1 , TETRA2 , POINT_SET , LINE1 , LINE2 , QUAD1 , QUAD2 , HEX1 , HEX2 , BEAM2 , BEAM3 , PRISM1 , PRISM2 , COH2D4 , COH2D6 , COH3D6 , COH3D12 , MAX_ELEM_TYPE }; /* -------------------------------------------------------------------------- */ enum FileStorageMode{ TEXT = 0, BASE64 = 1, COMPRESSED = 2 }; enum TextDumpMode { _tdm_space, _tdm_csv, }; /* -------------------------------------------------------------------------- */ static UInt nb_node_per_elem[MAX_ELEM_TYPE] __attribute__((unused)) = { 3, // TRIANGLE1 6, // TRIANGLE2 4, // TETRA1 10, // TETRA2 1, // POINT_SET 2, // LINE1 3, // LINE2 4, // QUAD1 8, // QUAD2 8, // HEX1 20, // HEX2 2, // BEAM2 2, // BEAM3 6, // PRISM1 15, // PRISM2 4, // COH2D4 6, // COH2D6 6, // COH3D6 12 // COH3D12 }; /* -------------------------------------------------------------------------- */ static UInt nb_quad_points[MAX_ELEM_TYPE] __attribute__((unused)) = { 1, // TRIANGLE1 3, // TRIANGLE2 1, // TETRA1 4, // TETRA2 0, // POINT_SET 1, // LINE1 2, // LINE2 4, // QUAD1 9, // QUAD2 1, // HEX1 8, // HEX2 2, // BEAM2 3, // BEAM3 6, // PRISM1 8, // PRISM2 1, // COH2D4 2, // COH2D6 1, // COH3D6 3 // COH3D12 }; /* -------------------------------------------------------------------------- */ template class IOHelperVector { public: virtual ~IOHelperVector() {} inline IOHelperVector(T * ptr, UInt size){ this->ptr = ptr; this->_size = size; }; inline UInt size() const {return _size;}; inline const T & operator[] (UInt i) const { return ptr[i]; }; inline const T * getPtr() const { return ptr; }; private: T* ptr; UInt _size; }; /* -------------------------------------------------------------------------- */ /* Iterator interface */ /* -------------------------------------------------------------------------- */ template< typename T, class daughter, class ret_cont = IOHelperVector > class iterator { public: typedef ret_cont type; virtual ~iterator() {} virtual bool operator!=(const daughter & it) const = 0; virtual daughter & operator++() = 0; virtual ret_cont operator*() = 0; //! This function is only for the element iterators virtual ElemType element_type() { return MAX_ELEM_TYPE; } }; /* -------------------------------------------------------------------------- */ class IOHelperException : public std::exception { public: enum ErrorType { _et_non_homogeneous_data, _et_unknown_visitor_stage, _et_file_error, _et_missing_field, _et_data_type, _et_options_error }; public: IOHelperException(const std::string & message, const ErrorType type) throw() { this->message = message; this->type = type; }; ~IOHelperException() throw(){}; virtual const char* what() const throw(){ return message.c_str(); }; private: std::string message; ErrorType type; }; /* -------------------------------------------------------------------------- */ #define IOHELPER_THROW(x,type) { \ std::stringstream ioh_throw_sstr; \ ioh_throw_sstr << __FILE__ << ":" << __LINE__ << ":" \ << __PRETTY_FUNCTION__ << ": " << x; \ std::string ioh_message(ioh_throw_sstr.str()); \ throw ::iohelper::IOHelperException(ioh_message, \ ::iohelper::IOHelperException::type); \ } /* -------------------------------------------------------------------------- */ template DataType getDataType(); #define DEFINE_GET_DATA_TYPE(type, data_type ) \ template <> inline DataType getDataType() { return data_type; } DEFINE_GET_DATA_TYPE(bool, _bool) DEFINE_GET_DATA_TYPE(ElemType, _int) DEFINE_GET_DATA_TYPE(int, _int) DEFINE_GET_DATA_TYPE(unsigned int, _uint) DEFINE_GET_DATA_TYPE(float, _float) DEFINE_GET_DATA_TYPE(double, _double) +DEFINE_GET_DATA_TYPE(long int, _int64) +DEFINE_GET_DATA_TYPE(unsigned long int, _uint64) #undef DEFINE_GET_DATA_TYPE inline std::ostream & operator <<(std::ostream & stream, DataType type) { switch(type) { case _bool : stream << "bool" ; break; case _uint : stream << "uint32" ; break; case _int : stream << "int32" ; break; case _float : stream << "float32" ; break; case _double : stream << "float64" ; break; + case _uint64 : stream << "uint64" ; break; + case _int64 : stream << "int64" ; break; } return stream; } inline std::ostream & operator <<(std::ostream & stream, TextDumpMode mode) { switch(mode) { case _tdm_space : stream << "space" ; break; case _tdm_csv : stream << "csv" ; break; } return stream; } __END_IOHELPER__ #endif /* __IOHELPER_COMMON_H__ */ diff --git a/src/paraview_helper.tcc b/src/paraview_helper.tcc index d8a3043..b016755 100644 --- a/src/paraview_helper.tcc +++ b/src/paraview_helper.tcc @@ -1,306 +1,308 @@ #include #if defined(__INTEL_COMPILER) #pragma warning ( push ) /// remark #981: operands are evaluated in unspecified order #pragma warning ( disable : 981 ) #endif //defined(__INTEL_COMPILER) inline std::string ParaviewHelper::dataTypeToStr(DataType data_type) { std::string str; switch(data_type) { case _bool : str = "UInt8" ; break; case _uint : str = "UInt32" ; break; case _int : str = "Int32" ; break; case _float : str = "Float32"; break; case _double : str = "Float64"; break; + case _uint64 : str = "UInt64" ; break; + case _int64 : str = "Int64" ; break; } return str; } /* -------------------------------------------------------------------------- */ template inline void ParaviewHelper::visitField(T & visited){ this->position_flag = false; switch (current_stage){ case _s_writeFieldProperty: writeFieldProperty(visited); break; case _s_writePosition: this->position_flag = true; case _s_writeField: writeField(visited); break; case _s_writeConnectivity: writeConnectivity(visited); break; case _s_writeElemType: writeElemType(visited); break; case _s_buildOffsets: writeOffsets(visited); break; default: std::stringstream sstr; sstr << "the stage " << current_stage << " is not a known paraviewhelper stage"; IOHELPER_THROW(sstr.str(), IOHelperException::_et_unknown_visitor_stage); } } /* -------------------------------------------------------------------------- */ template inline void ParaviewHelper::writeFieldProperty(T & data){ if (data.isHomogeneous() == false) IOHELPER_THROW(std::string("try to write field property of a non homogeneous field"), IOHelperException::_et_non_homogeneous_data); UInt dim = data.getDim(); std::string name = data.getName(); PDataArray(name, dim, dataTypeToStr(data.getDataType())); } /* -------------------------------------------------------------------------- */ template inline void ParaviewHelper::writeField(T & data){ typename T::iterator it = data.begin(); typename T::iterator end = data.end(); compteur = 0; UInt dim; if(data.isHomogeneous()) { dim = data.getDim(); if(position_flag) dim = 3; for (; it != end; ++it) pushData((*it), dim); } else { for (; it != end; ++it) pushData((*it)); } } /* -------------------------------------------------------------------------- */ template inline void ParaviewHelper::writeConnectivity(T & data) { typename T::iterator it = data.begin(); typename T::iterator end = data.end(); for (; it != end; ++it) { ElemType type = (ElemType) it.element_type(); //typename T::iterator::type & n = *it; UInt dim = (*it).size(); assert(nb_node_per_elem[type] == dim); UInt * reorder = this->write_reorder[type]; for (UInt i = 0; i < dim; ++i) { this->pushDatum((*it)[reorder[i]], dim); } } } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ template inline void ParaviewHelper::writeElemType(T & data){ typename T::iterator it = data.begin(); typename T::iterator end = data.end(); for (; it != end; ++it) { ElemType type = (ElemType) it.element_type(); this->pushDatum(this->paraview_code_type[type], 1); } } /* -------------------------------------------------------------------------- */ template inline void ParaviewHelper::writeOffsets(T & data){ typename T::iterator it = data.begin(); typename T::iterator end = data.end(); UInt count = 0; for (; it != end; ++it) { count += (*it).size(); pushDatum(count); } } /* -------------------------------------------------------------------------- */ template class Cont, typename T> inline void ParaviewHelper::pushData(const Cont & n, UInt dim){ for (UInt i = 0; i < n.size(); ++i) { pushDatum(n[i], dim); } for (UInt i = n.size(); i < dim; ++i) { T t = T(); this->pushDatum(t, dim); } } /* -------------------------------------------------------------------------- */ template class Cont, typename T> inline void ParaviewHelper::pushData(const Cont & n) { for (UInt i = 0; i < n.size(); ++i) { pushDatum(n[i], n.size()); } } /* -------------------------------------------------------------------------- */ inline void ParaviewHelper::setMode(int mode){ bflag = BASE64 & mode; } /* -------------------------------------------------------------------------- */ template inline void ParaviewHelper::writePVTU(T & per_node_data, T & per_elem_data, const std::vector & vtus){ current_stage = _s_writeFieldProperty; file << "" << std::endl; file << " " << std::endl; file << " " << std::endl; file << " " << std::endl; file << " " << std::endl; file << " " << std::endl; typename T::iterator itNodeField = per_node_data.begin(); typename T::iterator endNodeField = per_node_data.end(); for ( ; itNodeField != endNodeField ; ++itNodeField) if ((*itNodeField).first != "positions") (*itNodeField).second->accept(*this); file << " " << std::endl; file << " " << std::endl; typename T::iterator itElemField = per_elem_data.begin(); typename T::iterator endElemField = per_elem_data.end(); for (; itElemField != endElemField ; ++itElemField) { std::string name = (*itElemField).first; if (name == "connectivities" || name == "element_type") continue; (*itElemField).second->accept(*this); } file << " " << std::endl; for (UInt l = 0 ; l < vtus.size() ; ++l) file << " " << std::endl; file << " " << std::endl; file << "" << std::endl; file.close(); } /* -------------------------------------------------------------------------- */ template void ParaviewHelper::pushDataFields(T & per_node_data, T & per_elem_data){ startPointDataList(); { typename T::iterator itNodeField = per_node_data.begin(); typename T::iterator endNodeField = per_node_data.end(); for ( ; itNodeField != endNodeField ; ++itNodeField) { std::string name = (*itNodeField).first; if (name == "positions") continue; FieldInterface & f = *(*itNodeField).second; startData(f.getName(), f.getDim(), dataTypeToStr(f.getDataType())); pushField(f); endData(); } } endPointDataList(); startCellDataList(); { typename T::iterator itElemField = per_elem_data.begin(); typename T::iterator endElemField = per_elem_data.end(); for ( ; itElemField != endElemField ; ++itElemField) { std::string name = (*itElemField).first; if (name == "connectivities" || name == "element_type") continue; FieldInterface & f = *(*itElemField).second; startData(f.getName(),f.getDim(), dataTypeToStr(f.getDataType())); pushField(f); endData(); } } endCellDataList(); } /* -------------------------------------------------------------------------- */ template inline void ParaviewHelper::pushDatum(const T & n, __attribute__((unused)) UInt size){ if (bflag == BASE64) b64.push(n); else{ if (compteur == 0) file << " "; ++compteur; file << n << " "; } } /* -------------------------------------------------------------------------- */ template <> inline void ParaviewHelper::pushDatum(const double & n, UInt size){ if (bflag == BASE64) b64.push(n); else { if (compteur % size == 0) file << " "; file << std::setw(22); file << std::setprecision(15); file << std::scientific; file << n; file << " "; ++compteur; if (compteur % size == 0) file << std::endl; } } /* -------------------------------------------------------------------------- */ template <> inline void ParaviewHelper::pushDatum(const ElemType & type, __attribute__((unused)) UInt size){ UInt n = this->paraview_code_type[type]; pushDatum(n); } /* -------------------------------------------------------------------------- */ inline void ParaviewHelper::pushPosition(FieldInterface & f){ current_stage = _s_writePosition; f.accept(*this); } /* -------------------------------------------------------------------------- */ inline void ParaviewHelper::pushField(FieldInterface & f){ current_stage = _s_writeField; f.accept(*this); } /* -------------------------------------------------------------------------- */ inline void ParaviewHelper::pushConnectivity(FieldInterface & f) { current_stage = _s_writeConnectivity; f.accept(*this); } /* -------------------------------------------------------------------------- */ inline void ParaviewHelper::pushElemType(FieldInterface & f) { current_stage = _s_writeElemType; f.accept(*this); } /* -------------------------------------------------------------------------- */ inline void ParaviewHelper::buildOffsets(FieldInterface & f){ current_stage = _s_buildOffsets; f.accept(*this); } /* -------------------------------------------------------------------------- */ #if defined(__INTEL_COMPILER) #pragma warning ( pop ) #endif //defined(__INTEL_COMPILER)