v0.9.0
DirichletBC.hpp
Go to the documentation of this file.
1 /* \file Dirichlet.hpp
2  * \brief Implementation of Dirichlet boundary conditions
3  * \ingroup Dirichlet_bc
4  *
5  * Structures and method in this file erase rows and column, set value on
6  * matrix diagonal and on the right hand side vector to enforce boundary
7  * condition.
8  *
9  * Current implementation is suboptimal, classes name too long. Need to
10  * rethinking and improved, more elegant and more efficient implementation.
11  *
12  */
13 
14 /* Notes:
15 
16  DirichletSetFieldFromBlock implemented by Zahur Ullah
17  (Zahur.Ullah@glasgow.ac.uk)
18 
19  */
20 
21 /* This file is part of MoFEM.
22  * MoFEM is free software: you can redistribute it and/or modify it under
23  * the terms of the GNU Lesser General Public License as published by the
24  * Free Software Foundation, either version 3 of the License, or (at your
25  * option) any later version.
26  *
27  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
28  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
30  * License for more details.
31  *
32  * You should have received a copy of the GNU Lesser General Public
33  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
34 
35 #ifndef __DIRICHLET_HPP__
36 #define __DIRICHLET_HPP__
37 
38 using namespace boost::numeric;
39 
40 /** \brief Set Dirichlet boundary conditions on displacements
41  * \ingroup Dirichlet_bc
42  */
44 
46  const std::string fieldName; ///< field name to set Dirichlet BC
47  double dIag; ///< diagonal value set on zeroed column and rows
48 
50  const std::string &field_name, Mat Aij, Vec X, Vec F);
52  const std::string &field_name);
53 
54  std::map<DofIdx, FieldData> mapZeroRows;
55  std::vector<int> dofsIndices;
56  std::vector<double> dofsValues;
57  std::vector<double> dofsXValues;
58  virtual MoFEMErrorCode iNitalize();
59 
60  MoFEMErrorCode preProcess();
61  MoFEMErrorCode postProcess();
62 
63  boost::ptr_vector<MethodForForceScaling> methodsOp;
64 };
65 
66 /// \deprecated use DirichletDisplacementBc
68 
69 /** \brief Set Dirichlet boundary conditions on spatial displacements
70  * \ingroup Dirichlet_bc
71  */
73 
75  MoFEM::Interface &m_field, const std::string &field_name, Mat aij, Vec x,
76  Vec f, const std::string material_positions = "MESH_NODE_POSITIONS",
77  const std::string blockset_name = "DISPLACEMENT")
78  : DirichletDisplacementBc(m_field, field_name, aij, x, f),
79  materialPositions(material_positions), blocksetName(blockset_name) {}
80 
82  MoFEM::Interface &m_field, const std::string &field_name,
83  const std::string material_positions = "MESH_NODE_POSITIONS",
84  const std::string blockset_name = "DISPLACEMENT")
85  : DirichletDisplacementBc(m_field, field_name),
86  materialPositions(material_positions), blocksetName(blockset_name) {}
87 
88  std::string materialPositions; ///< name of the field with reference material
89  ///< positions
90  std::vector<std::string> fixFields; ///<
91  const std::string blocksetName;
92 
94  MoFEMErrorCode iNitalize();
95 };
96 
97 /// \deprecated use DirichletSpatialPositionsBc
100 
102 
104  const std::string &field_name, Mat aij, Vec x, Vec f)
105  : DirichletDisplacementBc(m_field, field_name, aij, x, f) {}
106 
108  const std::string &field_name)
109  : DirichletDisplacementBc(m_field, field_name) {}
110 
111  MoFEMErrorCode iNitalize();
112 };
113 
114 /// \deprecated use DirichletTemperatureBc
116 
117 /** \brief Fix dofs on entities
118  * \ingroup Dirichlet_bc
119  */
121 
122  Range eNts;
123  std::vector<std::string> fieldNames;
125  const std::string &field_name, Mat aij, Vec x,
126  Vec f, Range &ents)
127  : DirichletDisplacementBc(m_field, field_name, aij, x, f), eNts(ents) {
128  fieldNames.push_back(fieldName);
129  }
130 
132  const std::string &field_name, Range &ents)
133  : DirichletDisplacementBc(m_field, field_name), eNts(ents) {
134  fieldNames.push_back(fieldName);
135  }
136 
137  MoFEMErrorCode iNitalize();
138  MoFEMErrorCode preProcess();
139  MoFEMErrorCode postProcess();
140 };
141 
142 /// \deprecated use DirichletFixFieldAtEntitiesBc
144 
145 /** \brief Blockset boundary conditions
146  * \ingroup Dirichlet_bc
147  *
148  * Implementation of generalized Dirichlet Boundary Conditions from CUBIT
149 Blockset
150  * (or not using CUBIT building boundary conditions, e.g. Temperature or
151 Displacements etc).
152  * It can work for any Problem rank (1,2,3)
153  *
154  * Usage in Cubit for displacement:
155  block 1 surface 12
156  block 1 name "DISPLACEMENT_1"
157  block 1 attribute count 3
158  block 1 attribute index 1 0 # value for x direction
159  block 1 attribute index 2 2 # value for y direction
160  block 1 attribute index 3 0 # value for z direction
161 
162  With above command we set displacement of 2 on y-direction and constrain
163 x,z direction (0 displacement)
164  *
165 **/
167 
168  const std::string blocksetName;
170  const std::string &field_name,
171  const std::string &blockset_name, Mat aij, Vec x,
172  Vec f)
173  : DirichletDisplacementBc(m_field, field_name, aij, x, f),
174  blocksetName(blockset_name) {}
175 
177  const std::string &field_name,
178  const std::string &blockset_name)
179  : DirichletDisplacementBc(m_field, field_name),
180  blocksetName(blockset_name) {}
181 
182  MoFEMErrorCode iNitalize();
183 };
184 
185 /// \deprecated use DirichletSetFieldFromBlock
188 
189 /**
190  * \brief Add boundary conditions form block set having 6 attributes
191  *
192  * First 3 values are magnitudes of dofs e.g. in x,y,z direction and next 3 are
193  flags, respectively.
194  * If flag is false ( = 0), particular dof is not taken into account.
195  Usage in Cubit for displacement:
196  block 1 tri 28 32
197  block 1 name "DISPLACEMENT_1"
198  block 1 attribute count 6
199  block 1 attribute index 1 97 # any value (Cubit doesnt allow for blank
200  attributes) block 1 attribute index 2 0 block 1 attribute index 3 0 block 1
201  attribute index 4 0 # flag for x direction block 1 attribute index 5 1 #
202  flag for y direction block 1 attribute index 6 1 # flag for z direction
203  This means that we set zero displacement on y and z direction and on x set
204  direction freely. (value 97 is irrelevant because flag for 1 value is 0
205  (false)) It can be usefull if we want to set boundary conditions directly to
206  triangles e.g, since standard boundary conditions in Cubit allow only using
207  nodeset or surface which might not work with mesh based on facet engine (e.g.
208  STL file)
209  */
211 
212  const std::string blocksetName;
214  const std::string &field_name,
215  const std::string &blockset_name, Mat aij,
216  Vec x, Vec f)
217  : DirichletDisplacementBc(m_field, field_name, aij, x, f),
218  blocksetName(blockset_name) {}
219 
221  const std::string &field_name,
222  const std::string &blockset_name)
223  : DirichletDisplacementBc(m_field, field_name),
224  blocksetName(blockset_name) {}
225 
226  MoFEMErrorCode iNitalize();
227 };
228 
229 /// \deprecated use DirichletSetFieldFromBlockWithFlags
232 
233 /**
234  * @brief calculate reactions from vector of internal forces on meshsets
235  *
236  * example usage
237  *
238  * \code
239  Vec F_int;
240  DMCreateGlobalVector_MoFEM(dm, &F_int);
241 
242  feRhs->snes_ctx = FEMethod::CTX_SNESSETFUNCTION;
243  feRhs->snes_f = F_int;
244  DMoFEMLoopFiniteElements(dm, "ELASTIC", feRhs);
245 
246  VecAssemblyBegin(F_int);
247  VecAssemblyEnd(F_int);
248  VecGhostUpdateBegin(F_int, INSERT_VALUES, SCATTER_FORWARD);
249  VecGhostUpdateEnd(F_int, INSERT_VALUES, SCATTER_FORWARD);
250 
251  Reactions my_react(m_field, "DM_ELASTIC", "U");
252  my_react.calculateReactions(F_int);
253  int fix_nodes_meshset_id = 1;
254  cout << my_react.getReactionsFromSet(fix_nodes_meshset_id) << endl;
255 
256 * \endcode
257  */
258 struct Reactions {
259 
260  Reactions(MoFEM::Interface &m_field, string problem_name, string field_name)
261  : mField(m_field), problemName(problem_name), fieldName(field_name) {}
262 
263  typedef std::map<int, VectorDouble> ReactionsMap;
265  /**
266  * @brief Get the Reactions Map
267  *
268  * @return const ReactionsMap&
269  */
270  inline const ReactionsMap &getReactionsMap() const { return reactionsMap; }
271  /**
272  * @brief Get the Reactions at specified meshset id
273  *
274  * @param id meshset id (from Cubit)
275  * @return const VectorDouble&
276  */
277  inline const VectorDouble &getReactionsFromSet(const int &id) const {
278  return reactionsMap.at(id);
279  }
280  /**
281  * @brief calculate reactions from a given vector
282  *
283  * @param internal forces vector
284  * @return MoFEMErrorCode
285  */
286  MoFEMErrorCode calculateReactions(Vec &internal);
287 
288 private:
289  std::string problemName;
290  std::string fieldName;
292 };
293 
294 #endif //__DIRICHLET_HPP__
295 
296 /**
297  * \defgroup Dirichlet_bc Dirichlet boundary conditions
298  * \ingroup user_modules
299  **/
structure for User Loop Methods on finite elementsIt can be used to calculate stiffness matrices,...
std::string fieldName
const ReactionsMap & getReactionsMap() const
Get the Reactions Map.
const std::string fieldName
field name to set Dirichlet BC
Definition: DirichletBC.hpp:46
DEPRECATED typedef DirichletDisplacementBc DisplacementBCFEMethodPreAndPostProc
Definition: DirichletBC.hpp:67
std::vector< std::string > fieldNames
const std::string blocksetName
std::vector< std::string > fixFields
Definition: DirichletBC.hpp:90
std::string problemName
DEPRECATED typedef DirichletFixFieldAtEntitiesBc FixBcAtEntities
Blockset boundary conditions.
std::map< int, VectorDouble > ReactionsMap
DEPRECATED typedef DirichletTemperatureBc TemperatureBCFEMethodPreAndPostProc
Set Dirichlet boundary conditions on spatial displacements.
Definition: DirichletBC.hpp:72
MoFEM::Interface & mField
MoFEM::Interface & mField
Definition: DirichletBC.hpp:45
DEPRECATED typedef DirichletSetFieldFromBlockWithFlags DirichletBCFromBlockSetFEMethodPreAndPostProcWithFlags
DirichletSetFieldFromBlock(MoFEM::Interface &m_field, const std::string &field_name, const std::string &blockset_name, Mat aij, Vec x, Vec f)
ReactionsMap reactionsMap
DirichletTemperatureBc(MoFEM::Interface &m_field, const std::string &field_name)
std::vector< double > dofsXValues
Definition: DirichletBC.hpp:57
Add boundary conditions form block set having 6 attributes.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
DEPRECATED typedef DirichletSpatialPositionsBc SpatialPositionsBCFEMethodPreAndPostProc
Definition: DirichletBC.hpp:99
std::vector< int > dofsIndices
Definition: DirichletBC.hpp:55
DirichletSpatialPositionsBc(MoFEM::Interface &m_field, const std::string &field_name, const std::string material_positions="MESH_NODE_POSITIONS", const std::string blockset_name="DISPLACEMENT")
Definition: DirichletBC.hpp:81
Set Dirichlet boundary conditions on displacements.
Definition: DirichletBC.hpp:43
double dIag
diagonal value set on zeroed column and rows
Definition: DirichletBC.hpp:47
std::vector< double > dofsValues
Definition: DirichletBC.hpp:56
const VectorDouble & getReactionsFromSet(const int &id) const
Get the Reactions at specified meshset id.
Reactions(MoFEM::Interface &m_field, string problem_name, string field_name)
DirichletFixFieldAtEntitiesBc(MoFEM::Interface &m_field, const std::string &field_name, Mat aij, Vec x, Vec f, Range &ents)
DirichletSetFieldFromBlockWithFlags(MoFEM::Interface &m_field, const std::string &field_name, const std::string &blockset_name)
boost::ptr_vector< MethodForForceScaling > methodsOp
Definition: DirichletBC.hpp:63
DirichletFixFieldAtEntitiesBc(MoFEM::Interface &m_field, const std::string &field_name, Range &ents)
Fix dofs on entities.
DirichletSpatialPositionsBc(MoFEM::Interface &m_field, const std::string &field_name, Mat aij, Vec x, Vec f, const std::string material_positions="MESH_NODE_POSITIONS", const std::string blockset_name="DISPLACEMENT")
Definition: DirichletBC.hpp:74
DEPRECATED typedef DirichletSetFieldFromBlock DirichletBCFromBlockSetFEMethodPreAndPostProc
#define DEPRECATED
Definition: definitions.h:29
const std::string blocksetName
Definition: DirichletBC.hpp:91
DirichletTemperatureBc(MoFEM::Interface &m_field, const std::string &field_name, Mat aij, Vec x, Vec f)
ublas::vector< double, DoubleAllocator > VectorDouble
Definition: Types.hpp:72
DirichletSetFieldFromBlock(MoFEM::Interface &m_field, const std::string &field_name, const std::string &blockset_name)
DirichletSetFieldFromBlockWithFlags(MoFEM::Interface &m_field, const std::string &field_name, const std::string &blockset_name, Mat aij, Vec x, Vec f)
std::map< DofIdx, FieldData > mapZeroRows
Definition: DirichletBC.hpp:54
calculate reactions from vector of internal forces on meshsets