xc
PropRecorder.h
1 //----------------------------------------------------------------------------
2 // XC program; finite element analysis code
3 // for structural analysis and design.
4 //
5 // Copyright (C) Luis Claudio Pérez Tato
6 //
7 // This program derives from OpenSees <http://opensees.berkeley.edu>
8 // developed by the «Pacific earthquake engineering research center».
9 //
10 // Except for the restrictions that may arise from the copyright
11 // of the original program (see copyright_opensees.txt)
12 // XC is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program.
25 // If not, see <http://www.gnu.org/licenses/>.
26 //----------------------------------------------------------------------------
27 //PropRecorder.h
28 
29 #ifndef PropRecorder_h
30 #define PropRecorder_h
31 
32 #include <utility/recorder/DomainRecorderBase.h>
33 #include "xc_utils/src/kernel/python_utils.h"
34 
35 namespace XC {
36 
38 //
40  {
41  protected:
42  std::string CallbackSetup;
43  std::string CallbackRecord;
44  std::string CallbackRestart;
46  double lastTimeStamp;
47 
48  void callSetupCallback(const int &,const double &);
49  template <class Container>
50  void callRecordCallback(Container &c,const int &,const double &);
51  template <class Container>
52  void callRestartCallback(Container &c);
53  public:
54  PropRecorder(int classTag, Domain *ptr_dom= nullptr);
55 
56  std::string getCurrentCombinationName(void) const;
57 
58  inline int getLastCommitTag(void) const
59  { return lastCommitTag; }
60  inline double getLastTimeStamp(void) const
61  { return lastTimeStamp; }
62  double getCurrentTime(void) const;
63  double getCommittedTime(void) const;
64  int getCommitTag(void) const;
65 
66  void setCallbackSetup(const std::string &);
67  std::string getCallbackSetup(void);
68  void setCallbackRecord(const std::string &);
69  std::string getCallbackRecord(void);
70  void setCallbackRestart(const std::string &);
71  std::string getCallbackRestart(void);
72 
73  };
74 
76 template <class Container>
77 void XC::PropRecorder::callRecordCallback(Container &c,const int &commitTag,const double &timeStamp)
78  {
79  this->callSetupCallback(commitTag,timeStamp);
80  for(typename Container::iterator i= c.begin();i!=c.end();i++)
81  {
82  typename Container::value_type tmp= *i;
83  if(tmp)
84  {
85  boost::python::object pyObj(boost::ref(*tmp));
86  CommandEntity_exec(pyObj,CallbackRecord);
87  }
88  else
89  std::cerr << getClassName() << "::" << __FUNCTION__
90  << "; pointer is null." << std::endl;
91  }
92  }
93 
95 template <class Container>
97  {
98  for(typename Container::iterator i= c.begin();i!=c.end();i++)
99  {
100  typename Container::value_type tmp= *i;
101  if(tmp)
102  {
103  boost::python::object pyObj(boost::ref(*tmp));
104  CommandEntity_exec(pyObj,this->CallbackRestart);
105  }
106  else
107  std::cerr << getClassName() << "::" << __FUNCTION__
108  << "; pointer is null." << std::endl;
109  }
110  }
111 
112 } // end of XC namespace
113 
114 #endif
Base class for the recorders that store a link with the domain.
Definition: DomainRecorderBase.h:41
Definition: PropRecorder.h:39
void callRestartCallback(Container &c)
Calls restart callback on each container element.
Definition: PropRecorder.h:96
std::string CallbackRestart
Python script to execute on each restart call.
Definition: PropRecorder.h:44
double lastTimeStamp
TimeStamp of the last record call.
Definition: PropRecorder.h:46
void callRecordCallback(Container &c, const int &, const double &)
Calls record callback on each container element.
Definition: PropRecorder.h:77
std::string getCurrentCombinationName(void) const
Returns the name of the current combination.
Definition: PropRecorder.cc:48
std::string CallbackRecord
Python script to execute on each record call.
Definition: PropRecorder.h:43
std::string CallbackSetup
Python script to execute before any record calls.
Definition: PropRecorder.h:42
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:34
void callSetupCallback(const int &, const double &)
Runs setup callback.
Definition: PropRecorder.cc:57
Domain (mesh and boundary conditions) of the finite element model.
Definition: Domain.h:116
PropRecorder(int classTag, Domain *ptr_dom=nullptr)
Constructor.
Definition: PropRecorder.cc:36
int lastCommitTag
CommitTag of the last record call.
Definition: PropRecorder.h:45