xc
MaterialWrapper.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 
29 #ifndef MaterialWrapper_h
30 #define MaterialWrapper_h
31 
32 #include "utility/actor/actor/MovableObject.h"
33 #include <utility/recorder/response/MaterialResponse.h>
34 
35 namespace XC {
36 
38 //
40 template <typename MatType, int cTag>
42  {
43  public:
44  typedef MatType MaterialType;
45  protected:
46  MatType *theMaterial;
47 
48  void free_mem(void);
49  void copy(const MatType *);
50  public:
51  MaterialWrapper(void);
52  MaterialWrapper( const MatType &material);
55  ~MaterialWrapper(void);
56 
58  inline const MatType *getMaterial(void) const
59  { return theMaterial; }
61  inline MatType *getMaterial(void)
62  { return theMaterial; }
63  virtual void setMaterial(const MatType &);
64 
65  void Print(std::ostream &, int flag =0) const;
66  int getMainClassTag(void) const;
67 
68  int sendData(Communicator &);
69  int recvData(const Communicator &);
70 
71  int sendSelf(Communicator &);
72  int recvSelf(const Communicator &);
73 
74  };
75 
77 template <typename MatType, int cTag>
79  {
80  if(theMaterial) delete theMaterial;
81  theMaterial= nullptr;
82  }
83 
85 template <typename MatType, int cTag>
86 void MaterialWrapper<MatType, cTag>::copy(const MatType *other)
87  {
88  free_mem();
89  if(other)
90  theMaterial= other->getCopy();
91  }
92 
94 template <typename MatType, int cTag>
95 void MaterialWrapper<MatType, cTag>::setMaterial(const MatType &material)
96  {
97  copy(&material);
98  if(!theMaterial)
99  {
100  std::cerr << "MaterialWrapper::" << __FUNCTION__
101  << "; failed to get copy of material\n";
102  exit(-1);
103  }
104  }
106 template <typename MatType, int cTag>
108  : MovableObject(cTag), theMaterial(nullptr) {}
109 
111 template <typename MatType, int cTag>
113  :MovableObject(cTag), theMaterial(nullptr)
114  {
115  setMaterial(material);
116  }
117 
118 template <typename MatType, int cTag>
120  { free_mem(); }
121 
123 template <typename MatType, int cTag>
125  :MovableObject(other), theMaterial(nullptr)
126  { copy(other.theMaterial); }
127 
129 template <typename MatType, int cTag>
131  {
132  MovableObject::operator=(other);
133  copy(other.theMaterial);
134  return *this;
135  }
136 
137 template <typename MatType, int cTag>
139 // this function sends the class tag of the main material
140  { return theMaterial->getClassTag(); }
141 
142 template <typename MatType, int cTag>
144  {
145  //int res= MovableObject::recvData(comm);
146  int res= 0;
147  res+= sendMaterialPtr(theMaterial,getDbTagData(),comm,BrokedPtrCommMetaData(1,2,3));
148  return res;
149  }
150 
151 template <typename MatType, int cTag>
152 void MaterialWrapper<MatType, cTag>::Print(std::ostream &s, int flag) const
153  {
154  theMaterial->Print(s, flag);
155  }
156 
157 template <typename MatType, int cTag>
159  {
160  //int res= MovableObject::recvData(comm);
161  int res= 0;
162  theMaterial= dynamic_cast<MatType *>(receiveMaterialPtr(theMaterial,getDbTagData(),comm,BrokedPtrCommMetaData(1,2,3)));
163  if(!theMaterial)
164  res= -1;
165 
166  return res;
167  }
168 
169 template <typename MatType, int cTag>
171  {
172  setDbTag(comm);
173  const int dataTag= getDbTag();
174  inicComm(5);
175  int res= sendData(comm);
176 
177  res+= comm.sendIdData(getDbTagData(),dataTag);
178  if(res < 0)
179  std::cerr << "WARNING MaterialWrapper::sendSelf() - "
180  << dataTag << " failed to send.";
181  return res;
182  }
183 
184 template <typename MatType, int cTag>
186  {
187  inicComm(5);
188  const int dataTag= getDbTag();
189  int res= comm.receiveIdData(getDbTagData(),dataTag);
190 
191  if(res<0)
192  std::cerr << "WARNING MaterialWrapper::recvSelf() - "
193  << dataTag << " failed to receive ID\n";
194  else
195  res+= recvData(comm);
196  return res;
197  }
198 
199 
200 } // end of XC namespace
201 
202 
203 #endif
204 
int sendIdData(const DbTagData &, const int &)
Sends miembro data through the communicator argument.
Definition: Communicator.cc:411
MaterialWrapper & operator=(const MaterialWrapper &)
Assignment operator.
Definition: MaterialWrapper.h:130
virtual void setMaterial(const MatType &)
Sets the wrapped material.
Definition: MaterialWrapper.h:95
MaterialWrapper(void)
Default constructor.
Definition: MaterialWrapper.h:107
Communication parameters between processes.
Definition: Communicator.h:66
int sendSelf(Communicator &)
Send the object.
Definition: MaterialWrapper.h:170
Object that can move between processes.
Definition: MovableObject.h:100
Encapsulates a copy to a material.
Definition: MaterialWrapper.h:41
const MatType * getMaterial(void) const
Return a pointer to the wrapped material.
Definition: MaterialWrapper.h:58
MatType * getMaterial(void)
Return a pointer to the wrapped material.
Definition: MaterialWrapper.h:61
int getClassTag(void) const
Return the class identifier.
Definition: MovableObject.cpp:95
void free_mem(void)
Free memory allocated for the uniaxial material.
Definition: MaterialWrapper.h:78
int recvSelf(const Communicator &)
Receive the object.
Definition: MaterialWrapper.h:185
int sendMaterialPtr(Material *, DbTagData &, Communicator &comm, const BrokedPtrCommMetaData &)
Sends a pointer to material through the communicator being passed as parameter.
Definition: Material.cpp:260
Data to transmit for a pointer «broked».
Definition: BrokedPtrCommMetaData.h:40
int receiveIdData(DbTagData &, const int &) const
Receives el miembro data through the communicator argument.
Definition: Communicator.cc:415
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
Material * receiveMaterialPtr(Material *, DbTagData &, const Communicator &comm, const BrokedPtrCommMetaData &)
Receives a pointer to material through the communicator being passed as parameter.
Definition: Material.cpp:278
void copy(const MatType *)
brief Copy object members.
Definition: MaterialWrapper.h:86