Particles.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: Particles.h
28  * Author: dducks
29  *
30  * Created on April 12, 2014, 2:19 PM
31  */
32 
33 #ifndef SERIALIZATION_PARTICLES_H
34 #define SERIALIZATION_PARTICLES_H
35 
36 #include <cereal/cereal.hpp>
37 
38 #include <ParticleHandler.h>
39 #include <Particles/BaseParticle.h>
40 
41 template<class Archive>
42 void load(Archive& ar, ParticleHandler& handl) {
43  cereal::size_type size;
44  ar ( cereal::make_size_tag(size) );
45 
47 
48  for (int i = 0; i < size; i++) {
49  ar(p);
50  logger(INFO, "Particle: \n\tPOS: % \n\tVEL: % \n\tRAD: %", p.getPosition(), p.getVelocity(), p.getRadius());
51  handl.copyAndAddObject(p);
52  }
53 }
54 
55 template<class Archive>
56 void save(Archive& ar, const ParticleHandler& handl) {
57  ar ( cereal::make_size_tag( handl.getNumberOfObjects() ));
58  for (const auto& p : handl) {
59  ar ( p );
60  }
61 }
62 
63 template<class Archive>
64 void load(Archive& ar, BaseParticle& p) {
65  Vec3D position;
66  Vec3D velocity;
67  Mdouble radius;
68 
69  ar( CEREAL_NVP(position),
70  CEREAL_NVP(velocity),
71  CEREAL_NVP(radius));
72 
73  p.setPosition(position);
74  p.setRadius(radius);
75  p.setVelocity(velocity);
76 }
77 
78 template<class Archive>
79 void save(Archive& ar, const BaseParticle& p) {
80  ar( cereal::make_nvp("position", p.getPosition()),
81  cereal::make_nvp("velocity", p.getVelocity()),
82  cereal::make_nvp("radius", p.getRadius()));
83 }
84 
85 
86 
87 #endif /* PARTICLES_H */
88 
double Mdouble
Definition: GeneralDefine.h:34
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
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 ParticleHandler &handl)
Definition: Particles.h:56
void load(Archive &ar, ParticleHandler &handl)
Definition: Particles.h:42
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 const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Definition: BaseInteractable.cc:329
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
Definition: BaseInteractable.cc:350
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: BaseParticle.h:54
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:348
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species)
Definition: BaseParticle.cc:553
Container to store all BaseParticle.
Definition: ParticleHandler.h:48
unsigned int getNumberOfObjects() const override
Returns the number of objects in the container. In parallel code this practice is forbidden to avoid ...
Definition: ParticleHandler.cc:1325
A spherical particle is the most simple particle used in MercuryDPM.
Definition: SphericalParticle.h:37
Definition: Vector.h:51
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51