Refinement stream capable of input and output. More...
#include <element_to_refine.h>
Public Member Functions | |
| ElementToRefineStream (const char *filename, std::ios_base::openmode mode) | |
| Constructor. Opens a stream. | |
| void | open (const char *filename, std::ios_base::openmode mode) |
| Opens a file stream. | |
| bool | is_open () const |
| Returns true if the stream is open. Used to test success of the method open(). | |
| bool | eof () const |
| Returns true if EOF has been reached. | |
| bool | good () const |
| Returns true if the stream did not failed and EOF has not been reached. | |
| bool | fail () const |
| Returns true if the stream failed (to read header, ...). | |
| bool | operator! () const |
| Returns true if the an error occured. | |
| void | close () |
| Closes the stream. | |
Friends | |
| H2D_API ElementToRefineStream & | operator<< (ElementToRefineStream &stream, const std::vector< ElementToRefine > &elem_refs) |
| Operator. Stores a vector of refinements to a stream. | |
| H2D_API ElementToRefineStream & | operator>> (ElementToRefineStream &stream, std::vector< ElementToRefine > &elem_refs) |
| Operator. Reads a vector of refinemens. It erases the contents of the vector that it is reading to. | |
Refinement stream capable of input and output.
This class allows to store a vector of refinements to a file. It is intended for debugging purposes when a certain problem appearts at higher iteration. The stream is designed to work with the class Adapt.
The stream is able to read, store and append. If appending, an existing file has to have a valid format. This is checked when the stream is opened.
Assuming that it=1 is the first iteration and the variable hp is an instance of the class Adapt, the code that writes the refinements is
std::ios_base::openmode mode = std::ios_base::app;
if (it == 2)
mode = std::ios_base::out;
ElementToRefineStream erstream("data.ers", mode | std::ios_base::binary);
erstream << hp.get_last_refinements();
erstream.close();
The code that reads and applies all refinements in a file is
ElementToRefineStream erstream("data.ers", std::ios_base::in | std::ios_base::binary); if (erstream.is_open()) { while (erstream.good()) { std::vector<ElementToRefine> refinements; errstream >> refinements; hp.apply_refinements(refinements); } errstream.close(); }
Currently, only binary format is supported. The file consist of a header and a sequence of refinements organized to blocks. All binary data are little-endian, always. All numbers are signed if not noted otherwise and all sizes are in bytes.
The file header is:
------------------------------------------------------------------
field size contents
------------------------------------------------------------------
Start Tag 3 'ERS' (i.e. Element to Refine Stream)
Delimiter 1 A space (ASCII: 32)
Format Tag 3 'BIN' (i.e. Uncompressed Binary format)
New Line 1 LF or '\n' ------------------------------------------------------------------
The header of a refinement block is:
------------------------------------------------------------------
name size contents
------------------------------------------------------------------
Start Tag 3 'ERV' (i.e. Element to Refine Vector)
SZ_NUM 1 A byte length of NUM
SZ_ID_ROOT 1 A byte length of ID_ROOT
SZ_ID_OFFS 1 A byte length of ID_OFFS
SZ_COMP_ROOT 1 A byte length of COMP_ROOT
SZ_COMP_OFFS 1 A byte length of COMP_OFFS
SZ_ORDER 1 A byte length of an order
NUM SZ_NUM A number of refinements in the block.
ID_ROOT SZ_ID_ROOT A root element ID. All IDs
in the block are relative.
COMP_ROOT SZ_COMP_ROOT A root component index.
All indices in the block are relative.
------------------------------------------------------------------The format of a refinement is:
------------------------------------------------------------------
name size contents
------------------------------------------------------------------
ID_OFFS SZ_ID_OFFS An offset of an element ID.
COMP_OFFS SZ_COMP_OFFS An offset of a component index.
If SZ_COMP_OFFS is zero, COMP_OFFS is
zero and it is not present in the file.
SPLIT 1 A refinement type, see RefinementTypes.
ORDERS 2*SZ_ORDER*N A sequence of pairs of orders in
the attribute ElementToRefine::p, where
N is a number of sons generated by the
refinement.
A pair consists of a horizontal and
a vertical orders. The vertical order
is zero in a case of a triangle.
------------------------------------------------------------------| ElementToRefineStream::ElementToRefineStream | ( | const char * | filename, | |
| std::ios_base::openmode | mode | |||
| ) | [explicit] |
Constructor. Opens a stream.
| [in] | filename | A file name. |
| [in] | mode | An open mode. The file has to be opened in a binary mode (std::ios_base::binary) and it can be opened either for reading (std::ios_base::in), for writing (std::ios_base::out) or for appending (std::ios_base::append). |
| void ElementToRefineStream::close | ( | ) | [inline] |
Closes the stream.
| bool ElementToRefineStream::eof | ( | ) | const [inline] |
Returns true if EOF has been reached.
| bool ElementToRefineStream::fail | ( | ) | const [inline] |
Returns true if the stream failed (to read header, ...).
| bool ElementToRefineStream::good | ( | ) | const [inline] |
Returns true if the stream did not failed and EOF has not been reached.
| bool ElementToRefineStream::is_open | ( | ) | const [inline] |
Returns true if the stream is open. Used to test success of the method open().
| void ElementToRefineStream::open | ( | const char * | filename, | |
| std::ios_base::openmode | mode | |||
| ) |
Opens a file stream.
| [in] | filename | A file name. |
| [in] | mode | An open mode. The file has to be opened in a binary mode (std::ios_base::binary) and it can be opened either for reading (std::ios_base::in), for writing (std::ios_base::out) or for appending (std::ios_base::append). |
| bool ElementToRefineStream::operator! | ( | ) | const [inline] |
Returns true if the an error occured.
| H2D_API ElementToRefineStream& operator<< | ( | ElementToRefineStream & | stream, | |
| const std::vector< ElementToRefine > & | elem_refs | |||
| ) | [friend] |
Operator. Stores a vector of refinements to a stream.
| H2D_API ElementToRefineStream& operator>> | ( | ElementToRefineStream & | stream, | |
| std::vector< ElementToRefine > & | elem_refs | |||
| ) | [friend] |
Operator. Reads a vector of refinemens. It erases the contents of the vector that it is reading to.
1.6.3