diff --git a/AMDiS/src/BasisFunction.h b/AMDiS/src/BasisFunction.h index 56a68a3518d9ab725829c46a02a11acc7be907b0..848b8dd599d7487b4173c032c454c7d46696fc80 100644 --- a/AMDiS/src/BasisFunction.h +++ b/AMDiS/src/BasisFunction.h @@ -362,9 +362,7 @@ namespace AMDiS { virtual void coarseRestr(DOFVector<WorldVector<double> >*, RCNeighbourList*, int) {} - /** \brief - * Returns local dof indices of the element for the given fe space. - */ + /// Returns local dof indices of the element for the given fe space. virtual const DegreeOfFreedom *getLocalIndices(const Element*, const DOFAdmin*, DegreeOfFreedom*) const @@ -372,9 +370,7 @@ namespace AMDiS { return NULL; } - /** \brief - * Returns local dof indices of the element for the given fe space. - */ + /// Returns local dof indices of the element for the given fe space. virtual void getLocalIndicesVec(const Element*, const DOFAdmin*, Vector<DegreeOfFreedom>*) const diff --git a/AMDiS/src/DOFMatrix.cc b/AMDiS/src/DOFMatrix.cc index 98c48edc5d1325eb23f4c451bfa5297fd52211d5..4b44d3c5f7e5c50554e6ee84a4653c30a0bf724b 100644 --- a/AMDiS/src/DOFMatrix.cc +++ b/AMDiS/src/DOFMatrix.cc @@ -1,6 +1,7 @@ -#include "DOFMatrix.h" #include <algorithm> #include <png.h> + +#include "DOFMatrix.h" #include "QPsiPhi.h" #include "BasisFunction.h" #include "Boundary.h" @@ -754,7 +755,8 @@ namespace AMDiS { void DOFMatrix::createPictureFile(const char* filename, int dim) { - png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); if (!png_ptr) return; @@ -763,9 +765,8 @@ namespace AMDiS { for (int i = 0; i < dim; i++) { rowPointers[i] = (png_byte*)png_malloc(png_ptr, dim); - for (int j = 0; j < dim; j++) { + for (int j = 0; j < dim; j++) rowPointers[i][j] = 255; - } } double scalFactor = static_cast<double>(dim) / static_cast<double>(matrix.size()); diff --git a/AMDiS/src/DataCollector.h b/AMDiS/src/DataCollector.h index d917b49be96400875824f8842127a127a5c634a4..d052d82982cf63abec7590e7d3fd9f45f6d05980 100644 --- a/AMDiS/src/DataCollector.h +++ b/AMDiS/src/DataCollector.h @@ -42,17 +42,14 @@ namespace AMDiS { * \ingroup Output * * \brief - * Provides data collecting of element, vertex and value data - * for file writers. + * Provides data collecting of element, vertex and value data for file writer. */ class DataCollector { public: MEMORY_MANAGED(DataCollector); - /** \brief - * Constructor. - */ + /// Constructor DataCollector(const FiniteElemSpace *feSpace, DOFVector<double> *values, int level = -1, @@ -61,156 +58,96 @@ namespace AMDiS { ~DataCollector(); - /** \brief - * Fills the DataCollector with all possible datas. - */ + /// Fills the DataCollector with all possible datas. void fillAllData(); - /** \brief - * Returns list with element information. - */ + /// Returns list with element information. std::list<ElementInfo>* getElementInfos(); - /** \brief - * Returns vector with vertex information. - */ + /// Returns vector with vertex information. DOFVector< std::list<VertexInfo> >* getVertexInfos(); - /** \brief - * Returns the finite element space of the problem. - */ + /// Returns the finite element space of the problem. const FiniteElemSpace* getFeSpace(); - /** \brief - * Returns vector with value information. - */ + /// Returns vector with value information. DOFVector<double>* getValues(); - /** \brief - * Returns vector with information about dof coordinates. - */ + /// Returns vector with information about dof coordinates. DOFVector< std::list<WorldVector<double> > >* getDofCoords(); - /** \brief - * Returns vector with information about interpolation - * point indexing. - */ + /// Returns vector with information about interpolation point indexing. DOFVector<int>* getInterpPointInd(); - /** \brief - * - */ + /// DOFVector< std::list<WorldVector<double> > >* getInterpPointCoords(); - /** \brief - * Returns list of interpolation point information. - */ + /// Returns list of interpolation point information. std::vector< std::vector<int> >* getInterpPoints(); - /** \brief - * Returns list of information about periodics. - */ + /// Returns list of information about periodics. std::list<PeriodicInfo>* getPeriodicInfos(); - /** \brief - * Returns the number of vertices. - */ + /// Returns the number of vertices. int getNumberVertices(); - /** \brief - * Returns the number of elements. - */ + /// Returns the number of elements. int getNumberElements(); - /** \brief - * Returns the number of interpolation points. - */ + /// Returns the number of interpolation points. int getNumberInterpPoints(); - /** \brief - * Returns the number of connections. - */ + // Returns the number of connections. int getNumberConnections(); - /** \brief - * Returns the mesh of the problem. - */ + /// Returns the mesh of the problem. Mesh* getMesh(); void setMesh(Mesh *mesh) { mesh_ = mesh; - }; + } protected: - /** \brief - * Start collecting element and vertex data of the problem. - */ + /// Start collecting element and vertex data of the problem. int startCollectingElementData(); - /** \brief - * Start collecting value data of the problem. - */ + /// Start collecting value data of the problem. int startCollectingValueData(); - /** \brief - * Start collecting periodic data of the problem. - */ + /// Start collecting periodic data of the problem. int startCollectingPeriodicData(); - /** \brief - * Adds information about one element and its vertices. - */ + /// Adds information about one element and its vertices. int addElementData(ElInfo* elInfo); - /** \brief - * Adds value information of one element. - */ + /// Adds value information of one element. int addValueData(ElInfo *elInfo); - /** \brief - * Adds information about interpolation points of vertices. - */ + /// Adds information about interpolation points of vertices. int addInterpData(ElInfo *elInfo); - /** \brief - * Adds value information of one element. - */ + /// Adds value information of one element. int addPeriodicData(ElInfo *elInfo); - - /** \brief - * Vector with vertex values - */ + /// Vector with vertex values DOFVector<double> *values_; - /** \brief - * Level information for traversing the mesh. - */ + /// Level information for traversing the mesh. int level_; - /** \brief - * Flags for traversing the mesh. - */ + /// Flags for traversing the mesh. Flag traverseFlag_; - /** \brief - * - */ + /// const FiniteElemSpace *feSpace_; - /** \brief - * Mesh that should be written - */ + /// Mesh that should be written Mesh *mesh_; - /** \brief - * DOFAdmin of values - */ + /// DOFAdmin of values DOFAdmin *localAdmin_; - /** \brief - * vertex pre-dofs - */ + /// vertex pre-dofs int nPreDofs_; /// Number of vertices. diff --git a/AMDiS/src/ElInfo.h b/AMDiS/src/ElInfo.h index 3782bce2ece64c64fcd196725b96b3a9f41513e2..4ce0bfd5f4fef5fdc49378a8fe79f930eaf0380b 100644 --- a/AMDiS/src/ElInfo.h +++ b/AMDiS/src/ElInfo.h @@ -101,57 +101,42 @@ namespace AMDiS { return *this; } - // ===== getting-methods ====================================================== public: /** \name getting methods * \{ */ - /** \brief - * Get ElInfo's \ref mesh_ - */ + /// Get ElInfo's \ref mesh_ inline Mesh* getMesh() const { return mesh_; } - /** \brief - * Get ElInfo's \ref macroElement_ - */ + /// Get ElInfo's \ref macroElement_ inline MacroElement* getMacroElement() const { return macroElement_; } - /** \brief - * Get ElInfo's \ref element - */ + /// Get ElInfo's \ref element inline Element* getElement() const { return element_; } - /** \brief - * Get ElInfo's \ref parent_ - */ + /// Get ElInfo's \ref parent_ inline Element* getParent() const { return parent_; } - /** \brief - * Get ElInfo's \ref fillFlag_ - */ + /// Get ElInfo's \ref fillFlag_ inline Flag getFillFlag() const { return fillFlag_; } - /** \brief - * Get ElInfo's \ref level - */ + /// Get ElInfo's \ref level inline int getLevel() const { return level; } - /** \brief - * Get ElInfo's \ref iChild - */ + /// Get ElInfo's \ref iChild inline int getIChild() const { return iChild; } @@ -188,12 +173,10 @@ namespace AMDiS { return coord_; } - /** \brief - * Get ElInfo's \ref oppCoord_[i] - */ + /// Get ElInfo's \ref oppCoord_[i] inline WorldVector<double>& getOppCoord(int i) { return oppCoord_[i]; - }; + } /** \brief * Get ElInfo's \ref boundary_[i] @@ -466,20 +449,13 @@ namespace AMDiS { int iChild) const = 0; protected: - - /** \brief - * Pointer to the current mesh - */ + /// Pointer to the current mesh Mesh *mesh_; - /** \brief - * Pointer to the current element - */ + /// Pointer to the current element Element *element_; - /** \brief - * \ref element is child of element parent_ - */ + /// \ref element is child of element parent_ Element *parent_; /** \brief diff --git a/AMDiS/src/ElementMatrix.h b/AMDiS/src/ElementMatrix.h index db13efb53610e1b06813d91c9e861ec24c7e2040..fc6a275c14290ab78831b682f6f931c2e87c114e 100644 --- a/AMDiS/src/ElementMatrix.h +++ b/AMDiS/src/ElementMatrix.h @@ -27,10 +27,6 @@ namespace AMDiS { - // ============================================================================= - // ===== class ElementMatrix =================================================== - // ============================================================================= - /** \ingroup Assembler * * \brief @@ -42,24 +38,18 @@ namespace AMDiS { public: MEMORY_MANAGED(ElementMatrix); - /** \brief - * Constructor. - */ + /// Constructor ElementMatrix(int numRows, int numCols) : Matrix<double>(numRows, numCols), rowIndices(numRows), colIndices(numCols) - {}; + {} public: - /** \brief - * row dof indices. - */ + /// Row dof indices. Vector<DegreeOfFreedom> rowIndices; - /** \brief - * column dof indices. - */ + /// Column dof indices. Vector<DegreeOfFreedom> colIndices; }; diff --git a/AMDiS/src/FileWriter.cc b/AMDiS/src/FileWriter.cc index 905f1e54c7146b56e2880bba9285b7e0ad454df9..aee4d2c1d01f7ec61bd4757f9822ee2906ab9bf6 100644 --- a/AMDiS/src/FileWriter.cc +++ b/AMDiS/src/FileWriter.cc @@ -108,6 +108,7 @@ namespace AMDiS { writeParaViewAnimation = 0; writePeriodicFormat = 0; writePngFormat = 0; + pngType = 0; appendIndex = 0; indexLength = 5; indexDecimals = 3; @@ -135,6 +136,7 @@ namespace AMDiS { GET_PARAMETER(0, name + "->Periodic format", "%d", &writePeriodicFormat); GET_PARAMETER(0, name + "->Periodic ext", &periodicFileExt); GET_PARAMETER(0, name + "->PNG format", "%d", &writePngFormat); + GET_PARAMETER(0, name + "->PNG type", "%d", &pngType); GET_PARAMETER(0, name + "->append index", "%d", &appendIndex); GET_PARAMETER(0, name + "->index length", "%d", &indexLength); GET_PARAMETER(0, name + "->index decimals", "%d", &indexDecimals); @@ -233,14 +235,14 @@ namespace AMDiS { VtkWriter vtkWriter(&dataCollectors); vtkWriter.updateAnimationFile(fn + paraViewFileExt, ¶ViewAnimationFrames_, - const_cast<char*>((filename + ".pvd").c_str())); + filename + ".pvd"); } if (writePngFormat) { PngWriter pngWriter(dataCollectors[0]); - pngWriter.writeFile(const_cast<char*>((fn + paraViewFileExt).c_str())); + pngWriter.writeFile(fn + ".png", pngType); - MSG("PNG image file written to %s\n", (fn + paraViewFileExt).c_str()); + MSG("PNG image file written to %s\n", (fn + ".png").c_str()); } diff --git a/AMDiS/src/FileWriter.h b/AMDiS/src/FileWriter.h index 1f30308a5bdf1d52bba4ea0ba32aadbbb8d46bd5..5c397425e8091461d6bc5657d9ea26f012add8f9 100644 --- a/AMDiS/src/FileWriter.h +++ b/AMDiS/src/FileWriter.h @@ -184,6 +184,9 @@ namespace AMDiS { /// 0: Don't write png files; 1: Write png image files. int writePngFormat; + /// 0: Gray color picture; 1: RGB picture. + int pngType; + /** \brief * 0: Don't append time index to filename prefix. * 1: Append time index to filename prefix. diff --git a/AMDiS/src/FiniteElemSpace.h b/AMDiS/src/FiniteElemSpace.h index 59982e0ef475a524514d726ff56e35ca28e22363..f09f1384fba1153cd1deca9235a8bff538fa3d19 100644 --- a/AMDiS/src/FiniteElemSpace.h +++ b/AMDiS/src/FiniteElemSpace.h @@ -32,10 +32,6 @@ namespace AMDiS { - // ============================================================================ - // ===== forward declarations ================================================= - // ============================================================================ - class DOFAdmin; class BasisFunction; class Mesh; @@ -43,29 +39,19 @@ namespace AMDiS { template<typename T> class DOFVector; template<typename T> class DimVec; - // ============================================================================ - // ===== class FiniteElemSpace ================================================ - // ============================================================================ - /** \ingroup FEMSpace * \brief - * A FiniteElemSpace is a triple of a DOFAdmin and a set of BasisFunction on a - * Mesh. + * A FiniteElemSpace is a triple of a DOFAdmin and a set of BasisFunction on a mesh. */ class FiniteElemSpace { public: MEMORY_MANAGED(FiniteElemSpace); - - /** \brief - * Create an empty fe space. - */ + /// Create an empty fe space. FiniteElemSpace(); - /** \brief - * - */ + /// static FiniteElemSpace *provideFESpace(DOFAdmin *admin, const BasisFunction *basFcts, Mesh *mesh, @@ -116,29 +102,19 @@ namespace AMDiS { const std::string& name = ""); protected: - /** \brief - * Name of this FiniteElemSpace - */ + /// Name of this FiniteElemSpace. const std::string name; - /** \brief - * DOFAdmin corresponding to this FiniteElemSpace - */ + /// DOFAdmin corresponding to this FiniteElemSpace. DOFAdmin* admin; - /** \brief - * set of BasisFunction of this FiniteElemSpace - */ + /// Set of BasisFunction of this FiniteElemSpace. const BasisFunction* basFcts; - /** \brief - * The Mesh this FiniteElemSpace belongs to - */ + /// The Mesh this FiniteElemSpace belongs to. Mesh* mesh; - /** \brief - * - */ + /// static std::vector<FiniteElemSpace*> feSpaces; }; diff --git a/AMDiS/src/PngWriter.cc b/AMDiS/src/PngWriter.cc index 274da6c1116a457382ebf80682fb53b8d2a45bc6..d8c24360f03aeeb1ed88d849ad434f5bf04f22c2 100644 --- a/AMDiS/src/PngWriter.cc +++ b/AMDiS/src/PngWriter.cc @@ -1,7 +1,115 @@ +#include <float.h> +#include <png.h> + #include "PngWriter.h" +#include "Traverse.h" +#include "DOFVector.h" namespace AMDiS { - int PngWriter::writeFile(const std::string name) + int PngWriter::writeFile(const std::string filename, int imageType) { + FUNCNAME("PngWriter::writeFile()"); + + double minX = DBL_MAX, minY = DBL_MAX; + double maxX = DBL_MIN, maxY = DBL_MIN; + + TraverseStack stack; + ElInfo *elInfo = stack.traverseFirst(dataCollector->getMesh(), -1, + Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS); + double pointdist = min(absteukl(elInfo->getCoord(0), elInfo->getCoord(1)), + min(absteukl(elInfo->getCoord(1), elInfo->getCoord(2)), + absteukl(elInfo->getCoord(2), elInfo->getCoord(0)))); + while (elInfo) { + for (int i = 0; i < 3; i++) { + double x = (elInfo->getCoord(i))[0]; + double y = (elInfo->getCoord(i))[1]; + if (x < minX) minX = x; + if (x > maxX) maxX = x; + if (y < minY) minY = y; + if (y > maxY) maxY = y; + } + + elInfo = stack.traverseNext(elInfo); + } + + TEST_EXIT(minX == 0.0 && minY == 0.0)("Only supported for minX = minY = 0.0!\n"); + TEST_EXIT(pointdist > 0.0)("This should not happen!\n"); + + int imageX = static_cast<int>(maxX / pointdist) + 1; + int imageY = static_cast<int>(maxY / pointdist) + 1; + + png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + if (!png_ptr) + return 0; + + png_bytep rowPointers[imageY]; + for (int i = 0; i < imageY; i++) { + rowPointers[i] = (png_byte*)png_malloc(png_ptr, + (imageType == 0 ? imageX : imageX * 3)); + } + + const BasisFunction* basisFcts = dataCollector->getFeSpace()->getBasisFcts(); + Vector<DegreeOfFreedom> localDofs(3); + DOFVector<double>* dofvalues = dataCollector->getValues(); + + elInfo = stack.traverseFirst(dataCollector->getMesh(), -1, + Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS); + while (elInfo) { + basisFcts->getLocalIndicesVec(elInfo->getElement(), + dataCollector->getFeSpace()->getAdmin(), + &localDofs); + + for (int i = 0; i < 3; i++) { + if (imageType == 0) { + int indexX = static_cast<int>((elInfo->getCoord(i))[0] / pointdist); + int indexY = static_cast<int>((elInfo->getCoord(i))[1] / pointdist); + rowPointers[indexY][indexX] = + static_cast<unsigned char>((*dofvalues)[localDofs[i]]); + } else { + int indexX = static_cast<int>((elInfo->getCoord(i))[0] / pointdist) * 3; + int indexY = static_cast<int>((elInfo->getCoord(i))[1] / pointdist); + int value = static_cast<int>((*dofvalues)[localDofs[i]]); + + unsigned char r = value % 256; + unsigned char g = (value - r % (256 * 256)) / 256; + unsigned char b = (value - r - g) / (256 * 256); + rowPointers[indexY][indexX] = r; + rowPointers[indexY][indexX + 1] = g; + rowPointers[indexY][indexX + 2] = b; + } + + } + + elInfo = stack.traverseNext(elInfo); + } + + FILE *fp = fopen(filename.c_str(), "wb"); + TEST_EXIT(fp)("Cannot open file for writing matrix picture file!\n"); + + png_infop info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) { + png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + return 0; + } + + png_init_io(png_ptr, fp); + + png_set_IHDR(png_ptr, info_ptr, imageX, imageY, 8, + (imageType == 0 ? PNG_COLOR_TYPE_GRAY : PNG_COLOR_TYPE_RGB), + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); + + png_set_rows(png_ptr, info_ptr, rowPointers); + + png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); + + png_destroy_write_struct(&png_ptr, &info_ptr); + + fclose(fp); + + return 0; } } diff --git a/AMDiS/src/PngWriter.h b/AMDiS/src/PngWriter.h index 28141d1b00b4a9c27e97a5999fb3b3dfad3a4537..5ab2f56187a2ac33189411f7da61cddd7bda8cca 100644 --- a/AMDiS/src/PngWriter.h +++ b/AMDiS/src/PngWriter.h @@ -44,7 +44,7 @@ namespace AMDiS { } /// Writes a PNG image file. - int writeFile(const std::string name); + int writeFile(const std::string name, int imageType); private: /// Datacollector with values for the output file. diff --git a/AMDiS/src/VtkWriter.cc b/AMDiS/src/VtkWriter.cc index 432270cdc28c91f11943df61324fe042b1aace12..7d4616fdd2752a0052f49a62ca5fd5baf709e2ba 100644 --- a/AMDiS/src/VtkWriter.cc +++ b/AMDiS/src/VtkWriter.cc @@ -46,13 +46,13 @@ namespace AMDiS { int VtkWriter::updateAnimationFile(std::string valueFilename, std::vector< std::string > *paraViewAnimationFrames, - const char *animationFilename) + std::string animationFilename) { size_t found = valueFilename.find_last_of("/\\"); paraViewAnimationFrames->push_back(valueFilename.substr(found + 1)); std::ofstream file; - file.open(animationFilename); + file.open(animationFilename.c_str()); file << "<?xml version=\"1.0\"?>\n"; file << "<VTKFile type=\"Collection\" version=\"0.1\" >" << "\n"; diff --git a/AMDiS/src/VtkWriter.h b/AMDiS/src/VtkWriter.h index 6a2ef31f30ab6ce4246045994458567b20dc27be..65d71fca2f2177ae51e9cde02e1f0fbaa86b5ffc 100644 --- a/AMDiS/src/VtkWriter.h +++ b/AMDiS/src/VtkWriter.h @@ -62,7 +62,7 @@ namespace AMDiS { /// Adds a new entry to a ParaView animation file. int updateAnimationFile(std::string valueFilename, std::vector< std::string > *paraViewAnimationFrames, - const char *animationFilename); + std::string animationFilename); protected: /// Writes the VTK file to an arbitrary stream. template<typename T>