GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Periodic.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Jean-luc CHARLES I2M-DuMAS/ENSAM Talence France
4 // <jean-luc.charles@ensam.eu>
5 // - Damien ANDRE SPCTS/ENS Ceramique industrielle, Limoges France
6 // <damien.andre@unilim.fr>
7 // - Jeremie GIRARDOT I2M-DuMAS/ENSAM Talence France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UVHC Valenciennes France
10 // <cedric.hubert@univ-valenciennes.fr>
11 // - Ivan IORDANOFF I2M-DuMAS-MPI/ENSAM Talence France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2016 JL. CHARLES, D. ANDRE, I. IORDANOFF, J. GIRARDOT
15 //
16 //
17 //x
18 //
19 //
20 // This program is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 // This program is distributed in the hope that it will be useful,
26 // but WITHOUT ANY WARRANTY; without even the implied warranty of
27 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 // GNU General Public License for more details.
29 //
30 // You should have received a copy of the GNU General Public License
31 // along with this program. If not, see <http://www.gnu.org/licenses/>.
32 
33 
34 #ifndef _libDEM_Prop_Periodic_hpp_
35 #define _libDEM_Prop_Periodic_hpp_
36 
37 
38 #include <functional>
39 
40 #include "GranOO3/Core/Prop.hpp"
41 #include "GranOO3/DEM/Element.hpp"
42 
43 
44 namespace GranOO3
45 {
46 
47 
48  namespace DEM
49  {
50 
51 
52  class Periodic : public Core::Prop<Element>,
53  public Core::Register<Periodic>
54  {
55 
56  GRANOO_CLASS(DEM::Periodic, Core::Prop<Element>);
57 
58  public:
59  Periodic();
60  virtual ~Periodic();
61 
62  void make_master(std::function<Geom::Vector (const Geom::Vector&, bool&)> f);
63  void set_master_function(std::function<Geom::Vector (const Geom::Vector&, bool&)> f);
64  void set_teleport_master_function(std::function<Geom::Vector (const Geom::Vector&, bool&)> f);
65 
66  void make_slave(Periodic& master, std::function<Geom::Vector (const Geom::Vector&)> f, int slave_number = 0);
67  void set_slave_function(std::function<Geom::Vector (const Geom::Vector&)> f);
68  void set_follow_master_function(std::function<Geom::Vector (const Geom::Vector&)> f);
69 
70  unsigned int get_slave_number() const;
71  unsigned int get_total_slave_number() const;
72 
73  bool is_slave() const;
74  bool is_master() const;
75  bool has_slave() const;
76 
77  void teleport_master();
78  void follow_master_motion(bool follow_master_velocity);
79  void follow_master_strain();
80  void swap_bond(Core::SetOfBase<Element>& set, const Geom::Point& p);
81 
82  void remove_slave(Periodic&);
83 
85 
87  const Periodic* get_master() const;
89 
91  const Element* get_master_element() const;
92 
93  // IO
94  virtual std::ostream& write_ascii (std::ostream& out) const;
95  virtual std::istream& read_ascii (std::istream& in);
96 
97  private:
98  //BOOST SERIALIZATION
100  template<class Archive> void serialize(Archive&, const unsigned int);
101 
102  private:
105  bool _is_slave;
106  unsigned int _slave_number;
110  std::function<Geom::Vector (const Geom::Vector&, bool&)> _function_teleport_master;
112  };
113 
114 
115  template<class Archive> void
116  Periodic::serialize(Archive& ar, const unsigned int version) {
117  ar & boost::serialization::base_object<Core::Prop<Element> >(*this);
118  ar & _has_slave;
119  ar & _is_slave;
120  ar & _slave_number;
121  ar & _is_master;
122  ar & _master_element;
123  }
124 
125  }
126 }
127 
128 
129 #include <boost/serialization/version.hpp>
131 
132 
133 namespace GranOO3
134 {
135  GRANOO_CLASS_DECLARE_TPL(DEM::Periodic);
136 }
137 
138 // FOR IO
139 namespace GranOO3
140 {
141  namespace Core
142  {
143  template<>
144  struct Read<DEM::Periodic>
145  {
146  static Base* new_object(const std::string& classID, std::istream& in);
147  };
148  }
149 }
150 
151 
152 
153 #endif
BOOST_CLASS_VERSION(GranOO3::DEM::Periodic, 0) namespace GranOO3
Definition: Periodic.hpp:130
Definition: Base.hpp:61
Definition: Prop.hpp:48
Definition: SetOf.hpp:346
Definition: SetOf.hpp:153
a base class that represents an element
Definition: Element.hpp:55
a property for adding periodic behavior to DEM::Element
Definition: Periodic.hpp:54
virtual ~Periodic()
destructor
Definition: Periodic.cpp:63
bool _has_slave
a variable that stores if the element has slave or not
Definition: Periodic.hpp:104
void set_master_from_element()
Definition: Periodic.cpp:87
std::function< Geom::Vector(const Geom::Vector &)> _function_follow_master
Definition: Periodic.hpp:111
void swap_bond(Core::SetOfBase< Element > &set, const Geom::Point &p)
this method allows to swap a bond if a master becomes a slave
Definition: Periodic.cpp:242
bool is_slave() const
for knowing if the element is a slave or not
Definition: Periodic.cpp:186
void make_slave(Periodic &master, std::function< Geom::Vector(const Geom::Vector &)> f, int slave_number=0)
set the element as a slave one
Definition: Periodic.cpp:123
void set_follow_master_function(std::function< Geom::Vector(const Geom::Vector &)> f)
similar as set_slave_function (with a more explicit name), provided for convenience
Definition: Periodic.cpp:175
Periodic * get_master()
an accessor to the master element
Definition: Periodic.cpp:77
Element * _master_element
a variable that stores the master element
Definition: Periodic.hpp:109
void set_master_function(std::function< Geom::Vector(const Geom::Vector &, bool &)> f)
set the master function (only allowed for master element)
Definition: Periodic.cpp:112
void teleport_master()
this method allows to teleport the master element if it crosses a boundary
Definition: Periodic.cpp:281
void set_teleport_master_function(std::function< Geom::Vector(const Geom::Vector &, bool &)> f)
similar as set_master_function (with a more explicit name), provided for convenience
Definition: Periodic.cpp:118
bool _is_slave
a variable that stores if the element is a slave or not
Definition: Periodic.hpp:105
void make_master(std::function< Geom::Vector(const Geom::Vector &, bool &)> f)
set the element as a master one
Definition: Periodic.cpp:105
virtual std::istream & read_ascii(std::istream &in)
Definition: Periodic.cpp:341
unsigned int _slave_number
a variable that stores the number of slave
Definition: Periodic.hpp:106
unsigned int get_slave_number() const
get the slave number
Definition: Periodic.cpp:181
bool has_slave() const
for knowing if the element has slave or not
Definition: Periodic.cpp:191
Periodic()
constructor
Definition: Periodic.cpp:50
void follow_master_motion(bool follow_master_velocity)
this method allows for a slave to follow its master motion
Definition: Periodic.cpp:201
void serialize(Archive &, const unsigned int)
Definition: Periodic.hpp:116
Periodic * _master
a variable that stores the master periodic element
Definition: Periodic.hpp:108
void follow_master_strain()
Definition: Periodic.cpp:227
virtual std::ostream & write_ascii(std::ostream &out) const
Definition: Periodic.cpp:327
Core::SetOfBase< Periodic > * _slave
the list of slave periodic elements
Definition: Periodic.hpp:103
bool is_master() const
for knowing if the element is a master or not
Definition: Periodic.cpp:196
friend class boost::serialization::access
Definition: Periodic.hpp:99
bool _is_master
a variable that stores if the element is a master or not
Definition: Periodic.hpp:107
Core::SetOfBase< Periodic > & slave()
Definition: Periodic.cpp:319
Element * get_master_element()
an accessor to the master element
Definition: Periodic.cpp:94
void set_slave_function(std::function< Geom::Vector(const Geom::Vector &)> f)
set the slave function (only allowed for slave element)
Definition: Periodic.cpp:154
unsigned int get_total_slave_number() const
get the total slave number
Definition: Periodic.cpp:145
std::function< Geom::Vector(const Geom::Vector &, bool &)> _function_teleport_master
Definition: Periodic.hpp:110
void remove_slave(Periodic &)
Definition: Periodic.cpp:308
Definition: Point.hpp:62
Definition: Vector.hpp:75
Definition: Common.hpp:198
static char_cptr version
Definition: Exprtk.hpp:44221
Definition: SetOfManager.hpp:63
static Base * new_object(const std::string &classID, std::istream &in)
Definition: SetOfManager.hpp:64