XC Open source finite element analysis program
MEDTFieldInfo.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 // XC is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program.
20 // If not, see <http://www.gnu.org/licenses/>.
21 //----------------------------------------------------------------------------
22 //MEDTFieldInfo.h
23 
24 #ifndef MEDTFIELDINFO_H
25 #define MEDTFIELDINFO_H
26 
27 #include "MEDFieldInfo.h"
28 #include "xc_basic/src/med_xc/MEDMEM_ArrayInterface.hxx"
29 #include "xc_basic/src/med_xc/MEDMEM_Field.hxx"
30 #include "MEDGaussModel.h"
31 #include "preprocessor/set_mgmt/Set.h"
32 #include "domain/mesh/element/Element.h"
33 
34 namespace XC {
35 class Set;
36 class MEDGroupInfo;
37 
39 //
41 template <class T>
43  {
44  public:
45  typedef typename MEDMEM::MEDMEM_ArrayInterface<T,MEDMEM::FullInterlace,MEDMEM::Gauss>::Array ArrayGauss;
46  typedef typename MEDMEM::FIELD<T> TipoCampo;
47  protected:
48  mutable TipoCampo *campo;
49  bool has_gauss_points;
50  void libera(void) const;
51  void alloc(void) const;
52  ArrayGauss *getArrayGauss(void) const;
53  static void checkVectorDimension(const std::string &,const std::vector<T> &, const size_t &);
54 
55  private:
57  MEDTFieldInfo &operator=(const MEDTFieldInfo &);
58  void setGaussModel(const MEDGaussModel &);
59  public:
61  ~MEDTFieldInfo(void);
62  void setValueIJ(int i, int j,const T &valor);
63  void defineGaussModels(const Set &);
64  void setValueIJK(int i, int j,int k,int t,const T &valor);
65  void to_med(void) const;
66  void write(const std::string &) const;
67 
68 
69  };
70 
72 template <class T>
74  : MEDFieldInfo(fi,grp), campo(nullptr), has_gauss_points(false) {}
75 
77 template <class T>
79  { libera(); }
80 
82 template <class T>
83 void MEDTFieldInfo<T>::libera(void) const
84  {
85  if(campo)
86  {
87  delete campo;
88  campo= nullptr;
89  }
90  }
91 
93 template <class T>
94 void MEDTFieldInfo<T>::alloc(void) const
95  {
96  libera();
97  const int nc= getXCFieldInfo().getNumberOfComponents();
98  if(nc>0)
99  {
100  MEDMEM::GROUP *grupo= getGrupoMED();
101  assert(grupo);
102  campo= new MEDMEM::FIELD<T>(grupo,nc);
103  }
104  else
105  std::cerr << "El campo: '" << getXCFieldInfo().GetNombre()
106  << "' tiene 0 componentes; se ignora." << std::endl;
107  }
108 
110 template <class T>
111 typename MEDTFieldInfo<T>::ArrayGauss *MEDTFieldInfo<T>::getArrayGauss(void) const
112  {
113  ArrayGauss *retval= nullptr;
114  const int numberOfComponents= getXCFieldInfo().getNumberOfComponents();
115  const MEDMapNumCeldasPorTipo &cell_types= getGrupo().getMapCellTypes();
116  const size_t numberOfTypes= cell_types.getNumberOfTypes();
117  std::vector<int> numberOfElementsOfTypeC(numberOfTypes+1,0);
118  std::vector<int> numberOfGaussPoint(numberOfTypes+1,1);
119  numberOfElementsOfTypeC[0]= 1;
120  numberOfGaussPoint[0]= 1;
121  size_t conta= 1;
122  for(MEDMapNumCeldasPorTipo::const_iterator i= cell_types.begin();i!=cell_types.end();i++,conta++)
123  {
124  const MED_EN::medGeometryElement tipo= i->first;
125  numberOfElementsOfTypeC[conta]= i->second+numberOfElementsOfTypeC[conta-1]; //Acumulados.
126  numberOfGaussPoint[conta]= campo->getGaussLocalization(tipo).getNbGauss();
127  }
128  retval= new ArrayGauss(numberOfComponents,numberOfElementsOfTypeC[numberOfTypes]-1,numberOfTypes, &numberOfElementsOfTypeC[0], &numberOfGaussPoint[0]);
129  return retval;
130  }
131 
133 template <class T>
134  void XC::MEDTFieldInfo<T>::checkVectorDimension(const std::string &nmb_prop,const std::vector<T> &valor, const size_t &dim)
135  {
136  if(valor.size()!=dim)
137  std::cerr << "The property: '" << nmb_prop
138  << "' returns a vector with dimension: "
139  << valor.size() << "; a vector of dimension "
140  << dim << " was expected" << std::endl;
141  }
142 
144 template <class T>
146  {
147  assert(campo);
148  const MEDGaussModel::med_gauss_model *model= gm.getGaussModelMED();
149  assert(model);
150  campo->setGaussLocalization(gm.getTipo(),*model);
151  has_gauss_points= true;
152  }
153 
155 template <class T>
157  {
158  const DqPtrsElem &elements= set.getElements();
159  std::set<std::string> nombres;
160  for(DqPtrsElem::const_iterator j= elements.begin();j!=elements.end();j++)
161  {
162  MEDGaussModel gm= (*j)->getMEDGaussModel();
163  const std::string nmb= gm.getNombre();
164  if(nombres.find(nmb)==nombres.end()) //Nuevo
165  {
166  nombres.insert(nmb);
167  setGaussModel(gm);
168  }
169  }
170  if(has_gauss_points)
171  campo->setArray(getArrayGauss());
172  }
173 
175 template <class T>
176 void MEDTFieldInfo<T>::setValueIJ(int i, int j,const T &valor)
177  {
178  const int nc= getXCFieldInfo().getNumberOfComponents();
179  if(j>nc)
180  std::cerr << "j index: " << j
181  << " out of range (1," << nc
182  << ").\n" << std::endl;
183  const int ne= getGrupo().getNumberOfElements();
184  if(i>ne)
185  std::cerr << "i index: " << i
186  << " out of range (1," << ne
187  << ").\n" << std::endl;
188  assert(campo);
189  campo->setValueIJ(i,j,valor);
190  }
191 
193 template <class T>
194 void MEDTFieldInfo<T>::setValueIJK(int i, int j,int k,int t,const T &valor)
195  {
196  const int nc= getXCFieldInfo().getNumberOfComponents();
197  if(j>nc)
198  std::cerr << "j index: " << j
199  << " out of range (1," << nc
200  << ").\n" << std::endl;
201  const int ne= getGrupo().getNumberOfElements();
202  if(i>ne)
203  std::cerr << "i index: " << i
204  << " out of range (1," << ne
205  << ").\n" << std::endl;
206  assert(campo);
207  const int num_ptos_gauss= campo->getNumberOfGaussPoints(t);
208  if(k>num_ptos_gauss)
209  std::cerr << "k index: " << k
210  << " out of range (1," << num_ptos_gauss
211  << ").\n" << std::endl;
212  campo->setValueIJK(i,j,k,valor);
213  }
214 
216 template <class T>
217 void MEDTFieldInfo<T>::to_med(void) const
218  {
219  alloc();
220  campo->setName(getXCFieldInfo().GetNombre());
221  //Information about components.
222  campo->setComponentsNames(getComponentNamesPtr());
223  campo->setComponentsDescriptions(getComponentDescriptionsPtr());
224  campo->setMEDComponentsUnits(getComponentUnitsPtr());
225  //Information about iteration.
226  campo->setIterationNumber(getXCFieldInfo().getIterationNumber());
227  campo->setOrderNumber(getXCFieldInfo().getOrderNumber());
228  campo->setTime(getXCFieldInfo().getTime());
229  }
230 
232 template <class T>
233 void MEDTFieldInfo<T>::write(const std::string &filename) const
234  {
235  if(campo)
236  campo->write(MEDMEM::MED_DRIVER,filename.c_str());
237  else
238  std::cerr << "the pointer al campo es nulo." << std::endl;
239  }
240 
241 } // end of XC namespace
242 #endif
TipoCampo * campo
Field definition in MEDMEM.
Definition: MEDTFieldInfo.h:48
Information about a field defined over a set.
Definition: FieldInfo.h:39
void to_med(void) const
Dumps the field definition into MEDMEM.
Definition: MEDTFieldInfo.h:217
Information about node and element sets.
Definition: MEDGroupInfo.h:36
void setValueIJ(int i, int j, const T &valor)
Value of the field at indexes i,j.
Definition: MEDTFieldInfo.h:176
void libera(void) const
Frees memory (and erases the field definition).
Definition: MEDTFieldInfo.h:83
~MEDTFieldInfo(void)
Destructor.
Definition: MEDTFieldInfo.h:78
Information about Gauss model.
Definition: MEDGaussModel.h:38
void alloc(void) const
Creates MEDMEM field definition.
Definition: MEDTFieldInfo.h:94
const std::string & getNombre(void) const
Returns the nombre del model.
Definition: MEDGaussModel.cc:70
const MEDGroupInfo & getGrupo(void) const
Returns the group over which the field is defined.
Definition: MEDFieldInfo.cc:38
ArrayGauss * getArrayGauss(void) const
Crea la matriz para los valores del campo en los puntos de Gauss.
Definition: MEDTFieldInfo.h:111
Number of cells de cada tipo.
Definition: MEDMapNumCeldasPorTipo.h:36
void write(const std::string &) const
Escribe el campo en el archivo cuyo nombre being passed as parameter.
Definition: MEDTFieldInfo.h:233
Pointer to element container.
Definition: DqPtrsElem.h:45
void defineGaussModels(const Set &)
Sets the Gauss integration model for the elements in the set.
Definition: MEDTFieldInfo.h:156
static void checkVectorDimension(const std::string &, const std::vector< T > &, const size_t &)
Checks vector dimension.
Definition: MEDTFieldInfo.h:134
const MED_EN::medGeometryElement & getTipo(void) const
Returns the element type the model.
Definition: MEDGaussModel.cc:74
Iformation about a field defined over a mesh subset.
Definition: MEDTFieldInfo.h:42
Information about a field defined over a mesh subset.
Definition: MEDFieldInfo.h:38
Object set.
Definition: Set.h:63
size_t getNumberOfElements(void) const
Returns the number of elements.
Definition: MEDCellBaseInfo.cc:28
size_t getNumberOfTypes(void) const
Returns the number of cell types.
Definition: MEDMapNumCeldasPorTipo.cc:42
================================================================================
Definition: ContinuaReprComponent.h:34
void setValueIJK(int i, int j, int k, int t, const T &valor)
Value of the field at indexes i,j y k (punto de Gauss).
Definition: MEDTFieldInfo.h:194