libMesh::XdrMESH Class Reference

#include <xdr_mesh.h>

Inheritance diagram for libMesh::XdrMESH:

Public Types

enum  XdrIO_TYPE {
  UNKNOWN = -1, ENCODE =0, DECODE, W_ASCII,
  R_ASCII
}
 

Public Member Functions

 XdrMESH ()
 
void init (XdrIO_TYPE type, const char *fn, int icnt, int dim=3)
 
 ~XdrMESH ()
 
int header (XdrMHEAD *hd)
 
int Icon (int *array, int numvar, int num)
 
int coord (Real *array, int dim, int size)
 
int BC (int *array, int size)
 
void init (XdrIO_TYPE t, const char *fn, const char *type, int icnt)
 
void fini ()
 
int dataBlk (int *array, int numvar, int size)
 
int dataBlk (Real *array, int numvar, int size)
 
LegacyXdrIO::FileFormat get_orig_flag () const
 
void set_orig_flag (LegacyXdrIO::FileFormat in_orig_flag)
 
void set_num_levels (unsigned int num_levels)
 
unsigned int get_num_levels ()
 

Protected Attributes

unsigned int _num_levels
 
XdrIO_TYPE m_type
 
XDR * mp_xdr_handle
 
LegacyXdrIO::FileFormat orig_flag
 
std::ifstream mp_in
 
std::ofstream mp_out
 

Private Attributes

int m_dim
 

Detailed Description

The XdrMESH class. This class is responsible for reading/writing information about the mesh to xdr style binary files.

Author
Bill Barth
Robert McLay
Date
2000

Definition at line 43 of file xdr_mesh.h.

Member Enumeration Documentation

This enum specifies the access permission which will be acquired for the current xdr file. Note that it is only possible to read (DECODE) or write (ENCODE) but not both. For ASCII type files, use WRITE or READ instead!

Enumerator
UNKNOWN 
ENCODE 
DECODE 
W_ASCII 
R_ASCII 

Definition at line 100 of file xdr_mgf.h.

Constructor & Destructor Documentation

libMesh::XdrMESH::XdrMESH ( )
inline

Constructor. Initializes m_dim to -1.

Definition at line 51 of file xdr_mesh.h.

51 : m_dim(-1) {}
libMesh::XdrMESH::~XdrMESH ( )
inline

Destructor.

Definition at line 69 of file xdr_mesh.h.

69 {}

Member Function Documentation

int libMesh::XdrMESH::BC ( int *  array,
int  size 
)
inline

Read/Write a BC of appropriate size

Parameters
arrayPointer to an array of Reals
sizeSize of array (number of elements)
Returns
3*size

Definition at line 107 of file xdr_mesh.h.

References libMesh::XdrMGF::dataBlk().

Referenced by libMesh::LegacyXdrIO::read_mesh(), and libMesh::LegacyXdrIO::write_mesh().

107 { return dataBlk(array, 3, size);}
int dataBlk(int *array, int numvar, int size)
Definition: xdr_mgf.C:264
int libMesh::XdrMESH::coord ( Real array,
int  dim,
int  size 
)
inline

Read/Write a coord of appropriate size.

Parameters
arrayPointer to an array of Reals
sizeSize of array (number of elements)
Returns
dim*size

Definition at line 98 of file xdr_mesh.h.

References libMesh::XdrMGF::dataBlk().

Referenced by libMesh::LegacyXdrIO::read_mesh(), and libMesh::LegacyXdrIO::write_mesh().

98 { return dataBlk(array, dim, size);}
int dataBlk(int *array, int numvar, int size)
Definition: xdr_mgf.C:264
void ExactErrorEstimator::estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector, bool estimate_parent_error) void ExactErrorEstimator const unsigned in dim)
int libMesh::XdrMGF::dataBlk ( int *  array,
int  numvar,
int  size 
)
inherited

Reads/Writes a block of ints to/from the current xdr file/file handle.

Parameters
arrayPointer to data to be read/written
numvarThe total number of variables (size of the array)
sizeThe size of each individual variable in the array

Definition at line 264 of file xdr_mgf.C.

References libMesh::XdrMGF::DECODE, libMesh::XdrMGF::ENCODE, libMesh::libmesh_assert(), libMesh::XdrMGF::m_type, libMesh::XdrMGF::mp_in, libMesh::XdrMGF::mp_out, libMesh::XdrMGF::mp_xdr_handle, libMesh::XdrMGF::R_ASCII, and libMesh::XdrMGF::W_ASCII.

Referenced by BC(), coord(), Icon(), and libMesh::XdrSOLN::values().

