www.mooseframework.org
Functions
DataIO.C File Reference

Go to the source code of this file.

Functions

template<>
void dataStore (std::ostream &stream, Real &v, void *)
 
template<>
void dataStore (std::ostream &stream, std::string &v, void *)
 
template<>
void dataStore (std::ostream &stream, NumericVector< Real > &v, void *)
 
template<>
void dataStore (std::ostream &stream, DenseVector< Real > &v, void *)
 
template<>
void dataStore (std::ostream &stream, DenseMatrix< Real > &v, void *)
 
template<>
void dataStore (std::ostream &stream, ColumnMajorMatrix &v, void *)
 
template<>
void dataStore (std::ostream &stream, RealTensorValue &v, void *)
 
template<>
void dataStore (std::ostream &stream, RealVectorValue &v, void *)
 
template<>
void dataStore (std::ostream &stream, const Elem *&e, void *context)
 
template<>
void dataStore (std::ostream &stream, const Node *&n, void *context)
 
template<>
void dataStore (std::ostream &stream, Elem *&e, void *context)
 
template<>
void dataStore (std::ostream &stream, Node *&n, void *context)
 
template<>
void dataStore (std::ostream &stream, std::stringstream &s, void *)
 
template<>
void dataStore (std::ostream &stream, std::stringstream *&s, void *context)
 
template<>
void dataLoad (std::istream &stream, Real &v, void *)
 
template<>
void dataLoad (std::istream &stream, std::string &v, void *)
 
template<>
void dataLoad (std::istream &stream, NumericVector< Real > &v, void *)
 
template<>
void dataLoad (std::istream &stream, DenseVector< Real > &v, void *)
 
template<>
void dataLoad (std::istream &stream, DenseMatrix< Real > &v, void *)
 
template<>
void dataLoad (std::istream &stream, ColumnMajorMatrix &v, void *)
 
template<>
void dataLoad (std::istream &stream, RealTensorValue &v, void *)
 
template<>
void dataLoad (std::istream &stream, RealVectorValue &v, void *)
 
template<>
void dataLoad (std::istream &stream, const Elem *&e, void *context)
 
template<>
void dataLoad (std::istream &stream, const Node *&n, void *context)
 
template<>
void dataLoad (std::istream &stream, Elem *&e, void *context)
 
template<>
void dataLoad (std::istream &stream, Node *&n, void *context)
 
template<>
void dataLoad (std::istream &stream, std::stringstream &s, void *)
 
template<>
void dataLoad (std::istream &stream, std::stringstream *&s, void *context)
 

Function Documentation

template<>
void dataLoad ( std::istream &  stream,
Real &  v,
void *   
)

Definition at line 208 of file DataIO.C.

Referenced by dataLoad().

209 {
210  stream.read((char *)&v, sizeof(v));
211 }
template<>
void dataLoad ( std::istream &  stream,
std::string &  v,
void *   
)

Definition at line 215 of file DataIO.C.

216 {
217  // Read the size of the string
218  unsigned int size = 0;
219  stream.read((char *)&size, sizeof(size));
220 
221  // Resize the string data
222  v.resize(size);
223 
224  // Read the string
225  stream.read(&v[0], sizeof(char) * size);
226 }
template<>
void dataLoad ( std::istream &  stream,
NumericVector< Real > &  v,
void *   
)

Definition at line 230 of file DataIO.C.

