v0.14.0
Loading...
Searching...
No Matches
ElasticMaterials.hpp
Go to the documentation of this file.
1/** \file ElasticMaterials.hpp
2 * \ingroup nonlinear_elastic_elem
3 * \brief Elastic materials
4 */
5
6
7
8#ifndef __ELASTICMATERIALS_HPP__
9#define __ELASTICMATERIALS_HPP__
10
11#include <boost/program_options.hpp>
12namespace po = boost::program_options;
13
14#include <Hooke.hpp>
15#include <NeoHookean.hpp>
16
17#define MAT_KIRCHHOFF "KIRCHHOFF"
18#define MAT_HOOKE "HOOKE"
19#define MAT_NEOHOOKEAN "NEOHOOKEAN"
20
21/** \brief Manage setting parameters and constitutive equations for
22 * nonlinear/linear elastic materials \ingroup nonlinear_elastic_elem
23 */
25
27 std::string defMaterial; ///< default material, if block is set to elastic,
28 ///< this material is used as default
29 std::string configFile; //< default name of config file
30
31 bool iNitialized; ///< true if class is initialized
32
34 std::string def_material = MAT_KIRCHHOFF)
35 : mField(m_field), defMaterial(def_material),
36 configFile("elastic_material.in"), iNitialized(false) {}
37
38 virtual ~ElasticMaterials() {}
39
40 std::map<std::string,
41 boost::shared_ptr<NonlinearElasticElement::
42 FunctionsToCalculatePiolaKirchhoffI<adouble>>>
43 aDoubleMaterialModel; ///< Hash map of materials for evaluation with
44 ///< adouble, i.e. ADOL-C
45
46 std::map<
47 std::string,
48 boost::shared_ptr<
50 doubleMaterialModel; ///< Hash map of materials for evaluation with double
51
52 /**
53 * Structure for material parameters for block
54 */
56 string mAterial;
57 int oRder;
58 double yOung;
59 double pOisson;
60 double dEnsity;
61 double dashG;
63 double aX, aY, aZ;
65 : mAterial(MAT_KIRCHHOFF), oRder(-1), yOung(-1), pOisson(-2),
66 dEnsity(-1), dashG(-1), dashPoisson(-1), aX(0), aY(0), aZ(0) {}
67 };
68
69 std::map<int, BlockOptionData> blockData; ///< Material parameters on blocks
70
71 PetscBool isConfigFileSet; ///< True if config file is set from command line
72 po::variables_map vM;
73
74 /**
75 * Initialize model parameters
76 * @return [description]
77 */
78 virtual MoFEMErrorCode iNit() {
80 // add new material below
81 string mat_name;
83 boost::make_shared<NonlinearElasticElement::
84 FunctionsToCalculatePiolaKirchhoffI<adouble>>();
85 doubleMaterialModel[MAT_KIRCHHOFF] = boost::make_shared<
87 aDoubleMaterialModel[MAT_HOOKE] = boost::make_shared<Hooke<adouble>>();
88 doubleMaterialModel[MAT_HOOKE] = boost::make_shared<Hooke<double>>();
90 boost::make_shared<NeoHookean<adouble>>();
92 boost::make_shared<NeoHookean<double>>();
93 std::ostringstream avilable_materials;
94 avilable_materials << "set elastic material < ";
95 std::map<std::string,
96 boost::shared_ptr<
98 double>>>::iterator mit;
99 mit = doubleMaterialModel.begin();
100 for (; mit != doubleMaterialModel.end(); mit++) {
101 avilable_materials << mit->first << " ";
102 }
103 avilable_materials << ">";
104
105 CHKERR PetscOptionsBegin(mField.get_comm(), "",
106 "Elastic Materials Configuration", "none");
107 char default_material[255];
108 PetscBool def_mat_set;
109 CHKERR PetscOptionsString(
110 "-default_material", avilable_materials.str().c_str(), "",
111 defMaterial.c_str(), default_material, 255, &def_mat_set);
112 if (def_mat_set) {
113 defMaterial = default_material;
115 aDoubleMaterialModel.end()) {
116 SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
117 "material <%s> not implemented", default_material);
118 }
119 }
120 char config_file[255];
121 CHKERR PetscOptionsString("-elastic_material_configuration",
122 "elastic materials configure file name", "",
123 configFile.c_str(), config_file, 255,
125 if (isConfigFileSet) {
126 configFile = config_file;
127 }
128 ierr = PetscOptionsEnd();
129 CHKERRG(ierr);
131 }
132
133 /** \brief read Elastic materials declaration for blocks and meshsets
134
135 File parameters:
136 \code
137 [block_1]
138 displacemet_order = 1/2 .. N
139 material = KIRCHHOFF/HOOKE/NEOHOOKEAN
140 young_modulus = 1
141 poisson_ratio = 0.25
142 density = 1
143 a_x = 0
144 a_y = 0
145 a_z = 10
146 \endcode
147
148 To read material configuration file you need to use option:
149 \code
150 -elastic_material_configuration name_of_config_file
151 \endcode
152
153 */
154 virtual MoFEMErrorCode readConfigFile() {
156
157 ifstream file(configFile.c_str());
158 if (isConfigFileSet) {
159 if (!file.good()) {
160 SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "file < %s > not found",
161 configFile.c_str());
162 }
163 } else {
164 if (!file.good()) {
166 }
167 }
168
169 po::options_description config_file_options;
171
172 std::ostringstream str_order;
173 str_order << "block_" << it->getMeshsetId() << ".displacemet_order";
174 config_file_options.add_options()(
175 str_order.str().c_str(),
176 po::value<int>(&blockData[it->getMeshsetId()].oRder)
177 ->default_value(-1));
178
179 std::ostringstream str_material;
180 str_material << "block_" << it->getMeshsetId() << ".material";
181 config_file_options.add_options()(
182 str_material.str().c_str(),
183 po::value<std::string>(&blockData[it->getMeshsetId()].mAterial)
184 ->default_value(defMaterial));
185
186 std::ostringstream str_ym;
187 str_ym << "block_" << it->getMeshsetId() << ".young_modulus";
188 config_file_options.add_options()(
189 str_ym.str().c_str(),
190 po::value<double>(&blockData[it->getMeshsetId()].yOung)
191 ->default_value(-1));
192
193 std::ostringstream str_pr;
194 str_pr << "block_" << it->getMeshsetId() << ".poisson_ratio";
195 config_file_options.add_options()(
196 str_pr.str().c_str(),
197 po::value<double>(&blockData[it->getMeshsetId()].pOisson)
198 ->default_value(-2));
199
200 std::ostringstream str_density;
201 str_density << "block_" << it->getMeshsetId() << ".density";
202 config_file_options.add_options()(
203 str_density.str().c_str(),
204 po::value<double>(&blockData[it->getMeshsetId()].dEnsity)
205 ->default_value(-1));
206
207 std::ostringstream str_dashG;
208 str_dashG << "block_" << it->getMeshsetId() << ".dashG";
209 config_file_options.add_options()(
210 str_dashG.str().c_str(),
211 po::value<double>(&blockData[it->getMeshsetId()].dashG)
212 ->default_value(-1));
213
214 std::ostringstream str_dashPoisson;
215 str_dashPoisson << "block_" << it->getMeshsetId() << ".dashPoisson";
216 config_file_options.add_options()(
217 str_dashPoisson.str().c_str(),
218 po::value<double>(&blockData[it->getMeshsetId()].dashPoisson)
219 ->default_value(-2));
220
221 std::ostringstream str_ax;
222 str_ax << "block_" << it->getMeshsetId() << ".a_x";
223 config_file_options.add_options()(
224 str_ax.str().c_str(),
225 po::value<double>(&blockData[it->getMeshsetId()].aX)
226 ->default_value(0));
227
228 std::ostringstream str_ay;
229 str_ay << "block_" << it->getMeshsetId() << ".a_y";
230 config_file_options.add_options()(
231 str_ay.str().c_str(),
232 po::value<double>(&blockData[it->getMeshsetId()].aY)
233 ->default_value(0));
234
235 std::ostringstream str_az;
236 str_az << "block_" << it->getMeshsetId() << ".a_z";
237 config_file_options.add_options()(
238 str_az.str().c_str(),
239 po::value<double>(&blockData[it->getMeshsetId()].aZ)
240 ->default_value(0));
241 }
242 po::parsed_options parsed =
243 parse_config_file(file, config_file_options, true);
244 store(parsed, vM);
245 po::notify(vM);
246 std::vector<std::string> additional_parameters;
247 additional_parameters =
248 collect_unrecognized(parsed.options, po::include_positional);
249 for (std::vector<std::string>::iterator vit = additional_parameters.begin();
250 vit != additional_parameters.end(); vit++) {
251 CHKERR PetscPrintf(PETSC_COMM_WORLD,
252 "** WARNING Unrecognized option %s\n", vit->c_str());
253 }
254
256 }
257
258 MoFEMErrorCode setBlocksOrder() {
260
261 // set app. order
262 PetscBool flg = PETSC_TRUE;
263 PetscInt disp_order;
264 CHKERR PetscOptionsGetInt(PETSC_NULL, PETSC_NULL, "-order", &disp_order,
265 &flg);
266 if (flg != PETSC_TRUE) {
267 disp_order = 1;
268 }
270 if (blockData[it->getMeshsetId()].oRder == -1)
271 continue;
272 if (blockData[it->getMeshsetId()].oRder == disp_order)
273 continue;
274 PetscPrintf(mField.get_comm(), "Set block %d oRder to %d\n",
275 it->getMeshsetId(), blockData[it->getMeshsetId()].oRder);
276 Range block_ents;
277 rval = mField.get_moab().get_entities_by_handle(it->meshset, block_ents,
278 true);
279 CHKERRG(rval);
280 Range ents_to_set_order;
281 CHKERR mField.get_moab().get_adjacencies(
282 block_ents, 3, false, ents_to_set_order, moab::Interface::UNION);
283 ents_to_set_order = ents_to_set_order.subset_by_type(MBTET);
284 CHKERR mField.get_moab().get_adjacencies(
285 block_ents, 2, false, ents_to_set_order, moab::Interface::UNION);
286 CHKERR mField.get_moab().get_adjacencies(
287 block_ents, 1, false, ents_to_set_order, moab::Interface::UNION);
288 if (mField.check_field("DISPLACEMENT")) {
289 CHKERR mField.set_field_order(ents_to_set_order, "DISPLACEMENT",
290 blockData[it->getMeshsetId()].oRder);
291 }
292 if (mField.check_field("SPATIAL_POSITION")) {
293 CHKERR mField.set_field_order(ents_to_set_order, "SPATIAL_POSITION",
294 blockData[it->getMeshsetId()].oRder);
295 }
296 if (mField.check_field("DOT_SPATIAL_POSITION")) {
297 CHKERR mField.set_field_order(ents_to_set_order, "DOT_SPATIAL_POSITION",
298 blockData[it->getMeshsetId()].oRder);
299 }
300 if (mField.check_field("SPATIAL_VELOCITY")) {
301 CHKERR mField.set_field_order(ents_to_set_order, "SPATIAL_VELOCITY",
302 blockData[it->getMeshsetId()].oRder);
303 }
304 }
306 }
307
308#ifdef __NONLINEAR_ELASTIC_HPP
309
310 virtual MoFEMErrorCode
311 setBlocks(std::map<int, NonlinearElasticElement::BlockData> &set_of_blocks) {
313
314 if (!iNitialized) {
315 CHKERR iNit();
318 iNitialized = true;
319 }
322 int id = it->getMeshsetId();
323 Mat_Elastic mydata;
324 CHKERR it->getAttributeDataStructure(mydata);
325 EntityHandle meshset = it->getMeshset();
326 CHKERR mField.get_moab().get_entities_by_type(
327 meshset, MBTET, set_of_blocks[id].tEts, true);
328 set_of_blocks[id].iD = id;
329 set_of_blocks[id].E = mydata.data.Young;
330 set_of_blocks[id].PoissonRatio = mydata.data.Poisson;
331 if (blockData[id].yOung >= 0)
332 set_of_blocks[id].E = blockData[id].yOung;
333 if (blockData[id].pOisson >= -1)
334 set_of_blocks[id].PoissonRatio = blockData[id].pOisson;
335
336 blockData[id].mAterial = defMaterial;
337 set_of_blocks[id].materialDoublePtr = doubleMaterialModel.at(defMaterial);
338 set_of_blocks[id].materialAdoublePtr =
340
341 MOFEM_LOG_C("WORLD", Sev::verbose,
342 "Block Id %d Young Modulus %3.2g Poisson Ratio %3.2f "
343 "Material model %s Nb. of elements %d\n",
344 id, set_of_blocks[id].E, set_of_blocks[id].PoissonRatio,
345 blockData[id].mAterial.c_str(),
346 set_of_blocks[id].tEts.size());
347
348 if (blockData[id].mAterial.compare(MAT_KIRCHHOFF) == 0) {
349 set_of_blocks[id].materialDoublePtr =
351 set_of_blocks[id].materialAdoublePtr =
353 } else if (blockData[id].mAterial.compare(MAT_HOOKE) == 0) {
354 set_of_blocks[id].materialDoublePtr = doubleMaterialModel.at(MAT_HOOKE);
355 set_of_blocks[id].materialAdoublePtr =
357 } else if (blockData[id].mAterial.compare(MAT_NEOHOOKEAN) == 0) {
358 set_of_blocks[id].materialDoublePtr =
360 set_of_blocks[id].materialAdoublePtr =
362 } else {
363 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
364 "field with that space is not implemented");
365 }
366 }
368 }
369
370#endif //__NONLINEAR_ELASTIC_HPP
371
372#ifdef __CONVECTIVE_MASS_ELEMENT_HPP
373
375 setBlocks(std::map<int, ConvectiveMassElement::BlockData> &set_of_blocks) {
377
378 if (!iNitialized) {
379 CHKERR iNit();
382 iNitialized = true;
383 }
385 mField, BLOCKSET | BODYFORCESSET, it)) {
386 int id = it->getMeshsetId();
387 EntityHandle meshset = it->getMeshset();
388 CHKERR mField.get_moab().get_entities_by_type(
389 meshset, MBTET, set_of_blocks[id].tEts, true);
390 Block_BodyForces mydata;
391 CHKERR it->getAttributeDataStructure(mydata);
392 set_of_blocks[id].rho0 = mydata.data.density;
393 set_of_blocks[id].a0.resize(3);
394 set_of_blocks[id].a0[0] = mydata.data.acceleration_x;
395 set_of_blocks[id].a0[1] = mydata.data.acceleration_y;
396 set_of_blocks[id].a0[2] = mydata.data.acceleration_z;
397 if (blockData[id].dEnsity >= 0) {
398 set_of_blocks[id].rho0 = blockData[id].dEnsity;
399 std::ostringstream str_ax;
400 str_ax << "block_" << it->getMeshsetId() << ".a_x";
401 std::ostringstream str_ay;
402 str_ay << "block_" << it->getMeshsetId() << ".a_y";
403 std::ostringstream str_az;
404 str_az << "block_" << it->getMeshsetId() << ".a_z";
405 if (vM.count(str_ax.str().c_str())) {
406 set_of_blocks[id].a0[0] = blockData[id].aX;
407 }
408 if (vM.count(str_ay.str().c_str())) {
409 set_of_blocks[id].a0[1] = blockData[id].aY;
410 }
411 if (vM.count(str_az.str().c_str())) {
412 set_of_blocks[id].a0[2] = blockData[id].aZ;
413 }
414 }
415 PetscPrintf(mField.get_comm(),
416 "Block Id %d Density %3.2g a_x = %3.2g a_y = %3.2g a_z = "
417 "%3.2g Nb. of elements %d\n",
418 id, set_of_blocks[id].rho0, set_of_blocks[id].a0[0],
419 set_of_blocks[id].a0[1], set_of_blocks[id].a0[2],
420 set_of_blocks[id].tEts.size());
421 }
422
424 }
425
426#endif //__CONVECTIVE_MASS_ELEMENT_HPP
427
428#ifdef __KELVIN_VOIGT_DAMPER_HPP__
429
431 std::map<int, KelvinVoigtDamper::BlockMaterialData> &set_of_blocks) {
433
434 if (!iNitialized) {
435 CHKERR iNit();
438 iNitialized = true;
439 }
440
442 bool set = false;
443 int id = it->getMeshsetId();
444 EntityHandle meshset = it->getMeshset();
445 if (it->getName().compare(0, 6, "DAMPER") == 0) {
446 set = true;
447 std::vector<double> data;
448 CHKERR it->getAttributes(data);
449 if (data.size() < 2) {
450 SETERRQ(PETSC_COMM_SELF, 1, "Data inconsistency");
451 }
452 rval = mField.get_moab().get_entities_by_type(
453 it->meshset, MBTET, set_of_blocks[it->getMeshsetId()].tEts, true);
454 CHKERRG(rval);
455 set_of_blocks[it->getMeshsetId()].gBeta = data[0];
456 set_of_blocks[it->getMeshsetId()].vBeta = data[1];
457 }
458 if (blockData[id].dashG > 0) {
459 set = true;
460 Range tEts;
461 rval =
462 mField.get_moab().get_entities_by_type(meshset, MBTET, tEts, true);
463 CHKERRG(rval);
464 if (tEts.empty())
465 continue;
466 set_of_blocks[it->getMeshsetId()].tEts = tEts;
467 set_of_blocks[it->getMeshsetId()].gBeta = blockData[id].dashG;
468 set_of_blocks[it->getMeshsetId()].vBeta = blockData[id].dashPoisson;
469 }
470 if (set) {
471 PetscPrintf(
473 "Block Id %d Damper Shear Modulus = %3.2g Poisson ratio = %3.2g\n",
474 id, set_of_blocks[id].gBeta, set_of_blocks[id].vBeta);
475 }
476 }
477
479 }
480
481#endif //__KELVIN_VOIGT_DAMPER_HPP__
482};
483
484#endif //__ELASTICMATERIALS_HPP__
#define MAT_KIRCHHOFF
#define MAT_NEOHOOKEAN
#define MAT_HOOKE
Implementation of linear elastic material.
static MoFEMErrorCode setBlocks(MoFEM::Interface &m_field, boost::shared_ptr< map< int, BlockData > > &block_sets_ptr)
#define MOFEM_LOG_C(channel, severity, format,...)
Implementation of Neo-Hookean elastic material.
static PetscErrorCode ierr
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ BODYFORCESSET
block name is "BODY_FORCES"
@ MAT_ELASTICSET
block name is "MAT_ELASTIC"
@ BLOCKSET
@ MOFEM_NOT_FOUND
Definition definitions.h:33
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual bool check_field(const std::string &name) const =0
check if field is in database
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Manage setting parameters and constitutive equations for nonlinear/linear elastic materials.
std::map< std::string, boost::shared_ptr< NonlinearElasticElement::FunctionsToCalculatePiolaKirchhoffI< adouble > > > aDoubleMaterialModel
virtual MoFEMErrorCode readConfigFile()
read Elastic materials declaration for blocks and meshsets
std::map< std::string, boost::shared_ptr< NonlinearElasticElement::FunctionsToCalculatePiolaKirchhoffI< double > > > doubleMaterialModel
Hash map of materials for evaluation with double.
virtual MoFEMErrorCode iNit()
MoFEMErrorCode setBlocksOrder()
MoFEM::Interface & mField
std::map< int, BlockOptionData > blockData
Material parameters on blocks.
po::variables_map vM
PetscBool isConfigFileSet
True if config file is set from command line.
ElasticMaterials(MoFEM::Interface &m_field, std::string def_material=MAT_KIRCHHOFF)
bool iNitialized
true if class is initialized
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
Deprecated interface functions.
Implementation of elastic (non-linear) St. Kirchhoff equation.