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