265 {
266  int totalSize = numvar*size;
267 
268  switch (m_type)
269  {
270 
271 #ifdef LIBMESH_HAVE_XDR
272 
273  case (XdrMGF::DECODE):
274  case (XdrMGF::ENCODE):
275  {
276  xdr_vector(mp_xdr_handle,
277  (char *) &array[0],
278  totalSize,
279  sizeof(int),
280  (xdrproc_t) xdr_int);
281  break;
282  }
283 
284 #endif
285 
286  case (XdrMGF::W_ASCII):
287  {
288  for (int i=0; i<size; i++)
289  {
290  for (int j=0; j<numvar; j++)
291  mp_out << array[i*numvar + j] << " ";
292 
293  mp_out << '\n';
294  }
295 
296  mp_out.flush();
297  break;
298  }
299 
300  case (XdrMGF::R_ASCII):
301  {
302  libmesh_assert (mp_in.good());
303 
304  for (int i=0; i<size; i++)
305  {
306  for (int j=0; j<numvar; j++)
307  {
308  mp_in >> array[i*numvar + j];
309  }
310 
311  mp_in.ignore(); // Read newline
312  }
313 
314  break;
315  }
316 
317  default:
318  // Unknown access type
319  libmesh_error_msg("Unknown m_type" << m_type);
320  }
321 
322  return totalSize;
323 }
libmesh_assert(remote_elem)
std::ifstream mp_in
Definition: xdr_mgf.h:228
std::ofstream mp_out
Definition: xdr_mgf.h:233
XdrIO_TYPE m_type
Definition: xdr_mgf.h:200
XDR * mp_xdr_handle
Definition: xdr_mgf.h:210
int libMesh::XdrMGF::dataBlk ( Real array,
int  numvar,
int  size 
)
inherited

Read/Writes a block of Reals to/from the current xdr file/file handle.

Definition at line 327 of file xdr_mgf.C.

References libMesh::XdrMGF::DECODE, libMesh::XdrMGF::ENCODE, libMesh::libmesh_assert(), libMesh::XdrMGF::m_type, libMesh::XdrMGF::mp_in, libMesh::XdrMGF::mp_out, libMesh::XdrMGF::mp_xdr_handle, libMesh::XdrMGF::R_ASCII, libMesh::Real, and libMesh::XdrMGF::W_ASCII.

328 {
329  int totalSize = numvar*size;
330 
331  // If this function is called by coord(),
332  // numvar is the problem dimension, and
333  // size is the number of nodes in the problem.
334 
335  //libMesh::out << "Total amount of data to be written: " << totalSize << std::endl;
336 
337  switch (m_type)
338  {
339 
340 #ifdef LIBMESH_HAVE_XDR
341 
342  case (XdrMGF::DECODE):
343  case (XdrMGF::ENCODE):
344  {
345  // FIXME - this is probably broken for Real == long double
346  // RHS
347  xdr_vector(mp_xdr_handle,
348  (char *) &array[0],
349  totalSize,
350  sizeof(Real),
351  (xdrproc_t) xdr_REAL);
352  }
353 
354 #endif
355 
356  case (XdrMGF::W_ASCII):
357  {
358  // Save stream flags
359  std::ios_base::fmtflags out_flags = mp_out.flags();
360 
361  // We will use scientific notation with a precision of 16
362  // digits in the following output. The desired precision and
363  // format will automatically determine the width.
364  mp_out << std::scientific
365  << std::setprecision(16);
366 
367  for (int i=0; i<size; i++)
368  {
369  for (int j=0; j<numvar; j++)
370  mp_out << array[i*numvar + j] << " \t";
371 
372  mp_out << '\n';
373  }
374 
375  // Restore stream flags
376  mp_out.flags(out_flags);
377 
378  mp_out.flush();
379  break;
380  }
381 
382  case (XdrMGF::R_ASCII):
383  {
384  libmesh_assert (mp_in.good());
385 
386  for (int i=0; i<size; i++)
387  {
388  libmesh_assert (mp_in.good());
389 
390  for (int j=0; j<numvar; j++)
391  mp_in >> array[i*numvar + j];
392 
393  mp_in.ignore(); // Read newline
394  }
395 
396  break;
397  }
398 
399  default:
400  // Unknown access type
401  libmesh_error_msg("Unknown m_type" << m_type);
402  }
403 
404  return totalSize;
405 }
libmesh_assert(remote_elem)
std::ifstream mp_in
Definition: xdr_mgf.h:228
std::ofstream mp_out
Definition: xdr_mgf.h:233
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
XdrIO_TYPE m_type
Definition: xdr_mgf.h:200
XDR * mp_xdr_handle
Definition: xdr_mgf.h:210
void libMesh::XdrMGF::fini ( )
inherited

