ArhReader.h 6.17 KB
Newer Older
1 2 3 4 5 6 7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9 10 11 12 13 14 15 16 17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
20 21


22 23 24 25 26 27

/** \file ArhReader.h */

#ifndef AMDIS_ARH_READER_H
#define AMDIS_ARH_READER_H

28 29
#include "Mesh.h"
#include "DOFVector.h"
30
#include "Global.h"
31
#include "SystemVector.h"
32

33 34 35 36 37
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#define WRITE_PARALLEL true
#else
#define WRITE_PARALLEL false
#endif
38

39
namespace AMDiS { namespace io {
40

41 42
  /** \ingroup Input
    * \brief Reader for the AMDiS ARH-format - version 1
43
    *
44 45 46 47
    * A collection of methods to read to various container types from
    * ARH-files.
    **/
  namespace ArhReader
48
  {
49 50

    /// Read a file to 1-3 \ref DOFVector. Using container pointers.
51
    void readFile(std::string filename,
52 53 54
		     DOFVector<double>* vec0 = NULL,
		     DOFVector<double>* vec1 = NULL,
		     DOFVector<double>* vec2 = NULL,
55
		     bool writeParallel = WRITE_PARALLEL,
56
		     int nProcs = -1);
57 58


59 60
    /// Read a file to a \ref DOFVector. Using container reference.
    inline
61
    void readFile(std::string filename,
62 63 64 65
		     DOFVector<double>& vec0,
		     bool writeParallel = WRITE_PARALLEL,
		     int nProcs = -1)
    {
66
      readFile(filename, &vec0, NULL, NULL, writeParallel, nProcs);
67
    }
68

69 70


71
    /// Read a file to a vector of \ref DOFVector.
72
    void readFile(std::string filename,
73 74
		     std::vector<DOFVector<double>*> vecs,
		     bool writeParallel = WRITE_PARALLEL,
75
		     int nProcs = -1);
76 77


78 79 80 81 82 83 84 85 86 87 88 89
    /// Read a file to a \ref SystemVector. Using container pointer.
    inline
    void readFile(std::string filename,
                     SystemVector* sysVec,
		     bool writeParallel = WRITE_PARALLEL,
                     int nProcs = -1)
    {
      std::vector<DOFVector<double>*> vecs;
      for (int i = 0; i < sysVec->getSize(); i++)
	vecs.push_back(sysVec->getDOFVector(i));
      readFile(filename, vecs, writeParallel, nProcs);
    }
90 91


92 93 94 95 96 97 98 99 100
    /// Read a file to a \ref SystemVector. Using container reference.
    inline
    void readFile(std::string filename,
                     SystemVector& sysVec,
		     bool writeParallel = WRITE_PARALLEL,
                     int nProcs = -1)
    {
      readFile(filename, &sysVec, writeParallel, nProcs);
    }
101 102


103 104 105 106 107
    /// Read a file to a \ref Mesh.
    void readFile(std::string filename,
		    Mesh* mesh,
		    bool writeParallel = WRITE_PARALLEL,
		    int nProcs = -1);
108

109

110 111 112 113 114
    /** \brief first read a meta ARH file and get \ref elInRank. And then uses the elInRank map
      * to find all the arh files that contains the dof value vecs needs and sets data into vecs by order.
      * \param filename the name of meta ARH file.
      * \param vec0 the first \ref DOFVector you want to read to.
      * \param vec1 the second \ref DOFVector you want to read to.
115
      * \param vec2 the third \ref DOFVector you want to read to.
116 117
      */
    void readMeta(std::string filename,
118 119 120
			 DOFVector<double>* vec0 = NULL,
			 DOFVector<double>* vec1 = NULL,
			 DOFVector<double>* vec2 = NULL);
121 122


123
    /// read a meta ARH file and the corresponding parallel ARH files to a vector
124 125
    /// of \ref DOFVector.
    void readMeta(std::string filename, std::vector<DOFVector<double>*> vecs);
Thomas Witkowski's avatar
Thomas Witkowski committed
126

127 128 129 130 131 132 133

    /// read only the meta data from a meta ARH file
    int readMetaData(std::string filename,
			    std::map<int, int> &elInRank,
			    std::map<int, int> &elCodeSize,
			    std::string &arhPrefix);

134

135 136 137 138
    /// read only the meta data from a meta ARH file
    inline int readMetaData(std::string filename,
			    std::map<int, int> &elInRank,
			    std::map<int, int> &elCodeSize)
Thomas Witkowski's avatar
Thomas Witkowski committed
139
    {
140
      std::string tmp;
Thomas Witkowski's avatar
Thomas Witkowski committed
141 142 143
      return readMetaData(filename, elInRank, elCodeSize, tmp);
    }

144

Thomas Witkowski's avatar
Thomas Witkowski committed
145
    /// Returns just the number of subdomains a meta ARH file is defined for.
146 147
    int readMetaData(std::string filename);

Thomas Witkowski's avatar
Thomas Witkowski committed
148

149 150
    /// Reader like readFile, but reads to data from the block \ref data.
    void readFromMemoryBlock(std::vector<char> &data, Mesh *mesh,
151 152 153
				    DOFVector<double>* vec0 = NULL,
				    DOFVector<double>* vec1 = NULL,
				    DOFVector<double>* vec2 = NULL,
154
			            bool writeParallel = WRITE_PARALLEL,
155
				    int nProcs = -1);
156

157 158 159 160 161

    /// Reader like readFile, but reads to data from the block \ref data.
    void readFromMemoryBlock(std::vector<char> &data, Mesh *mesh,
				    std::vector<DOFVector<double>*> vecs,
			            bool writeParallel = WRITE_PARALLEL,
162
				    int nProcs = -1);
163

164

165 166
    /// read the header information of an ARH file to extract the number of components
    int readNumOfValueVectors(std::string filename);
167 168


169
    // ________ below are obsolete functions, for backward compatibility _______
170 171


172
    void readFile(std::string filename,
173
			 Mesh *mesh,
174
			 std::vector<DOFVector<double>*> vecs);
175 176

    void read(std::string filename,
177
		     Mesh *mesh,
178 179 180
		     DOFVector<double>* vec0 = NULL,
		     DOFVector<double>* vec1 = NULL,
		     DOFVector<double>* vec2 = NULL,
181 182 183
		     bool writeParallel = WRITE_PARALLEL,
		     int nProcs = -1);

184
    void read(std::string filename,
185 186 187 188 189 190
		     Mesh *mesh,
		     std::vector<DOFVector<double>*> vecs,
		     bool writeParallel = WRITE_PARALLEL,
		     int nProcs = -1);

    int getNumValueVectors(std::string filename);
191

192 193
    void setDofValues(int macroElIndex, Mesh *mesh,
			     std::vector<double>& values, DOFVector<double>* vec);
194

195
    void readBlock(std::vector<char> &data,
196
			  Mesh *mesh,
197
			  std::vector<DOFVector<double>*> vecs);
198

199 200 201 202 203 204
    void readMeta(std::string filename,
			 Mesh *mesh,
			 std::vector<DOFVector<double>*> vecs);

    void readMeta(std::string filename,
		         Mesh* mesh,
205 206 207
			 DOFVector<double>* vec0 = NULL,
			 DOFVector<double>* vec1 = NULL,
			 DOFVector<double>* vec2 = NULL);
208

209
  } // end namespace ArhReader
210
} } // end namespace io, AMDiS
211 212

#endif