From 94d3e79a8617f88dc0219cfdeedfa3147833719d Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender
Date: Mon, 24 Jun 2019 14:43:36 +0200
Subject: Initialize at openlb-1-3
---
src/io/MakeHeader | 48 ++
src/io/base64.cpp | 72 +++
src/io/base64.h | 82 +++
src/io/base64.hh | 200 +++++++
src/io/blockGifWriter.cpp | 32 +
src/io/blockGifWriter.h | 90 +++
src/io/blockGifWriter.hh | 202 +++++++
src/io/blockVtkWriter2D.cpp | 37 ++
src/io/blockVtkWriter2D.h | 86 +++
src/io/blockVtkWriter2D.hh | 281 +++++++++
src/io/blockVtkWriter3D.cpp | 37 ++
src/io/blockVtkWriter3D.h | 88 +++
src/io/blockVtkWriter3D.hh | 289 +++++++++
src/io/colormaps.cpp | 46 ++
src/io/colormaps.h | 135 +++++
src/io/colormaps.hh | 432 ++++++++++++++
src/io/fileName.cpp | 98 +++
src/io/fileName.h | 59 ++
src/io/gnuplotHeatMapWriter.cpp | 33 +
src/io/gnuplotHeatMapWriter.h | 127 ++++
src/io/gnuplotHeatMapWriter.hh | 250 ++++++++
src/io/gnuplotWriter.cpp | 32 +
src/io/gnuplotWriter.h | 108 ++++
src/io/gnuplotWriter.hh | 296 +++++++++
src/io/io2D.h | 39 ++
src/io/io2D.hh | 35 ++
src/io/io3D.h | 42 ++
src/io/io3D.hh | 39 ++
src/io/module.mk | 27 +
src/io/octree.h | 157 +++++
src/io/octree.hh | 756 +++++++++++++++++++++++
src/io/ostreamManager.cpp | 133 +++++
src/io/ostreamManager.h | 106 ++++
src/io/parallelIO.cpp | 335 +++++++++++
src/io/parallelIO.h | 108 ++++
src/io/serializerIO.cpp | 33 +
src/io/serializerIO.h | 42 ++
src/io/serializerIO.hh | 94 +++
src/io/stlReader.cpp | 35 ++
src/io/stlReader.h | 290 +++++++++
src/io/stlReader.hh | 1258 +++++++++++++++++++++++++++++++++++++++
src/io/superVtmWriter2D.cpp | 39 ++
src/io/superVtmWriter2D.h | 115 ++++
src/io/superVtmWriter2D.hh | 448 ++++++++++++++
src/io/superVtmWriter3D.cpp | 39 ++
src/io/superVtmWriter3D.h | 115 ++++
src/io/superVtmWriter3D.hh | 439 ++++++++++++++
src/io/vtiReader.cpp | 44 ++
src/io/vtiReader.h | 189 ++++++
src/io/vtiReader.hh | 534 +++++++++++++++++
src/io/vtiWriter.cpp | 38 ++
src/io/vtiWriter.h | 75 +++
src/io/vtiWriter.hh | 225 +++++++
src/io/xmlReader.cpp | 329 ++++++++++
src/io/xmlReader.h | 161 +++++
55 files changed, 9479 insertions(+)
create mode 100644 src/io/MakeHeader
create mode 100644 src/io/base64.cpp
create mode 100644 src/io/base64.h
create mode 100644 src/io/base64.hh
create mode 100644 src/io/blockGifWriter.cpp
create mode 100644 src/io/blockGifWriter.h
create mode 100644 src/io/blockGifWriter.hh
create mode 100644 src/io/blockVtkWriter2D.cpp
create mode 100644 src/io/blockVtkWriter2D.h
create mode 100644 src/io/blockVtkWriter2D.hh
create mode 100644 src/io/blockVtkWriter3D.cpp
create mode 100644 src/io/blockVtkWriter3D.h
create mode 100644 src/io/blockVtkWriter3D.hh
create mode 100644 src/io/colormaps.cpp
create mode 100644 src/io/colormaps.h
create mode 100644 src/io/colormaps.hh
create mode 100644 src/io/fileName.cpp
create mode 100644 src/io/fileName.h
create mode 100644 src/io/gnuplotHeatMapWriter.cpp
create mode 100644 src/io/gnuplotHeatMapWriter.h
create mode 100644 src/io/gnuplotHeatMapWriter.hh
create mode 100644 src/io/gnuplotWriter.cpp
create mode 100644 src/io/gnuplotWriter.h
create mode 100644 src/io/gnuplotWriter.hh
create mode 100644 src/io/io2D.h
create mode 100644 src/io/io2D.hh
create mode 100644 src/io/io3D.h
create mode 100644 src/io/io3D.hh
create mode 100644 src/io/module.mk
create mode 100644 src/io/octree.h
create mode 100644 src/io/octree.hh
create mode 100644 src/io/ostreamManager.cpp
create mode 100644 src/io/ostreamManager.h
create mode 100644 src/io/parallelIO.cpp
create mode 100644 src/io/parallelIO.h
create mode 100644 src/io/serializerIO.cpp
create mode 100644 src/io/serializerIO.h
create mode 100644 src/io/serializerIO.hh
create mode 100644 src/io/stlReader.cpp
create mode 100644 src/io/stlReader.h
create mode 100644 src/io/stlReader.hh
create mode 100644 src/io/superVtmWriter2D.cpp
create mode 100644 src/io/superVtmWriter2D.h
create mode 100644 src/io/superVtmWriter2D.hh
create mode 100644 src/io/superVtmWriter3D.cpp
create mode 100644 src/io/superVtmWriter3D.h
create mode 100644 src/io/superVtmWriter3D.hh
create mode 100644 src/io/vtiReader.cpp
create mode 100644 src/io/vtiReader.h
create mode 100644 src/io/vtiReader.hh
create mode 100644 src/io/vtiWriter.cpp
create mode 100644 src/io/vtiWriter.h
create mode 100644 src/io/vtiWriter.hh
create mode 100644 src/io/xmlReader.cpp
create mode 100644 src/io/xmlReader.h
(limited to 'src/io')
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
+#
+#
+# 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
+ *
+ *
+ * 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 struct DistinctUint;
+
+template<>
+struct DistinctUint {
+ typedef unsigned char T1;
+ typedef size_t T2;
+};
+
+template<>
+struct DistinctUint {
+ typedef unsigned int T1;
+ typedef size_t T2;
+};
+
+typedef DistinctUint::T1 T1;
+typedef DistinctUint::T2 T2;
+
+template class Base64Encoder;
+template class Base64Encoder;
+template class Base64Encoder;
+template class Base64Encoder;
+template class Base64Encoder;
+template class Base64Encoder;
+
+template class Base64Decoder;
+template class Base64Decoder;
+template class Base64Decoder;
+template class Base64Decoder;
+template class Base64Decoder;
+
+}
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
+ *
+ *
+ * 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
+
+namespace olb {
+
+template
+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
+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
+ *
+ *
+ * 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
+#include
+
+
+namespace olb {
+
+////////////// class Base64Encoder ////////////////////////////////////////////
+
+template
+const char Base64Encoder::enc64[65]=
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
+ "abcdefghijklmnopqrstuvwxyz0123456789+/";
+
+template
+Base64Encoder::Base64Encoder(std::ostream& ostr_, size_t fullLength_)
+ : ostr(ostr_),
+ charFullLength(fullLength_ * sizeof(T)),
+ numWritten(0),
+ numOverflow(0)
+{ }
+
+template
+void Base64Encoder::encode(const T* data, size_t length)
+{
+ const unsigned char* charData = reinterpret_cast(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
+void Base64Encoder::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
+void Base64Encoder::flushOverflow()
+{
+ if (numOverflow > 0) {
+ for (int iOverflow = numOverflow; iOverflow<3; ++iOverflow) {
+ overflow[iOverflow] = 0;
+ }
+ encodeUnfinishedBlock(overflow, numOverflow);
+ numOverflow = 0;
+ }
+}
+
+template
+void Base64Encoder::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
+void Base64Encoder::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
+const char Base64Decoder::dec64[82]=
+ "|###}rstuvwxyz{#######>?@"\
+ "ABCDEFGHIJKLMNOPQRSTUVW######XYZ"\
+ "[\\]^_`abcdefghijklmnopq";
+
+
+template
+Base64Decoder::Base64Decoder(std::istream& istr_, size_t fullLength_)
+ : istr(istr_),
+ charFullLength(fullLength_ * sizeof(T)),
+ numRead(0),
+ posOverflow(3)
+{ }
+
+template
+void Base64Decoder::decode(T* data, size_t length)
+{
+ unsigned char* charData = reinterpret_cast(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
+void Base64Decoder::flushOverflow(unsigned char* charData, size_t charLength, size_t& pos)
+{
+ while (posOverflow < 3 && pos < charLength) {
+ charData[pos] = overflow[posOverflow];
+ ++pos;
+ ++posOverflow;
+ }
+}
+
+template
+unsigned char Base64Decoder::getNext()
+{
+ unsigned char nextChar;
+ istr >> nextChar;
+ return (unsigned char) (dec64[nextChar - 43] - 62);
+}
+
+template
+void Base64Decoder::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
+ *
+ *
+ * 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;
+
+} // 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
+ *
+ *
+ * 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
+#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& f, T minValue, T maxValue, int iT=0,
+ std::string const& name="emptyName" );
+ /// writes functor data and determines its min-/maxValue
+ void write( BlockF2D& 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& f, std::string const& name="emptyName" );
+ void addFunctor( BlockF2D& 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 _colorMap;
+
+ /// Holds added functor, to simplify the use of write function
+ std::vector< BlockF2D* > _pointerVec;
+ /// Holds the names of added functors
+ std::vector _name;
+ /// Holds the scale instruction of added functors
+ std::vector _autoScale;
+ /// Holds the minValues of added functors
+ std::vector _minValue;
+ /// Holds the maxValues of added functors
+ std::vector _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
+ *
+ *
+ * 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
+#include
+#include
+
+#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::BlockGifWriter(std::string const& map)
+ : clout(std::cout, "BlockGifWriter"), _colorRange(1024), _numColors(1024),
+ _colorMap(graphics::mapGenerators::generateMap(map)), _minValue(0),
+ _maxValue(1)
+{ }
+
+template< typename T >
+void BlockGifWriter::write(BlockF2D& 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_str() );
+
+ // write header
+ fout << "P3\n";
+ // dimension of image
+ fout << f.getBlockStructure().getNx() << " "
+ << f.getBlockStructure().getNy() << "\n";
+ // dynamic range
+ fout << (_colorRange - 1) << "\n";
+
+ int i[2] = {0,0};
+ for (i[1] = f.getBlockStructure().getNy() - 1; i[1] >= 0; --i[1]) {
+ for (i[0] = 0; i[0] < f.getBlockStructure().getNx(); ++i[0]) {
+ T evaluated[1];
+ f(evaluated,i);
+ // scales evaluated in [getMinValue(),getMaxValue()] to [0,1]
+ evaluated[0] = (minValue - evaluated[0]) / (minValue - maxValue);
+ // sets evaluated notin [getMinValue(),getMaxValue()] to 1
+ if ( evaluated[0] >= T(1) ) {
+ evaluated[0] = 1;
+ }
+ graphics::rgb color = _colorMap.get(evaluated[0]);
+ fout << (int)(color.r * (_colorRange - 1)) << " "
+ << (int)(color.g * (_colorRange - 1)) << " "
+ << (int)(color.b * (_colorRange - 1)) << "\n";
+ }
+ }
+ fout.close();
+ }
+ }
+}
+
+template< typename T >
+void BlockGifWriter::write(BlockF2D& f, int iT, std::string const& name)
+{
+ // determine min-/maxValue
+ int i[2] = {0,0};
+ // initialize min-/maxValue
+ T minValue[1];
+ T maxValue[1];
+ f(minValue,i);
+ f(maxValue,i);
+ for (i[0] = 1; i[0] < f.getBlockStructure().getNx(); i[0]++) {
+ for (i[1] = 1; i[1] < f.getBlockStructure().getNy(); i[1]++) {
+ T valueTmp[1];
+ f(valueTmp,i);
+ if (valueTmp[0] < minValue[0]) {
+ minValue[0] = valueTmp[0];
+ }
+ if (valueTmp[0] > maxValue[0]) {
+ maxValue[0] = valueTmp[0];
+ }
+ }
+ }
+ if (maxValue[0] <= minValue[0]) {
+ minValue[0] = T();
+ maxValue[0] = T(1);
+ }
+ // call write() with min-/maxValue
+ write(f, minValue[0], maxValue[0], iT, name);
+}
+
+// iteration on _pointerVec is realized by function
+// dataArray() respective dataArrayBinary()
+template< typename T >
+void BlockGifWriter::write(int iT)
+{
+ if ( _pointerVec.empty() ) {
+ // secure code. doesn't appear on console ??
+ clout << "Error: Please add functor via addFunctor()";
+ } else {
+ int i = 0;
+ for ( auto it = _pointerVec.cbegin(); it != _pointerVec.cend(); ++it, ++i) {
+ if (_autoScale[i]) {
+ write(**it, iT, _name[i]);
+ } else {
+ write(**it, _minValue[i], _maxValue[i], iT, _name[i]);
+ }
+ }
+ }
+}
+
+template< typename T >
+void BlockGifWriter::addFunctor(BlockF2D& f, std::string const& name)
+{
+ _pointerVec.push_back(&f);
+
+ if ( name == "emptyName") {
+ _name.push_back(f.getName() );
+ }
+ _name.push_back(name);
+
+ _autoScale.push_back(true);
+ _minValue.push_back(T());
+ _maxValue.push_back(T());
+}
+
+template< typename T >
+void BlockGifWriter::addFunctor(BlockF2D& f, T minValue, T maxValue,
+ std::string const& name)
+{
+ _pointerVec.push_back(&f);
+
+ if ( name == "emptyName") {
+ _name.push_back(f.getName() );
+ }
+ _name.push_back(name);
+
+ _autoScale.push_back(false);
+ _minValue.push_back(minValue);
+ _maxValue.push_back(maxValue);
+}
+
+
+
+
+/// platform specific code
+//template
+//void BlockGifWriter::ppm2gif(const std::string& fullNamePpm,
+// const std::string& fullNameGif)
+//{
+// std::string consoleCommand = "convert " + fullNamePpm
+// + " -resize 600x800^ "
+// + fullNameGif;
+// system(consoleCommand.c_str());
+// consoleCommand = std::string("rm ") + fullNamePpm;
+// system(consoleCommand.c_str());
+//}
+
+
+
+
+
+
+} // namespace olb
+
+#endif
diff --git a/src/io/blockVtkWriter2D.cpp b/src/io/blockVtkWriter2D.cpp
new file mode 100644
index 0000000..1d399e6
--- /dev/null
+++ b/src/io/blockVtkWriter2D.cpp
@@ -0,0 +1,37 @@
+/* This file is part of the OpenLB library
+ *
+ * Copyright (C) 2014 Albert Mink, Mathias J. Krause
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * 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.
+*/
+
+/** \file
+ * A method to write vtk data for cuboid geometries
+ * (only for uniform grids) -- template instantiation.
+ */
+
+#include "io/blockVtkWriter2D.h"
+#include "io/blockVtkWriter2D.hh"
+
+namespace olb {
+
+template class BlockVTKwriter2D;
+
+} // end namespace olb
+
diff --git a/src/io/blockVtkWriter2D.h b/src/io/blockVtkWriter2D.h
new file mode 100644
index 0000000..1671e3f
--- /dev/null
+++ b/src/io/blockVtkWriter2D.h
@@ -0,0 +1,86 @@
+/* This file is part of the OpenLB library
+ *
+ * Copyright (C) 2014 Albert Mink, Mathias J. Krause
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * 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.
+*/
+
+/** \file
+ * A method to write vtk data for block geometries
+ * (only for uniform grids) -- header file.
+ */
+
+#ifndef BLOCK_VTK_WRITER_2D_H
+#define BLOCK_VTK_WRITER_2D_H
+
+#include "io/ostreamManager.h"
+#include "functors/lattice/blockBaseF2D.h"
+
+namespace olb {
+
+/** BlockVTKwriter2D writes any BLockF2D to vtk-based output files
+ *
+ * One can add functors via addFunctors. To write added functors
+ * call write(int iT=0).
+ *
+ * To write a functor without adding him, call
+ * call write(BlockF3D& f, int iT).
+ *
+ * Default output type is binary, to change it have a look on the
+ * constructor.
+ */
+template
+class BlockVTKwriter2D {
+public:
+ BlockVTKwriter2D( std::string name, bool binary=true );
+ ~BlockVTKwriter2D();
+ /// method calls preamble(), pointData(), data() and coresponding
+ /// closing methods.
+ /// writes functors stored at pointerVec
+ void write(int iT=0);
+ /// writes given functor
+ void write( BlockF2D& f, int iT=0 );
+ /// put functor to _pointerVec
+ /// to simplify writing process of several functors
+ void addFunctor( BlockF2D& f );
+ /// to clear stored functors
+ void clearAddedFunctors();
+private:
+ /// writes , , and
+ void preamble( const std::string& fullName, int nx,int ny, T originX=0, T originY=0, T originZ=0);
+ /// writes , , and
+ void closePreamble( const std::string& fullName );
+ /// writes data of given functor f as ASCII code
+ void writeRawData( const std::string& fullNameVti, BlockF2D& f, int nx, int ny);
+ /// writes data of given functor f as binary code
+ void writeRawDataBinary( const std::string& fullNameVti, BlockF2D& f, int nx, int ny );
+private:
+ mutable OstreamManager clout;
+ /// determines the name of .vti per iT
+ std::string _name;
+ /// default is true, may be changed at constructor
+ bool _binary;
+ /// holds added functor, to simplify the use of write function
+ std::vector< BlockF2D* > _pointerVec;
+};
+
+} // namespace olb
+
+
+#endif
diff --git a/src/io/blockVtkWriter2D.hh b/src/io/blockVtkWriter2D.hh
new file mode 100644
index 0000000..6c8634a
--- /dev/null
+++ b/src/io/blockVtkWriter2D.hh
@@ -0,0 +1,281 @@
+/* This file is part of the OpenLB library
+*
+* Copyright (C) 2014 Albert Mink, Mathias J. Krause
+* E-mail contact: info@openlb.net
+* The most recent release of OpenLB can be downloaded at
+*
+*
+* 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.
+*/
+
+/** \file
+ * A method to write vtk data for cuboid geometries
+ * (only for uniform grids) -- generic implementation.
+ */
+
+#ifndef BLOCK_VTK_WRITER_2D_HH
+#define BLOCK_VTK_WRITER_2D_HH
+
+#include
+#include
+#include "communication/mpiManager.h"
+#include "core/singleton.h"
+#include "io/blockVtkWriter2D.h"
+#include "io/base64.h"
+#include "io/fileName.h"
+
+namespace olb {
+
+
+template
+BlockVTKwriter2D::BlockVTKwriter2D( std::string name, bool binary )
+ : clout( std::cout,"BlockVTKwriter2D" ), _name(name), _binary(binary)
+{}
+
+template
+BlockVTKwriter2D::~BlockVTKwriter2D ()
+{
+ clearAddedFunctors();
+}
+
+// iteration on _pointerVec is realized by function
+// dataArray() respective dataArrayBinary()
+template
+void BlockVTKwriter2D::write(int iT)
+{
+ if ( _pointerVec.empty() ) {
+ clout << "Error: Please add functor via addFunctor()";
+ } else {
+ auto it = _pointerVec.cbegin();
+
+ T originX = 0;
+ T originY = 0;
+ T originZ = 0;
+ int nx = (**it).getBlockStructure().getNx() -1;
+ int ny = (**it).getBlockStructure().getNy() -1;
+
+ std::string fullNameVti = singleton::directories().getVtkOutDir()
+ + createFileName( _name, iT ) + ".vti";
+
+
+ preamble( fullNameVti, nx,ny, originX,originY,originZ );
+ if ( _binary ) {
+ for ( auto functor = _pointerVec.cbegin(); functor != _pointerVec.cend(); ++functor) {
+ writeRawDataBinary( fullNameVti, **functor, nx, ny);
+ }
+ } else {
+ for ( auto functor = _pointerVec.cbegin(); functor != _pointerVec.cend(); ++functor) {
+ writeRawData( fullNameVti, **functor, nx, ny);
+ }
+ }
+ closePreamble( fullNameVti );
+ }
+}
+
+template
+void BlockVTKwriter2D::write(BlockF2D& f, int iT)
+{
+ T originX = 0;
+ T originY = 0;
+ T originZ = 0;
+ int nx = f.getBlockStructure().getNx() -1;
+ int ny = f.getBlockStructure().getNy() -1;
+
+ std::string fullNameVti = singleton::directories().getVtkOutDir()
+ + createFileName( f.getName(), iT ) + ".vti";
+
+ preamble( fullNameVti, nx,ny, originX,originY,originZ );
+ if ( _binary ) {
+ writeRawDataBinary( fullNameVti, f, nx,ny );
+ } else {
+ writeRawData( fullNameVti, f, nx,ny );
+ }
+ closePreamble( fullNameVti );
+}
+
+template
+void BlockVTKwriter2D::addFunctor(BlockF2D& f)
+{
+ _pointerVec.push_back(&f);
+}
+
+template
+void BlockVTKwriter2D::clearAddedFunctors()
+{
+ _pointerVec.clear();
+}
+
+template
+void BlockVTKwriter2D::preamble(const std::string& fullName, int nx, int ny,
+ T originX, T originY, T originZ)
+{
+ if (singleton::mpi().getRank()==0) {
+ std::ofstream fout(fullName.c_str());
+ if (!fout) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+
+ // spacing is not known for BlockF2D classes
+ // prone to error: spacing might correspond to extension in y direction
+ // at the end of the day, is can be fixed by apply a scaling in paraview
+ double spacing = double(1.0/nx);
+
+ fout << "\n";
+ fout << "\n";
+ fout << "\n";
+
+ fout << "\n";
+
+ fout << "\n";
+ fout.close();
+ }
+}
+
+template
+void BlockVTKwriter2D::closePreamble(const std::string& fullNamePiece)
+{
+ if (singleton::mpi().getRank()==0) {
+ std::ofstream fout(fullNamePiece.c_str(), std::ios::app );
+ if (!fout) {
+ clout << "Error: could not open " << fullNamePiece << std::endl;
+ }
+ fout << "\n";
+ fout << "\n";
+ fout << "\n";
+ fout << "\n";
+ fout.close();
+ }
+}
+
+template
+void BlockVTKwriter2D::writeRawData(const std::string& fullNameVti, BlockF2D& f,
+ int nx, int ny)
+{
+ std::ofstream fout(fullNameVti.c_str(), std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fullNameVti << std::endl;
+ }
+
+ if (singleton::mpi().getRank()==0) {
+ fout << "\n";
+ }
+
+ int i[2] = {int()};
+ T evaluated[f.getTargetDim()];
+ for (int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
+ evaluated[iDim] = T();
+ }
+ for (i[1] = 0; i[1] < ny+1; ++i[1]) {
+ for (i[0] = 0; i[0] < nx+1; ++i[0]) {
+ f(evaluated,i);
+ for (int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
+ if (singleton::mpi().getRank()==0) {
+ fout << evaluated[iDim] << " ";
+ }
+ }
+ }
+ }
+
+ if (singleton::mpi().getRank()==0) {
+ fout << "\n\n";
+ }
+
+ fout.close();
+}
+
+template
+void BlockVTKwriter2D::writeRawDataBinary(const std::string& fullNameVti,
+ BlockF2D& f, int nx, int ny)
+{
+ const char* fileName = fullNameVti.c_str();
+ std::ofstream fout(fileName, std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fileName << std::endl;
+ }
+
+ if (singleton::mpi().getRank()==0) {
+ fout << "\n";
+ } else {
+ fout << "type=\"Float32\" Name=\"" << f.getName() << "\" "
+ << "format=\"binary\" encoding=\"base64\" "
+ << "NumberOfComponents=\"" << f.getTargetDim() <<"\">\n";
+ }
+ }
+ fout.close();
+
+ std::ofstream ofstr( fileName, std::ios::out | std::ios::app | std::ios::binary );
+ if (!ofstr) {
+ clout << "Error: could not open " << fileName << std::endl;
+ }
+
+ size_t fullSize = f.getTargetDim() * (1 + nx) * (1 + ny) * (1);
+ size_t binarySize = size_t( fullSize * sizeof(float) );
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int)binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder* dataEncoder = nullptr;
+ dataEncoder = new Base64Encoder( ofstr, fullSize );
+
+
+ int i[2] = {int()};
+ T evaluated[f.getTargetDim()];
+ for (int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
+ evaluated[iDim] = T();
+ }
+ for (i[1] = 0; i[1] < ny+1; ++i[1]) {
+ for (i[0] = 0; i[0] < nx+1; ++i[0]) {
+ f(evaluated,i);
+ for (int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
+ if (singleton::mpi().getRank()==0) {
+ const float evaluated2 = float( evaluated[iDim] );
+ dataEncoder->encode( &evaluated2, 1 );
+ }
+ }
+ }
+ }
+ ofstr.close();
+
+ if (singleton::mpi().getRank()==0) {
+ std::ofstream foutt(fileName, std::ios::out | std::ios::app);
+ if (!foutt) {
+ clout << "Error: could not open " << fileName << std::endl;
+ }
+ foutt << "\n\n";
+ foutt.close();
+ }
+ delete dataEncoder;
+}
+
+
+} // namespace olb
+
+#endif
diff --git a/src/io/blockVtkWriter3D.cpp b/src/io/blockVtkWriter3D.cpp
new file mode 100644
index 0000000..d511d3d
--- /dev/null
+++ b/src/io/blockVtkWriter3D.cpp
@@ -0,0 +1,37 @@
+/* This file is part of the OpenLB library
+ *
+ * Copyright (C) 2014 Albert Mink, Mathias J. Krause
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * 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.
+*/
+
+/** \file
+ * A method to write vtk data for cuboid geometries
+ * (only for uniform grids) -- template instantiation.
+ */
+
+#include "io/blockVtkWriter3D.h"
+#include "io/blockVtkWriter3D.hh"
+
+namespace olb {
+
+template class BlockVTKwriter3D;
+
+} // end namespace olb
+
diff --git a/src/io/blockVtkWriter3D.h b/src/io/blockVtkWriter3D.h
new file mode 100644
index 0000000..a7b6f56
--- /dev/null
+++ b/src/io/blockVtkWriter3D.h
@@ -0,0 +1,88 @@
+/* This file is part of the OpenLB library
+ *
+ * Copyright (C) 2014 Albert Mink, Mathias J. Krause
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * 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.
+*/
+
+/** \file
+ * A method to write vtk data for block geometries
+ * (only for uniform grids) -- header file.
+ */
+
+#ifndef BLOCK_VTK_WRITER_3D_H
+#define BLOCK_VTK_WRITER_3D_H
+
+#include "io/ostreamManager.h"
+#include "functors/lattice/blockBaseF3D.h"
+
+namespace olb {
+
+/** BlockVTKwriter3D writes any BLockF3D to vtk-based output files
+ *
+ * One can add functors via addFunctors. To write added functors
+ * call write(int iT=0).
+ *
+ * To write a functor without adding him, call
+ * call write(BlockF3D& f, int iT).
+ *
+ * Default output type is binary, to change it have a look on the
+ * constructor.
+ */
+template
+class BlockVTKwriter3D {
+public:
+ BlockVTKwriter3D( std::string name, bool binary=true );
+ ~BlockVTKwriter3D();
+ /// method calls preamble(), pointData(), data() and coresponding
+ /// closing methods.
+ /// writes given functor
+ void write( BlockF3D& f, int iT=0 );
+ /// writes functors stored at pointerVec
+ void write( int iT=0 );
+ /// put functor to _pointerVec
+ /// to simplify writing process of several functors
+ void addFunctor( BlockF3D& f );
+ /// to clear stored functors
+ void clearAddedFunctors();
+private:
+ /// writes , , and
+ void preamble( const std::string& fullName, int nx, int ny, int nz,
+ T originX=0, T originY=0, T originZ=0);
+ /// writes , , and
+ void closePreamble( const std::string& fullName );
+ /// writes data of given functor f as ASCII
+ void writeRawData( const std::string& fullNameVti, BlockF3D& f, int nx, int ny, int nz );
+ /// writes data of given functor f as binary
+ void writeRawDataBinary( const std::string& fullNameVti, BlockF3D& f,
+ int nx, int ny, int nz );
+private:
+ mutable OstreamManager clout;
+ /// determines the name of .vti per iT
+ std::string _name;
+ /// default is true, may be changed at constructor
+ bool _binary;
+ /// holds added functor, to simplify the use of write function
+ std::vector< BlockF3D* > _pointerVec;
+};
+
+} // namespace olb
+
+
+#endif
diff --git a/src/io/blockVtkWriter3D.hh b/src/io/blockVtkWriter3D.hh
new file mode 100644
index 0000000..3da95b2
--- /dev/null
+++ b/src/io/blockVtkWriter3D.hh
@@ -0,0 +1,289 @@
+/* This file is part of the OpenLB library
+ *
+ * Copyright (C) 2014 Albert Mink, Mathias J. Krause
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * 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.
+*/
+
+/** \file
+ * A method to write vtk data for cuboid geometries
+ * (only for uniform grids) -- generic implementation.
+ */
+
+#ifndef BLOCK_VTK_WRITER_3D_HH
+#define BLOCK_VTK_WRITER_3D_HH
+
+#include
+#include
+#include "communication/mpiManager.h"
+#include "core/singleton.h"
+#include "io/blockVtkWriter3D.h"
+#include "io/base64.h"
+#include "io/fileName.h"
+
+namespace olb {
+
+template
+BlockVTKwriter3D::BlockVTKwriter3D( std::string name, bool binary )
+ : clout( std::cout,"BlockVTKwriter3D" ), _name(name), _binary(binary)
+{}
+
+template
+BlockVTKwriter3D::~BlockVTKwriter3D ()
+{
+ clearAddedFunctors();
+}
+
+template
+void BlockVTKwriter3D::write(int iT)
+{
+ if ( _pointerVec.empty() ) {
+ clout << "Error: Please add functor via addFunctor()";
+ } else {
+ // get first functor
+ auto it = _pointerVec.cbegin();
+
+ T originX = 0;
+ T originY = 0;
+ T originZ = 0;
+ int nx = (**it).getBlockStructure().getNx() -1;
+ int ny = (**it).getBlockStructure().getNy() -1;
+ int nz = (**it).getBlockStructure().getNz() -1;
+
+ std::string fullNameVti = singleton::directories().getVtkOutDir()
+ + createFileName( _name, iT ) + ".vti";
+
+ preamble( fullNameVti, nx,ny,nz, originX,originY,originZ );
+ if ( _binary ) {
+ // iterate on functors
+ for ( auto functor = _pointerVec.cbegin(); functor != _pointerVec.cend(); ++functor) {
+ writeRawDataBinary( fullNameVti, **functor, nx, ny, nz);
+ }
+ } else {
+ for ( auto functor = _pointerVec.cbegin(); functor != _pointerVec.cend(); ++functor) {
+ writeRawData( fullNameVti, **functor, nx, ny, nz);
+ }
+ }
+ closePreamble( fullNameVti );
+ }
+}
+
+template
+void BlockVTKwriter3D::write(BlockF3D& f, int iT)
+{
+ T originX = 0;
+ T originY = 0;
+ T originZ = 0;
+ int nx = f.getBlockStructure().getNx() -1;
+ int ny = f.getBlockStructure().getNy() -1;
+ int nz = f.getBlockStructure().getNz() -1;
+
+ std::string fullNameVti = singleton::directories().getVtkOutDir()
+ + createFileName( f.getName(), iT ) + ".vti";
+
+ preamble( fullNameVti, nx,ny,nz, originX,originY,originZ );
+ if ( _binary ) {
+ writeRawData( fullNameVti, f, nx,ny,nz );
+ } else {
+ writeRawDataBinary( fullNameVti, f, nx,ny,nz );
+ }
+ closePreamble( fullNameVti );
+}
+
+template
+void BlockVTKwriter3D::addFunctor(BlockF3D& f)
+{
+ _pointerVec.push_back(&f);
+}
+
+template
+void BlockVTKwriter3D::clearAddedFunctors()
+{
+ _pointerVec.clear();
+}
+
+template
+void BlockVTKwriter3D::preamble(const std::string& fullName, int nx, int ny, int nz,
+ T originX, T originY, T originZ)
+{
+ if (singleton::mpi().getRank()==0) {
+ std::ofstream fout(fullName.c_str());
+ if (!fout) {
+ clout << "Error: could not open " << fullName << std::endl;
+ }
+ // spacing is not known for BlockF3D classes
+ // prone to error: spacing might correspond to extension in y or z direction
+ // at the end of the day, is can be fixed by apply a scaling in paraview
+ double spacing = 1/double(nx);
+
+ fout << "\n";
+ fout << "\n";
+ fout << "\n";
+
+ fout << "\n";
+
+ fout << "\n";
+ fout.close();
+ }
+}
+
+template
+void BlockVTKwriter3D::closePreamble(const std::string& fullNamePiece)
+{
+ if (singleton::mpi().getRank()==0) {
+ std::ofstream fout(fullNamePiece.c_str(), std::ios::app );
+ if (!fout) {
+ clout << "Error: could not open " << fullNamePiece << std::endl;
+ }
+ fout << "\n";
+ fout << "\n";
+ fout << "\n";
+ fout << "\n";
+ fout.close();
+ }
+}
+
+
+
+template
+void BlockVTKwriter3D::writeRawData(const std::string& fullNameVti, BlockF3D& f,
+ int nx, int ny, int nz)
+{
+ std::ofstream fout(fullNameVti.c_str(), std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fullNameVti << std::endl;
+ }
+
+ if (singleton::mpi().getRank()==0) {
+ fout << "\n";
+ }
+
+ int i[3] = {int()};
+ T evaluated[f.getTargetDim()];
+ for (int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
+ evaluated[iDim] = T();
+ }
+ for (i[2] = 0; i[2] < nz+1; ++i[2]) {
+ for (i[1] = 0; i[1] < ny+1; ++i[1]) {
+ for (i[0] = 0; i[0] < nx+1; ++i[0]) {
+ f(evaluated,i);
+ for (int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
+ if (singleton::mpi().getRank()==0) {
+ fout << evaluated[iDim] << " ";
+ }
+ }
+ }
+ }
+ }
+ if (singleton::mpi().getRank()==0) {
+ fout << "\n\n";
+ }
+
+ fout.close();
+}
+
+// uses base64 encoder to write binary output
+// first number is written by a seperate sizeEncoder
+// this number indicates how many numbers will be stored.
+// then dataEncoder will be called to write output.
+// !!code is fixed to float functor values!!
+template
+void BlockVTKwriter3D::writeRawDataBinary(const std::string& fullNameVti,
+ BlockF3D& f, int nx, int ny, int nz)
+{
+ const char* fileName = fullNameVti.c_str();
+ std::ofstream fout(fileName, std::ios::app);
+ if (!fout) {
+ clout << "Error: could not open " << fileName << std::endl;
+ }
+
+ if (singleton::mpi().getRank()==0) {
+ fout << "\n";
+ } else {
+ fout << "type=\"Float32\" Name=\"" << f.getName() << "\" "
+ << "format=\"binary\" encoding=\"base64\" "
+ << "NumberOfComponents=\"" << f.getTargetDim() << "\">\n";
+ }
+ }
+ fout.close();
+
+ std::ofstream ofstr( fileName, std::ios::out | std::ios::app | std::ios::binary );
+ if (!ofstr) {
+ clout << "Error: could not open " << fileName << std::endl;
+ }
+
+ size_t fullSize = f.getTargetDim() * (1 + nx) * (1 + ny) * (1 + nz);
+ size_t binarySize = size_t( fullSize * sizeof(float) );
+ // writes first number, which have to be the size(byte) of the following data
+ Base64Encoder sizeEncoder(ofstr, 1);
+ unsigned int uintBinarySize = (unsigned int)binarySize;
+ sizeEncoder.encode(&uintBinarySize, 1);
+ // write numbers from functor
+ Base64Encoder* dataEncoder = nullptr;
+ dataEncoder = new Base64Encoder( ofstr, fullSize );
+
+ int i[3] = {int()};
+ T evaluated[f.getTargetDim()];
+ for (int iDim = 0; iDim < f.getTargetDim(); ++iDim) {
+ evaluated[iDim] = T();
+ }
+ for (i[2] = 0; i[2] < nz+1; ++i[2]) {
+ for (i[1] = 0; i[1] < ny+1; ++i[1]) {
+ for (i[0] = 0; i[0] < nx+1; ++i[0]) {
+ f(evaluated,i);
+ for (int iDim = 0; iDimencode( &evaluated2, 1 );
+ }
+ }
+ }
+ }
+ }
+ ofstr.close();
+
+ if (singleton::mpi().getRank()==0) {
+ std::ofstream foutt(fileName, std::ios::out | std::ios::app);
+ if (!foutt) {
+ clout << "Error: could not open " << fileName << std::endl;
+ }
+ foutt << "\n\n";
+ foutt.close();
+ }
+ delete dataEncoder;
+}
+
+
+} // namespace olb
+
+#endif
diff --git a/src/io/colormaps.cpp b/src/io/colormaps.cpp
new file mode 100644
index 0000000..69c0a80
--- /dev/null
+++ b/src/io/colormaps.cpp
@@ -0,0 +1,46 @@
+/* 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
+ *
+ *
+ * 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 "colormaps.h"
+#include "colormaps.hh"
+
+namespace olb {
+
+namespace graphics {
+
+template class LinearFunction;
+template class PowerLawFunction;
+template struct Piece;
+template class PiecewiseFunction;
+template struct rgb;
+template class ColorMap;
+
+namespace mapGenerators {
+
+template ColorMap generateMap(std::string mapName);
+
+} // namespace mapGenerators
+
+}
+
+}
diff --git a/src/io/colormaps.h b/src/io/colormaps.h
new file mode 100644
index 0000000..673425d
--- /dev/null
+++ b/src/io/colormaps.h
@@ -0,0 +1,135 @@
+/* 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
+ *
+ *
+ * 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 COLORMAPS_H
+#define COLORMAPS_H
+
+#include
+#include
+
+namespace olb {
+
+namespace graphics {
+
+template
+struct ScalarFunction {
+ virtual ~ScalarFunction() { }
+ virtual T operator() (T x) const =0;
+ virtual ScalarFunction* clone() const=0;
+};
+
+template
+class LinearFunction : public ScalarFunction {
+public:
+ LinearFunction(T x1_, T x2_, T y1_, T y2_);
+ T operator() (T x) const override;
+ LinearFunction* clone() const override;
+private:
+ T x1, x2, y1, y2;
+};
+
+template
+class PowerLawFunction : public ScalarFunction {
+public:
+ PowerLawFunction(T x1_, T x2_, T y1_, T y2_, T b_);
+ T operator() (T x) const override;
+ PowerLawFunction* clone() const override;
+private:
+ T x1, x2, y1, y2;
+ T b;
+};
+
+template
+struct Piece {
+ Piece(T closedBegin_, T openEnd_) : closedBegin(closedBegin_), openEnd(openEnd_)
+ {
+ }
+ T closedBegin, openEnd;
+};
+
+template
+class PiecewiseFunction : public ScalarFunction {
+public:
+ PiecewiseFunction() { }
+ ~PiecewiseFunction() override;
+ PiecewiseFunction(PiecewiseFunction const& rhs);
+ PiecewiseFunction& operator=(PiecewiseFunction const& rhs);
+ void swap(PiecewiseFunction& rhs);
+ void addPiece(Piece piece, ScalarFunction* f);
+ T operator() (T x) const override;
+ PiecewiseFunction* clone() const override;
+private:
+ std::vector > pieces;
+ std::vector*> functions;
+};
+
+template
+struct rgb {
+ rgb(T r_, T g_, T b_) : r(r_), g(g_), b(b_)
+ {
+ }
+ T r,g,b;
+};
+
+template
+class ColorMap {
+public:
+ ColorMap(PiecewiseFunction const& red_,
+ PiecewiseFunction const& green_,
+ PiecewiseFunction const& blue_);
+ rgb get(T x) const;
+private:
+ PiecewiseFunction red, green, blue;
+};
+
+namespace mapGenerators {
+
+template PiecewiseFunction generateEarthRed();
+template PiecewiseFunction generateEarthGreen();
+template PiecewiseFunction generateEarthBlue();
+
+template PiecewiseFunction generateWaterRed();
+template PiecewiseFunction generateWaterGreen();
+template PiecewiseFunction generateWaterBlue();
+
+template PiecewiseFunction generateAirRed();
+template PiecewiseFunction generateAirGreen();
+template PiecewiseFunction generateAirBlue();
+
+template PiecewiseFunction generateFireRed();
+template PiecewiseFunction generateFireGreen();
+template PiecewiseFunction generateFireBlue();
+
+template PiecewiseFunction generateLeeLooRed();
+template PiecewiseFunction generateLeeLooGreen();
+template PiecewiseFunction generateLeeLooBlue();
+
+template ColorMap generateMap(std::string mapName);
+
+} // namespace mapGenerators
+
+} // namespace graphics
+
+} // namespace olb
+
+#endif
diff --git a/src/io/colormaps.hh b/src/io/colormaps.hh
new file mode 100644
index 0000000..24cf98b
--- /dev/null
+++ b/src/io/colormaps.hh
@@ -0,0 +1,432 @@
+/* This file is part of the OpenLB library
+ *
+ * Copyright (C) 2006, 2007 Jonas Latt
+ * E-mail contact: info@openlb.net
+ * The most recent release of OpenLB can be downloaded at
+ *
+ *
+ * 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 COLORMAPS_HH
+#define COLORMAPS_HH
+
+#include "colormaps.h"
+#include
+
+namespace olb {
+
+namespace graphics {
+
+template
+LinearFunction::LinearFunction(T x1_, T x2_, T y1_, T y2_)
+ : x1(x1_), x2(x2_), y1(y1_), y2(y2_)
+{ }
+
+template
+T LinearFunction::operator() (T x) const
+{
+ return ( (y2-y1) * x + x2*y1-x1*y2 )/(x2-x1);
+}
+
+template
+LinearFunction* LinearFunction::clone() const
+{
+ return new LinearFunction(*this);
+}
+
+template
+PowerLawFunction::PowerLawFunction(T x1_, T x2_, T y1_, T y2_, T b_)
+ : x1(std::pow(x1_,b_)), x2(std::pow(x2_,b_)), y1(y1_), y2(y2_), b(b_)
+{ }
+
+template
+T PowerLawFunction::operator() (T x) const
+{
+ return ( (y2-y1) * std::pow(x,b) + x2*y1-x1*y2 )/(x2-x1);
+}
+
+template
+PowerLawFunction* PowerLawFunction::clone() const
+{
+ return n