Finalizes operations on the current xdr file handle, and closes the xdr file.

Uses xdr_destroy found in rpc/rpc.h.

Definition at line 35 of file xdr_mgf.C.

References libmesh_nullptr, libMesh::XdrMGF::mp_fp, and libMesh::XdrMGF::mp_xdr_handle.

Referenced by libMesh::XdrMGF::init(), and libMesh::XdrMGF::~XdrMGF().

36 {
37 
38 #ifdef LIBMESH_HAVE_XDR
39 
40  if (mp_xdr_handle)
41  {
42  //libMesh::out << "Destroying XDR file handle." << std::endl;
43  xdr_destroy(mp_xdr_handle);
44  }
45 
46  //libMesh::out << "Deleting the file handle pointer." << std::endl;
47  delete mp_xdr_handle;
48 
50 
51 #endif
52 
53  if (mp_fp)
54  {
55  //libMesh::out << "Closing file." << std::endl;
56  std::fflush(mp_fp);
57  std::fclose(mp_fp);
58  }
59 
61 }
std::FILE * mp_fp
Definition: xdr_mgf.h:236
const class libmesh_nullptr_t libmesh_nullptr
XDR * mp_xdr_handle
Definition: xdr_mgf.h:210
unsigned int libMesh::XdrMGF::get_num_levels ( )
inlineinherited

Get number of levels

Definition at line 184 of file xdr_mgf.h.

References libMesh::XdrMGF::_num_levels.

Referenced by header(), libMesh::XdrMGF::init(), and libMesh::LegacyXdrIO::read_mesh().

184 { return _num_levels; }
unsigned int _num_levels
Definition: xdr_mgf.h:191
LegacyXdrIO::FileFormat libMesh::XdrMGF::get_orig_flag ( ) const
inlineinherited

Get the originator flag.

Definition at line 168 of file xdr_mgf.h.

References libMesh::XdrMGF::orig_flag.

Referenced by libMesh::XdrMGF::init(), libMesh::LegacyXdrIO::read_mesh(), and libMesh::LegacyXdrIO::write_mesh().

168 { return orig_flag; }
LegacyXdrIO::FileFormat orig_flag
Definition: xdr_mgf.h:223
int libMesh::XdrMESH::header ( XdrMHEAD hd)

Read/Write the mesh_base.header. Uses xdr_int found in rpc/rpc.h.

Parameters
hdPointer to an xdr mesh_base.header object
Returns
1 on success

Definition at line 28 of file xdr_mesh.C.

References libMesh::XdrHEAD::cpyString(), libMesh::XdrMGF::DECODE, libMesh::XdrMGF::ENCODE, libMesh::XdrMHEAD::get_block_elt_types(), libMesh::XdrMHEAD::get_n_blocks(), libMesh::XdrMHEAD::get_num_elem_each_block(), libMesh::XdrMGF::get_num_levels(), libMesh::XdrHEAD::getId(), libMesh::XdrHEAD::getTitle(), libMesh::libmesh_assert(), libMesh::XdrHEAD::m_numBCs, libMesh::XdrHEAD::m_numel, libMesh::XdrHEAD::m_numNodes, libMesh::XdrHEAD::m_strSize, libMesh::XdrHEAD::m_sumWghts, libMesh::XdrMGF::m_type, libMesh::XdrHEAD::mp_id, libMesh::XdrMGF::mp_in, libMesh::XdrMGF::mp_out, libMesh::XdrHEAD::mp_title, libMesh::XdrMGF::mp_xdr_handle, libMesh::XdrMGF::orig_flag, libMesh::XdrMGF::R_ASCII, libMesh::XdrMHEAD::set_block_elt_types(), libMesh::XdrMHEAD::set_n_blocks(), libMesh::XdrMHEAD::set_num_elem_each_block(), libMesh::XdrHEAD::setId(), libMesh::XdrHEAD::setTitle(), and libMesh::XdrMGF::W_ASCII.

Referenced by libMesh::LegacyXdrIO::read_mesh(), and libMesh::LegacyXdrIO::write_mesh().

