xc
ElemWithMaterial.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 //ElemWithMaterials.h
29 
30 #ifndef ElemWithMaterial_h
31 #define ElemWithMaterial_h
32 
33 #include "ElementBase.h"
34 #include "domain/mesh/element/utils/Information.h"
35 #include "utility/recorder/response/ElementResponse.h"
36 
37 #include "preprocessor/Preprocessor.h"
38 #include "preprocessor/prep_handlers/MaterialHandler.h"
39 
40 namespace XC {
41 
44 template <int NNODOS, class PhysProp>
45 class ElemWithMaterial: public ElementBase<NNODOS>
46  {
47  public:
48  typedef typename PhysProp::material_type material_type;
49  protected:
50  PhysProp physicalProperties;
51 
52  bool set_material_ptr(const Material *);
53  int sendData(Communicator &);
54  int recvData(const Communicator &);
55 
56  public:
57  ElemWithMaterial(int tag, int classTag);
58  ElemWithMaterial(int tag, int classTag,const PhysProp &);
59 
60  // public methods to set the state of the element
61  int commitState(void);
62  int revertToLastCommit(void);
63  int revertToStart(void);
64 
65  virtual void zeroInitialGeneralizedStrains(void);
66 
67  void setMaterial(const Material &);
68  void setMaterial(const std::string &);
69  inline PhysProp &getPhysicalProperties(void)
70  { return physicalProperties; }
71  inline const PhysProp &getPhysicalProperties(void) const
72  { return physicalProperties; }
73  void setPhysicalProperties(const PhysProp &);
74  inline virtual std::set<std::string> getMaterialNames(void) const
75  { return physicalProperties.getMaterialNames(); }
76  void copyMaterialFrom(const ElemWithMaterial &, bool reverToStart= true);
77 
78  virtual const Matrix &getExtrapolationMatrix(void) const;
79  Matrix getExtrapolatedValues(const Matrix &) const;
80 
81  int getResponse(int responseID, Information &eleInformation);
82  Response *setResponse(const std::vector<std::string> &argv, Information &eleInformation);
83  boost::python::list getValuesAtNodes(const std::string &, bool silent= false) const;
84  };
85 
86 template <int NNODOS,class PhysProp>
88  : ElementBase<NNODOS>(tag,classTag) {}
89 
90 template <int NNODOS,class PhysProp>
91 ElemWithMaterial<NNODOS,PhysProp>::ElemWithMaterial(int tag, int classTag,const PhysProp &physProp)
92  : ElementBase<NNODOS>(tag,classTag), physicalProperties(physProp) {}
93 
95 template <int NNODOS,class PhysProp>
97  {
98  bool retval= false;
99  if(ptr_mat)
100  {
101  const material_type *tmp= dynamic_cast<const material_type *>(ptr_mat);
102  if(tmp)
103  {
104  physicalProperties.setMaterial(tmp);
105  retval= true;
106  }
107  else
108  std::cerr << this->getClassName() << "::" << __FUNCTION__ << "; "
109  << "material with tag: " << ptr_mat->getTag()
110  << " with type: '" << ptr_mat->getClassName()
111  << "' is not a suitable material.\n";
112  }
113  return retval;
114  }
115 
117 template <int NNODOS,class PhysProp>
119  { this->set_material_ptr(&mat); }
120 
122 template <int NNODOS,class PhysProp>
123 void ElemWithMaterial<NNODOS, PhysProp>::setMaterial(const std::string &matName)
124  {
125  const Material *ptr_mat= this->get_material_ptr(matName);
126  const bool ok= this->set_material_ptr(ptr_mat);
127  if(!ok)
128  {
129  std::cerr << this->getClassName() << "::" << __FUNCTION__
130  << "; "
131  << "material identified by: '" << matName
132  << "' is not a suitable material.\n";
133  }
134  }
135 
137 template <int NNODOS,class PhysProp>
139  {
141  this->physicalProperties.revertToStart();
142  }
143 
144 template <int NNODOS,class PhysProp>
146  {
147  int retVal= 0;
148  if((retVal= ElementBase<NNODOS>::commitState()) != 0)
149  {
150  std::cerr << this->getClassName() << "::" << __FUNCTION__
151  << "; failed in base class." << std::endl;
152  return (-1);
153  }
154  retVal+= physicalProperties.commitState();
155  return retVal;
156  }
157 
158 template <int NNODOS,class PhysProp>
160  {
161  // DON'T call Element::revertToLastCommit() because
162  // it's a pure virtual method.
163  int retval= physicalProperties.revertToLastCommit();
164  return retval;
165  }
166 
167 template <int NNODOS,class PhysProp>
169  {
171  retval+= physicalProperties.revertToStart();
172  return retval;
173  }
174 
175 template <int NNODOS,class PhysProp>
177  {
178  physicalProperties.getMaterialsVector().zeroInitialGeneralizedStrains();
179  }
180 
181 template <int NNODOS,class PhysProp>
183  { physicalProperties= physProp; }
184 
187 template <int NNODOS,class PhysProp>
189  {
190  std::cerr << this->getClassName() << "::" << __FUNCTION__
191  << "; must be overloaded in derived classes."
192  << std::endl;
193  static const Matrix retval;
194  return retval;
195  }
196 
198 template <int NNODOS,class PhysProp>
200  { return getExtrapolationMatrix()*values; }
201 
213 template <int NNODOS,class PhysProp>
214 boost::python::list ElemWithMaterial<NNODOS, PhysProp>::getValuesAtNodes(const std::string &code, bool silent) const
215  {
216  boost::python::list retval;
217  const Matrix matValues= physicalProperties.getMaterialsVector().getValues(code, silent);
218  if(matValues.noRows()>0)
219  {
220  const Matrix nodeValues= getExtrapolatedValues(matValues);
221  const size_t nRows= nodeValues.noRows();
222  for(size_t i= 0;i<nRows;i++)
223  {
224  Vector valueAtNode= nodeValues.getRow(i);
225  retval.append(valueAtNode);
226  }
227  }
228  else
229  retval= ElementBase<NNODOS>::getValuesAtNodes(code, silent);
230  return retval;
231  }
232 
234 template <int NNODOS,class PhysProp>
236  {
237  int res= ElementBase<NNODOS>::sendData(comm);
239  return res;
240  }
241 
243 template <int NNODOS,class PhysProp>
245  {
246  int res= ElementBase<NNODOS>::recvData(comm);
248  return res;
249  }
250 
252 template <int NNODOS,class PhysProp>
254  {
255  int retval= -1;
256  if(responseID == 1)
257  { retval= eleInfo.setVector(this->getResistingForce()); }
258  else if(responseID == 2)
259  { retval= eleInfo.setMatrix(this->getTangentStiff()); }
260  else if(responseID == 3)
261  { retval= physicalProperties.getResponse(responseID, eleInfo); }
262  else if(responseID == 4)
263  { retval= physicalProperties.getResponse(responseID, eleInfo); }
264  return retval;
265  }
266 
268 template <int NNODOS,class PhysProp>
269 XC::Response *ElemWithMaterial<NNODOS, PhysProp>::setResponse(const std::vector<std::string> &argv, Information &eleInfo)
270  {
271  Response *retval= nullptr;
272  if(argv[0] == "force" || argv[0] == "forces")
273  retval= new ElementResponse(this, 1, this->getResistingForce());
274  else if(argv[0] == "stiff" || argv[0] == "stiffness")
275  retval= new ElementResponse(this, 2, this->getTangentStiff());
276  else if(argv[0] == "material" || (argv[0]=="Material") || argv[0] == "integrPoint")
277  {
278  size_t pointNum = atoi(argv[1]);
279  if(pointNum > 0 && pointNum <= this->physicalProperties.size())
280  retval= this->setMaterialResponse(this->physicalProperties[pointNum-1],argv,2,eleInfo);
281  else
282  retval= nullptr;
283  }
284  else if(argv[0] == "stress" || argv[0] == "stresses")
285  { retval= new ElementResponse(this, 3, this->getResistingForce()); }
286  else if(argv[0] == "strain" || argv[0] == "strains")
287  { retval= new ElementResponse(this, 3, this->getResistingForce()); }
288  else // otherwise response quantity is unknown for the quad class
289  retval= nullptr;
290  return retval;
291  }
292 
293 } //end of XC namespace
294 #endif
int sendMovable(MovableObject &, DbTagData &, const CommMetaData &)
Sends a movable object through the communicator argument.
Definition: Communicator.cc:1163
const Material * get_material_ptr(const std::string &) const
Return a pointer to the material that corresponds to the name.
Definition: Element.cpp:1077
int revertToStart(void)
Reverts the element to its initial state.
Definition: ElemWithMaterial.h:168
virtual int revertToStart(void)
Reverts the element to its initial state.
Definition: Element.cpp:148
Float vector abstraction.
Definition: Vector.h:94
Information about an element.
Definition: Information.h:81
Communication parameters between processes.
Definition: Communicator.h:66
Base class response objects.
Definition: Response.h:81
virtual std::set< std::string > getMaterialNames(void) const
Return the names of the material(s) of the element.
Definition: ElemWithMaterial.h:74
virtual const Vector & getResistingForce(void) const =0
Returns the resisting force vector for the element.
void copyMaterialFrom(const ElemWithMaterial &, bool reverToStart=true)
Copy the material from the given element.
Definition: ElemWithMaterial.h:138
virtual const Matrix & getExtrapolationMatrix(void) const
Return the matrix that extrapolates results at material points to results at nodes.
Definition: ElemWithMaterial.h:188
void setMaterial(const Material &)
Set the element material.
Definition: ElemWithMaterial.h:118
int commitState(void)
Commit the current element state.
Definition: ElemWithMaterial.h:145
int receiveMovable(MovableObject &, DbTagData &, const CommMetaData &) const
Receives a movable object trhrough the communicator argument.
Definition: Communicator.cc:1174
boost::python::list getValuesAtNodes(const std::string &, bool silent=false) const
Return a python list with the values of the argument property at element nodes.
Definition: ElemWithMaterial.h:214
Base class for materials.
Definition: Material.h:93
int sendData(Communicator &)
Send members through the communicator argument.
Definition: ElemWithMaterial.h:235
virtual const Matrix & getTangentStiff(void) const =0
Return the tangent stiffness matrix.
Data about the index, size,,...
Definition: CommMetaData.h:39
PhysProp physicalProperties
pointers to the material objects and physical properties.
Definition: ElemWithMaterial.h:50
Response of an element.
Definition: ElementResponse.h:68
int recvData(const Communicator &)
Receives members through the communicator argument.
Definition: ElemWithMaterial.h:244
virtual DbTagData & getDbTagData(void) const
Returns a vector to store class dbTags.
Definition: DistributedBase.cc:43
virtual std::string getClassName(void) const
Returns demangled class name.
Definition: EntityWithOwner.cc:90
Matrix getExtrapolatedValues(const Matrix &) const
Extrapolate from Gauss points to nodes.
Definition: ElemWithMaterial.h:199
int noRows() const
Returns the number of rows, numRows, of the Matrix.
Definition: Matrix.h:269
int getResponse(int responseID, Information &eleInformation)
Obtain information from an analysis.
Definition: ElemWithMaterial.h:253
bool set_material_ptr(const Material *)
Set the element material.
Definition: ElemWithMaterial.h:96
Vector getRow(int row) const
Return the row which index being passed as parameter.
Definition: Matrix.cpp:1101
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
int sendData(Communicator &comm)
Send members through the communicator argument.
Definition: ElementBase.h:170
virtual boost::python::list getValuesAtNodes(const std::string &, bool silent=false) const
Return a python list with the values of the argument property at element nodes.
Definition: Element.cpp:1602
int getTag(void) const
Returns the tag associated with the object.
Definition: TaggedObject.h:119
Base class for finite element with pointer to nodes container.
Definition: ElementBase.h:48
Element with material.
Definition: ElemWithMaterial.h:45
Matrix of floats.
Definition: Matrix.h:111
Response * setResponse(const std::vector< std::string > &argv, Information &eleInformation)
element response.
Definition: ElemWithMaterial.h:269
int revertToLastCommit(void)
Revert to the last committed state.
Definition: ElemWithMaterial.h:159
int recvData(const Communicator &comm)
Receives members through the communicator argument.
Definition: ElementBase.h:179