63 m_connectivity = connectivity ;
73void VTKUnstructuredGrid::HomogeneousInfoStreamer::flushData( std::fstream &str,
const std::string &name,
VTKFormat format){
75 assert( m_type != VTKElementType::UNDEFINED ) ;
77 VTKDataType connectivityDataType = m_connectivity->getDataType();
80 uint8_t type = (uint8_t) m_type ;
81 for( uint64_t i=0; i<m_nCells; ++i){
82 flushValue(str, format, type );
85 }
else if(name ==
"offsets" ){
87 if (connectivityDataType == VTKDataType::Int64 || connectivityDataType == VTKDataType::UInt64) {
89 for( uint64_t i=0; i<m_nCells; ++i){
91 flushValue(str, format, offset );
93 }
else if (connectivityDataType == VTKDataType::Int32 || connectivityDataType == VTKDataType::UInt32) {
95 for( uint64_t i=0; i<m_nCells; ++i){
97 flushValue(str, format, offset );
99 }
else if (connectivityDataType == VTKDataType::Int16 || connectivityDataType == VTKDataType::UInt16) {
101 for( uint64_t i=0; i<m_nCells; ++i){
103 flushValue(str, format, offset );
105 }
else if (connectivityDataType == VTKDataType::Int8 || connectivityDataType == VTKDataType::UInt8) {
107 for( uint64_t i=0; i<m_nCells; ++i){
109 flushValue(str, format, offset );
144 m_geometry[getFieldGeomId(VTKUnstructuredField::CONNECTIVITY)] =
VTKField(
"connectivity") ;
146 m_geometry[getFieldGeomId(VTKUnstructuredField::FACE_OFFSETS)] =
VTKField(
"faceoffsets") ;
149 field.setLocation( VTKLocation::CELL ) ;
150 field.setFieldType( VTKFieldType::SCALAR ) ;
151 field.setDataType( VTKDataType::Int32 ) ;
155 m_geometry[getFieldGeomId(VTKUnstructuredField::POINTS)].setLocation( VTKLocation::POINT ) ;
156 m_geometry[getFieldGeomId(VTKUnstructuredField::POINTS)].setFieldType( VTKFieldType::VECTOR ) ;
157 m_geometry[getFieldGeomId(VTKUnstructuredField::POINTS)].setDataType( VTKDataType::Float64 ) ;
159 m_geometry[getFieldGeomId(VTKUnstructuredField::FACE_STREAMS)].disable();
160 m_geometry[getFieldGeomId(VTKUnstructuredField::FACE_OFFSETS)].disable();
199 int types_gid = getFieldGeomId(VTKUnstructuredField::TYPES);
200 m_geometry[types_gid].setDataType( VTKDataType::UInt8) ;
205 int offsets_gid = getFieldGeomId(VTKUnstructuredField::OFFSETS);
238 bool unevenConnectivity =
false;
239 unevenConnectivity |= (
m_elementType == VTKElementType::UNDEFINED ) ;
240 unevenConnectivity |= (
m_elementType == VTKElementType::POLYGON ) ;
241 unevenConnectivity |= (
m_elementType == VTKElementType::POLYHEDRON ) ;
243 if ( unevenConnectivity ) {
252 bool faceSteamEnabled =
false;
253 faceSteamEnabled |= (
m_elementType == VTKElementType::POLYGON ) ;
254 faceSteamEnabled |= (
m_elementType == VTKElementType::POLYHEDRON ) ;
255 faceSteamEnabled |= (
m_elementType == VTKElementType::UNDEFINED && nfacestream > 0 ) ;
257 if ( faceSteamEnabled ) {
260 m_geometry[getFieldGeomId(VTKUnstructuredField::FACE_STREAMS)].enable();
261 m_geometry[getFieldGeomId(VTKUnstructuredField::FACE_OFFSETS)].enable();
265 m_geometry[getFieldGeomId(VTKUnstructuredField::FACE_STREAMS)].disable();
266 m_geometry[getFieldGeomId(VTKUnstructuredField::FACE_OFFSETS)].disable();
278 int index = getFieldGeomId(fieldEnum) ;
294 std::fstream::pos_type position_appended;
301 int connectivity_gid = getFieldGeomId(VTKUnstructuredField::CONNECTIVITY);
302 if(connectivity_gid < 0)
return nconn;
304 if(!
m_geometry[connectivity_gid].hasAllMetaData() || !
m_geometry[connectivity_gid].isEnabled()){
305 throw std::runtime_error(
"VTKUnstructuredGrid::readConnectivityEntries. Connectivity field is missing meta information or disabled");
308 if(
m_geometry[connectivity_gid].getCodification() == VTKFormat::APPENDED ){
309 str.open(
m_fh.
getPath( ), std::ios::in | std::ios::binary ) ;
313 while( c_ !=
'_') str >> c_;
314 position_appended = str.tellg();
319 if(
m_geometry[connectivity_gid].getCodification() == VTKFormat::APPENDED ){
320 str.open(
m_fh.
getPath( ), std::ios::in | std::ios::binary);
321 str.seekg( position_appended) ;
322 str.seekg(
m_geometry[connectivity_gid].getOffset(), std::ios::cur) ;
325 assert(dataSize > 0) ;
329 nconn = nbytes32 / dataSize ;
334 nconn = nbytes64 / dataSize ;
342 if(
m_geometry[connectivity_gid].getCodification() == VTKFormat::ASCII ){
343 str.open(
m_fh.
getPath( ), std::ios::in | std::ios::binary);
344 str.seekg(
m_geometry[connectivity_gid].getPosition() ) ;
347 std::vector<uint64_t> temp;
351 getline( str, line) ;
355 nconn += temp.size() ;
356 getline( str, line) ;
373 std::fstream::pos_type position_appended;
380 int facestream_gid = getFieldGeomId(VTKUnstructuredField::FACE_STREAMS);
381 if(facestream_gid < 0 )
return nface;
382 if(!
m_geometry[facestream_gid].hasAllMetaData() || !
m_geometry[facestream_gid].isEnabled())
return nface;
384 if(
m_geometry[facestream_gid].getCodification() == VTKFormat::APPENDED ){
385 str.open(
m_fh.
getPath( ), std::ios::in | std::ios::binary ) ;
389 while( c_ !=
'_') str >> c_;
390 position_appended = str.tellg();
395 if(
m_geometry[facestream_gid].getCodification() == VTKFormat::APPENDED ){
396 str.open(
m_fh.
getPath( ), std::ios::in | std::ios::binary);
397 str.seekg( position_appended) ;
398 str.seekg(
m_geometry[facestream_gid].getOffset(), std::ios::cur) ;
401 assert(dataSize > 0) ;
405 nface = nbytes32 / dataSize ;
410 nface = nbytes64 / dataSize ;
415 if(
m_geometry[facestream_gid].getCodification() == VTKFormat::ASCII ){
416 str.open(
m_fh.
getPath( ), std::ios::in | std::ios::binary );
417 str.seekg(
m_geometry[facestream_gid].getPosition() ) ;
420 std::vector<uint64_t> temp;
424 getline( str, line) ;
428 nface += temp.size() ;
429 getline( str, line) ;
448 if (!str.is_open()) {
449 throw std::runtime_error(
"Cannot create file \"" +
m_fh.
getName() +
"\"" +
" inside the directory \"" +
m_fh.
getDirectory() +
"\"");
453 str <<
"<?xml version=\"1.0\"?>" << std::endl;
456 str <<
"<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" byte_order=\"LittleEndian\" header_type=\"" <<
m_headerType <<
"\">" << std::endl;
457 str <<
" <UnstructuredGrid>" << std::endl;;
458 str <<
" <Piece NumberOfPoints=\"" <<
m_points <<
"\" NumberOfCells=\"" <<
m_cells <<
"\">" << std::endl;
464 str <<
" <Points>" << std::endl ;;
466 str <<
" </Points>" << std::endl;
468 str <<
" <Cells>" << std::endl ;;
476 str <<
" </Cells>" << std::endl;
479 str <<
" </Piece>" << std::endl;
480 str <<
" </UnstructuredGrid>" << std::endl;
484 str <<
" <AppendedData encoding=\"raw\">" << std::endl;
485 str <<
"_" << std::endl;
489 str <<
"</VTKFile>" << std::endl;
513 str.open( fhp.
getPath( ), std::ios::out ) ;
514 if (!str.is_open()) {
515 throw std::runtime_error(
"Cannot create file \"" + fhp.
getName() +
"\"" +
" inside the directory \"" + fhp.
getDirectory() +
"\"");
519 str <<
"<?xml version=\"1.0\"?>" << std::endl;
522 str <<
"<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << std::endl;
523 str <<
" <PUnstructuredGrid GhostLevel=\"0\">" << std::endl;;
529 str <<
" <PPoints>" << std::endl;
531 str <<
" </PPoints>" << std::endl;
533 str <<
" <PCells>" << std::endl;
541 str <<
" </PCells>" << std::endl;
549 str <<
" <Piece Source=\"" << fho.
getPath() <<
"\"/>" << std::endl;
552 str <<
" </PUnstructuredGrid>" << std::endl;
553 str <<
"</VTKFile>" << std::endl;
567 std::string line, temp;
569 std::fstream::pos_type position;
574 str.open(
m_fh.
getPath( ), std::ios::in | std::ios::binary ) ;
596 position = str.tellg() ;
601 str.seekg( position) ;
603#if BITPIT_ENABLE_DEBUG
604 log::cout() <<
"Geometry field " << field.
getName() <<
" not found, it will be disabled" << std::endl ;
658 uint64_t entries(0) ;
659 const std::string &name = field.
getName() ;
661 if( name ==
"Points" ){
664 }
else if( name ==
"offsets" ){
667 }
else if( name ==
"types" ){
670 }
else if( name ==
"connectivity"){
673 }
else if( name ==
"faces"){
676 }
else if( name ==
"faceoffsets"){
682 assert( location != VTKLocation::UNDEFINED) ;
684 if( location == VTKLocation::CELL ){
687 }
else if( location == VTKLocation::POINT ){
708 const std::string &name = field.
getName() ;
710 if( name ==
"Points" ){
713 }
else if( name ==
"offsets" ){
716 }
else if( name ==
"types" ){
719 }
else if( name ==
"connectivity" ){
728 }
else if( name ==
"faces" ){
731 }
else if( name ==
"faceoffsets" ){
750 return static_cast<std::underlying_type<VTKElementType>::type
>(field) ;
Creates file names and checks status.
std::string getPath() const
const std::string & getDirectory() const
void setDirectory(const std::string &d_)
void setName(const std::string &n_)
const std::string & getName() const
void setAppendix(const std::string &a_)
std::string getName() const
The base class to be used to derive VTK streamers form.
VTKField handles geometry and data field information for the VTK format.
const std::string & getName() const
VTKLocation getLocation() const
unsigned getComponentCount() const
void setStreamer(VTKBaseStreamer &)
static unsigned getComponentCount(VTKFieldType fieldType)
VTKDataType getDataType() const
static uint8_t sizeOfType(VTKDataType type)
void setElementType(VTKElementType)
void setConnectivityField(const VTKField *connectivity)
void setCellCount(uint64_t)
VTK input output for Unstructured Meshes.
uint8_t calcFieldComponents(const VTKField &) const override
HomogeneousInfoStreamer m_homogeneousInfoStreamer
uint64_t readFaceStreamEntries()
uint64_t calcConnectivityEntries() const
std::string getExtension() const override
uint64_t m_nConnectivityEntries
uint64_t calcFieldSize(const VTKField &) const override
uint64_t m_nFaceStreamEntries
void setElementType(VTKElementType)
void writeMetaInformation() const override
uint64_t readConnectivityEntries()
void setDimensions(uint64_t, uint64_t, uint64_t nconn=0, uint64_t nfacestream=0)
VTKUnstructuredGrid(VTKElementType elementType=VTKElementType::UNDEFINED)
VTKElementType m_elementType
uint64_t calcFieldEntries(const VTKField &) const override
void readMetaInformation() override
void setGeomData(VTKUnstructuredField, std::vector< T > &)
A base class for VTK input output.
std::vector< VTKField > m_geometry
void readDataHeader(std::fstream &)
void setNames(const std::string &, const std::string &)
void setHeaderType(const std::string &)
bool readDataArray(std::fstream &, VTKField &) const
void writeCollection() const
void writePDataArray(std::fstream &, const VTKField &) const
void writeDataHeader(std::fstream &, bool parallel=false) const
bool isAppendedActive() const
void writeDataArray(std::fstream &, const VTKField &) const
FileHandler createCollectionHandler(const std::string &collectionName) const
bool keywordInString(const std::string &line, const std::string &key)
void convertString(std::string input, T &output)
bool getAfterKeyword(const std::string &line, const std::string &key, char del, std::string &result)
void absorbBINARY(std::fstream &str, data_T &data)
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
uint8_t getElementNodeCount(VTKElementType)