29 {
30  // Temporary variables to facilitate stream reading
31  const int comm_len= 256;
32  char comment[comm_len];
33 
34  switch (m_type)
35  {
36 
37 #ifdef LIBMESH_HAVE_XDR
38 
39  case (XdrMGF::DECODE):
40  case (XdrMGF::ENCODE):
41  {
42  xdr_int(mp_xdr_handle, &(hd->m_numel));
43  xdr_int(mp_xdr_handle, &(hd->m_numNodes));
44  xdr_int(mp_xdr_handle, &(hd->m_sumWghts));
45  xdr_int(mp_xdr_handle, &(hd->m_numBCs));
46  xdr_int(mp_xdr_handle, &(hd->m_strSize));
47  break;
48  }
49 
50 #endif
51 
52  case (XdrMGF::W_ASCII):
53  {
54  mp_out << hd->m_numel << "\t # Num. Elements\n";
55  mp_out << hd->m_numNodes << "\t # Num. Nodes\n";
56  mp_out << hd->m_sumWghts << "\t # Sum of Element Weights\n";
57  mp_out << hd->m_numBCs << "\t # Num. Boundary Conds.\n";
58  mp_out << hd->m_strSize << "\t # String Size (ignore)\n";
59  break;
60  }
61 
62  case (XdrMGF::R_ASCII):
63  {
64  libmesh_assert (mp_in.good());
65 
66  mp_in >> hd->m_numel ; mp_in.getline(comment, comm_len);
67  mp_in >> hd->m_numNodes ; mp_in.getline(comment, comm_len);
68  mp_in >> hd->m_sumWghts ; mp_in.getline(comment, comm_len);
69  mp_in >> hd->m_numBCs ; mp_in.getline(comment, comm_len);
70  mp_in >> hd->m_strSize ; mp_in.getline(comment, comm_len);
71 
72  libmesh_assert(mp_in.good());
73 
74  break;
75  }
76 
77  default:
78  // Unknown access type
79  libmesh_error_msg("Unknown m_type" << m_type);
80  }
81 
82  // Let's write the augmented header information
83  // before we write the title and id string
84 
85  // Both DEAL and LIBM style files have augmented headers.
86  if ((orig_flag == 0) || (orig_flag == 2))
87  {
88 
89  switch (m_type)
90  {
91 
92 #ifdef LIBMESH_HAVE_XDR
93 
94  case (XdrMGF::ENCODE):
95  case (XdrMGF::DECODE):
96  {
97  // this used to be 0. How did that work?
98  unsigned int temp_n_blocks = hd->get_n_blocks();
99  xdr_u_int(mp_xdr_handle, &temp_n_blocks);
100  hd->set_n_blocks(temp_n_blocks);
101 
102  // The number of blocks (i.e. the number of element types)
103  // for any mesh must always
104  // be at least 1.
105  libmesh_assert_not_equal_to (hd->get_n_blocks(), 0);
106  break;
107  }
108 
109 #endif
110 
111  case (XdrMGF::W_ASCII):
112  {
113  mp_out << hd->get_n_blocks() << "\t # Num. Element Blocks.\n";
114  break;
115  }
116 
117  case (XdrMGF::R_ASCII):
118  {
119  libmesh_assert (mp_in.good());
120  unsigned int temp_n_blocks=0;
121  mp_in >> temp_n_blocks;
122  hd->set_n_blocks(temp_n_blocks);
123  mp_in.getline(comment, comm_len);
124  break;
125  }
126 
127  default:
128  // Unknown access type
129  libmesh_error_msg("Unknown m_type" << m_type);
130  }
131 
132 
133  std::vector<ElemType> et;
134  hd->get_block_elt_types(et);
135 
136 
137  // Note: If DECODING or READING, allocate space in the vector
138  if ((m_type == DECODE) || (m_type == R_ASCII))
139  et.resize(hd->get_n_blocks());
140 
141 
142  switch (m_type)
143  {
144 
145 #ifdef LIBMESH_HAVE_XDR
146 
147  case (XdrMGF::ENCODE):
148  case (XdrMGF::DECODE):
149  {
150  xdr_vector(mp_xdr_handle,
151  (char *) &et[0],
152  cast_int<unsigned int>(et.size()),
153  sizeof(unsigned int),
154  (xdrproc_t) xdr_u_int);
155  break;
156  }
157 
158 #endif
159 
160  case (XdrMGF::W_ASCII):
161  {
162  for (unsigned int i=0; i<hd->get_n_blocks(); i++)
163  mp_out << et[i] << " ";
164 
165  mp_out << "\t # Element types in each block.\n";
166  break;
167  }
168 
169  case (XdrMGF::R_ASCII):
170  {
171  libmesh_assert (mp_in.good());
172 
173  for (unsigned int i=0; i<hd->get_n_blocks(); i++)
174  {
175  // convoluted way of doing it to
176  // satisfy icc
177  unsigned int type;
178 
179  mp_in >> type ;
180 
181  et[i] = static_cast<ElemType>(type) ;
182  }
183  mp_in.getline(comment, comm_len);
184  break;
185  }
186 
187  default:
188  // Unknown access type
189  libmesh_error_msg("Unknown m_type" << m_type);
190  }
191 
192 
193 
194  // Note: If DECODING or READING, you need to set the value
195  // in the header data structure.
196  if ((m_type == DECODE) || (m_type == R_ASCII))
197  hd->set_block_elt_types(et);
198 
199 
200  std::vector<unsigned int> neeb;
201  hd->get_num_elem_each_block(neeb);
202 
203  // If DECODING or READING, allocate space for the vector
204  if ((m_type == DECODE) || (m_type == R_ASCII))
205  neeb.resize( hd->get_n_blocks()*(this->get_num_levels()+1) );
206 
207  switch (m_type)
208  {
209 
210 #ifdef LIBMESH_HAVE_XDR
211 
212  case (XdrMGF::ENCODE):
213  case (XdrMGF::DECODE):
214  {
215  xdr_vector(mp_xdr_handle,
216  (char *) &neeb[0],
217  cast_int<unsigned int>(neeb.size()),
218  sizeof(unsigned int),
219  (xdrproc_t) xdr_u_int);
220  }
221 
222 #endif
223 
224  case (XdrMGF::W_ASCII):
225  {
226  for (unsigned int i=0; i<neeb.size(); i++)
227  mp_out << neeb[i] << " ";
228 
229  mp_out << "\t # Num. of elements in each block at each level.\n";
230  break;
231  }
232 
233  case (XdrMGF::R_ASCII):
234  {
235 
236  // We will treat this line as containing
237  // 1.) The number of elements in each block OR
238  // 2.) The number of elements at each level in each block
239  // Therefore, we don't know a-priori how many ints to read.
240 
241  // Get the full line from the stream up to the newline
242  mp_in.getline(comment, comm_len);
243 
244  // Construct a char buffer to hold the tokens as we
245  // process them, and construct a std::string object and
246  // a std::stringstream object for tokenizing this line.
247  char token[comm_len];
248  std::string s_temp(comment);
249  std::stringstream ss(s_temp);
250 
251  // Resize the neeb vector to zero so we can push back
252  // values onto it. Note that we are using a tokenizer
253  // scheme again here to read the line, but it's not entirely
254  // necessary since we know the size neeb should have.
255  neeb.resize(0);
256 
257  // Process the tokens one at a time
258  while (ss >> token)
259  {
260  // If you reach the hash, the rest of the line is a comment,
261  // so quit reading.
262  if (token[0] == '#')
263  break;
264 
265  // If you reach an alphabetic character, this is an error
266  if (!isdigit(token[0]))
267  libmesh_error_msg("Error: Unrecognized character detected.");
268 
269  // Otherwise, add the value to the neeb vector
270  neeb.push_back( std::atoi(token) );
271  }
272 
273  // Be sure you have the right number of entries in neeb
274  libmesh_assert_equal_to (neeb.size(), (hd->get_n_blocks() * (this->get_num_levels()+1)));
275 
276  break;
277  }
278 
279  default:
280  // Unknown access type
281  libmesh_error_msg("Unknown m_type" << m_type);
282  }
283 
284  if ((m_type == DECODE) || (m_type == R_ASCII))
285  hd->set_num_elem_each_block(neeb);
286  }
287 
288  else if (orig_flag == 1) // MGF originator
289  {
290  }
291  else // Unknown Originator!
292  libmesh_error_msg("Unknown orig_flag " << orig_flag);
293 
294 
295 
296 
297  // Write the ID and TITLE strings (can be safely ignored)
298  switch (m_type)
299  {
300 
301 #ifdef LIBMESH_HAVE_XDR
302 
303  case (XdrMGF::ENCODE):
304  case (XdrMGF::DECODE):
305  {
306  char * temp = hd->cpyString(hd->getId());
307  xdr_string(mp_xdr_handle, &temp,
308  ((m_type == XdrMGF::ENCODE) ?
309  cast_int<unsigned int>(std::strlen(temp)) :
310  hd->m_strSize));
311  hd->setId(temp);
312  delete [] temp;
313 
314  temp = hd->cpyString(hd->getTitle());
315 
316  xdr_string(mp_xdr_handle, &temp,
317  ((m_type == XdrMGF::ENCODE) ?
318  cast_int<unsigned int>(std::strlen(temp)) :
319  hd->m_strSize));
320  hd->setTitle(temp);
321  delete [] temp;
322  break;
323  }
324 
325 #endif
326 
327  case (XdrMGF::W_ASCII):
328  {
329  mp_out << hd->mp_id << '\n';
330  mp_out << hd->mp_title << '\n';
331  break;
332  }
333 
334  case (XdrMGF::R_ASCII):
335  {
336  libmesh_assert (mp_in.good());
337 
338  mp_in.getline(comment, comm_len);
339  hd->setId(comment);
340 
341  libmesh_assert (mp_in.good());
342 
343  mp_in.getline(comment, comm_len);
344  hd->setTitle(comment);
345 
346  break;
347  }
348 
349  default:
350  // Unknown access type
351  libmesh_error_msg("Unknown m_type" << m_type);
352  }
353 
354  return 1;
355 }
unsigned int get_num_levels()
Definition: xdr_mgf.h:184
libmesh_assert(remote_elem)
std::ifstream mp_in
Definition: xdr_mgf.h:228
LegacyXdrIO::FileFormat orig_flag
Definition: xdr_mgf.h:223
std::ofstream mp_out
Definition: xdr_mgf.h:233
XdrIO_TYPE m_type
Definition: xdr_mgf.h:200
XDR * mp_xdr_handle
Definition: xdr_mgf.h:210
int libMesh::XdrMESH::Icon ( int *  array,
int  numvar,
int  num 
)
inline

