diff options
Initialize at openlb-1-3
Diffstat (limited to 'src/io')
55 files changed, 9479 insertions, 0 deletions
diff --git a/src/io/MakeHeader b/src/io/MakeHeader new file mode 100644 index 0000000..d86ae79 --- /dev/null +++ b/src/io/MakeHeader @@ -0,0 +1,48 @@ +# This file is part of the OpenLB library +# +# Copyright (C) 2007 Mathias Krause +# E-mail contact: info@openlb.net +# The most recent release of OpenLB can be downloaded at +# <http://www.openlb.net/> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. + + +generic := fileName \ + gnuplotWriter \ + ostreamManager \ + parallelIO \ + vtiReader \ + vtiWriter \ + xmlReader + +precompiled := base64 \ + blockGifWriter \ + blockVtkWriter2D \ + blockVtkWriter3D \ + colormaps \ + fileName \ + gnuplotWriter \ + gnuplotHeatMapWriter \ + ostreamManager \ + parallelIO \ + serializerIO \ + stlReader \ + superVtmWriter2D \ + superVtmWriter3D \ + vtiReader \ + vtiWriter \ + xmlReader diff --git a/src/io/base64.cpp b/src/io/base64.cpp new file mode 100644 index 0000000..de373e0 --- /dev/null +++ b/src/io/base64.cpp @@ -0,0 +1,72 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2007 Jonas Latt + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * <http://www.openlb.net/> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "base64.h" +#include "base64.hh" + +namespace olb { + +// All of the following is a workaround to the following problem: on a +// 32-bit machine where unsigned int is the same as size_t, Base64Encoder +// needs to be instantiated on one integer type only. On some 64-bit +// platforms however, size_t is not equal to unsigned int. In that case, +// Base64Encoder needs to be instantiated twice. It is however not +// possible to instantiate this class first on unsigned int and then +// on size_t, because this yields a double instantiation, and thus +// an error, where these types are the same. To avoid this problem, +// the chosen instantiation types are unsigned int and size_t where +// these types are different, and unsigned char and unsigned int where +// they are similar. A template-based if-then-else construct is used +// to distinguish the two cases. + +template<bool areEqual> struct DistinctUint; + +template<> +struct DistinctUint<true> { + typedef unsigned char T1; + typedef size_t T2; +}; + +template<> +struct DistinctUint<false> { + typedef unsigned int T1; + typedef size_t T2; +}; + +typedef DistinctUint<sizeof(unsigned int)==sizeof(size_t)>::T1 T1; +typedef DistinctUint<sizeof(unsigned int)==sizeof(size_t)>::T2 T2; + +template class Base64Encoder<bool>; +template class Base64Encoder<float>; +template class Base64Encoder<double>; +template class Base64Encoder<T1>; +template class Base64Encoder<T2>; +template class Base64Encoder<unsigned char>; + +template class Base64Decoder<bool>; +template class Base64Decoder<float>; +template class Base64Decoder<double>; +template class Base64Decoder<T1>; +template class Base64Decoder<T2>; + +} diff --git a/src/io/base64.h b/src/io/base64.h new file mode 100644 index 0000000..f2248e6 --- /dev/null +++ b/src/io/base64.h @@ -0,0 +1,82 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2007 Jonas Latt + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * <http://www.openlb.net/> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* Acknowledgment: The strategy adopted here to encode + * and decode Base64, and in particular the expression of the + * arrays Base64Encoder::enc64 and Base64Decoder::dec64, + * is inspired by the open source library b64 by Bob Trower, + * which is distributed with a MIT license at the address + * http://base64.sourceforge.net/b64.c + */ + + +#ifndef BASE64_H +#define BASE64_H + +#include <iosfwd> + +namespace olb { + +template<typename T> +class Base64Encoder { +public: + Base64Encoder(std::ostream& ostr_, size_t fullLength_); + void encode(const T* data, size_t length); +private: + void fillOverflow(const unsigned char* charData, size_t charLength, size_t& pos); + void flushOverflow(); + void writeSize(); + void encodeBlock( const unsigned char* data); + void encodeUnfinishedBlock( const unsigned char* data, int length); +private: + static const char enc64[65]; +private: + std::ostream& ostr; + size_t charFullLength; + size_t numWritten; + int numOverflow; + unsigned char overflow[3]; +}; + +template<typename T> +class Base64Decoder { +public: + Base64Decoder(std::istream& istr_, size_t fullLength_); + void decode(T* data, size_t length); +private: + void flushOverflow(unsigned char* charData, size_t charLength, size_t& pos); + unsigned char getNext(); + void decodeBlock(unsigned char* data); +private: + static const char dec64[82]; +private: + std::istream& istr; + size_t charFullLength; + size_t numRead; + int posOverflow; + unsigned char overflow[3]; +}; + +} // namespace olb + +#endif diff --git a/src/io/base64.hh b/src/io/base64.hh new file mode 100644 index 0000000..7091fe7 --- /dev/null +++ b/src/io/base64.hh @@ -0,0 +1,200 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2007 Jonas Latt + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * <http://www.openlb.net/> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* Acknowledgment: The strategy adopted here to encode + * and decode Base64, and in particular the expression of the + * arrays Base64Encoder::enc64 and Base64Decoder::dec64, + * is inspired by the open source library b64 by Bob Trower, + * which is distributed with a MIT license at the address + * http://base64.sourceforge.net/b64.c + */ + +#ifndef BASE64_HH +#define BASE64_HH + +#include "base64.h" +#include "core/olbDebug.h" +#include <ostream> +#include <istream> + + +namespace olb { + +////////////// class Base64Encoder //////////////////////////////////////////// + +template<typename T> +const char Base64Encoder<T>::enc64[65]= + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + "abcdefghijklmnopqrstuvwxyz0123456789+/"; + +template<typename T> +Base64Encoder<T>::Base64Encoder(std::ostream& ostr_, size_t fullLength_) + : ostr(ostr_), + charFullLength(fullLength_ * sizeof(T)), + numWritten(0), + numOverflow(0) +{ } + +template<typename T> +void Base64Encoder<T>::encode(const T* data, size_t length) +{ + const unsigned char* charData = reinterpret_cast<const unsigned char*>(data); + size_t charLength = length * sizeof(T); + OLB_PRECONDITION( numWritten+charLength <= charFullLength ); + + size_t pos=0; + fillOverflow(charData, charLength, pos); + while (pos+3 <= charLength) { + encodeBlock(charData+pos); + pos += 3; + } + fillOverflow(charData, charLength, pos); + numWritten += charLength; + if (numWritten == charFullLength) { + flushOverflow(); + } +} + +template<typename T> +void Base64Encoder<T>::fillOverflow(const unsigned char* charData, size_t charLength, size_t& pos) +{ + while (numOverflow < 3 && pos < charLength) { + overflow[numOverflow] = charData[pos]; + ++numOverflow; + ++pos; + } + if (numOverflow == 3) { + encodeBlock(overflow); + numOverflow = 0; + } +} + +template<typename T> +void Base64Encoder<T>::flushOverflow() +{ + if (numOverflow > 0) { + for (int iOverflow = numOverflow; iOverflow<3; ++iOverflow) { + overflow[iOverflow] = 0; + } + encodeUnfinishedBlock(overflow, numOverflow); + numOverflow = 0; + } +} + +template<typename T> +void Base64Encoder<T>::encodeBlock( const unsigned char* data) +{ + ostr << enc64[ data[0] >> 2 ]; + ostr << enc64[ ((data[0] & 0x03) << 4) | ((data[1] & 0xf0) >> 4) ]; + ostr << (unsigned char) (enc64[ ((data[1] & 0x0f) << 2) | ((data[2] & 0xc0) >> 6) ]); + ostr << (unsigned char) (enc64[ data[2] & 0x3f ]); +} + +template<typename T> +void Base64Encoder<T>::encodeUnfinishedBlock( const unsigned char* data, int length ) +{ + ostr << enc64[ data[0] >> 2 ]; + ostr << enc64[ ((data[0] & 0x03) << 4) | ((data[1] & 0xf0) >> 4) ]; + ostr << (unsigned char) ( + length == 2 ? + enc64[ ((data[1] & 0x0f) << 2) | ((data[2] & 0xc0) >> 6) ] : + '=' + ); + ostr << (unsigned char) ( '=' ); +} + + +////////////// struct Base64Decoder //////////////////////////////////////////// + +template<typename T> +const char Base64Decoder<T>::dec64[82]= + "|###}rstuvwxyz{#######>?@"\ + "ABCDEFGHIJKLMNOPQRSTUVW######XYZ"\ + "[\\]^_`abcdefghijklmnopq"; + + +template<typename T> +Base64Decoder<T>::Base64Decoder(std::istream& istr_, size_t fullLength_) + : istr(istr_), + charFullLength(fullLength_ * sizeof(T)), + numRead(0), + posOverflow(3) +{ } + +template<typename T> +void Base64Decoder<T>::decode(T* data, size_t length) +{ + unsigned char* charData = reinterpret_cast<unsigned char*>(data); + size_t charLength = length * sizeof(T); + OLB_PRECONDITION( numRead+charLength <= charFullLength ); + + size_t pos = 0; + flushOverflow(charData, charLength, pos); + while (pos+3 <= charLength) { + decodeBlock(charData+pos); + pos += 3; + } + if (pos < charLength) { + decodeBlock(overflow); + posOverflow=0; + flushOverflow(charData, charLength, pos); + } + numRead += charLength; +} + +template<typename T> +void Base64Decoder<T>::flushOverflow(unsigned char* charData, size_t charLength, size_t& pos) +{ + while (posOverflow < 3 && pos < charLength) { + charData[pos] = overflow[posOverflow]; + ++pos; + ++posOverflow; + } +} + +template<typename T> +unsigned char Base64Decoder<T>::getNext() +{ + unsigned char nextChar; + istr >> nextChar; + return (unsigned char) (dec64[nextChar - 43] - 62); +} + +template<typename T> +void Base64Decoder<T>::decodeBlock(unsigned char* data) +{ + unsigned char input[4]; + input[0] = getNext(); + input[1] = getNext(); + input[2] = getNext(); + input[3] = getNext(); + data[0] = (unsigned char) (input[0] << 2 | input[1] >> 4); + data[1] = (unsigned char) (input[1] << 4 | input[2] >> 2); + data[2] = (unsigned char) (((input[2] << 6) & 0xc0) | input[3]); +} + +} // namespace olb + +#endif + + diff --git a/src/io/blockGifWriter.cpp b/src/io/blockGifWriter.cpp new file mode 100644 index 0000000..087e07f --- /dev/null +++ b/src/io/blockGifWriter.cpp @@ -0,0 +1,32 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2015 Albert Mink, Mathias Krause + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * <http://www.openlb.net/> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "blockGifWriter.h" +#include "blockGifWriter.hh" + + +namespace olb { + +template class BlockGifWriter<double>; + +} // end namespace olb diff --git a/src/io/blockGifWriter.h b/src/io/blockGifWriter.h new file mode 100644 index 0000000..33923dc --- /dev/null +++ b/src/io/blockGifWriter.h @@ -0,0 +1,90 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2015 Albert Mink, Mathias J. Krause + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * <http://www.openlb.net/> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef BLOCK_GIF_WRITER_H +#define BLOCK_GIF_WRITER_H + +#include <iomanip> +#include "io/colormaps.h" +#include "io/ostreamManager.h" +#include "functors/lattice/blockBaseF2D.h" + + +namespace olb { + +/** BlockGifWriter writes given functor data to image file of format .ppm + * + * There are two different modes + * 1. mode: image maxValue and minValue are computed every time. + * this implies that image data is scaled every time exactly to + * interval [0,1]. this may lead to different scaling of the functor data + * concerning the time steps + * 2. mode: image maxValue and minValue are passed by the user once. + * this static use, prevents a rescaling effect for each time step. + * + * \param map determines the color of the graphics + */ +template< typename T > +class BlockGifWriter { +public: + // constructor + BlockGifWriter( std::string const& map="leeloo" ); + + /** writes functor values normed to interval [0,1]. + * imageValue is computed according to : + * if functorValue >= maxValue then the imageValue is clipped to 1 + * else imageValue = (minValue - functorValue) / (minValue - maxValue) + */ + void write( BlockF2D<T>& f, T minValue, T maxValue, int iT=0, + std::string const& name="emptyName" ); + /// writes functor data and determines its min-/maxValue + void write( BlockF2D<T>& f, int iT=0, std::string const& name="emptyName" ); + /// writes functors stored at pointerVec + void write(int iT=0); + /// put functor to _pointerVec, to simplify writing process of several functors + void addFunctor( BlockF2D<T>& f, std::string const& name="emptyName" ); + void addFunctor( BlockF2D<T>& f, T minValue, T maxValue, std::string const& name="emptyName" ); + +private: + // void ppm2gif(const std::string& fullNamePpm, const std::string& fullNameGif); + mutable OstreamManager clout; + int _colorRange; // set to 1024 + int _numColors; // set to 1024 + graphics::ColorMap<T> _colorMap; + + /// Holds added functor, to simplify the use of write function + std::vector< BlockF2D<T>* > _pointerVec; + /// Holds the names of added functors + std::vector<std::string> _name; + /// Holds the scale instruction of added functors + std::vector<bool> _autoScale; + /// Holds the minValues of added functors + std::vector<T> _minValue; + /// Holds the maxValues of added functors + std::vector<T> _maxValue; +}; + + +} // namespace olb + +#endif diff --git a/src/io/blockGifWriter.hh b/src/io/blockGifWriter.hh new file mode 100644 index 0000000..ef95d6c --- /dev/null +++ b/src/io/blockGifWriter.hh @@ -0,0 +1,202 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2015 Albert Mink, Mathias Krause + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * <http://www.openlb.net/> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef BLOCK_GIF_WRITER_HH +#define BLOCK_GIF_WRITER_HH + +#include <fstream> +#include <string> +#include <vector> + +#include "io/blockGifWriter.h" +#include "io/fileName.h" +#include "utilities/vectorHelpers.h" +#include "core/singleton.h" +#include "communication/mpiManager.h" + +namespace olb { + + +template< typename T > +BlockGifWriter<T>::BlockGifWriter(std::string const& map) + : clout(std::cout, "BlockGifWriter"), _colorRange(1024), _numColors(1024), + _colorMap(graphics::mapGenerators::generateMap<T>(map)), _minValue(0), + _maxValue(1) +{ } + +template< typename T > +void BlockGifWriter<T>::write(BlockF2D<T>& f, T minValue, T maxValue, int iT, + std::string const& name) +{ + // [!] exeption image(f) != 1 + if ( f.getTargetDim() != 1 ) { + clout << "Error: Functor targetDim is not 1. " << std::endl; + exit(-1); + } else { + if ( singleton::mpi().getRank() == 0 ) { + std::string fullNamePpm; + if ( name == "emptyName") { + fullNamePpm = createFileName( singleton::directories().getImageOutDir(), + f.getName(), iT); + } else { + fullNamePpm = createFileName( singleton::directories().getImageOutDir(), + name, iT); + } + fullNamePpm = fullNamePpm + ".ppm" ; + std::ofstream fout( fullNamePpm.c |