Liebe Gitlab-Nutzerin, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

Serializer.h 4.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file Serializer.h */

#ifndef AMDIS_SERIALIZER_H
#define AMDIS_SERIALIZER_H

#include "FileWriter.h"
#include "MemoryManager.h"
#include "Parameters.h"
#include "AdaptInfo.h"
#include "ProblemStatBase.h"

namespace AMDiS {

  template<typename ProblemType>
  class Serializer : public FileWriterInterface
  {
  public:
    MEMORY_MANAGED(Serializer);

    Serializer(ProblemType *problem) 
      : name_(""), 
	problem_(problem), 
	tsModulo_(1), 
	timestepNumber_(-1)
	  {
      GET_PARAMETER(0, problem_->getName() + "->output->serialization filename", 
		    &name_);
      GET_PARAMETER(0, problem_->getName() + "->output->write every i-th timestep",
		    "%d", &tsModulo_);
      TEST_EXIT(name_ != "")("no filename\n");
    };

    virtual ~Serializer() {};

    virtual void writeFiles(AdaptInfo *adaptInfo, 
			    bool force,
			    int level = -1,
			    Flag traverseFlag = Mesh::CALL_LEAF_EL,
			    bool (*writeElem)(ElInfo*) = NULL) 
    {
      FUNCNAME("Serializer::writeFiles()");

      timestepNumber_++;
      timestepNumber_ %= tsModulo_;
      if ((timestepNumber_ != 0) && !force) {
	return;
      }

      TEST_EXIT(adaptInfo)("No AdaptInfo\n");

      ::std::ofstream out(name_.c_str());
      problem_->serialize(out);
      adaptInfo->serialize(out);
      out.close();

      MSG("problem serialized to %s \n", name_.c_str());
    };

Thomas Witkowski's avatar
Thomas Witkowski committed
78 79 80 81 82
    void writeDelayedFiles() {};

    bool isWritingDelayed() { 
      return false; 
    };
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

  protected:
    /** \brief
     * Name of file to which the problem is serialized.
     */
    ::std::string name_;

    /** \brief
     * Pointer to the problem.
     */
    ProblemType *problem_;

    /** \brief
     * The problem is serialized every tsModulo-th timestep.
     */
    int tsModulo_;

    /** \brief
     * Current timestep number.
     */
    int timestepNumber_;
  };


  class SerializerUtil {
  public:
    static void serializeInt(::std::ostream &out, int* ptrInt) {
      out.write(reinterpret_cast<const char*>(ptrInt), sizeof(int));
    };

    static void serializeDouble(::std::ostream &out, double* ptrInt) {
      out.write(reinterpret_cast<const char*>(ptrInt), sizeof(double));
    };

    static void serializeBool(::std::ostream &out, bool* ptrBool) {
      out.write(reinterpret_cast<const char*>(ptrBool), sizeof(bool));
    }


    static void deserializeInt(::std::istream &in, int* ptrInt) {
      in.read(reinterpret_cast<char*>(ptrInt), sizeof(int));
    };

    static void deserializeDouble(::std::istream &in, double* ptrInt) {
      in.read(reinterpret_cast<char*>(ptrInt), sizeof(double));
    };

    static void deserializeBool(::std::istream &in, bool* ptrBool) {
      in.read(reinterpret_cast<char*>(ptrBool), sizeof(bool));
    };

  };
}
#endif