Read/Write an integer connectivity array

Parameters
arrayPointer to an array of ints
numvarTotal number of variables to be read/written
numBasically a dummy parameter
Returns
numvar*num

Definition at line 89 of file xdr_mesh.h.

References libMesh::XdrMGF::dataBlk().

Referenced by libMesh::LegacyXdrIO::read_mesh(), and libMesh::LegacyXdrIO::write_mesh().

89 { return dataBlk(array, numvar, num);}
int dataBlk(int *array, int numvar, int size)
Definition: xdr_mgf.C:264
void libMesh::XdrMESH::init ( XdrIO_TYPE  type,
const char *  fn,
int  icnt,
int  dim = 3 
)
inline

Calls the init method in the parent class, XdrMGF with the appropriate parameters.

Parameters
typeOne of: UNKNOWN, ENCODE, DECODE
fnconst char pointer which points to the filename
icntNumber to be appended to file e.g. name.mesh.0000
dimProblem dimension (always three in MGF)

Definition at line 63 of file xdr_mesh.h.

References libMesh::dim, libMesh::XdrMGF::init(), and m_dim.

Referenced by libMesh::LegacyXdrIO::read_mesh(), and libMesh::LegacyXdrIO::write_mesh().

64  { XdrMGF::init(type, fn, "mesh", icnt); m_dim = dim;}
void init(XdrIO_TYPE t, const char *fn, const char *type, int icnt)
Definition: xdr_mgf.C:68
void ExactErrorEstimator::estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector, bool estimate_parent_error) void ExactErrorEstimator const unsigned in dim)
void libMesh::XdrMGF::init ( XdrMGF::XdrIO_TYPE  t,
const char *  fn,
const char *  type,
int  icnt 
)
inherited

