Walls.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 /*
6  * File: Walls.h
7  * Author: dducks
8  *
9  * Created on April 12, 2014, 2:19 PM
10  */
11 
12 #ifndef SERIALIZATION_WALLS_H
13 #define SERIALIZATION_WALLS_H
14 
15 #include <Walls/BaseWall.h>
16 #include <Walls/InfiniteWall.h>
17 #include <Walls/CylindricalWall.h>
19 
21  template< typename Base >
22  struct Wrapper {
23  Wrapper() {
24  data = nullptr;
25  }
27  if (data != nullptr)
28  delete data;
29  }
30 
31  Base * data;
32  };
33 }
34 
35 template<class Archive>
36 void save(Archive& ar, const WallHandler& w) {
37  ar ( cereal::make_size_tag(w.getNumberOfObjects()));
38  for (const auto& wall UNUSED : w ) {
39  ar ( w );
40  }
41 }
42 
43 template<class Archive>
44 void load(Archive& ar, WallHandler& w) {
45  cereal::size_type count;
46  ar ( cereal::make_size_tag(count));
47 
48  //Due to inheritance etc etc, we need to create pointers here.
49  logger(VERBOSE, "WallHandler");
50  for (int i = 0; i < count; i++)
51  {
53  logger(INFO, " Pass % / %\n", i, count, Flusher::NO_FLUSH);
54  ar(wall);
55  logger(INFO, " Adding...\n", Flusher::NO_FLUSH);
56  w.copyAndAddObject(wall.data);
57  logger(INFO, " Done. ");
58  }
59 }
60 
61 template<class Archive>
62 void save(Archive& ar, const SerializationWrappers::Wrapper<BaseWall> w ) {
63  if (typeid(*(w.data)) == typeid(InfiniteWall)) {
64  ar( cereal::make_nvp("type","InfiniteWall"));
65  save( ar, *(dynamic_cast<InfiniteWall*>(w.data)));
66  //ar( cereal::make_nvp("value", dynamic_cast<const InfiniteWall*>(b)));
67  /*} else if (typeid(b) == typeid(FiniteWall)) {
68  ar( cereal::make_nvp("type","FiniteWall"));
69  ar( cereal::make_nvp("value", dynamic_cast<const FiniteWall*>(b))); */
70  } else if (typeid(*(w.data)) == typeid (InfiniteWallWithHole)) {
71  ar( cereal::make_nvp("type","InfiniteWallWithHole"));
72  //save( ar, *(dynamic_cast<InfiniteWallWithHole*>(w.data)));
73  } else if (typeid(*(w.data)) == typeid (CylindricalWall)) {
74  ar( cereal::make_nvp("type","CylindricalWall"));
75  save( ar, *(dynamic_cast<CylindricalWall*>(w.data)));
76  }
77 
78 }
79 
80 template<class Archive>
82 {
83  logger(DEBUG, "In load Generic Wall!");
85  ar(cereal::make_nvp("type", type));
86  logger(INFO, "Type = %", type);
87  if (type == "InfiniteWall")
88  {
89  b.data = new InfiniteWall();
90  //ar( cereal::make_nvp("value", dynamic_cast<InfiniteWall*>(b)));
91  load(ar, *(dynamic_cast<InfiniteWall*>(b.data)));
92  /* } else if (type == "FiniteWall") {
93  b = new InfiniteWall();
94  ar( cereal::make_nvp("value", dynamic_cast<FiniteWall*>(b)));*/
95  }
96  else if (type == "InfiniteWallWithHole")
97  {
98  b.data = new InfiniteWallWithHole();
99  //ar( cereal::make_nvp("value", dynamic_cast<InfiniteWallWithHole*>(b)));
100  } else if (type == "CylindricalWall") {
101  b.data = new CylindricalWall();
102  //ar( cereal::make_nvp("value", dynamic_cast<CylindricalWall*>(b)));
103  load( ar, *(dynamic_cast<CylindricalWall*>(b.data)));
104  }
105 
106 }
107 
108 template<class Archive>
109 void load(Archive& ar, InfiniteWall & w) {
110  Vec3D position, normal;
111  ar( CEREAL_NVP( position ),
112  CEREAL_NVP( normal ));
113  w.setPosition( position );
114  w.setNormal( normal );
115 }
116 
117 template<class Archive>
118 void save(Archive& ar, const InfiniteWall & w ) {
119  ar( cereal::make_nvp("position", w.getPosition()),
120  cereal::make_nvp("normal", w.getNormal()));
121 }
122 
123 template<class Archive>
124 void load(Archive& ar, CylindricalWall & w ) {
125  //Vec3D position;
126  Mdouble radius;
127  ar( //CEREAL_NVP( position ),
128  CEREAL_NVP( radius ));
129 }
130 
131 template<class Archive>
132 void save(Archive& ar, const CylindricalWall & w ) {
133  ar ( //cereal::make_nvp("position", w.getPosition()),
134  cereal::make_nvp("radius", w.getRadius()));
135 }
136 
137 #endif /* WALLS_H */
138 
int i
Definition: BiCGSTAB_step_by_step.cpp:9
double Mdouble
Definition: GeneralDefine.h:13
#define UNUSED
Definition: GeneralDefine.h:18
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:36
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
RowVector3d w
Definition: Matrix_resize_int.cpp:3
void save(Archive &ar, const WallHandler &w)
Definition: Walls.h:36
void load(Archive &ar, WallHandler &w)
Definition: Walls.h:44
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: CylindricalWall.h:17
Definition: InfiniteWallWithHole.h:17
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: InfiniteWall.h:27
Definition: Kernel/Math/Vector.h:30
Container to store all BaseWall.
Definition: WallHandler.h:22
#define DEBUG
Definition: main.h:181
#define INFO(i)
Definition: mumps_solver.h:54
Definition: Walls.h:20
radius
Definition: UniformPSDSelfTest.py:15
void normal(const Vector< double > &x, Vector< double > &normal)
Definition: free_surface_rotation.cc:65
type
Definition: compute_granudrum_aor.py:141
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
Definition: Walls.h:22
Base * data
Definition: Walls.h:31
~Wrapper()
Definition: Walls.h:26
Wrapper()
Definition: Walls.h:23