v0.9.1
SaveVertexDofOnTag.hpp
Go to the documentation of this file.
1 /** \file SaveVertexDofOnTag.hpp
2 
3 Save field DOFS on vertices/tags
4 This is another example how to use MoFEM::DofMethod when some operator for each
5 node need to be applied.
6 
7 */
8 
9 /* This file is part of MoFEM.
10  * MoFEM is free software: you can redistribute it and/or modify it under
11  * the terms of the GNU Lesser General Public License as published by the
12  * Free Software Foundation, either version 3 of the License, or (at your
13  * option) any later version.
14  *
15  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
22 
23 #ifndef __SAVEVERTEXDOFONTAG_HPP__
24 #define __SAVEVERTEXDOFONTAG_HPP__
25 
27 
28 /** \brief Save field DOFS on vertices/tags
29  */
31 
33  std::string tagName;
34  SaveVertexDofOnTag(MoFEM::Interface &m_field, std::string tag_name)
35  : mField(m_field), tagName(tag_name) {}
36 
37  Tag tH;
38 
41  if (!fieldPtr) {
43  "Null pointer, probably field not found");
44  }
45  if (fieldPtr->getSpace() != H1) {
47  "Field must be in H1 space");
48  }
49  std::vector<double> def_vals(fieldPtr->getNbOfCoeffs(), 0);
50  rval = mField.get_moab().tag_get_handle(tagName.c_str(), tH);
51  if (rval != MB_SUCCESS) {
52  CHKERR mField.get_moab().tag_get_handle(
53  tagName.c_str(), fieldPtr->getNbOfCoeffs(), MB_TYPE_DOUBLE, tH,
54  MB_TAG_CREAT | MB_TAG_SPARSE, &def_vals[0]);
55  }
56 
58  }
59 
63  }
64 
67  if (dofPtr->getEntType() != MBVERTEX)
69  EntityHandle ent = dofPtr->getEnt();
70  int rank = dofPtr->getNbOfCoeffs();
71  double tag_val[rank];
72 
73  CHKERR mField.get_moab().tag_get_data(tH, &ent, 1, tag_val);
74  tag_val[dofPtr->getDofCoeffIdx()] = dofPtr->getFieldData();
75  CHKERR mField.get_moab().tag_set_data(tH, &ent, 1, &tag_val);
77  }
78 };
79 
80 } // BasicFiniteElements
81 
82 #endif // __SAVEVERTEXDOFONTAG_HPP__
boost::shared_ptr< DofEntity > dofPtr
Deprecated interface functions.
virtual moab::Interface & get_moab()=0
MoFEMErrorCode preProcess()
function is run at the beginning of loop
SaveVertexDofOnTag(MoFEM::Interface &m_field, std::string tag_name)
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:482
boost::shared_ptr< Field > fieldPtr
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:513
Data structure to exchange data between mofem and User Loop Methods on entities.It allows to exchange...
Save field DOFS on vertices/tags.
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:84
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
MoFEMErrorCode postProcess()
function is run at the end of loop
#define CHKERR
Inline error check.
Definition: definitions.h:601
MoFEMErrorCode operator()()
function is run for every finite element
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:412
virtual MPI_Comm & get_comm() const =0
continuous field
Definition: definitions.h:176