Initialization of the xdr file. This function performs the following operations:

  • Closes the old xdr file if necessary.
  • Creates a new xdr file name and opens this file.
  • Opens the appropriate xdr file handle.
  • Reads/Writes a signature to the file.

Definition at line 68 of file xdr_mgf.C.

References libMesh::LegacyXdrIO::DEAL, libMesh::XdrMGF::DECODE, libMesh::XdrMGF::ENCODE, libMesh::XdrMGF::fini(), libMesh::XdrMGF::get_num_levels(), libMesh::XdrMGF::get_orig_flag(), libMesh::LegacyXdrIO::LIBM, libMesh::XdrMGF::m_type, libMesh::LegacyXdrIO::MGF, libMesh::XdrMGF::mp_fp, libMesh::XdrMGF::mp_in, libMesh::XdrMGF::mp_out, libMesh::XdrMGF::mp_xdr_handle, libMesh::Quality::name(), libMesh::XdrMGF::orig_flag, libMesh::out, libMesh::XdrMGF::R_ASCII, libMesh::XdrMGF::tokenize_first_line(), and libMesh::XdrMGF::W_ASCII.

Referenced by libMesh::XdrSOLN::init(), and init().

69 {
70  m_type=t;
71 
72  // Close old file if necessary
73  if (mp_fp) this->fini();
74 
75 
76  // Open file
77  switch (m_type)
78  {
79 
80 #ifdef LIBMESH_HAVE_XDR
81 
82  case (XdrMGF::ENCODE):
83  case (XdrMGF::DECODE):
84  {
85  mp_fp = fopen (fn, (m_type == ENCODE) ? "w" : "r");
86 
87  // Make sure the file is ready for use
88  if (!mp_fp)
89  libmesh_error_msg("XDR Error: Accessing file: " << fn << " failed.");
90 
91  // Create the XDR handle
92  mp_xdr_handle = new XDR;
93  xdrstdio_create(mp_xdr_handle,
94  mp_fp,
95  ((m_type == ENCODE) ? XDR_ENCODE : XDR_DECODE));
96 
97  break;
98  }
99 
100 #endif
101 
102  case (XdrMGF::R_ASCII):
103  {
104  mp_in.open(fn, std::ios::in);
105 
106  // Make sure it opened correctly
107  if (!mp_in.good())
108  libmesh_file_error(fn);
109 
110  break;
111  }
112 
113  case (XdrMGF::W_ASCII):
114  {
115  mp_out.open(fn, std::ios::out);
116 
117  // Make sure it opened correctly
118  if (!mp_out.good())
119  libmesh_file_error(fn);
120 
121  break;
122  }
123 
124  default:
125  libmesh_error_msg("Unrecognized file access type!");
126  }
127 
128 
129 
130 
131 
132  // Read/Write the file signature
133  const int bufLen = 12;
134  char buf[bufLen+1];
135 
136  switch (m_type)
137  {
138 
139 #ifdef LIBMESH_HAVE_XDR
140 
141  case (XdrMGF::ENCODE):
142  {
143  char * p = &buf[0];
144  const LegacyXdrIO::FileFormat orig = this->get_orig_flag();
145 
146  std::ostringstream name;
147  if (orig == LegacyXdrIO::DEAL)
148  name << "DEAL 003:003";
149 
150  else if (orig == LegacyXdrIO::MGF)
151  name << "MGF 002:000";
152 
153  else if (orig == LegacyXdrIO::LIBM)
154  name << "LIBM " << this->get_num_levels();
155 
156  else
157  libmesh_error_msg("Unknown orig " << orig);
158 
159  // Fill the buffer
160  std::sprintf(&buf[0], "%s", name.str().c_str());
161 
162  xdr_string(mp_xdr_handle, &p, bufLen); // Writes binary signature
163 
164  break;
165  }
166 
167  case (XdrMGF::DECODE):
168  {
169  char * p = &buf[0];
170  xdr_string(mp_xdr_handle, &p, bufLen); // Reads binary signature
171 
172  // Set the number of levels used in the mesh
173  this->tokenize_first_line(p);
174 
175  break;
176  }
177 
178 #endif
179 
180  case (XdrMGF::W_ASCII):
181  {
182  const LegacyXdrIO::FileFormat orig = this->get_orig_flag();
183 
184  if (orig == LegacyXdrIO::DEAL)
185  std::sprintf(&buf[0], "%s %03d:%03d", "DEAL", 3, 3);
186 
187  else if (orig == LegacyXdrIO::MGF)
188  std::sprintf(&buf[0], "%s %03d:%03d", "MGF ", 2, 0);
189 
190  else if (orig == LegacyXdrIO::LIBM)
191  std::sprintf(&buf[0], "%s %d", "LIBM", this->get_num_levels());
192 
193  mp_out << buf << '\n';
194 
195  break;
196  }
197 
198  case (XdrMGF::R_ASCII):
199  {
200 
201 #ifdef __HP_aCC
202  // weirdly, _only_ here aCC
203  // is not fond of mp_in.getline()
204  // however, using mp_in.getline()
205  // further below is ok...
206  std::string buf_buf;
207  std::getline (mp_in, buf_buf, '\n');
208  libmesh_assert_less_equal (buf_buf.size(), bufLen);
209 
210  buf_buf.copy (buf, std::string::npos);
211 #else
212 
213  // Here we first use getline() to grab the very
214  // first line of the file into a char buffer. Then
215  // this line is tokenized to look for:
216  // 1.) The name LIBM, which specifies the new Mesh style.
217  // 2.) The number of levels in the Mesh which is being read.
218  // Note that "buf" will be further processed below, here we
219  // are just attempting to get the number of levels.
220  mp_in.getline(buf, bufLen+1);
221 
222 #endif
223 
224  // Determine the number of levels in this mesh
225  this->tokenize_first_line(buf);
226 
227  break;
228  }
229 
230  default:
231  libmesh_error_msg("Unknown m_type" << m_type);
232  }
233 
234 
235 
236  // If you are reading or decoding, process the signature
237  if ((m_type == R_ASCII) || (m_type == DECODE))
238  {
239  char name[5];
240  std::strncpy(name, &buf[0], 4);
241  name[4] = '\0';
242 
243  if (std::strcmp (name, "DEAL") == 0)
244  {
245  this->orig_flag = LegacyXdrIO::DEAL; // 0 is the DEAL identifier by definition
246  }
247  else if (std::strcmp (name, "MGF ") == 0)
248  {
249  this->orig_flag = LegacyXdrIO::MGF; // 1 is the MGF identifier by definition
250  }
251  else if (std::strcmp (name, "LIBM") == 0)
252  {
253  this->orig_flag = LegacyXdrIO::LIBM; // the New and Improved XDA
254  }
255 
256  else
257  libmesh_error_msg("ERROR: No originating software can be determined for header string '" << name);
258  }
259 
260 }
unsigned int get_num_levels()
Definition: xdr_mgf.h:184
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
void tokenize_first_line(const char *p)
Definition: xdr_mgf.h:242
void fini()
Definition: xdr_mgf.C:35
std::FILE * mp_fp
Definition: xdr_mgf.h:236
std::ifstream mp_in
Definition: xdr_mgf.h:228
LegacyXdrIO::FileFormat orig_flag
Definition: xdr_mgf.h:223
std::ofstream mp_out
Definition: xdr_mgf.h:233
XdrIO_TYPE m_type
Definition: xdr_mgf.h:200
LegacyXdrIO::FileFormat get_orig_flag() const
Definition: xdr_mgf.h:168
OStreamProxy out(std::cout)
XDR * mp_xdr_handle
Definition: xdr_mgf.h:210
void libMesh::XdrMGF::set_num_levels ( unsigned int  num_levels)
inlineinherited

