-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMechanicalPhysics.cc
More file actions
634 lines (580 loc) · 25.2 KB
/
Copy pathMechanicalPhysics.cc
File metadata and controls
634 lines (580 loc) · 25.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
/* SPDX-FileCopyrightText: Copyright (c) 2022 - 2026, the adamantine authors.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <MechanicalPhysics.hh>
#include <instantiation.hh>
#include <deal.II/base/symmetric_tensor.h>
#include <deal.II/base/tensor.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/fe/fe_nothing.h>
#include <deal.II/fe/fe_q.h>
#include <deal.II/hp/fe_values.h>
#include <deal.II/lac/la_parallel_vector.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/numerics/vector_tools.h>
#ifdef ADAMANTINE_WITH_CALIPER
#include <caliper/cali.h>
#endif
namespace adamantine
{
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
MechanicalPhysics<dim, n_materials, p_order, MaterialStates, MemorySpaceType>::
MechanicalPhysics(
MPI_Comm const &communicator, unsigned int const fe_degree,
Geometry<dim> &geometry, Boundary const &boundary,
MaterialProperty<dim, n_materials, p_order, MaterialStates,
MemorySpaceType> &material_properties,
std::vector<double> const &reference_temperatures)
: _geometry(geometry), _boundary(boundary),
_material_properties(material_properties),
_dof_handler(_geometry.get_triangulation()),
_solution_transfer(_dof_handler),
_cell_data_transfer(
dynamic_cast<const dealii::parallel::distributed::Triangulation<dim>
&>(_dof_handler.get_triangulation()))
{
// Create the FECollection
_fe_collection.push_back(
dealii::FESystem<dim>(dealii::FE_Q<dim>(fe_degree) ^ dim));
_fe_collection.push_back(
dealii::FESystem<dim>(dealii::FE_Nothing<dim>() ^ dim));
// Create the QCollection
_q_collection.push_back(dealii::QGauss<dim>(fe_degree + 1));
_q_collection.push_back(dealii::QGauss<dim>(1));
// Solve the mechanical problem only on the part of the domain that has solid
// material.
unsigned int n_active_cells =
_dof_handler.get_triangulation().n_active_cells();
for (auto const &cell :
dealii::filter_iterators(_dof_handler.active_cell_iterators(),
dealii::IteratorFilters::LocallyOwnedCell()))
{
if (_material_properties.get_state_ratio(
cell, MaterialStates::State::solid) > 0.99)
{
cell->set_active_fe_index(0);
}
else
{
cell->set_active_fe_index(1);
}
}
// Create the mechanical operator
_mechanical_operator =
std::make_unique<MechanicalOperator<dim, n_materials, p_order,
MaterialStates, MemorySpaceType>>(
communicator, _material_properties, reference_temperatures);
// Create the data used to compute the stress tensor
unsigned int const n_quad_pts = _q_collection.max_n_quadrature_points();
_plastic_internal_variable.reserve(n_active_cells);
for (auto const &cell : _dof_handler.active_cell_iterators())
{
if (cell->is_locally_owned())
{
auto elastic_limit = _material_properties.get_mechanical_property(
cell, StateProperty::elastic_limit);
_plastic_internal_variable.emplace_back(
std::vector<double>(n_quad_pts, elastic_limit));
}
else
{
_plastic_internal_variable.emplace_back(std::vector<double>(
n_quad_pts, std::numeric_limits<double>::signaling_NaN()));
}
}
_stress.resize(n_active_cells,
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
_back_stress.resize(n_active_cells,
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
}
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
MemorySpaceType>::
setup_dofs(std::vector<std::shared_ptr<BodyForce<dim>>> const &body_forces)
{
_dof_handler.distribute_dofs(_fe_collection);
dealii::IndexSet locally_relevant_dofs =
dealii::DoFTools::extract_locally_relevant_dofs(_dof_handler);
dealii::IndexSet locally_owned_dofs = _dof_handler.locally_owned_dofs();
_affine_constraints.reinit(locally_owned_dofs, locally_relevant_dofs);
dealii::DoFTools::make_hanging_node_constraints(_dof_handler,
_affine_constraints);
std::map<dealii::types::boundary_id, const dealii::Function<dim> *>
boundary_function_map;
dealii::Functions::ZeroFunction<dim> zero_function(dim);
auto boundary_ids = _boundary.get_boundary_ids(BoundaryType::clamped);
for (auto id : boundary_ids)
{
boundary_function_map[id] = &zero_function;
}
dealii::VectorTools::interpolate_boundary_values(
_dof_handler, boundary_function_map, _affine_constraints);
_affine_constraints.close();
_mechanical_operator->reinit(_dof_handler, _affine_constraints, _q_collection,
body_forces);
}
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
MemorySpaceType>::
update_rhs(std::vector<std::shared_ptr<BodyForce<dim>>> const &body_forces)
{
_mechanical_operator->assemble_rhs(body_forces);
}
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
MemorySpaceType>::
update_rhs(
dealii::DoFHandler<dim> const &thermal_dof_handler,
dealii::LA::distributed::Vector<double, dealii::MemorySpace::Host> const
&temperature,
std::vector<bool> const &has_melted,
std::vector<std::shared_ptr<BodyForce<dim>>> const &body_forces)
{
_mechanical_operator->update_temperature(thermal_dof_handler, temperature,
has_melted);
_mechanical_operator->assemble_rhs(body_forces);
}
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
MemorySpaceType>::prepare_transfer_mpi()
{
_old_displacement.update_ghost_values();
_solution_transfer.prepare_for_coarsening_and_refinement(_old_displacement);
_data_to_transfer.clear();
unsigned int const n_quad_pts = _q_collection.max_n_quadrature_points();
unsigned int const n_doubles_per_quad_plastic = 1;
unsigned int const n_doubles_per_quad_stress =
dealii::SymmetricTensor<2, dim>::n_independent_components;
unsigned int const n_doubles_per_quad =
n_doubles_per_quad_plastic + n_doubles_per_quad_stress * 2;
std::vector<double> dummy_cell_data(n_quad_pts * n_doubles_per_quad,
std::numeric_limits<double>::infinity());
unsigned int cell_id = 0;
for (auto const &cell : _dof_handler.active_cell_iterators())
{
if (cell->is_locally_owned())
{
std::vector<double> cell_data(n_quad_pts * n_doubles_per_quad);
unsigned int const stress_offset =
n_quad_pts * n_doubles_per_quad_plastic;
unsigned int const back_stress_offset =
n_quad_pts * (n_doubles_per_quad_plastic + n_doubles_per_quad_stress);
std::copy(_plastic_internal_variable[cell_id].begin(),
_plastic_internal_variable[cell_id].end(), cell_data.begin());
for (unsigned int quad = 0; quad < n_quad_pts; ++quad)
{
for (unsigned int i = 0; i < n_doubles_per_quad_stress; ++i)
{
cell_data[stress_offset + quad * n_doubles_per_quad_stress + i] =
_stress[cell_id][quad].access_raw_entry(i);
cell_data[back_stress_offset + quad * n_doubles_per_quad_stress + i] =
_back_stress[cell_id][quad].access_raw_entry(i);
}
}
_data_to_transfer.push_back(std::move(cell_data));
}
else
{
_data_to_transfer.push_back(dummy_cell_data);
}
++cell_id;
}
_cell_data_transfer.prepare_for_coarsening_and_refinement(_data_to_transfer);
}
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
MemorySpaceType>::complete_transfer_mpi()
{
_dof_handler.distribute_dofs(_fe_collection);
const dealii::IndexSet locally_relevant_dofs =
dealii::DoFTools::extract_locally_relevant_dofs(_dof_handler);
_old_displacement.reinit(_dof_handler.locally_owned_dofs(),
locally_relevant_dofs,
#if DEAL_II_VERSION_GTE(9, 7, 0)
_dof_handler.get_mpi_communicator()
#else
_dof_handler.get_communicator()
#endif
);
_solution_transfer.interpolate(_old_displacement);
auto n_active_cells = _dof_handler.get_triangulation().n_active_cells();
unsigned int const n_quad_pts = _q_collection.max_n_quadrature_points();
_plastic_internal_variable.resize(n_active_cells,
std::vector<double>(n_quad_pts));
_stress.resize(n_active_cells,
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
_back_stress.resize(n_active_cells,
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
unsigned int const n_doubles_per_quad_plastic = 1;
unsigned int const n_doubles_per_quad_stress =
dealii::SymmetricTensor<2, dim>::n_independent_components;
unsigned int const n_doubles_per_quad =
n_doubles_per_quad_plastic + n_doubles_per_quad_stress * 2;
std::vector<std::vector<double>> data_to_unpack(
n_active_cells, std::vector<double>(n_doubles_per_quad * n_quad_pts));
_cell_data_transfer.unpack(data_to_unpack);
unsigned int cell_id = 0;
for (auto const &cell : _dof_handler.active_cell_iterators())
{
if (cell->is_locally_owned())
{
unsigned int const stress_offset =
n_quad_pts * n_doubles_per_quad_plastic;
unsigned int const back_stress_offset =
n_quad_pts * (n_doubles_per_quad_plastic + n_doubles_per_quad_stress);
std::copy(data_to_unpack[cell_id].begin(),
data_to_unpack[cell_id].begin() + stress_offset,
_plastic_internal_variable[cell_id].begin());
for (unsigned int quad = 0; quad < n_quad_pts; ++quad)
{
for (unsigned int i = 0; i < n_doubles_per_quad_stress; ++i)
{
_stress[cell_id][quad].access_raw_entry(i) =
data_to_unpack[cell_id][stress_offset +
quad * n_doubles_per_quad_stress + i];
_back_stress[cell_id][quad].access_raw_entry(i) =
data_to_unpack[cell_id][back_stress_offset +
quad * n_doubles_per_quad_stress + i];
}
}
}
++cell_id;
}
}
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
MemorySpaceType>::
setup_dofs(
dealii::DoFHandler<dim> const &thermal_dof_handler,
dealii::LA::distributed::Vector<double, dealii::MemorySpace::Host> const
&temperature,
std::vector<bool> const &has_melted, bool rebuild_matrix,
std::vector<std::shared_ptr<BodyForce<dim>>> const &body_forces)
{
_mechanical_operator->update_temperature(thermal_dof_handler, temperature,
has_melted);
// Update the active fe indices, the plastic variables, and the displacement.
unsigned int const n_quad_pts = _q_collection.max_n_quadrature_points();
unsigned int cell_id = 0;
std::vector<std::vector<double>> saved_old_displacement;
std::vector<std::vector<double>> tmp_plastic_internal_variable;
std::vector<std::vector<dealii::SymmetricTensor<2, dim>>> tmp_stress;
std::vector<std::vector<dealii::SymmetricTensor<2, dim>>> tmp_back_stress;
// The number of cells to activate/deactive should be small, so we can
// already reserve the memory.
unsigned int const n_dofs_per_cell = _fe_collection.max_dofs_per_cell();
unsigned int const n_old_active_cells = _plastic_internal_variable.size();
std::vector<dealii::types::global_dof_index> global_dof_indices(
n_dofs_per_cell);
tmp_plastic_internal_variable.reserve(n_old_active_cells);
tmp_stress.reserve(n_old_active_cells);
tmp_back_stress.reserve(_back_stress.size());
// First we save _old_displacement if it exists
if (_old_displacement.size())
{
_old_displacement.update_ghost_values();
std::vector<double> cell_values(n_dofs_per_cell);
saved_old_displacement.reserve(n_old_active_cells);
for (auto const &cell : _dof_handler.active_cell_iterators())
{
if (cell->is_locally_owned())
{
auto fe_index = cell->active_fe_index();
if (fe_index == 0)
{
// The cell contains solid material, we need to save the displacement
cell->get_dof_indices(global_dof_indices);
for (unsigned int i = 0; i < n_dofs_per_cell; ++i)
{
cell_values[i] = _old_displacement[global_dof_indices[i]];
}
}
else
{
// The cell does not contain material or it is liquid. The
// displacement is ignored.
cell_values.assign(n_dofs_per_cell, 0.);
}
saved_old_displacement.push_back(cell_values);
}
else
{
saved_old_displacement.push_back(std::vector<double>(n_dofs_per_cell));
}
}
}
// Now we can update the fe indices and the plastic variables.
for (auto const &cell : _dof_handler.active_cell_iterators())
{
if (cell->is_locally_owned())
{
auto current_fe_index = cell->active_fe_index();
if (_material_properties.get_state_ratio(
cell, MaterialStates::State::solid) > 0.99)
{
// Only enable the cell if it is also enabled for the thermal simulation
// Get the thermal DoFHandler cell iterator
dealii::DoFCellAccessor<dim, dim, false> thermal_cell(
&(_dof_handler.get_triangulation()), cell->level(), cell->index(),
&thermal_dof_handler);
auto updated_fe_index = thermal_cell.active_fe_index();
if (current_fe_index == updated_fe_index)
{
// The cells is unchanged, we just copy the plastic variables as-is.
tmp_plastic_internal_variable.push_back(
_plastic_internal_variable[cell_id]);
tmp_stress.push_back(_stress[cell_id]);
tmp_back_stress.push_back(_back_stress[cell_id]);
}
else
{
// The cell has solidified or material has been added. The new cells
// are initialized with default values.
auto elastic_limit = _material_properties.get_mechanical_property(
cell, StateProperty::elastic_limit);
tmp_plastic_internal_variable.push_back(
std::vector<double>(n_quad_pts, elastic_limit));
tmp_stress.push_back(
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
tmp_back_stress.push_back(
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
cell->set_active_fe_index(updated_fe_index);
rebuild_matrix = true;
}
}
else
{
if (current_fe_index == 0)
{
rebuild_matrix = true;
}
// The cell is liquid. We don't need to save the plastic variables.
cell->set_active_fe_index(1);
tmp_plastic_internal_variable.push_back(std::vector<double>(
n_quad_pts, std::numeric_limits<double>::signaling_NaN()));
tmp_stress.push_back(
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
tmp_back_stress.push_back(
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
}
}
else
{
tmp_plastic_internal_variable.push_back(std::vector<double>(
n_quad_pts, std::numeric_limits<double>::signaling_NaN()));
tmp_stress.push_back(
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
tmp_back_stress.push_back(
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
}
++cell_id;
}
// Check if we need to rebuild the matrix
rebuild_matrix =
dealii::Utilities::MPI::logical_or(rebuild_matrix,
#if DEAL_II_VERSION_GTE(9, 7, 0)
_dof_handler.get_mpi_communicator()
#else
_dof_handler.get_communicator()
#endif
);
// If we do not need to rebuild the matrix. Update the rhs and exit.
if (!rebuild_matrix)
{
update_rhs(body_forces);
return;
}
_plastic_internal_variable.swap(tmp_plastic_internal_variable);
_stress.swap(tmp_stress);
_back_stress.swap(tmp_back_stress);
setup_dofs(body_forces);
// Update _old_displacement if necessary
const dealii::IndexSet locally_relevant_dofs =
dealii::DoFTools::extract_locally_relevant_dofs(_dof_handler);
const dealii::IndexSet locally_owned_dofs = _dof_handler.locally_owned_dofs();
_old_displacement.reinit(locally_owned_dofs, locally_relevant_dofs,
#if DEAL_II_VERSION_GTE(9, 7, 0)
_dof_handler.get_mpi_communicator()
#else
_dof_handler.get_communicator()
#endif
);
if (saved_old_displacement.size())
{
cell_id = 0;
for (auto const &cell : _dof_handler.active_cell_iterators())
{
if (cell->is_locally_owned())
{
auto fe_index = cell->active_fe_index();
if (fe_index == 0)
{
cell->get_dof_indices(global_dof_indices);
for (unsigned int i = 0; i < n_dofs_per_cell; ++i)
{
if (locally_owned_dofs.is_element(global_dof_indices[i]))
_old_displacement[global_dof_indices[i]] =
saved_old_displacement[cell_id][i];
}
}
}
++cell_id;
}
_old_displacement.compress(dealii::VectorOperation::insert);
}
}
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
dealii::LA::distributed::Vector<double, dealii::MemorySpace::Host>
MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
MemorySpaceType>::solve()
{
#ifdef ADAMANTINE_WITH_CALIPER
CALI_MARK_BEGIN("solve mechanical system");
#endif
dealii::IndexSet locally_owned_dofs = _dof_handler.locally_owned_dofs();
dealii::IndexSet locally_relevant_dofs =
dealii::DoFTools::extract_locally_relevant_dofs(_dof_handler);
#if DEAL_II_VERSION_GTE(9, 7, 0) && defined(DEAL_II_TRILINOS_WITH_TPETRA)
using TrilinosVectorType = dealii::LinearAlgebra::TpetraWrappers::Vector<
double, dealii::MemorySpace::Default>;
#else
using TrilinosVectorType = dealii::TrilinosWrappers::MPI::Vector;
#endif
TrilinosVectorType displacement(
locally_owned_dofs, _mechanical_operator->rhs().get_mpi_communicator());
TrilinosVectorType rhs_device(
locally_owned_dofs, _mechanical_operator->rhs().get_mpi_communicator());
dealii::LinearAlgebra::ReadWriteVector<double> rw_vector(locally_owned_dofs);
rw_vector.import_elements(_mechanical_operator->rhs(),
dealii::VectorOperation::insert);
rhs_device.import_elements(rw_vector, dealii::VectorOperation::insert);
// Solve the mechanical problem assuming that the deformation is elastic
// TODO check that we are computing only difference of the displacement
// compared to the previous time step!!
unsigned int const max_iter = _dof_handler.n_dofs() / 10;
double const tol = 1e-12 * _mechanical_operator->rhs().l2_norm();
dealii::SolverControl solver_control(max_iter, tol);
dealii::SolverCG<TrilinosVectorType> cg(solver_control);
cg.solve(_mechanical_operator->system_matrix(), displacement, rhs_device,
_mechanical_operator->preconditioner());
rw_vector.import_elements(displacement, dealii::VectorOperation::insert);
dealii::LA::distributed::Vector<double, dealii::MemorySpace::Host>
displacement_host(locally_owned_dofs, locally_relevant_dofs,
_mechanical_operator->rhs().get_mpi_communicator());
displacement_host.import_elements(rw_vector, dealii::VectorOperation::insert);
_affine_constraints.distribute(displacement_host);
// Compute the new stress assuming the deformation is elastic.
// If the stress is under the yield criterion, the deformation is elastic and
// we are done. Otherwise we need to use the radial return algorithm to
// compute the plastic deformation.
dealii::LA::distributed::Vector<double, dealii::MemorySpace::Host>
incremental_displacement(
locally_owned_dofs, locally_relevant_dofs,
_mechanical_operator->rhs().get_mpi_communicator());
incremental_displacement = displacement_host;
if (_old_displacement.size() > 0)
{
incremental_displacement -= _old_displacement;
}
incremental_displacement.update_ghost_values();
compute_stress(incremental_displacement);
_old_displacement.swap(displacement_host);
#ifdef ADAMANTINE_WITH_CALIPER
CALI_MARK_END("solve mechanical system");
#endif
return _old_displacement;
}
template <int dim, int n_materials, int p_order, typename MaterialStates,
typename MemorySpaceType>
void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
MemorySpaceType>::
compute_stress(
dealii::LA::distributed::Vector<double, dealii::MemorySpace::Host> const
&displacement)
{
dealii::hp::FEValues<dim> displacement_hp_fe_values(
_fe_collection, _q_collection, dealii::update_gradients);
unsigned int const n_q_points = _q_collection.max_n_quadrature_points();
std::vector<dealii::SymmetricTensor<2, dim>> strain_tensor(n_q_points);
const dealii::FEValuesExtractors::Vector displacement_extr(0);
unsigned int cell_id = 0;
for (auto const &cell : _dof_handler.active_cell_iterators())
{
if (cell->is_locally_owned() && cell->active_fe_index() == 0)
{
// Formulation based on the combined isotropic-kinematic hardening model
// for J2 plasticity in Chapter 3 of R. Borja, Plasticity: Modeling and
// Computation, Springer-Verlag, 2013. DOI: 10.1007/978-3-642-38547-6
//
// Compute the strain. We get the strain for all the quadrature points at
// once.
displacement_hp_fe_values.reinit(cell);
auto const &fe_values = displacement_hp_fe_values.get_present_fe_values();
fe_values[displacement_extr].get_function_symmetric_gradients(
displacement, strain_tensor);
double const lambda = _material_properties.get_mechanical_property(
cell, StateProperty::lame_first_parameter);
double const mu = _material_properties.get_mechanical_property(
cell, StateProperty::lame_second_parameter);
double const plastic_modulus =
_material_properties.get_mechanical_property(
cell, StateProperty::plastic_modulus);
double const iso_hardening_coef =
_material_properties.get_mechanical_property(
cell, StateProperty::isotropic_hardening);
dealii::SymmetricTensor<4, dim> stiffness_tensor =
lambda * dealii::outer_product(dealii::unit_symmetric_tensor<dim>(),
dealii::unit_symmetric_tensor<dim>()) +
2 * mu * dealii::identity_tensor<dim>();
// Loop over the quadrature points.
for (auto const q : fe_values.quadrature_point_indices())
{
// Compute the trial elastic stress.
dealii::SymmetricTensor<2, dim> elastic_stress = _stress[cell_id][q];
elastic_stress += stiffness_tensor * strain_tensor[q];
auto stress_deviator = dealii::deviator(elastic_stress);
auto effective_stress = stress_deviator - _back_stress[cell_id][q];
double const effective_stress_norm = effective_stress.norm();
if (effective_stress_norm < _plastic_internal_variable[cell_id][q])
{
// The deformation is elastic. We just update the stress with the
// elastic stress.
_stress[cell_id][q] = elastic_stress;
}
else
{
// The deformation is plastic. We need to compute a new stress and
// update the plastic internal variable and the back stress.
double plastic_strain_increment =
(effective_stress_norm - _plastic_internal_variable[cell_id][q]) /
(2. * mu + plastic_modulus);
auto plastic_flow_direction =
effective_stress / effective_stress_norm;
// Update stress
_stress[cell_id][q] = elastic_stress - 2. * mu *
plastic_strain_increment *
plastic_flow_direction;
// Update plastic internal variable
_plastic_internal_variable[cell_id][q] +=
iso_hardening_coef * plastic_modulus * plastic_strain_increment;
// Update back stress
_back_stress[cell_id][q] +=
(1. - iso_hardening_coef) * plastic_modulus *
plastic_strain_increment * plastic_flow_direction;
}
}
}
++cell_id;
}
}
} // namespace adamantine
INSTANTIATE_DIM_NMAT_PORDER_MATERIALSTATES_HOST(MechanicalPhysics)
INSTANTIATE_DIM_NMAT_PORDER_MATERIALSTATES_DEVICE(MechanicalPhysics)