Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
dc6cf98
Trying to establish a more specific design for SystemOfEquation (Syst…
mrtupek2 Apr 11, 2026
2e1778f
Fix multiphysics_time_integrator loose ends
mrtupek2 Apr 11, 2026
513972b
Decouple StateAdvancer from SystemBase, add helper functions.
mrtupek2 Apr 12, 2026
d870691
Try to cleanup construction of systems.
mrtupek2 Apr 12, 2026
7ec5a46
Document and update gretl tracking capabilities
mrtupek2 Apr 12, 2026
2564572
Update gretl_notracking.md with the Graph-Resident but Ephemeral plan
mrtupek2 Apr 12, 2026
ed004cd
Update gretl_notracking.md with the finalized Stop-Gradient approach
mrtupek2 Apr 12, 2026
35a8df8
Update gretl_notracking.md reflecting removal of ScopedGraphDisable
mrtupek2 Apr 12, 2026
533b1e2
Update gretl_notracking.md with the no-recompute optimization
mrtupek2 Apr 12, 2026
6797361
We are trying to usable stress output as an option at the end of soli…
mrtupek2 Apr 13, 2026
9f9d51c
Fix style.:
mrtupek2 Apr 13, 2026
6371ba5
Get solid mechanics problems passing, with style.
mrtupek2 Apr 13, 2026
0e9ddbd
Trying to implement system combine functionality.
mrtupek2 Apr 15, 2026
e7456fc
Increment on the path to coupled systems.
mrtupek2 Apr 15, 2026
5a53f4b
Refactor system interface to make it easy to combine systems.
mrtupek2 Apr 16, 2026
1b46d4c
Implement state variable system.
mrtupek2 Apr 16, 2026
4eecd96
Support a None preconditioner.
mrtupek2 Apr 16, 2026
b91c70a
Working toward our dream interface.
mrtupek2 Apr 17, 2026
dbfc11c
Working on simpler build methods.
mrtupek2 Apr 17, 2026
cad8ebb
trying to test 3 systems, also fix up some solve issues identifies as…
mrtupek2 Apr 17, 2026
2cbf8df
Style.
mrtupek2 Apr 17, 2026
91eeab6
Simplify field and system registration.
mrtupek2 Apr 20, 2026
1220878
Remove duplicated test.
mrtupek2 Apr 20, 2026
f7b90f6
style.
mrtupek2 Apr 20, 2026
8231f28
Clean up some interface issues, rename cz to be clearer.
mrtupek2 Apr 21, 2026
cbc7ed7
Fix style.
mrtupek2 Apr 21, 2026
396392f
Update submodules.
mrtupek2 Apr 21, 2026
16cd1d8
Merge branch 'tupek/system_solver' into tupek/system_solver_extended
mrtupek2 Apr 21, 2026
b461e9c
Remove files that were not indended to be saved
tupek2 Apr 21, 2026
54a04a0
Try to make sure the solver and system responsibilities are clear, cl…
tupek2 Apr 21, 2026
6a69b69
Fix cmake.
tupek2 Apr 21, 2026
63ca16d
Fix docs.
tupek2 Apr 21, 2026
ce5c10e
Use coupled system for interal vars.
tupek2 Apr 21, 2026
00ed115
Fix tests and styles, cleanup duplication.
tupek2 Apr 22, 2026
683ff3a
Working on cleaning up the interface more.
tupek2 Apr 22, 2026
f1b4327
Trying to unify and simplify the interface more.
tupek2 Apr 22, 2026
73ebfb4
Finsih last parts of this increment of design change.
tupek2 Apr 22, 2026
9766610
Fix style.
tupek2 Apr 23, 2026
7186714
Still trying to simplify the interface.
tupek2 Apr 23, 2026
13c504a
Add more examples, and slight clarification of interface issues.
tupek2 Apr 23, 2026
bb01110
Improve examples, more simple syntax.
tupek2 Apr 24, 2026
5ec942b
Working through some improvements.
tupek2 Apr 24, 2026
5e83a33
Working on improving the zero-cycle boundary conditions and time inte…
tupek2 Apr 24, 2026
37a9c6e
Working through various interface improvements.
mrtupek2 Apr 25, 2026
a640dd0
Address some more interface cleanups.
mrtupek2 Apr 26, 2026
a232080
Try to avoid duplication in weak form setup.
mrtupek2 Apr 27, 2026
bc699fa
Merge branch 'develop' into tupek/system_solver_extended
tupek2 Apr 27, 2026
df6dffa
Fix docs.
tupek2 Apr 27, 2026
4a5c481
Merge.
mrtupek2 May 10, 2026
e4a1812
Really refactor to use TimeInfo.
mrtupek2 May 9, 2026
7503dd1
Cleanup the interface a bit more to hide field_store when appropriate.
mrtupek2 May 10, 2026
d8f1a27
Refactor: Remove DependsOn combinatorial explosions and cycle-zero we…
mrtupek2 May 11, 2026
18c6b8a
Trying to simplify zero_cycle stuff.
mrtupek2 May 11, 2026
863b5dd
Update some examples.
mrtupek2 May 11, 2026
81fa042
trying to discretize all odes that are coupled into every coupled phy…
mrtupek2 May 11, 2026
6e84295
Minor changes.
mrtupek2 May 11, 2026
640626c
Put back depends on.
mrtupek2 May 12, 2026
21752aa
Trying to simplify and clarify templating.
mrtupek2 May 12, 2026
24185aa
Simplify coupled interface even more.
mrtupek2 May 12, 2026
784335b
Update system solver api again for coupled systems to make the templa…
mrtupek2 May 12, 2026
0f70b75
Clean up the sphinx a bit.
mrtupek2 May 12, 2026
ebc492e
Fix docs.
mrtupek2 May 13, 2026
6ab30a3
Fix docs, cleanup example sphinx doc.
mrtupek2 May 13, 2026
83f7a67
Allow for a simpler build system interface to better match legacy int…
mrtupek2 May 13, 2026
12de302
Merge branch 'develop' into tupek/system_solver_extended3
tupek2 May 13, 2026
5356443
Improve coupling param templating.
tupek2 May 14, 2026
64d58f0
Docs.
tupek2 May 14, 2026
cf161a1
Merge branch 'develop' into tupek/system_solver_extended
tupek2 May 18, 2026
188d1d0
Merge branch 'develop' into tupek/system_solver_extended
tupek2 May 20, 2026
62eed8b
Try to cleanup a few interface details, simpler TimeInfo material, so…
mrtupek2 May 21, 2026
0d4ebeb
Try to be better about using existing material models with the new in…
mrtupek2 May 21, 2026
3b0c7e9
Try to cleanup material wrappers even more.
mrtupek2 May 21, 2026
a2ab27a
fix docs.
mrtupek2 May 21, 2026
d5ebe10
Merge branch 'develop' into tupek/system_solver_extended
tupek2 Jun 1, 2026
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
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ install(
# Add the conduction examples
add_subdirectory(conduction)

# Add the solid mechanics examples
add_subdirectory(solid_mechanics)

# Add the thermo-mechanics examples
add_subdirectory(thermo_mechanics)

# Add the contact examples
add_subdirectory(contact)

Expand Down
6 changes: 3 additions & 3 deletions examples/contact/homotopy/two_blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ using DensitySpace = smith::L2<disp_order - 1>;

using SolidMaterial = smith::solid_mechanics::NeoHookeanWithFieldDensity;
using SolidWeakFormT =
smith::TimeDiscretizedWeakForm<dim, smith::H1<disp_order, dim>,
smith::Parameters<smith::H1<disp_order, dim>, smith::H1<disp_order, dim>,
smith::H1<disp_order, dim>, DensitySpace>>;
smith::FunctionalWeakForm<dim, smith::H1<disp_order, dim>,
smith::Parameters<smith::H1<disp_order, dim>, smith::H1<disp_order, dim>,
smith::H1<disp_order, dim>, DensitySpace>>;

enum FIELD
{
Expand Down
23 changes: 10 additions & 13 deletions examples/inertia_relief/inertia_relief_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ using DensitySpace = smith::L2<disp_order - 1>;

using SolidMaterial = smith::solid_mechanics::NeoHookeanWithFieldDensity;
using SolidWeakFormT =
smith::TimeDiscretizedWeakForm<dim, smith::H1<disp_order, dim>,
smith::Parameters<smith::H1<disp_order, dim>, smith::H1<disp_order, dim>,
smith::H1<disp_order, dim>, DensitySpace>>;
smith::FunctionalWeakForm<dim, smith::H1<disp_order, dim>,
smith::Parameters<smith::H1<disp_order, dim>, smith::H1<disp_order, dim>,
smith::H1<disp_order, dim>, DensitySpace>>;

enum FIELD
{
Expand Down Expand Up @@ -212,20 +212,17 @@ int main(int argc, char* argv[])

ObjectiveT mass_objective("mass constraining", mesh, param_space_ptrs);

mass_objective.addBodyIntegral(smith::DependsOn<1>{}, mesh->entireBodyName(),
[](double /*t*/, auto /*X*/, auto RHO) { return get<smith::VALUE>(RHO); });
mass_objective.addBodyIntegral(
mesh->entireBodyName(), [](auto /*t_info*/, auto /*X*/, auto /*U*/, auto RHO) { return get<smith::VALUE>(RHO); });
double mass = mass_objective.evaluate(time_info, shape_disp.get(), objective_states);

smith::tensor<double, dim> initial_cg; // center of gravity

for (int i = 0; i < dim; ++i) {
auto cg_objective = std::make_shared<ObjectiveT>("translation " + std::to_string(i), mesh, param_space_ptrs);
cg_objective->addBodyIntegral(smith::DependsOn<0, 1>{}, mesh->entireBodyName(),
[i](double
/*time*/,
auto X, auto U, auto RHO) {
return (get<smith::VALUE>(X)[i] + get<smith::VALUE>(U)[i]) * get<smith::VALUE>(RHO);
});
cg_objective->addBodyIntegral(mesh->entireBodyName(), [i](auto /*t_info*/, auto X, auto U, auto RHO) {
return (get<smith::VALUE>(X)[i] + get<smith::VALUE>(U)[i]) * get<smith::VALUE>(RHO);
});
initial_cg[i] = cg_objective->evaluate(time_info, shape_disp.get(), objective_states) / mass;

constraints.push_back(cg_objective);
Expand All @@ -234,8 +231,8 @@ int main(int argc, char* argv[])
for (int i = 0; i < dim; ++i) {
auto center_rotation_objective =
std::make_shared<ObjectiveT>("rotation" + std::to_string(i), mesh, param_space_ptrs);
center_rotation_objective->addBodyIntegral(smith::DependsOn<0, 1>{}, mesh->entireBodyName(),
[i, initial_cg](double /*time*/, auto X, auto U, auto RHO) {
center_rotation_objective->addBodyIntegral(mesh->entireBodyName(),
[i, initial_cg](auto /*t_info*/, auto X, auto U, auto RHO) {
auto u = get<smith::VALUE>(U);
auto x = get<smith::VALUE>(X) + u;
auto dx = x - initial_cg;
Expand Down
24 changes: 24 additions & 0 deletions examples/solid_mechanics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) Lawrence Livermore National Security, LLC and
# other Smith Project Developers. See the top-level LICENSE file for
# details.
#
# SPDX-License-Identifier: (BSD-3-Clause)

smith_add_executable( NAME composable_solid_mechanics
SOURCES composable_solid_mechanics.cpp
OUTPUT_DIR ${EXAMPLE_OUTPUT_DIRECTORY}
DEPENDS_ON smith
)

install(
FILES
composable_solid_mechanics.cpp
DESTINATION
examples/smith/solid_mechanics
)

if(SMITH_ENABLE_TESTS)
blt_add_test(NAME composable_solid_mechanics
COMMAND composable_solid_mechanics
NUM_MPI_TASKS 1 )
endif()
205 changes: 205 additions & 0 deletions examples/solid_mechanics/composable_solid_mechanics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
// Copyright (c) Lawrence Livermore National Security, LLC and
// other Smith Project Developers. See the top-level LICENSE file for
// details.
//
// SPDX-License-Identifier: (BSD-3-Clause)

/**
* @file composable_solid_mechanics.cpp
* @brief Dynamic solid-mechanics example using composable differentiable numerics systems.
*/

#include <iostream>
#include <memory>
#include <stdexcept>
#include <vector>

// _includes_start
#include "smith/infrastructure/application_manager.hpp"
#include "smith/physics/state/state_manager.hpp"
#include "smith/physics/mesh.hpp"
#include "smith/numerics/solver_config.hpp"
#include "smith/physics/functional_objective.hpp"
#include "smith/differentiable_numerics/nonlinear_block_solver.hpp"
#include "smith/differentiable_numerics/system_solver.hpp"
#include "smith/differentiable_numerics/solid_mechanics_system.hpp"
#include "smith/differentiable_numerics/differentiable_physics.hpp"
#include "smith/differentiable_numerics/evaluate_objective.hpp"
#include "smith/differentiable_numerics/differentiable_test_utils.hpp"
#include "smith/differentiable_numerics/paraview_writer.hpp"
#include "smith/physics/materials/solid_material.hpp"
// _includes_end

namespace {

struct YoungsModulusNeoHookeanWithTimeInfo {
using State = smith::solid_mechanics::NeoHookean::State;

double density;
double nu;

template <typename T, int dim, typename GradVType, typename YoungsType>
auto operator()(const smith::TimeInfo&, [[maybe_unused]] State& state, const smith::tensor<T, dim, dim>& grad_u,
const GradVType&, const YoungsType& youngs_modulus) const
{
using std::log1p;
constexpr auto I = smith::Identity<dim>();
auto E = smith::get<0>(youngs_modulus);
auto G = E / (2.0 * (1.0 + nu));
auto K = E / (3.0 * (1.0 - 2.0 * nu));
auto lambda = K - (2.0 / dim) * G;
auto B_minus_I = grad_u * transpose(grad_u) + transpose(grad_u) + grad_u;
auto logJ = log1p(detApIm1(grad_u));
auto TK = lambda * logJ * I + G * B_minus_I;
auto F = grad_u + I;
return dot(TK, inv(transpose(F)));
}
};

} // namespace

int main(int argc, char* argv[])
{
// _init_start
smith::ApplicationManager application_manager(argc, argv);
axom::sidre::DataStore datastore;
smith::StateManager::initialize(datastore, "composable_solid_mechanics");
// _init_end

// _mesh_start
constexpr int dim = 3;
constexpr int order = 1;

auto mesh = std::make_shared<smith::Mesh>(
mfem::Mesh::MakeCartesian3D(8, 2, 2, mfem::Element::HEXAHEDRON, 1.0, 0.1, 0.1), "mesh", 0, 0);
mesh->addDomainOfBoundaryElements("left", smith::by_attr<dim>(3));
mesh->addDomainOfBoundaryElements("right", smith::by_attr<dim>(5));
// _mesh_end

// _solver_start
smith::LinearSolverOptions linear_options{.linear_solver = smith::LinearSolver::CG,
.preconditioner = smith::Preconditioner::HypreAMG,
.relative_tol = 1e-6,
.absolute_tol = 1e-10,
.max_iterations = 80,
.print_level = 0};
smith::NonlinearSolverOptions nonlinear_options{.nonlin_solver = smith::NonlinearSolver::TrustRegion,
.relative_tol = 1e-7,
.absolute_tol = 1e-8,
.max_iterations = 15,
.print_level = 0};

smith::SolidMechanicsOptions output_options{.enable_stress_output = true, .output_cauchy_stress = true};
// _solver_end

// _build_start
auto solid_system = smith::buildSolidMechanicsSystem<dim, order>(
nonlinear_options, linear_options, output_options, mesh, smith::FieldType<smith::L2<0>>("youngs_modulus"));

constexpr double E = 100.0;
constexpr double nu = 0.25;
solid_system->setMaterial(YoungsModulusNeoHookeanWithTimeInfo{.density = 1.0, .nu = nu}, mesh->entireBodyName());
// _build_end

// _bc_start
solid_system->setDisplacementBC(mesh->domain("left"), std::vector<int>{0, 2});
solid_system->addBodyForce(mesh->entireBodyName(), [](double, auto X, auto, auto, auto, auto... /*args*/) {
auto body_force = 0.0 * X;
body_force[1] = -0.02;
return body_force;
});
solid_system->addTraction("right", [](double, auto X, auto, auto, auto, auto, auto... /*args*/) {
auto traction = 0.0 * X;
traction[0] = -0.01;
return traction;
});
// _bc_end

// _ic_start
auto physics = smith::makeDifferentiablePhysics(solid_system, "composable_solid_mechanics");

if (solid_system->cycle_zero_systems.empty()) {
throw std::runtime_error("Expected cycle-zero solve for implicit dynamics.");
}

physics->getFieldParam("param_youngs_modulus").get()->setFromFieldFunction([=](smith::tensor<double, dim>) {
return E;
});

auto initial_displacement = [](smith::tensor<double, dim> X) {
auto displacement = 0.0 * X;
displacement[0] = 1.0e-3 * X[0];
return displacement;
};
auto initial_velocity = [](smith::tensor<double, dim> X) {
auto velocity = 0.0 * X;
velocity[1] = 2.0e-2 * X[0];
return velocity;
};

physics->getInitialFieldState("displacement_solve_state").get()->setFromFieldFunction(initial_displacement);
physics->getInitialFieldState("displacement").get()->setFromFieldFunction(initial_displacement);
physics->getInitialFieldState("velocity").get()->setFromFieldFunction(initial_velocity);
physics->getInitialFieldState("acceleration").get()->setFromFieldFunction([](smith::tensor<double, dim>) {
return smith::tensor<double, dim>{};
});
// _ic_end

// _run_start
using DispSpace = smith::H1<order, dim>;
const auto qoi_fields = std::vector<smith::FieldState>{physics->getInitialFieldState("displacement"),
physics->getInitialFieldState("velocity")};
smith::FunctionalObjective<dim, smith::Parameters<DispSpace, DispSpace>> qoi("solid_dynamic_energy_proxy", mesh,
smith::spaces(qoi_fields));
qoi.addBodyIntegral(mesh->entireBodyName(), [](const smith::TimeInfo&, auto, auto U, auto V) {
auto u = smith::get<smith::VALUE>(U);
auto v = smith::get<smith::VALUE>(V);
return 0.5 * (u[0] * u[0] + u[1] * u[1] + u[2] * u[2]) + 0.05 * (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
});

constexpr double dt = 0.25;
constexpr int num_steps = 3;
auto current_qoi_fields = [&]() {
return std::vector<smith::FieldState>{physics->getFieldState("displacement"), physics->getFieldState("velocity")};
};
auto qoi_state =
0.0 * smith::evaluateObjective(qoi, physics->getShapeDispFieldState(), qoi_fields,
smith::TimeInfo(physics->time(), dt, static_cast<size_t>(physics->cycle())));
for (int step = 0; step < num_steps; ++step) {
physics->advanceTimestep(dt);
qoi_state = qoi_state +
smith::evaluateObjective(qoi, physics->getShapeDispFieldState(), current_qoi_fields(),
smith::TimeInfo(physics->time(), dt, static_cast<size_t>(physics->cycle())));
}

std::cout << "reaction norm: " << physics->getReactionStates().front().get()->Norml2() << '\n';
gretl::set_as_objective(qoi_state);
std::cout << "QoI value: " << qoi_state.get() << '\n';
qoi_state.data_store().back_prop();
auto shape_displacement = physics->getShapeDispFieldState();
auto initial_displacement_state = physics->getInitialFieldState("displacement");
auto initial_velocity_state = physics->getInitialFieldState("velocity");
auto youngs_modulus_state = physics->getFieldParam("param_youngs_modulus");
std::cout << "dQoI/d(shape) norm: " << shape_displacement.get_dual()->Norml2() << '\n';
std::cout << "dQoI/d(youngs_modulus) norm: " << youngs_modulus_state.get_dual()->Norml2() << '\n';
std::cout << "dQoI/d(initial displacement) norm: " << initial_displacement_state.get_dual()->Norml2() << '\n';
std::cout << "dQoI/d(initial velocity) norm: " << initial_velocity_state.get_dual()->Norml2() << '\n';
std::cout << "shape FD rate: \n" << smith::checkGradWrt(qoi_state, shape_displacement, 1.0e-2, 4, false) << '\n';
std::cout << "youngs_modulus FD rate: \n"
<< smith::checkGradWrt(qoi_state, youngs_modulus_state, 5.0e-2, 4, false) << '\n';
std::cout << "initial displacement FD rate: \n"
<< smith::checkGradWrt(qoi_state, initial_displacement_state, 5.0e-3, 4, false) << '\n';
std::cout << "initial velocity FD rate: \n"
<< smith::checkGradWrt(qoi_state, initial_velocity_state, 5.0e-3, 4, false) << '\n';
// _run_end

// _output_start
auto writer =
smith::createParaviewWriter(*mesh, physics->getFieldStatesAndParamStates(), "paraview_composable_solid_mechanics",
smith::ParaviewWriter::Options{.write_duals = false});
writer.write(physics->cycle(), physics->time(), physics->getFieldStatesAndParamStates());
std::cout << "ParaView output: paraview_composable_solid_mechanics\n";
// _output_end

return 0;
}
34 changes: 34 additions & 0 deletions examples/thermo_mechanics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) Lawrence Livermore National Security, LLC and
# other Smith Project Developers. See the top-level LICENSE file for
# details.
#
# SPDX-License-Identifier: (BSD-3-Clause)

smith_add_executable( NAME composable_thermo_mechanics
SOURCES composable_thermo_mechanics.cpp
OUTPUT_DIR ${EXAMPLE_OUTPUT_DIRECTORY}
DEPENDS_ON smith
)

smith_add_executable( NAME composable_thermo_mechanics_advanced
SOURCES composable_thermo_mechanics_advanced.cpp
OUTPUT_DIR ${EXAMPLE_OUTPUT_DIRECTORY}
DEPENDS_ON smith
)

install(
FILES
composable_thermo_mechanics.cpp
composable_thermo_mechanics_advanced.cpp
DESTINATION
examples/smith/thermo_mechanics
)

if(SMITH_ENABLE_TESTS)
blt_add_test(NAME composable_thermo_mechanics
COMMAND composable_thermo_mechanics
NUM_MPI_TASKS 1 )
blt_add_test(NAME composable_thermo_mechanics_advanced
COMMAND composable_thermo_mechanics_advanced
NUM_MPI_TASKS 1 )
endif()
Loading