Set number of levels

Definition at line 179 of file xdr_mgf.h.

References libMesh::XdrMGF::_num_levels.

Referenced by libMesh::LegacyXdrIO::write_mesh().

179 { _num_levels = num_levels; }
unsigned int _num_levels
Definition: xdr_mgf.h:191
void libMesh::XdrMGF::set_orig_flag ( LegacyXdrIO::FileFormat  in_orig_flag)
inlineinherited

Set the originator flag.

Definition at line 173 of file xdr_mgf.h.

References libMesh::XdrMGF::orig_flag.

Referenced by libMesh::LegacyXdrIO::read_mesh(), and libMesh::LegacyXdrIO::write_mesh().

173 { orig_flag = in_orig_flag; }
LegacyXdrIO::FileFormat orig_flag
Definition: xdr_mgf.h:223

Member Data Documentation

unsigned int libMesh::XdrMGF::_num_levels
protectedinherited

Number of levels of refinement in the mesh

Definition at line 191 of file xdr_mgf.h.

Referenced by libMesh::XdrMGF::get_num_levels(), and libMesh::XdrMGF::set_num_levels().

int libMesh::XdrMESH::m_dim
private

Dimension of the mesh

Definition at line 115 of file xdr_mesh.h.

Referenced by init().

XdrIO_TYPE libMesh::XdrMGF::m_type
protectedinherited

