Particles.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: Particles.h
7  * Author: dducks
8  *
9  * Created on April 12, 2014, 2:19 PM
10  */
11 
12 #ifndef SERIALIZATION_PARTICLES_H
13 #define SERIALIZATION_PARTICLES_H
14 
15 #include <cereal/cereal.hpp>
16 
17 #include <ParticleHandler.h>
18 #include <Particles/BaseParticle.h>
19 
20 template<class Archive>
21 void load(Archive& ar, ParticleHandler& handl) {
22  cereal::size_type size;
23  ar ( cereal::make_size_tag(size) );
24 
26 
27  for (int i = 0; i < size; i++) {
28  ar(p);
29  logger(INFO, "Particle: \n\tPOS: % \n\tVEL: % \n\tRAD: %", p.getPosition(), p.getVelocity(), p.getRadius());
30  handl.copyAndAddObject(p);
31  }
32 }
33 
34 template<class Archive>
35 void save(Archive& ar, const ParticleHandler& handl) {
36  ar ( cereal::make_size_tag( handl.getNumberOfObjects() ));
37  for (const auto& p : handl) {
38  ar ( p );
39  }
40 }
41 
42 template<class Archive>
43 void load(Archive& ar, BaseParticle& p) {
44  Vec3D position;
47 
48  ar( CEREAL_NVP(position),
49  CEREAL_NVP(velocity),
50  CEREAL_NVP(radius));
51 
52  p.setPosition(position);
53  p.setRadius(radius);
54  p.setVelocity(velocity);
55 }
56 
57 template<class Archive>
58 void save(Archive& ar, const BaseParticle& p) {
59  ar( cereal::make_nvp("position", p.getPosition()),
60  cereal::make_nvp("velocity", p.getVelocity()),
61  cereal::make_nvp("radius", p.getRadius()));
62 }
63 
64 
65 
66 #endif /* PARTICLES_H */
67 
int i
Definition: BiCGSTAB_step_by_step.cpp:9
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:35
void load(Archive &ar, ParticleHandler &handl)
Definition: Particles.h:21
float * p
Definition: Tutorial_Map_using.cpp:9
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
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:360
Definition: BaseParticle.h:33
Container to store pointers to all particles.
Definition: ParticleHandler.h:28
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:1323
A spherical particle is the most simple particle used in MercuryDPM.
Definition: SphericalParticle.h:16
Definition: Kernel/Math/Vector.h:30
#define INFO(i)
Definition: mumps_solver.h:54
double velocity(const double &t)
Angular velocity as function of time t.
Definition: jeffery_orbit.cc:107
radius
Definition: UniformPSDSelfTest.py:15