231 {
232  numeric_index_type size = v.local_size();
233 
234  for (numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
235  {
236  Real r = 0;
237  stream.read((char *)&r, sizeof(r));
238  v.set(i, r);
239  }
240 
241  v.close();
242 }
template<>
void dataLoad ( std::istream &  stream,
DenseVector< Real > &  v,
void *   
)

Definition at line 246 of file DataIO.C.

247 {
248  unsigned int n = 0;
249  stream.read((char *)&n, sizeof(n));
250  v.resize(n);
251  for (unsigned int i = 0; i < n; i++)
252  {
253  Real r = 0;
254  stream.read((char *)&r, sizeof(r));
255  v(i) = r;
256  }
257 }
PetscInt n
template<>
void dataLoad ( std::istream &  stream,
DenseMatrix< Real > &  v,
void *   
)

Definition at line 261 of file DataIO.C.

262 {
263  unsigned int nr = 0, nc = 0;
264  stream.read((char *)&nr, sizeof(nr));
265  stream.read((char *)&nc, sizeof(nc));
266  v.resize(nr, nc);
267  for (unsigned int i = 0; i < v.m(); i++)
268  for (unsigned int j = 0; j < v.n(); j++)
269  {
270  Real r = 0;
271  stream.read((char *)&r, sizeof(r));
272  v(i, j) = r;
273  }
274 }
template<>
void dataLoad ( std::istream &  stream,
ColumnMajorMatrix v,
void *   
)

Definition at line 278 of file DataIO.C.

279 {
280  for (unsigned int i = 0; i < v.m(); i++)
281  for (unsigned int j = 0; j < v.n(); j++)
282  {
283  Real r = 0;
284  stream.read((char *)&r, sizeof(r));
285  v(i, j) = r;
286  }
287 }
unsigned int n() const
Returns the number of rows.
unsigned int m() const
Returns the number of columns.
template<>
void dataLoad ( std::istream &  stream,
RealTensorValue &  v,
void *   
)

Definition at line 291 of file DataIO.C.

292 {
293  // Obviously if someone loads data with different LIBMESH_DIM than was used for saving them, it
294  // won't work.
295  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
296  for (unsigned int j = 0; i < LIBMESH_DIM; i++)
297  {
298  Real r = 0;
299  stream.read((char *)&r, sizeof(r));
300  v(i, j) = r;
301  }
302 }
template<>
void dataLoad ( std::istream &  stream,
RealVectorValue &  v,
void *   
)

Definition at line 306 of file DataIO.C.

307 {
308  // Obviously if someone loads data with different LIBMESH_DIM than was used for saving them, it
309  // won't work.
310  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
311  {
312  Real r = 0;
313  stream.read((char *)&r, sizeof(r));
314  v(i) = r;
315  }
316 }
template<>
void dataLoad ( std::istream &  stream,
const Elem *&  e,
void *  context 
)

Definition at line 320 of file DataIO.C.

321 {
322  if (!context)
323  mooseError("Can only load Elem objects using a MooseMesh context!");
324 
325  MooseMesh * mesh = static_cast<MooseMesh *>(context);
326 
327  // TODO: Write out the unique ID of this element
328  dof_id_type id = libMesh::DofObject::invalid_id;
329 
330  loadHelper(stream, id, context);
331 
332  if (id != libMesh::DofObject::invalid_id)
333  e = mesh->elemPtr(id);
334  else
335  e = NULL;
336 }
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2062
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:592
template<>
void dataLoad ( std::istream &  stream,
const Node *&  n,
void *  context 
)

Definition at line 340 of file DataIO.C.

341 {
342  if (!context)
343  mooseError("Can only load Node objects using a MooseMesh context!");
344 
345  MooseMesh * mesh = static_cast<MooseMesh *>(context);
346 
347  // TODO: Write out the unique ID of this nodeent
348  dof_id_type id = libMesh::DofObject::invalid_id;
349 
350  loadHelper(stream, id, context);
351 
352  if (id != libMesh::DofObject::invalid_id)
353  n = mesh->nodePtr(id);
354  else
355  n = NULL;
356 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
virtual const Node * nodePtr(const dof_id_type i) const
Definition: MooseMesh.C:416
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
PetscInt n
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:592
template<>
void dataLoad ( std::istream &  stream,
Elem *&  e,
void *  context 
)

Definition at line 360 of file DataIO.C.

361 {
362  if (!context)
363  mooseError("Can only load Elem objects using a MooseMesh context!");
364 
365  MooseMesh * mesh = static_cast<MooseMesh *>(context);
366 
367  // TODO: Write out the unique ID of this element
368  dof_id_type id = libMesh::DofObject::invalid_id;
369 
370  loadHelper(stream, id, context);
371 
372  if (id != libMesh::DofObject::invalid_id)
373  e = mesh->elemPtr(id);
374  else
375  e = NULL;
376 }
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2062
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:592
template<>
void dataLoad ( std::istream &  stream,
Node *&  n,
void *  context 
)

Definition at line 380 of file DataIO.C.

381 {
382  if (!context)
383  mooseError("Can only load Node objects using a MooseMesh context!");
384 
385  MooseMesh * mesh = static_cast<MooseMesh *>(context);
386 
387  // TODO: Write out the unique ID of this nodeent
388  dof_id_type id = libMesh::DofObject::invalid_id;
389 
390  loadHelper(stream, id, context);
391 
392  if (id != libMesh::DofObject::invalid_id)
393  n = mesh->nodePtr(id);
394  else
395  n = NULL;
396 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
virtual const Node * nodePtr(const dof_id_type i) const
Definition: MooseMesh.C:416
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
PetscInt n
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:592
template<>
void dataLoad ( std::istream &  stream,
std::stringstream &  s,
void *   
)

Definition at line 400 of file DataIO.C.

401 {
402  size_t s_size = 0;
403 
404  stream.read((char *)&s_size, sizeof(s_size));
405 
406  char * s_s = new char[s_size];
407 
408  stream.read(s_s, s_size);
409 
410  s.write(s_s, s_size);
411  delete[] s_s;
412 }
template<>
void dataLoad ( std::istream &  stream,
std::stringstream *&  s,
void *  context 
)

Definition at line 416 of file DataIO.C.

417 {
418  dataLoad(stream, *s, context);
419 }
void dataLoad(std::istream &stream, Real &v, void *)
Definition: DataIO.C:208
template<>
void dataStore ( std::ostream &  stream,
Real &  v,
void *   
)

Definition at line 25 of file DataIO.C.

Referenced by dataStore().

26 {
27  stream.write((char *)&v, sizeof(v));
28 }
template<>
void dataStore ( std::ostream &  stream,
std::string &  v,
void *   
)

Definition at line 32 of file DataIO.C.

33 {
34  // Write the size of the string
35  unsigned int size = v.size();
36  stream.write((char *)&size, sizeof(size));
37 
38  // Write the string (Do not store the null byte)
39  stream.write(v.c_str(), sizeof(char) * size);
40 }
template<>
void dataStore ( std::ostream &  stream,
NumericVector< Real > &  v,
void *   
)

Definition at line 44 of file DataIO.C.

45 {
46  v.close();
47 
48  numeric_index_type size = v.local_size();
49 
50  for (numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
51  {
52  Real r = v(i);
53  stream.write((char *)&r, sizeof(r));
54  }
55 }
template<>
void dataStore ( std::ostream &  stream,
DenseVector< Real > &  v,
void *   
)

Definition at line 59 of file DataIO.C.

60 {
61  unsigned int m = v.size();
62  stream.write((char *)&m, sizeof(m));
63  for (unsigned int i = 0; i < v.size(); i++)
64  {
65  Real r = v(i);
66  stream.write((char *)&r, sizeof(r));
67  }
68 }
PetscInt m
template<>
void dataStore ( std::ostream &  stream,
DenseMatrix< Real > &  v,
void *   
)

Definition at line 72 of file DataIO.C.

73 {
74  unsigned int m = v.m();
75  unsigned int n = v.n();
76  stream.write((char *)&m, sizeof(m));
77  stream.write((char *)&n, sizeof(n));
78  for (unsigned int i = 0; i < v.m(); i++)
79  for (unsigned int j = 0; j < v.n(); j++)
80  {
81  Real r = v(i, j);
82  stream.write((char *)&r, sizeof(r));
83  }
84 }
PetscInt m
PetscInt n
template<>
void dataStore ( std::ostream &  stream,
ColumnMajorMatrix v,
void *   
)

Definition at line 88 of file DataIO.C.

89 {
90  for (unsigned int i = 0; i < v.m(); i++)
91  for (unsigned int j = 0; j < v.n(); j++)
92  {
93  Real r = v(i, j);
94  stream.write((char *)&r, sizeof(r));
95  }
96 }
unsigned int n() const
Returns the number of rows.
unsigned int m() const
Returns the number of columns.
template<>
void dataStore ( std::ostream &  stream,
RealTensorValue &  v,
void *   
)

Definition at line 100 of file DataIO.C.

101 {
102  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
103  for (unsigned int j = 0; i < LIBMESH_DIM; i++)
104  stream.write((char *)&v(i, j), sizeof(v(i, j)));
105 }
template<>
void dataStore ( std::ostream &  stream,
RealVectorValue &  v,
void *   
)

Definition at line 109 of file DataIO.C.

110 {
111  // Obviously if someone loads data with different LIBMESH_DIM than was used for saving them, it
112  // won't work.
113  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
114  stream.write((char *)&v(i), sizeof(v(i)));
115 }
template<>
void dataStore ( std::ostream &  stream,
const Elem *&  e,
void *  context 
)

Definition at line 119 of file DataIO.C.

120 {
121  // TODO: Write out the unique ID of this elem
122  dof_id_type id = libMesh::DofObject::invalid_id;
123 
124  if (e)
125  {
126  id = e->id();
127  if (id == libMesh::DofObject::invalid_id)
128  mooseError("Can't output Elems with invalid ids!");
129  }
130 
131  storeHelper(stream, id, context);
132 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:528
template<>
void dataStore ( std::ostream &  stream,
const Node *&  n,
void *  context 
)

Definition at line 136 of file DataIO.C.

137 {
138  // TODO: Write out the unique ID of this node
139  dof_id_type id = libMesh::DofObject::invalid_id;
140 
141  if (n)
142  {
143  id = n->id();
144  if (id == libMesh::DofObject::invalid_id)
145  mooseError("Can't output Nodes with invalid ids!");
146  }
147 
148  storeHelper(stream, id, context);
149 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:528
PetscInt n
template<>
void dataStore ( std::ostream &  stream,
Elem *&  e,
void *  context 
)

Definition at line 153 of file DataIO.C.

154 {
155  // TODO: Write out the unique ID of this elem
156  dof_id_type id = libMesh::DofObject::invalid_id;
157 
158  if (e)
159  {
160  id = e->id();
161  if (id == libMesh::DofObject::invalid_id)
162  mooseError("Can't output Elems with invalid ids!");
163  }
164 
165  storeHelper(stream, id, context);
166 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:528
template<>
void dataStore ( std::ostream &  stream,
Node *&  n,
void *  context 
)

Definition at line 170 of file DataIO.C.

171 {
172  // TODO: Write out the unique ID of this node
173  dof_id_type id = libMesh::DofObject::invalid_id;
174 
175  if (n)
176  {
177  id = n->id();
178  if (id == libMesh::DofObject::invalid_id)
179  mooseError("Can't output Nodes with invalid ids!");
180  }
181 
182  storeHelper(stream, id, context);
183 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:528
PetscInt n
template<>
void dataStore ( std::ostream &  stream,
std::stringstream &  s,
void *   
)

Definition at line 187 of file DataIO.C.

188 {
189  const std::string & s_str = s.str();
190 
191  size_t s_size = s_str.size();
192  stream.write((char *)&s_size, sizeof(s_size));
193 
194  stream.write(s_str.c_str(), sizeof(char) * (s_str.size()));
195 }
template<>
void dataStore ( std::ostream &  stream,
std::stringstream *&  s,
void *  context 
)

Definition at line 199 of file DataIO.C.

200 {
201  dataStore(stream, *s, context);
202 }
void dataStore(std::ostream &stream, Real &v, void *)
Definition: DataIO.C:25