Specifies the read/write permission for the current xdr file. Possibilities are:

  • UNKNOWN = -1
  • ENCODE = 0
  • DECODE = 1

Definition at line 200 of file xdr_mgf.h.

Referenced by libMesh::XdrMGF::dataBlk(), libMesh::XdrSOLN::header(), header(), and libMesh::XdrMGF::init().

std::ifstream libMesh::XdrMGF::mp_in
protectedinherited

An input file stream object

Definition at line 228 of file xdr_mgf.h.

Referenced by libMesh::XdrMGF::dataBlk(), libMesh::XdrSOLN::header(), header(), and libMesh::XdrMGF::init().

std::ofstream libMesh::XdrMGF::mp_out
protectedinherited

An output file stream object.

Definition at line 233 of file xdr_mgf.h.

Referenced by libMesh::XdrMGF::dataBlk(), libMesh::XdrSOLN::header(), header(), and libMesh::XdrMGF::init().

XDR* libMesh::XdrMGF::mp_xdr_handle
protectedinherited

Pointer to the standard {xdr} struct. See the standard header file rpc/rpc.h for more information.

Definition at line 210 of file xdr_mgf.h.

Referenced by libMesh::XdrMGF::dataBlk(), libMesh::XdrMGF::fini(), libMesh::XdrSOLN::header(), header(), and libMesh::XdrMGF::init().

LegacyXdrIO::FileFormat libMesh::XdrMGF::orig_flag
protectedinherited

Flag indicating how much checking we need to do. We can read in mgf meshes more quickly because there is only one type of element in these meshes. Deal meshes on the other hand will require a check for each element to find out what type it is. Possible values are:

  • 0: It's an DEAL style mesh
  • 1: It's a MGF style mesh

Definition at line 223 of file xdr_mgf.h.

Referenced by libMesh::XdrMGF::get_orig_flag(), header(), libMesh::XdrMGF::init(), and libMesh::XdrMGF::set_orig_flag().


The documentation for this class was generated from the following files: