KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
file_serializer.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 //
13 
14 #if !defined(KRATOS_FILE_SERIALIZER_H_INCLUDED )
15 #define KRATOS_FILE_SERIALIZER_H_INCLUDED
16 
17 // System includes
18 #include <string>
19 #include <cstring>
20 #include <iostream>
21 
22 // External includes
23 
24 // Project includes
25 #include "includes/define.h"
26 #include "includes/serializer.h"
27 
28 namespace Kratos
29 {
30  //This class provides a simpler interface for serialization to a file
31  // Note that you may not override any load or save method of the Serializer. They are not virtual
32  class FileSerializer : public Serializer
33  {
34  public:
36 
39  FileSerializer(std::string const& Filename, Serializer::TraceType const& rTrace=SERIALIZER_NO_TRACE)
40  : Serializer(nullptr, rTrace)
41  {
42  std::fstream* p_file = new std::fstream(std::string(Filename+".rest").c_str(), std::ios::binary|std::ios::in|std::ios::out);
43  if(!(*p_file))
44  {
45  delete p_file;
46  p_file = new std::fstream(std::string(Filename+".rest").c_str(), std::ios::binary|std::ios::out);
47  }
48  SetBuffer( p_file );
49  KRATOS_ERROR_IF_NOT(*pGetBuffer()) << "Error opening input file : "
50  << std::string(Filename+".rest") << std::endl;
51  }
52 
53  virtual ~FileSerializer(){}
54 
55  private:
56 
58  FileSerializer& operator=(FileSerializer const& rOther) = delete;
59 
61  FileSerializer(FileSerializer const& rOther) = delete;
62  };
63 }
64 
65 #endif // KRATOS_FILE_SERIALIZER_H_INCLUDED defined
Definition: file_serializer.h:33
FileSerializer(std::string const &Filename, Serializer::TraceType const &rTrace=SERIALIZER_NO_TRACE)
Definition: file_serializer.h:39
virtual ~FileSerializer()
Definition: file_serializer.h:53
KRATOS_CLASS_POINTER_DEFINITION(FileSerializer)
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
TraceType
Definition: serializer.h:129
@ SERIALIZER_NO_TRACE
Definition: serializer.h:129
BufferType * pGetBuffer()
Definition: serializer.h:903
void SetBuffer(BufferType *pBuffer)
Definition: serializer.h:186
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
out
Definition: isotropic_damage_automatic_differentiation.py:200