Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 35 additions & 27 deletions source/MechanicalPhysics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,23 @@ MechanicalPhysics<dim, n_materials, p_order, MaterialStates, MemorySpaceType>::
_material_properties(material_properties),
_dof_handler(_geometry.get_triangulation()),
_solution_transfer(_dof_handler),
_closest_quad_point_adaptation(dealii::QGauss<dim>(fe_degree + 1)),
_cell_data_transfer(
dynamic_cast<const dealii::parallel::distributed::Triangulation<dim>
&>(_dof_handler.get_triangulation()))
&>(_dof_handler.get_triangulation()),
/* transfer_variable_size_data */ false,
[&](const typename dealii::Triangulation<dim>::cell_iterator &parent,
const std::vector<std::vector<double>> &parent_values)
{
return _closest_quad_point_adaptation.coarse_to_fine(parent,
parent_values);
},
[&](const typename dealii::Triangulation<dim>::cell_iterator &parent,
const std::vector<std::vector<std::vector<double>>> &child_values)
{
return _closest_quad_point_adaptation.fine_to_coarse(parent,
child_values);
})
Comment thread
masterleinad marked this conversation as resolved.
{
// Create the FECollection
_fe_collection.push_back(
Expand Down Expand Up @@ -169,34 +183,32 @@ void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,

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());

std::vector<std::vector<double>> dummy_cell_data(
n_quad_pts, std::vector<double>(n_doubles_per_quad,
std::numeric_limits<double>::infinity()));
std::vector<std::vector<double>> cell_data = dummy_cell_data;
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 stress_offset = 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());
n_doubles_per_quad_plastic + n_doubles_per_quad_stress;

for (unsigned int quad = 0; quad < n_quad_pts; ++quad)
{
std::vector<double> &cell_data_quad = cell_data[quad];
cell_data_quad[0] = _plastic_internal_variable[cell_id][quad];
for (unsigned int i = 0; i < n_doubles_per_quad_stress; ++i)
{
cell_data[stress_offset + quad * n_doubles_per_quad_stress + i] =
cell_data_quad[stress_offset + i] =
_stress[cell_id][quad].access_raw_entry(i);
cell_data[back_stress_offset + quad * n_doubles_per_quad_stress + i] =
cell_data_quad[back_stress_offset + i] =
_back_stress[cell_id][quad].access_raw_entry(i);
}
}
_data_to_transfer.push_back(std::move(cell_data));
_data_to_transfer.push_back(cell_data);
}
else
{
Expand Down Expand Up @@ -242,34 +254,30 @@ void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,

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));
std::vector<std::vector<std::vector<double>>> data_to_unpack(
n_active_cells, std::vector<std::vector<double>>(
n_quad_pts, std::vector<double>(n_doubles_per_quad)));
_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 stress_offset = 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());
n_doubles_per_quad_plastic + n_doubles_per_quad_stress;

for (unsigned int quad = 0; quad < n_quad_pts; ++quad)
{
_plastic_internal_variable[cell_id][quad] =
data_to_unpack[cell_id][quad][0];
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];
data_to_unpack[cell_id][quad][stress_offset + 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];
data_to_unpack[cell_id][quad][back_stress_offset + i];
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions source/MechanicalPhysics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define MECHANICAL_PHYSICS_HH

#include <Boundary.hh>
#include <ClosestSourcePointAdaptation.hh>
#include <Geometry.hh>
#include <MechanicalOperator.hh>

Expand Down Expand Up @@ -183,19 +184,26 @@ private:
dim, dealii::LA::distributed::Vector<double, dealii::MemorySpace::Host>>
_solution_transfer;

/**
* Object used for interpolating to and from the closest quadrature point in
* the cell data transfer object.
*/
adamantine::ClosestQuadPointAdaptation<dim, dim, std::vector<double>>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
adamantine::ClosestQuadPointAdaptation<dim, dim, std::vector<double>>
ClosestQuadPointAdaptation<dim, dim, std::vector<double>>

_closest_quad_point_adaptation;

/**
* Cell data transfer object used for updating _plastic_internal_variable,
* _stress, and _back_stress when the triangulation is updated when adding
* material
*/
dealii::parallel::distributed::CellDataTransfer<
dim, dim, std::vector<std::vector<double>>>
dim, dim, std::vector<std::vector<std::vector<double>>>>
_cell_data_transfer;

/**
* Temporary storaged used by _cell_data_transfer
*/
std::vector<std::vector<double>> _data_to_transfer;
std::vector<std::vector<std::vector<double>>> _data_to_transfer;
};

template <int dim, int n_materials, int p_order, typename MaterialStates,
Expand Down
4 changes: 2 additions & 2 deletions tests/data/thermoelastic_bare_plate.info
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ boundary

refinement
{
n_refinements 0 ; Number of time the cells on the paths of the beams are
n_refinements 1 ; Number of time the cells on the paths of the beams are
; refined
time_steps_between_refinement 100 ; number of time steps after which
; the refinement process is performed
Expand Down Expand Up @@ -123,7 +123,7 @@ time_stepping
method forward_euler ; Possibilities: forward_euler, rk_third_order,
; rk_fourth_order
duration 4.0e0 ; [s]
time_step 4.0e-3 ; [s]
time_step 1.0e-3 ; [s]
}

post_processor
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integration_thermoelastic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(integration_thermoelastic, *utf::tolerance(1.0e-5))
// To generate a new gold solution
// std::cout << "dis l2:" << displacement.l2_norm() << std::endl;

BOOST_TEST(displacement.l2_norm() == 0.21537566016824577);
BOOST_TEST(displacement.l2_norm() == 0.38717686373752414);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex review (P2): This assertion only replaces the expected final displacement norm. It exercises the AMR path, but it does not verify that the nested payload preserves every component of plastic_internal_variable, stress, and back_stress across refinement/coarsening; a lossy transfer could still leave this single aggregate norm within tolerance. Please add a focused regression in test_mechanical_physics (or extend the adaptation test) with distinct values per quadrature point and per component, then assert all components after transfer.

}

BOOST_AUTO_TEST_CASE(integration_thermoelastic_add_material,
Expand Down Expand Up @@ -71,5 +71,5 @@ BOOST_AUTO_TEST_CASE(integration_thermoelastic_add_material,
// For now doing a simple regression test. Without a dof handler, it's hard to
// do something more meaningful with the vector.

BOOST_TEST(displacement.l2_norm() == 0.24117708846731);
BOOST_TEST(displacement.l2_norm() == 0.27838526776051664);
}
Loading