Skip to content

Commit

Permalink
Trying to fix a potential memory issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
tupek2 committed Sep 13, 2024
1 parent 9cdca8a commit 9a70819
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/serac/physics/solid_mechanics_contact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ class SolidMechanicsContact<order, dim, Parameters<parameter_space...>,
// See https://github.com/mfem/mfem/issues/3531
mfem::Vector r_blk(r, 0, displacement_.Size());
r_blk = res;
mfem::Vector uPlusShapeDisp = u;
mfem::Vector uPlusShapeDisp(u.Size());
uPlusShapeDisp = u;
uPlusShapeDisp += shape_displacement_;

contact_.residualFunction(uPlusShapeDisp, r);
r_blk.SetSubVector(bcs_.allEssentialTrueDofs(), 0.0);
};
Expand All @@ -139,7 +141,8 @@ class SolidMechanicsContact<order, dim, Parameters<parameter_space...>,
*parameters_[parameter_indices].state...);
J_ = assemble(drdu);

mfem::Vector uPlusShapeDisp = u;
mfem::Vector uPlusShapeDisp(u.Size());
uPlusShapeDisp = u;
uPlusShapeDisp += shape_displacement_;

// create block operator holding jacobian contributions
Expand Down Expand Up @@ -178,7 +181,8 @@ class SolidMechanicsContact<order, dim, Parameters<parameter_space...>,
*parameters_[parameter_indices].state...);
J_ = assemble(drdu);

mfem::Vector uPlusShapeDisp = u;
mfem::Vector uPlusShapeDisp(u.Size());
uPlusShapeDisp = u;
uPlusShapeDisp += shape_displacement_;

// get 11-block holding jacobian contributions
Expand Down Expand Up @@ -275,8 +279,10 @@ class SolidMechanicsContact<order, dim, Parameters<parameter_space...>,
*parameters_[parameter_indices].state...);
auto jacobian = assemble(drdu);

mfem::Vector uPlusShapeDisp = displacement_;
mfem::Vector uPlusShapeDisp(displacement_.Size());
uPlusShapeDisp = displacement_;
uPlusShapeDisp += shape_displacement_;

auto block_J = contact_.jacobianFunction(uPlusShapeDisp, jacobian.release());
block_J->owns_blocks = false;
jacobian = std::unique_ptr<mfem::HypreParMatrix>(static_cast<mfem::HypreParMatrix*>(&block_J->GetBlock(0, 0)));
Expand All @@ -300,8 +306,10 @@ class SolidMechanicsContact<order, dim, Parameters<parameter_space...>,

auto drdshape_mat = assemble(drdshape);

mfem::Vector uPlusShapeDisp = displacement_;
mfem::Vector uPlusShapeDisp(displacement_.Size());
uPlusShapeDisp = displacement_;
uPlusShapeDisp += shape_displacement_;

auto block_J = contact_.jacobianFunction(uPlusShapeDisp, drdshape_mat.release());
block_J->owns_blocks = false;
drdshape_mat = std::unique_ptr<mfem::HypreParMatrix>(static_cast<mfem::HypreParMatrix*>(&block_J->GetBlock(0, 0)));
Expand Down

0 comments on commit 9a70819

Please sign in to comment.