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  int sendData(Communicator &);
53  int recvData(const Communicator &);
54 
55  public:
56  ElemWithMaterial(int tag, int classTag);
57  ElemWithMaterial(int tag, int classTag,const PhysProp &);
58 
59  // public methods to set the state of the element
60  int commitState(void);
61  int revertToLastCommit(void);
62  int revertToStart(void);
63 
64  virtual void zeroInitialGeneralizedStrains(void);
65 
66  void setMaterial(const std::string &);
67  inline PhysProp &getPhysicalProperties(void)
68  { return physicalProperties; }
69  inline const PhysProp &getPhysicalProperties(void) const
70  { return physicalProperties; }
71  void setPhysicalProperties(const PhysProp &);
72  inline virtual std::set<std::string> getMaterialNames(void) const
73  { return physicalProperties.getMaterialNames(); }
74  void copyMaterialFrom(const ElemWithMaterial &, bool reverToStart= true);
75 
76  virtual const Matrix &getExtrapolationMatrix(void) const;
77  Matrix getExtrapolatedValues(const Matrix &) const;
78 
79  int getResponse(int responseID, Information &eleInformation);
80  Response *setResponse(const std::vector<std::string> &argv, Information &eleInformation);
81  boost::python::list getValuesAtNodes(const std::string &, bool silent= false) const;
82  };
83 
84 template <int NNODOS,class PhysProp>
86  : ElementBase<NNODOS>(tag,classTag) {}
87 
88 template <int NNODOS,class PhysProp>
89 ElemWithMaterial<NNODOS,PhysProp>::ElemWithMaterial(int tag, int classTag,const PhysProp &physProp)
90  : ElementBase<NNODOS>(tag,classTag), physicalProperties(physProp) {}
91 
93 template <int NNODOS,class PhysProp>
94 void ElemWithMaterial<NNODOS, PhysProp>::setMaterial(const std::string &matName)
95  {
96  const Material *ptr_mat= this->get_material_ptr(matName);
97  if(ptr_mat)
98  {
99  const material_type *tmp= dynamic_cast<const material_type *>(ptr_mat);
100  if(tmp)
101  physicalProperties.setMaterial(tmp);
102  else
103  std::cerr << this->getClassName() << "::" << __FUNCTION__ << "; "
104  << "material identified by: '" << matName
105  << "' is not a suitable material.\n";
106  }
107  }
108 
110 template <int NNODOS,class PhysProp>
112  {
114  this->physicalProperties.revertToStart();
115  }
116 
117 template <int NNODOS,class PhysProp>
119  {
120  int retVal= 0;
121  if((retVal= ElementBase<NNODOS>::commitState()) != 0)
122  {
123  std::cerr << this->getClassName() << "::" << __FUNCTION__
124  << "; failed in base class." << std::endl;
125  return (-1);
126  }
127  retVal+= physicalProperties.commitState();
128  return retVal;
129  }
130 
131 template <int NNODOS,class PhysProp>
133  {
134  // DON'T call Element::revertToLastCommit() because
135  // it's a pure virtual method.
136  int retval= physicalProperties.revertToLastCommit();
137  return retval;
138  }
139 
140 template <int NNODOS,class PhysProp>
142  {
144  retval+= physicalProperties.revertToStart();
145  return retval;
146  }
147 
148 template <int NNODOS,class PhysProp>
150  {
151  physicalProperties.getMaterialsVector().zeroInitialGeneralizedStrains();
152  }
153 
154 template <int NNODOS,class PhysProp>
156  { physicalProperties= physProp; }
157 
160 template <int NNODOS,class PhysProp>
162  {
163  std::cerr << this->getClassName() << "::" << __FUNCTION__
164  << "; must be overloaded in derived classes."
165  << std::endl;
166  static const Matrix retval;
167  return retval;
168  }
169 
171 template <int NNODOS,class PhysProp>
173  { return getExtrapolationMatrix()*values; }
174 
186 template <int NNODOS,class PhysProp>
187 boost::python::list ElemWithMaterial<NNODOS, PhysProp>::getValuesAtNodes(const std::string &code, bool silent) const
188  {
189  boost::python::list retval;
190  const Matrix matValues= physicalProperties.getMaterialsVector().getValues(code, silent);
191  if(matValues.noRows()>0)
192  {
193  const Matrix nodeValues= getExtrapolatedValues(matValues);
194  const size_t nRows= nodeValues.noRows();
195  for(size_t i= 0;i<nRows;i++)
196  {
197  Vector valueAtNode= nodeValues.getRow(i);
198  retval.append(valueAtNode);
199  }
200  }
201  else
202  retval= ElementBase<NNODOS>::getValuesAtNodes(code, silent);
203  return retval;
204  }
205 
207 template <int NNODOS,class PhysProp>
209  {
210  int res= ElementBase<NNODOS>::sendData(comm);
212  return res;
213  }
214 
216 template <int NNODOS,class PhysProp>
218  {
219  int res= ElementBase<NNODOS>::recvData(comm);
221  return res;
222  }
223 
225 template <int NNODOS,class PhysProp>
227  {
228  int retval= -1;
229  if(responseID == 1)
230  { retval= eleInfo.setVector(this->getResistingForce()); }
231  else if(responseID == 2)
232  { retval= eleInfo.setMatrix(this->getTangentStiff()); }
233  else if(responseID == 3)
234  { retval= physicalProperties.getResponse(responseID, eleInfo); }
235  else if(responseID == 4)
236  { retval= physicalProperties.getResponse(responseID, eleInfo); }
237  return retval;
238  }
239 
241 template <int NNODOS,class PhysProp>
242 XC::Response *ElemWithMaterial<NNODOS, PhysProp>::setResponse(const std::vector<std::string> &argv, Information &eleInfo)
243  {
244  Response *retval= nullptr;
245  if(argv[0] == "force" || argv[0] == "forces")
246  retval= new ElementResponse(this, 1, this->getResistingForce());
247  else if(argv[0] == "stiff" || argv[0] == "stiffness")
248  retval= new ElementResponse(this, 2, this->getTangentStiff());
249  else if(argv[0] == "material" || (argv[0]=="Material") || argv[0] == "integrPoint")
250  {
251  size_t pointNum = atoi(argv[1]);
252  if(pointNum > 0 && pointNum <= this->physicalProperties.size())
253  retval= this->setMaterialResponse(this->physicalProperties[pointNum-1],argv,2,eleInfo);
254  else
255  retval= nullptr;
256  }
257  else if(argv[0] == "stress" || argv[0] == "stresses")
258  { retval= new ElementResponse(this, 3, this->getResistingForce()); }
259  else if(argv[0] == "strain" || argv[0] == "strains")
260  { retval= new ElementResponse(this, 3, this->getResistingForce()); }
261  else // otherwise response quantity is unknown for the quad class
262  retval= nullptr;
263  return retval;
264  }
265 
266 } //end of XC namespace
267 #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:1024
int revertToStart(void)
Reverts the element to its initial state.
Definition: ElemWithMaterial.h:141
virtual int revertToStart(void)
Reverts the element to its initial state.
Definition: Element.cpp:148
Float vector abstraction.
Definition: Vector.h:94
void setMaterial(const std::string &)
Set the element material.
Definition: ElemWithMaterial.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:72
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:111
virtual const Matrix & getExtrapolationMatrix(void) const
Return the matrix that extrapolates results at material points to results at nodes.
Definition: ElemWithMaterial.h:161
int commitState(void)
Commit the current element state.
Definition: ElemWithMaterial.h:118
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:187
Base class for materials.
Definition: Material.h:93
int sendData(Communicator &)
Send members through the communicator argument.
Definition: ElemWithMaterial.h:208
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:217
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:172
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:226
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:145
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:1463
Base class for finite element with pointer to nodes container.
Definition: ElementBase.h:47
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:242
int revertToLastCommit(void)
Revert to the last committed state.
Definition: ElemWithMaterial.h:132
int recvData(const Communicator &comm)
Receives members through the communicator argument.
Definition: ElementBase.h:154