-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stress extrapolation #1179
Merged
Merged
stress extrapolation #1179
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fa30613
adding preliminary stress extrapolation implementation (untested)
samuelpmishLLNL 7b30197
add TODOs
samuelpmishLLNL c3a378a
making a more interesting test
samuelpmish 2cc04e6
Merge branch 'develop' into mish2/stress_extrapolation
samuelpmish 2e091db
add an example showing how to output derived quantities (e.g. J2 stress)
samuelpmish f7fdc66
pass communicator to CG + bump up iteration count
samuelpmish 9141b83
Merge branch 'develop' into mish2/stress_extrapolation
tupek2 61ae643
add to_3x3 function, fix shadowed variable warning
samuelpmishLLNL 67fa85f
Merge branch 'develop' into mish2/stress_extrapolation
white238 386442c
Merge branch 'develop' into mish2/stress_extrapolation
samuelpmish d1d01b5
fix shadowing warning from gcc, add doxygen comments for new functions
samuelpmish b04f7b1
update variable name on variant doxygen
samuelpmish 4976fca
apply style patch
samuelpmish 3a785a5
add fit.hpp to the list of physics_headers
samuelpmish a374cb5
Merge branch 'develop' into mish2/stress_extrapolation
samuelpmishLLNL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and | ||
// other Serac Project Developers. See the top-level LICENSE file for | ||
// details. | ||
// | ||
// SPDX-License-Identifier: (BSD-3-Clause) | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
#include "serac/numerics/functional/functional.hpp" | ||
#include "serac/numerics/functional/tensor.hpp" | ||
#include "serac/physics/state/finite_element_state.hpp" | ||
|
||
namespace serac { | ||
|
||
namespace detail { | ||
|
||
/// @overload | ||
template <int dim, typename signature, int... i, typename func, typename... T> | ||
FiniteElementState fit(std::integer_sequence<int, i...>, func f, mfem::ParMesh& mesh, const T&... solution_fields) | ||
{ | ||
// signature looks like return_type(arg0_type, arg1_type); | ||
// so this unpacks the return type | ||
using output_space = typename FunctionSignature<signature>::return_type; | ||
|
||
FiniteElementState fitted_field(mesh, output_space{}); | ||
fitted_field = 0.0; | ||
|
||
// mass term | ||
serac::Functional<output_space(output_space)> phi_phi(&fitted_field.space(), {&fitted_field.space()}); | ||
phi_phi.AddDomainIntegral( | ||
Dimension<dim>{}, DependsOn<0>{}, | ||
[](double /*t*/, auto /*x*/, auto u) { | ||
return tuple{get<0>(u), zero{}}; | ||
}, | ||
mesh); | ||
auto M = get<1>(phi_phi(DifferentiateWRT<0>{}, 0.0 /* t */, fitted_field)); | ||
|
||
// rhs | ||
std::array<const mfem::ParFiniteElementSpace*, sizeof...(T)> trial_spaces = {&solution_fields.space()...}; | ||
serac::Functional<signature> phi_f(&fitted_field.space(), trial_spaces); | ||
phi_f.AddDomainIntegral(Dimension<dim>{}, DependsOn<i...>{}, f, mesh); | ||
mfem::Vector b = phi_f(0.0, solution_fields...); | ||
|
||
mfem::CGSolver cg(MPI_COMM_WORLD); | ||
cg.SetOperator(M); | ||
cg.SetRelTol(1e-12); | ||
cg.SetMaxIter(500); | ||
cg.SetPrintLevel(2); | ||
cg.Mult(b, fitted_field); | ||
|
||
return fitted_field; | ||
} | ||
|
||
} // namespace detail | ||
|
||
/** | ||
* @brief determine field parameters to approximate the output of a user-provided q-function | ||
* @param[in] f the user-provided function to approximate | ||
* @param[in] mesh the region over which to approximate the function f | ||
* @param[in] solution_fields [optional] any auxiliary field quantities needed to evaluate f | ||
* | ||
* @note: mesh is passed by non-const ref because mfem mutates the mesh when creating ParGridFunctions | ||
*/ | ||
template <int dim, typename signature, int... n, typename func, typename... T> | ||
FiniteElementState fit(func f, mfem::ParMesh& mesh, const T&... solution_fields) | ||
{ | ||
auto iseq = std::make_integer_sequence<int, sizeof...(T)>{}; | ||
return detail::fit<dim, signature>(iseq, f, mesh, solution_fields...); | ||
} | ||
|
||
} // namespace serac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and | ||
// other Serac Project Developers. See the top-level LICENSE file for | ||
// details. | ||
// | ||
// SPDX-License-Identifier: (BSD-3-Clause) | ||
|
||
#include "serac/physics/fit.hpp" | ||
#include "serac/numerics/functional/functional.hpp" | ||
|
||
#include "serac/mesh/mesh_utils.hpp" | ||
#include "serac/physics/solid_mechanics.hpp" | ||
#include "serac/physics/materials/solid_material.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace serac; | ||
using namespace serac::profiling; | ||
|
||
int num_procs, myid; | ||
int nsamples = 1; // because mfem doesn't take in unsigned int | ||
|
||
int n = 0; | ||
double t = 0.0; | ||
|
||
template <typename output_space> | ||
void stress_extrapolation_test() | ||
{ | ||
int serial_refinement = 2; | ||
int parallel_refinement = 0; | ||
|
||
std::string filename = SERAC_REPO_DIR "/data/meshes/notched_plate.mesh"; | ||
|
||
auto mesh_ = mesh::refineAndDistribute(buildMeshFromFile(filename), serial_refinement, parallel_refinement); | ||
|
||
constexpr int p = 2; | ||
constexpr int dim = 2; | ||
|
||
using input_space = H1<2, dim>; | ||
|
||
// Create DataStore | ||
axom::sidre::DataStore datastore; | ||
serac::StateManager::initialize(datastore, "solid_mechanics_J2_test"); | ||
|
||
// Construct the appropriate dimension mesh and give it to the data store | ||
|
||
std::string mesh_tag{"mesh"}; | ||
|
||
auto& pmesh = StateManager::setMesh(std::move(mesh_), mesh_tag); | ||
|
||
LinearSolverOptions linear_options{.linear_solver = LinearSolver::SuperLU}; | ||
|
||
NonlinearSolverOptions nonlinear_options{.nonlin_solver = NonlinearSolver::Newton, | ||
.relative_tol = 1.0e-12, | ||
.absolute_tol = 1.0e-12, | ||
.max_iterations = 5000, | ||
.print_level = 1}; | ||
|
||
FiniteElementState sigma_J2(pmesh, output_space{}, "sigma_J2"); | ||
|
||
SolidMechanics<p, dim, serac::Parameters<output_space> > solid_solver( | ||
nonlinear_options, linear_options, solid_mechanics::default_quasistatic_options, GeometricNonlinearities::Off, | ||
"solid_mechanics", mesh_tag, {"sigma_J2"}); | ||
|
||
solid_mechanics::NeoHookean mat{ | ||
1.0, // density | ||
100.0, // bulk modulus | ||
50.0 // shear modulus | ||
}; | ||
|
||
solid_solver.setMaterial(mat); | ||
|
||
// prescribe small displacement at each hole, pulling the plate apart | ||
std::set<int> top_hole = {2}; | ||
auto up = [](const mfem::Vector&, mfem::Vector& u) -> void { u[1] = 0.01; }; | ||
solid_solver.setDisplacementBCs(top_hole, up); | ||
|
||
std::set<int> bottom_hole = {3}; | ||
auto down = [](const mfem::Vector&, mfem::Vector& u) -> void { u[1] = -0.01; }; | ||
solid_solver.setDisplacementBCs(bottom_hole, down); | ||
|
||
auto zero_displacement = [](const mfem::Vector&, mfem::Vector& u) -> void { u = 0.0; }; | ||
solid_solver.setDisplacement(zero_displacement); | ||
|
||
// Finalize the data structures | ||
solid_solver.completeSetup(); | ||
|
||
solid_solver.outputStateToDisk("paraview" + std::to_string(n)); | ||
|
||
double dt = 1.0; | ||
solid_solver.advanceTimestep(dt); | ||
|
||
auto u = solid_solver.displacement(); | ||
|
||
Empty internal_variables{}; | ||
|
||
sigma_J2 = fit<dim, output_space(input_space)>( | ||
[&](double /*t*/, [[maybe_unused]] auto position, [[maybe_unused]] auto displacement_) { | ||
mat3 du_dx = to_3x3(get_value(get<1>(displacement_))); | ||
auto stress = mat(internal_variables, du_dx); | ||
return tuple{I2(dev(stress)), zero{}}; | ||
}, | ||
pmesh, u); | ||
|
||
solid_solver.setParameter(0, sigma_J2); | ||
|
||
solid_solver.outputStateToDisk("paraview" + std::to_string(n)); | ||
n++; | ||
} | ||
|
||
TEST(StressExtrapolation, PiecewiseConstant2D) { stress_extrapolation_test<L2<0> >(); } | ||
TEST(StressExtrapolation, PiecewiseLinear2D) { stress_extrapolation_test<H1<1> >(); } | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
::testing::InitGoogleTest(&argc, argv); | ||
MPI_Init(&argc, &argv); | ||
MPI_Comm_size(MPI_COMM_WORLD, &num_procs); | ||
MPI_Comm_rank(MPI_COMM_WORLD, &myid); | ||
|
||
axom::slic::SimpleLogger logger; | ||
|
||
int result = RUN_ALL_TESTS(); | ||
MPI_Finalize(); | ||
return result; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the offending line of code that caused the incorrect results in parallel. Originally, I created the
CGSolver
without the parallel communicator which made each processor solve its own problem in isolation, rather than together.