PAPRECA hybrid off-lattice kMC/MD simulator  2.0.0 (17 September 2024)
event.h
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------------------
2 PAPRECA hybrid off-lattice kinetic Monte Carlo/Molecular dynamics simulator.
3 Copyright (C) 2024 Stavros Ntioudis, James P. Ewen, Daniele Dini, and C. Heath Turner
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 ----------------------------------------------------------------------------------------*/
19 
23 
24 #ifndef EVENT_H
25 #define EVENT_H
26 
27 //System Headers
28 #include <array>
29 #include <vector>
30 #include <mpi.h>
31 
32 
33 //LAMMPS headers
34 #include "lammps.h"
36 #include "pointers.h"
38 
39 //KMC headers
40 #include "event_list.h"
41 #include "lammps_wrappers.h"
42 #include "utilities.h"
43 
44 namespace PAPRECA{
45 
46  class Event{
47 
56 
57  public:
58 
59 
60  //Constructors/Destructors
61  Event( );
62  Event( const double &rate_in , const std::string &type_in );
63  virtual ~Event( ); // Virtual destructor to ensure proper clean-up of derived classes
64 
65  //functions
66  void assignRate( const double &rate_in );
67  void assignType( const std::string &type_in );
68  const double &getRate( ) const;
69  void setRate( const double &rate_in );
70  const std::string &getType( ) const;
71 
72  //Static functions
73  static void fillRatesArr( double *event_rates , const std::vector< Event* > &events );
74  static void fillRatesVec( std::vector< double > &event_rates , const std::vector< Event* > &events );
75  static std::vector< double > getRatesVec( const std::vector< Event* > &events ); //This is a static function (i.e., is not bound to an instance of class Event). You can provide an events* vector here to get a (copy) rates vec.
76  static double getSumOfRates( const std::vector< Event* > &events ); //This function uses the getRatesVec function and calculates the sum of all rates
77  static void deleteAndClearLocalEvents( LAMMPS_NS::LAMMPS *lmp , std::vector<Event*> &events_local );
78 
79  protected:
80  double rate;
81  std::string type;
82 
83  };
84 
85 
86  class Reaction : public Event{
87 
90 
91  public:
92  //Child class constructor/destructor
93  Reaction( const double &rate_in , const LAMMPS_NS::tagint &atom1id_in , const LAMMPS_NS::tagint &atom2id_in , const int &bond_type_in );
94  ~Reaction( );
95 
96  //Functions
97  const LAMMPS_NS::tagint &getAtom1ID( ) const;
98  const LAMMPS_NS::tagint &getAtom2ID( ) const;
99  const int &getBondType( ) const;
100  void initialize( const LAMMPS_NS::tagint &atom1id_in , const LAMMPS_NS::tagint &atom2id_in , const int &bond_type_in , const double &rate_in);
101  void resetEvent( );
102  void assignAtom1( const LAMMPS_NS::tagint &atom1id_in );
103  void assignAtom2( const LAMMPS_NS::tagint &atom2id_in );
104  void assignBondType( const int &bond_type_ind );
105 
106 
107  protected:
108  LAMMPS_NS::tagint atom1id = -1 , atom2id = -2;
109  int bond_type = -3;
110 
111  };
112 
113 
114  class BondBreak : public Reaction{
115 
118 
119  public:
120  //Child class constructor/destructor
121  BondBreak( const double &rate_in , const LAMMPS_NS::tagint &atom1id_in , const LAMMPS_NS::tagint &atom2id_in , const int &bond_type_in , PredefinedReaction *break_teamplate_in );
122  ~BondBreak( );
123 
124  //Functions
126 
127 
128  private:
130 
131  };
132 
133 
134  class BondForm : public Reaction{
135 
138 
139  public:
140  //Child class constructor/destructor
141  BondForm( const double &rate_in , const LAMMPS_NS::tagint &atom1id_in , const LAMMPS_NS::tagint &atom2id_in , const int &bond_type_in , PredefinedBondForm *form_template_in );
142  ~BondForm( );
143 
144  //Functions
146 
147 
148  private:
150 
151  };
152 
153 
154  class Deposition : public Event{
155 
158 
159  public:
160 
161  //Child class constructor/destructor
162  Deposition( const double &rate_in , const double site_pos_in[3] , const double rot_pos_in[3] , const double &rot_theta_in , const int &mol_id_in , const std::string &mol_name_in , PredefinedDeposition *depo_template_in );
163  ~Deposition( );
164 
165  //Functions
166  double *getSitePos( );
167  double *getRotPos( );
168  const double &getRotTheta( ) const;
169  const int &getMolId( ) const;
170  const std::string &getMolName( ) const;
172 
173 
174  protected:
175  double site_pos[3];
176  double rot_pos[3]; //Required by create_atoms command with the mol option, defines the centre of rotation of the inserted molecule (angle in degrees).
177  double rot_theta;
178  int mol_id;
179  std::string mol_name = "NONE";
180 
181 
182  private:
183  PredefinedDeposition *depo_template = NULL; //This is the associated predefined event to the discovered event. No need to new/delete anything here as that memory block is managed by the PredefinedDepositions class.
184 
185  };
186 
187  class Diffusion : public Event{
188 
191 
192  public:
193  //Child class constructor/destructor
194  Diffusion( const double &rate_in , const double vacancy_pos_in[3] , const LAMMPS_NS::tagint &parent_id_in , const int &parent_type_in , const int &is_displacive_in , const int &diffused_type_in , PredefinedDiffusionHop *diff_template_in );
195  ~Diffusion( );
196 
197  //Functions
198  double *getVacancyPos( );
199  const LAMMPS_NS::tagint &getParentId( ) const;
200  const int &getParentType( ) const;
201  int isDisplacive( );
202  const int &getDiffusedType( ) const;
204 
205  protected:
206  double vacancy_pos[3];
207 
208  LAMMPS_NS::tagint parent_id = -1;
209  int parent_type = -2;
210  int is_displacive = 0;
211  int diffused_type = -3;
212 
213  private:
215 
216 
217  };
218 
219  class MonoatomicDesorption : public Event{
220 
223 
224  public:
225  //Child class constructor/destructor
226  MonoatomicDesorption( const double &rate_in , const LAMMPS_NS::tagint &parent_id_in , const int &parent_type_in , PredefinedMonoatomicDesorption *des_template_in );
228 
229  //Functions
230  const LAMMPS_NS::tagint &getParentId( ) const;
231  const int &getParentType( ) const;
233 
234  protected:
235  LAMMPS_NS::tagint parent_id = -1;
236  int parent_type = -2;
237 
238  private:
240 
241  };
242 
243 }//end of PAPRECA namespace
244 
245 
246 #endif
child of PAPRECA::Reaction dedicated to bond-breaking events.
Definition: event.h:114
PredefinedReaction * getBreakTemplate()
Definition: event.cpp:183
BondBreak(const double &rate_in, const LAMMPS_NS::tagint &atom1id_in, const LAMMPS_NS::tagint &atom2id_in, const int &bond_type_in, PredefinedReaction *break_teamplate_in)
Definition: event.cpp:177
~BondBreak()
Definition: event.cpp:180
PredefinedReaction * break_template
Definition: event.h:129
child of PAPRECA::Reaction dedicated to bond formation events.
Definition: event.h:134
PredefinedBondForm * getFormTemplate()
Definition: event.cpp:199
PredefinedBondForm * form_template
Definition: event.h:149
BondForm(const double &rate_in, const LAMMPS_NS::tagint &atom1id_in, const LAMMPS_NS::tagint &atom2id_in, const int &bond_type_in, PredefinedBondForm *form_template_in)
Definition: event.cpp:193
~BondForm()
Definition: event.cpp:196
Child of PAPRECA::Event dedicated to monoatomic or molecular adsorption.
Definition: event.h:154
std::string mol_name
Definition: event.h:179
double rot_theta
Definition: event.h:177
double * getSitePos()
Definition: event.cpp:215
const double & getRotTheta() const
Definition: event.cpp:217
double * getRotPos()
Definition: event.cpp:216
Deposition(const double &rate_in, const double site_pos_in[3], const double rot_pos_in[3], const double &rot_theta_in, const int &mol_id_in, const std::string &mol_name_in, PredefinedDeposition *depo_template_in)
Definition: event.cpp:208
double rot_pos[3]
Definition: event.h:176
double site_pos[3]
Definition: event.h:175
const int & getMolId() const
Definition: event.cpp:218
PredefinedDeposition * depo_template
Definition: event.h:183
~Deposition()
Definition: event.cpp:212
PredefinedDeposition * getDepoTemplate()
Definition: event.cpp:220
int mol_id
Definition: event.h:178
const std::string & getMolName() const
Definition: event.cpp:219
child of PAPRECA::Event class dedicated to diffusion events.
Definition: event.h:187
PredefinedDiffusionHop * diff_template
Definition: event.h:214
const LAMMPS_NS::tagint & getParentId() const
Definition: event.cpp:235
int diffused_type
Definition: event.h:211
int parent_type
Definition: event.h:209
LAMMPS_NS::tagint parent_id
Definition: event.h:208
double vacancy_pos[3]
Definition: event.h:206
int is_displacive
Displacive diffusion events "displace" the parent atom. This is defined as an integer (and not as boo...
Definition: event.h:210
const int & getParentType() const
Definition: event.cpp:236
Diffusion(const double &rate_in, const double vacancy_pos_in[3], const LAMMPS_NS::tagint &parent_id_in, const int &parent_type_in, const int &is_displacive_in, const int &diffused_type_in, PredefinedDiffusionHop *diff_template_in)
Definition: event.cpp:228
~Diffusion()
Definition: event.cpp:231
double * getVacancyPos()
Definition: event.cpp:234
PredefinedDiffusionHop * getDiffTemplate()
Definition: event.cpp:239
const int & getDiffusedType() const
Definition: event.cpp:238
int isDisplacive()
Definition: event.cpp:237
Parent class for PAPRECA events.
Definition: event.h:46
static void fillRatesArr(double *event_rates, const std::vector< Event * > &events)
Definition: event.cpp:43
static std::vector< double > getRatesVec(const std::vector< Event * > &events)
Definition: event.cpp:74
void assignType(const std::string &type_in)
Definition: event.cpp:37
void setRate(const double &rate_in)
Definition: event.cpp:39
static void deleteAndClearLocalEvents(LAMMPS_NS::LAMMPS *lmp, std::vector< Event * > &events_local)
Definition: event.cpp:99
std::string type
Definition: event.h:81
double rate
Definition: event.h:80
const std::string & getType() const
Definition: event.cpp:40
const double & getRate() const
Definition: event.cpp:38
virtual ~Event()
Definition: event.cpp:33
Event()
Definition: event.cpp:31
static double getSumOfRates(const std::vector< Event * > &events)
Definition: event.cpp:93
void assignRate(const double &rate_in)
Definition: event.cpp:36
static void fillRatesVec(std::vector< double > &event_rates, const std::vector< Event * > &events)
Definition: event.cpp:59
child of PAPRECA::Event dedicated to monoatomic desorption events (i.e., where a single atom is eject...
Definition: event.h:219
PredefinedMonoatomicDesorption * getMonoDesTemplate()
Definition: event.cpp:250
const LAMMPS_NS::tagint & getParentId() const
Definition: event.cpp:248
const int & getParentType() const
Definition: event.cpp:249
LAMMPS_NS::tagint parent_id
Definition: event.h:235
~MonoatomicDesorption()
Definition: event.cpp:245
int parent_type
Definition: event.h:236
MonoatomicDesorption(const double &rate_in, const LAMMPS_NS::tagint &parent_id_in, const int &parent_type_in, PredefinedMonoatomicDesorption *des_template_in)
Definition: event.cpp:244
PredefinedMonoatomicDesorption * monodes_template
Definition: event.h:239
child class of PAPRECA::PredefinedReaction associated with bond formation events. This is a Predefine...
Definition: event_list.h:84
class associated with deposition events. This is a Predefined template for PAPRECA::Deposition events...
Definition: event_list.h:142
class associated with diffusion events. This is a Predefined template for PAPRECA::DiffusionHop event...
Definition: event_list.h:109
associated with monoatomic desorption events. This is a Predefined template for PAPRECA::MonoatomicDe...
Definition: event_list.h:194
class associated with reaction events. This is a Predefined template for PAPRECA::BondBreak and PAPRE...
Definition: event_list.h:55
Child of PAPRECA:Event and parent of PAPRECA::BondBreak and PAPRECA::BondForm classes.
Definition: event.h:86
void assignBondType(const int &bond_type_ind)
Definition: event.cpp:148
int bond_type
Definition: event.h:109
LAMMPS_NS::tagint atom1id
Definition: event.h:108
const int & getBondType() const
Definition: event.cpp:145
Reaction(const double &rate_in, const LAMMPS_NS::tagint &atom1id_in, const LAMMPS_NS::tagint &atom2id_in, const int &bond_type_in)
Definition: event.cpp:139
void assignAtom1(const LAMMPS_NS::tagint &atom1id_in)
Definition: event.cpp:146
void initialize(const LAMMPS_NS::tagint &atom1id_in, const LAMMPS_NS::tagint &atom2id_in, const int &bond_type_in, const double &rate_in)
Definition: event.cpp:150
void assignAtom2(const LAMMPS_NS::tagint &atom2id_in)
Definition: event.cpp:147
void resetEvent()
Definition: event.cpp:161
LAMMPS_NS::tagint atom2id
Definition: event.h:108
~Reaction()
Definition: event.cpp:140
const LAMMPS_NS::tagint & getAtom1ID() const
Definition: event.cpp:143
const LAMMPS_NS::tagint & getAtom2ID() const
Definition: event.cpp:144
Declarations of PredefinedEvent classes.
Declarations for LAMMPS wrapper functions.
Definition: bond.cpp:26
Utility functions (e.g., for arrays, strings etc.) and typedefs used in papreca.cpp main and in the o...