Walls.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 /*
27  * File: Walls.h
28  * Author: dducks
29  *
30  * Created on April 12, 2014, 2:19 PM
31  */
32 
33 #ifndef SERIALIZATION_WALLS_H
34 #define SERIALIZATION_WALLS_H
35 
36 #include <Walls/BaseWall.h>
37 #include <Walls/InfiniteWall.h>
38 #include <Walls/CylindricalWall.h>
40 
42  template< typename Base >
43  struct Wrapper {
44  Wrapper() {
45  data = nullptr;
46  }
48  if (data != nullptr)
49  delete data;
50  }
51 
52  Base * data;
53  };
54 }
55 
56 template<class Archive>
57 void save(Archive& ar, const WallHandler& w) {
58  ar ( cereal::make_size_tag(w.getNumberOfObjects()));
59  for (const auto& wall UNUSED : w ) {
60  ar ( w );
61  }
62 }
63 
64 template<class Archive>
65 void load(Archive& ar, WallHandler& w) {
66  cereal::size_type count;
67  ar ( cereal::make_size_tag(count));
68 
69  //Due to inheritance etc etc, we need to create pointers here.
70  logger(VERBOSE, "WallHandler");
71  for (int i = 0; i < count; i++)
72  {
74  logger(INFO, " Pass % / %\n", i, count, Flusher::NO_FLUSH);
75  ar(wall);
76  logger(INFO, " Adding...\n", Flusher::NO_FLUSH);
77  w.copyAndAddObject(wall.data);
78  logger(INFO, " Done. ");
79  }
80 }
81 
82 template<class Archive>
83 void save(Archive& ar, const SerializationWrappers::Wrapper<BaseWall> w ) {
84  if (typeid(*(w.data)) == typeid(InfiniteWall)) {
85  ar( cereal::make_nvp("type","InfiniteWall"));
86  save( ar, *(dynamic_cast<InfiniteWall*>(w.data)));
87  //ar( cereal::make_nvp("value", dynamic_cast<const InfiniteWall*>(b)));
88  /*} else if (typeid(b) == typeid(FiniteWall)) {
89  ar( cereal::make_nvp("type","FiniteWall"));
90  ar( cereal::make_nvp("value", dynamic_cast<const FiniteWall*>(b))); */
91  } else if (typeid(*(w.data)) == typeid (InfiniteWallWithHole)) {
92  ar( cereal::make_nvp("type","InfiniteWallWithHole"));
93  //save( ar, *(dynamic_cast<InfiniteWallWithHole*>(w.data)));
94  } else if (typeid(*(w.data)) == typeid (CylindricalWall)) {
95  ar( cereal::make_nvp("type","CylindricalWall"));
96  save( ar, *(dynamic_cast<CylindricalWall*>(w.data)));
97  }
98 
99 }
100 
101 template<class Archive>
103 {
104  logger(DEBUG, "In load Generic Wall!");
105  std::string type;
106  ar(cereal::make_nvp("type", type));
107  logger(INFO, "Type = %", type);
108  if (type == "InfiniteWall")
109  {
110  b.data = new InfiniteWall();
111  //ar( cereal::make_nvp("value", dynamic_cast<InfiniteWall*>(b)));
112  load(ar, *(dynamic_cast<InfiniteWall*>(b.data)));
113  /* } else if (type == "FiniteWall") {
114  b = new InfiniteWall();
115  ar( cereal::make_nvp("value", dynamic_cast<FiniteWall*>(b)));*/
116  }
117  else if (type == "InfiniteWallWithHole")
118  {
119  b.data = new InfiniteWallWithHole();
120  //ar( cereal::make_nvp("value", dynamic_cast<InfiniteWallWithHole*>(b)));
121  } else if (type == "CylindricalWall") {
122  b.data = new CylindricalWall();
123  //ar( cereal::make_nvp("value", dynamic_cast<CylindricalWall*>(b)));
124  load( ar, *(dynamic_cast<CylindricalWall*>(b.data)));
125  }
126 
127 }
128 
129 template<class Archive>
130 void load(Archive& ar, InfiniteWall & w) {
131  Vec3D position, normal;
132  ar( CEREAL_NVP( position ),
133  CEREAL_NVP( normal ));
134  w.setPosition( position );
135  w.setNormal( normal );
136 }
137 
138 template<class Archive>
139 void save(Archive& ar, const InfiniteWall & w ) {
140  ar( cereal::make_nvp("position", w.getPosition()),
141  cereal::make_nvp("normal", w.getNormal()));
142 }
143 
144 template<class Archive>
145 void load(Archive& ar, CylindricalWall & w ) {
146  //Vec3D position;
147  Mdouble radius;
148  ar( //CEREAL_NVP( position ),
149  CEREAL_NVP( radius ));
150 }
151 
152 template<class Archive>
153 void save(Archive& ar, const CylindricalWall & w ) {
154  ar ( //cereal::make_nvp("position", w.getPosition()),
155  cereal::make_nvp("radius", w.getRadius()));
156 }
157 
158 #endif /* WALLS_H */
159 
double Mdouble
Definition: GeneralDefine.h:34
#define UNUSED
Definition: GeneralDefine.h:39
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:57
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
LL< Log::DEBUG > DEBUG
Debug information.
Definition: Logger.cc:58
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
void save(Archive &ar, const WallHandler &w)
Definition: Walls.h:57
void load(Archive &ar, WallHandler &w)
Definition: Walls.h:65
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles)
Definition: BaseHandler.h:648
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
virtual void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Definition: BaseInteractable.h:239
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:218
Definition: CylindricalWall.h:38
double getRadius() const
access function for radius
Definition: CylindricalWall.cc:114
Definition: InfiniteWallWithHole.h:38
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: InfiniteWall.h:48
Vec3D getNormal() const
Access function for normal.
Definition: InfiniteWall.cc:213
void setNormal(Vec3D normal)
Changes the normal of the InfiniteWall.
Definition: InfiniteWall.cc:127
Definition: Vector.h:51
Container to store all BaseWall.
Definition: WallHandler.h:44
Definition: Walls.h:41
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Definition: Walls.h:43
Base * data
Definition: Walls.h:52
~Wrapper()
Definition: Walls.h:47
Wrapper()
Definition: Walls.h:44