LCOV - code coverage report
Current view: top level - ugbase/lib_grid/algorithms - serialization_impl.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 51 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 20 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2009-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__LIB_GRID__SERIALIZATION_IMPL__
      34              : #define __H__LIB_GRID__SERIALIZATION_IMPL__
      35              : 
      36              : #include "serialization.h"
      37              : 
      38              : namespace ug
      39              : {
      40              : 
      41              : ////////////////////////////////////////////////////////////////////////
      42              : //      DataSerializer
      43            0 : inline void GridDataSerializationHandler::
      44              : serialize(BinaryBuffer& out, Vertex* vrt) const
      45              : {
      46              :         serialize(out, vrt, m_vrtSerializers);
      47              :         serialize(out, vrt, m_gridSerializers);
      48            0 : }
      49              : 
      50            0 : inline void GridDataSerializationHandler::
      51              : serialize(BinaryBuffer& out, Edge* edge) const
      52              : {
      53              :         serialize(out, edge, m_edgeSerializers);
      54              :         serialize(out, edge, m_gridSerializers);
      55            0 : }
      56              : 
      57            0 : inline void GridDataSerializationHandler::
      58              : serialize(BinaryBuffer& out, Face* face) const
      59              : {
      60              :         serialize(out, face, m_faceSerializers);
      61              :         serialize(out, face, m_gridSerializers);
      62            0 : }
      63              : 
      64            0 : inline void GridDataSerializationHandler::
      65              : serialize(BinaryBuffer& out, Volume* vol) const
      66              : {
      67              :         serialize(out, vol, m_volSerializers);
      68              :         serialize(out, vol, m_gridSerializers);
      69            0 : }
      70              : 
      71              : template <class TIterator>
      72            0 : void GridDataSerializationHandler::
      73              : serialize(BinaryBuffer& out, TIterator begin, TIterator end) const
      74              : {
      75            0 :         for(TIterator iter = begin; iter != end; ++iter)
      76            0 :                 serialize(out, *iter);
      77            0 : }
      78              : 
      79              : template<class TGeomObj, class TSerializers>
      80              : void GridDataSerializationHandler::
      81              : serialize(BinaryBuffer& out, TGeomObj* o,
      82              :                   TSerializers& serializers) const
      83              : {
      84              : //      This method performs the serialization
      85            0 :         for(size_t i = 0; i < serializers.size(); ++i){
      86            0 :                 serializers[i]->write_data(out, o);
      87              :         }
      88              : }
      89              : 
      90              : 
      91              : ////////////////////////////////////////////////////////////////////////
      92            0 : inline void GridDataSerializationHandler::
      93              : deserialize(BinaryBuffer& in, Vertex* vrt)
      94              : {
      95              :         deserialize(in, vrt, m_vrtSerializers);
      96              :         deserialize(in, vrt, m_gridSerializers);
      97            0 : }
      98              : 
      99            0 : inline void GridDataSerializationHandler::
     100              : deserialize(BinaryBuffer& in, Edge* edge)
     101              : {
     102              :         deserialize(in, edge, m_edgeSerializers);
     103              :         deserialize(in, edge, m_gridSerializers);
     104            0 : }
     105              : 
     106            0 : inline void GridDataSerializationHandler::
     107              : deserialize(BinaryBuffer& in, Face* face)
     108              : {
     109              :         deserialize(in, face, m_faceSerializers);
     110              :         deserialize(in, face, m_gridSerializers);
     111            0 : }
     112              : 
     113            0 : inline void GridDataSerializationHandler::
     114              : deserialize(BinaryBuffer& in, Volume* vol)
     115              : {
     116              :         deserialize(in, vol, m_volSerializers);
     117              :         deserialize(in, vol, m_gridSerializers);
     118            0 : }
     119              : 
     120              : template <class TIterator>
     121            0 : void GridDataSerializationHandler::
     122              : deserialize(BinaryBuffer& in, TIterator begin, TIterator end)
     123              : {
     124            0 :         for(TIterator iter = begin; iter != end; ++iter)
     125            0 :                 deserialize(in, *iter);
     126            0 : }
     127              : 
     128              : template<class TGeomObj, class TDeserializers>
     129              : void GridDataSerializationHandler::
     130              : deserialize(BinaryBuffer& in, TGeomObj* o,
     131              :                         TDeserializers& deserializers)
     132              : {
     133              : //      This method performs the deserialization
     134            0 :         for(size_t i = 0; i < deserializers.size(); ++i){
     135              :                 deserializers[i]->read_data(in, o);
     136              :         }
     137              : }
     138              : 
     139              : 
     140              : ////////////////////////////////////////////////////////////////////////
     141              : ////////////////////////////////////////////////////////////////////////
     142              : //      SerializeAttachment
     143              : template <class TElem, class TAttachment>
     144            0 : bool SerializeAttachment(Grid& grid, TAttachment& attachment,
     145              :                                                  BinaryBuffer& out)
     146              : {
     147            0 :         return SerializeAttachment<TElem, TAttachment>(
     148              :                                                                 grid, attachment,
     149              :                                                                 grid.begin<TElem>(),
     150              :                                                                 grid.end<TElem>(),
     151            0 :                                                                 out);
     152              : }
     153              : 
     154              : ////////////////////////////////////////////////////////////////////////
     155              : //      SerializeAttachment
     156              : template <class TElem, class TAttachment>
     157            0 : bool SerializeAttachment(Grid& grid, TAttachment& attachment,
     158              :                                                  typename geometry_traits<TElem>::iterator iterBegin,
     159              :                                                  typename geometry_traits<TElem>::iterator iterEnd,
     160              :                                                  BinaryBuffer& out)
     161              : {
     162            0 :         if(!grid.has_attachment<TElem>(attachment))
     163              :                 return false;
     164              : 
     165              : //      copy data
     166              :         Grid::AttachmentAccessor<TElem, TAttachment> aa(grid, attachment);
     167              :         typedef typename TAttachment::ValueType ValueType;
     168              :         
     169              : //      write a magic number at the beginning and at the end.
     170            0 :         int magicNumber = 8304548;
     171            0 :         out.write((char*)&magicNumber, sizeof(int));
     172              : 
     173              : //TODO: remove the following test code.
     174              : //      test: write a number-value to check whether it is send correctly
     175              : /*
     176              :         number tNum = 1247.001234;
     177              :         out.write((char*)&tNum, sizeof(number));
     178              : */      
     179            0 :         for(; iterBegin != iterEnd; ++iterBegin)
     180              :         {
     181            0 :                 out.write((char*)&aa[*iterBegin], sizeof(ValueType));
     182              :         }
     183            0 :         out.write((char*)&magicNumber, sizeof(int));
     184              : 
     185              :         return true;
     186              : }
     187              : 
     188              : 
     189              : ////////////////////////////////////////////////////////////////////////
     190              : //      DeserializeAttachment
     191              : template <class TElem, class TAttachment>
     192            0 : bool DeserializeAttachment(Grid& grid, TAttachment& attachment,
     193              :                                                  BinaryBuffer& in)
     194              : {
     195            0 :         return DeserializeAttachment<TElem, TAttachment>(
     196              :                                         grid, attachment, grid.begin<TElem>(),
     197            0 :                                         grid.end<TElem>(), in);
     198              : }
     199              : 
     200              : ////////////////////////////////////////////////////////////////////////
     201              : //      DeserializeAttachment
     202              : template <class TElem, class TAttachment>
     203            0 : bool DeserializeAttachment(Grid& grid, TAttachment& attachment,
     204              :                                                  typename geometry_traits<TElem>::iterator iterBegin,
     205              :                                                  typename geometry_traits<TElem>::iterator iterEnd,
     206              :                                                  BinaryBuffer& in)
     207              : {
     208            0 :         if(!grid.has_attachment<TElem>(attachment))
     209            0 :                 grid.attach_to<TElem>(attachment);
     210              : 
     211              : //      copy data
     212              :         Grid::AttachmentAccessor<TElem, TAttachment> aa(grid, attachment);
     213              :         typedef typename TAttachment::ValueType ValueType;
     214              :         
     215              : //      compare with the magic number
     216              : 
     217              :         int magicNumber = 8304548;
     218              :         int tInt;
     219            0 :         in.read((char*)&tInt, sizeof(int));
     220              : 
     221            0 :         if(tInt != magicNumber){
     222              :                 UG_LOG("  WARNING: magic-number mismatch before read in DeserializeAttachment. Data-salad possible!\n");
     223            0 :                 return false;
     224              :         }
     225              : 
     226              : //TODO: remove the following test code.
     227              : //      test: write a number-value to check whether it is send correctly
     228              : /*
     229              :         number tNum;
     230              :         in.read((char*)&tNum, sizeof(number));
     231              :         if(tNum != 1247.001234){
     232              :                 UG_LOG("TEST-NUMBER TRANSMIT FAILED in DeserializeAttachment!\n");
     233              :                 return false;
     234              :         }
     235              : */
     236            0 :         for(; iterBegin != iterEnd; ++iterBegin)
     237              :         {
     238            0 :                 in.read((char*)&aa[*iterBegin], sizeof(ValueType));
     239              :         }
     240            0 :         in.read((char*)&tInt, sizeof(int));
     241              : 
     242            0 :         if(tInt != magicNumber){
     243              :                 UG_LOG("  WARNING: magic-number mismatch after read in DeserializeAttachment. Data-salad possible!\n");
     244            0 :                 return false;
     245              :         }
     246              : 
     247              :         return true;
     248              : }
     249              : }
     250              : 
     251              : #endif
        

Generated by: LCOV version 2.0-1