v0.9.2
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 Data from Cubit blocksets
41  * \ingroup Dirichlet_bc
42  */
43 struct DataFromBc {
46  Range bc_ents[3];
47 
48  //for rotation
52  double theta;
53 
55  : scaled_values(3), bc_flags(3), is_rotation(false) {
56  }
57 
58  MoFEMErrorCode getBcData(DisplacementCubitBcData &mydata,
59  const MoFEM::CubitMeshSets *it);
60  MoFEMErrorCode getBcData(std::vector<double> &mydata,
61  const MoFEM::CubitMeshSets *it);
62  MoFEMErrorCode getEntitiesFromBc(MoFEM::Interface &mField,
63  const MoFEM::CubitMeshSets *it);
64 };
65 
66 /** \brief Set Dirichlet boundary conditions on displacements
67  * \ingroup Dirichlet_bc
68  */
70 
72  const std::string fieldName; ///< field name to set Dirichlet BC
73  double dIag; ///< diagonal value set on zeroed column and rows
74 
76  const std::string &field_name, Mat Aij, Vec X, Vec F,
77  string blockset_name = "DISPLACEMENT");
79  const std::string &field_name,
80  string blockset_name = "DISPLACEMENT");
81 
82  std::map<DofIdx, FieldData> mapZeroRows;
83  std::vector<int> dofsIndices;
84  std::vector<double> dofsValues;
85  std::vector<double> dofsXValues;
86  const std::string blocksetName;
87 
88  virtual MoFEMErrorCode iNitalize();
89 
90  MoFEMErrorCode preProcess();
91  MoFEMErrorCode postProcess();
92  /**
93  * @brief Get the Bc Data From Sets And Blocks object
94  * Use DISPLACEMENT blockset name (default)
95  * with 6 atributes:
96  * 1,2,3 are values of displacements x,y,z
97  * 4,5,6 are flags for x,y,z (0 or 1)
98  * @param bc_data
99  * @return MoFEMErrorCode
100  */
101  MoFEMErrorCode getBcDataFromSetsAndBlocks(std::vector<DataFromBc> &bc_data);
102  /**
103  * @brief Get the Rotation Bc From Block object
104  * Use ROTATION blockset name
105  * with 7 atributes:
106  * 1 - is the rotation angle
107  * 2,3,4 are x,y,z coords of the center of rotation
108  * 5,6,7 are x,y,z coords of the normal of rotation
109  * @param bc_data
110  * @return MoFEMErrorCode
111  */
112  MoFEMErrorCode getRotationBcFromBlock(std::vector<DataFromBc> &bc_data);
113  boost::ptr_vector<MethodForForceScaling> methodsOp;
114 };
115 
116 /// \deprecated use DirichletDisplacementBc
118 
119 /** \brief Set Dirichlet boundary conditions on spatial displacements
120  * \ingroup Dirichlet_bc
121  */
123 
125  MoFEM::Interface &m_field, const std::string &field_name, Mat aij, Vec x,
126  Vec f, const std::string material_positions = "MESH_NODE_POSITIONS",
127  const std::string blockset_name = "DISPLACEMENT")
128  : DirichletDisplacementBc(m_field, field_name, aij, x, f, blockset_name),
129  materialPositions(material_positions) {}
130 
132  MoFEM::Interface &m_field, const std::string &field_name,
133  const std::string material_positions = "MESH_NODE_POSITIONS",
134  const std::string blockset_name = "DISPLACEMENT")
135  : DirichletDisplacementBc(m_field, field_name, blockset_name),
136  materialPositions(material_positions) {}
137 
138  std::string materialPositions; ///< name of the field with reference material
139  ///< positions
140  std::vector<std::string> fixFields; ///<
141 
143  MoFEMErrorCode iNitalize();
144 };
145 
146 /// \deprecated use DirichletSpatialPositionsBc
149 
151 
153  const std::string &field_name, Mat aij, Vec x, Vec f)
154  : DirichletDisplacementBc(m_field, field_name, aij, x, f) {}
155 
157  const std::string &field_name)
158  : DirichletDisplacementBc(m_field, field_name) {}
159 
160  MoFEMErrorCode iNitalize();
161 };
162 
163 /// \deprecated use DirichletTemperatureBc
165 
166 /** \brief Fix dofs on entities
167  * \ingroup Dirichlet_bc
168  */
170 
171  Range eNts;
172  std::vector<std::string> fieldNames;
174  const std::string &field_name, Mat aij, Vec x,
175  Vec f, Range &ents)
176  : DirichletDisplacementBc(m_field, field_name, aij, x, f), eNts(ents) {
177  fieldNames.push_back(fieldName);
178  }
179 
181  const std::string &field_name, Range &ents)
182  : DirichletDisplacementBc(m_field, field_name), eNts(ents) {
183  fieldNames.push_back(fieldName);
184  }
185 
186  MoFEMErrorCode iNitalize();
187  MoFEMErrorCode preProcess();
188  MoFEMErrorCode postProcess();
189 };
190 
191 /// \deprecated use DirichletFixFieldAtEntitiesBc
193 
194 /**
195  * \brief Add boundary conditions form block set having 6 attributes
196  *
197  * First 3 values are magnitudes of dofs e.g. in x,y,z direction and next 3 are
198  flags, respectively.
199  * If flag is false ( = 0), particular dof is not taken into account.
200  Usage in Cubit for displacement:
201  block 1 tri 28 32
202  block 1 name "DISPLACEMENT_1"
203  block 1 attribute count 6
204  block 1 attribute index 1 97 # any value
205  block 1 attribute index 2 0
206  block 1 attribute index 3 0
207  block 1 attribute index 4 0 # flag for x dir
208  block 1 attribute index 5 1 # flag for y dir
209  block 1 attribute index 6 1 # flag for z dir
210  This means that we set zero displacement on y and z dir and on x set
211  direction freely. (value 97 is irrelevant because flag for 1 value is 0
212  (false)) It can be usefull if we want to set boundary conditions directly to
213  triangles e.g, since standard boundary conditions in Cubit allow only using
214  nodeset or surface which might not work with mesh based on facet engine (e.g.
215  STL file)
216  */
218 
220  const std::string &field_name,
221  const std::string &blockset_name, Mat aij,
222  Vec x, Vec f)
223  : DirichletDisplacementBc(m_field, field_name, aij, x, f, blockset_name) {
224  }
225 
227  const std::string &field_name,
228  const std::string &blockset_name)
229  : DirichletDisplacementBc(m_field, field_name, blockset_name) {}
230 };
231 
232 /// \deprecated use DirichletSetFieldFromBlockWithFlags
235 
236 /// \deprecated use DirichletSetFieldFromBlockWithFlags
239 
240 /// \deprecated use DirichletSetFieldFromBlockWithFlags
243 /**
244  * @brief calculate reactions from vector of internal forces on meshsets
245  *
246  * example usage
247  *
248  * \code
249  Vec F_int;
250  DMCreateGlobalVector_MoFEM(dm, &F_int);
251 
252  feRhs->snes_ctx = FEMethod::CTX_SNESSETFUNCTION;
253  feRhs->snes_f = F_int;
254  DMoFEMLoopFiniteElements(dm, "ELASTIC", feRhs);
255 
256  VecAssemblyBegin(F_int);
257  VecAssemblyEnd(F_int);
258  VecGhostUpdateBegin(F_int, INSERT_VALUES, SCATTER_FORWARD);
259  VecGhostUpdateEnd(F_int, INSERT_VALUES, SCATTER_FORWARD);
260 
261  Reactions my_react(m_field, "DM_ELASTIC", "U");
262  my_react.calculateReactions(F_int);
263  int fix_nodes_meshset_id = 1;
264  cout << my_react.getReactionsFromSet(fix_nodes_meshset_id) << endl;
265 
266 * \endcode
267  */
268 struct Reactions {
269 
270  Reactions(MoFEM::Interface &m_field, string problem_name, string field_name)
271  : mField(m_field), problemName(problem_name), fieldName(field_name) {}
272 
273  typedef std::map<int, VectorDouble> ReactionsMap;
275  /**
276  * @brief Get the Reactions Map
277  *
278  * @return const ReactionsMap&
279  */
280  inline const ReactionsMap &getReactionsMap() const { return reactionsMap; }
281  /**
282  * @brief Get the Reactions at specified meshset id
283  *
284  * @param id meshset id (from Cubit)
285  * @return const VectorDouble&
286  */
287  inline const VectorDouble &getReactionsFromSet(const int &id) const {
288  return reactionsMap.at(id);
289  }
290  /**
291  * @brief calculate reactions from a given vector
292  *
293  * @param internal forces vector
294  * @return MoFEMErrorCode
295  */
296  MoFEMErrorCode calculateReactions(Vec &internal);
297 
298 private:
299  std::string problemName;
300  std::string fieldName;
302 };
303 
304 #endif //__DIRICHLET_HPP__
305 
306 /**
307  * \defgroup Dirichlet_bc Dirichlet boundary conditions
308  * \ingroup user_modules
309  **/
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.
Deprecated interface functions.
VectorDouble scaled_values
Definition: DirichletBC.hpp:44
const std::string fieldName
field name to set Dirichlet BC
Definition: DirichletBC.hpp:72
DEPRECATED typedef DirichletDisplacementBc DisplacementBCFEMethodPreAndPostProc
std::vector< std::string > fieldNames
std::vector< std::string > fixFields
double theta
Definition: DirichletBC.hpp:52
std::string problemName
DEPRECATED typedef DirichletFixFieldAtEntitiesBc FixBcAtEntities
std::map< int, VectorDouble > ReactionsMap
FTensor::Tensor1< double, 3 > t_normal
Definition: DirichletBC.hpp:50
this struct keeps basic methods for moab meshset about material and boundary conditions
DEPRECATED typedef DirichletTemperatureBc TemperatureBCFEMethodPreAndPostProc
Set Dirichlet boundary conditions on spatial displacements.
FTensor::Tensor1< double, 3 > t_centr
Definition: DirichletBC.hpp:51
MoFEM::Interface & mField
MoFEM::Interface & mField
Definition: DirichletBC.hpp:71
DEPRECATED typedef DirichletSetFieldFromBlockWithFlags DirichletBCFromBlockSetFEMethodPreAndPostProcWithFlags
DEPRECATED typedef DirichletSetFieldFromBlockWithFlags DirichletBCFromBlockSetFEMethodPreAndPostProc
Data from Cubit blocksets.
Definition: DirichletBC.hpp:43
ReactionsMap reactionsMap
VectorInt bc_flags
Definition: DirichletBC.hpp:45
DirichletTemperatureBc(MoFEM::Interface &m_field, const std::string &field_name)
bool is_rotation
Definition: DirichletBC.hpp:49
std::vector< double > dofsXValues
Definition: DirichletBC.hpp:85
Add boundary conditions form block set having 6 attributes.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
DEPRECATED typedef DirichletSpatialPositionsBc SpatialPositionsBCFEMethodPreAndPostProc
std::vector< int > dofsIndices
Definition: DirichletBC.hpp:83
DirichletSpatialPositionsBc(MoFEM::Interface &m_field, const std::string &field_name, const std::string material_positions="MESH_NODE_POSITIONS", const std::string blockset_name="DISPLACEMENT")
Set Dirichlet boundary conditions on displacements.
Definition: DirichletBC.hpp:69
double dIag
diagonal value set on zeroed column and rows
Definition: DirichletBC.hpp:73
std::vector< double > dofsValues
Definition: DirichletBC.hpp:84
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
DirichletFixFieldAtEntitiesBc(MoFEM::Interface &m_field, const std::string &field_name, Range &ents)
ublas::vector< int, IntAllocator > VectorInt
Definition: Types.hpp:72
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")
#define DEPRECATED
Definition: definitions.h:29
DirichletTemperatureBc(MoFEM::Interface &m_field, const std::string &field_name, Mat aij, Vec x, Vec f)
const std::string blocksetName
Definition: DirichletBC.hpp:86
ublas::vector< double, DoubleAllocator > VectorDouble
Definition: Types.hpp:73
DEPRECATED typedef DirichletSetFieldFromBlockWithFlags DirichletSetFieldFromBlock
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:82
calculate reactions from vector of internal forces on meshsets