Skip to content

Commit

Permalink
add to_3x3 function, fix shadowed variable warning
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelpmishLLNL committed Aug 8, 2024
1 parent 9141b83 commit 61ae643
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/serac/numerics/functional/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,16 @@ SERAC_HOST_DEVICE auto normalize(const tensor<T, n...>& A)
return A / norm(A);
}

template <typename T>
SERAC_HOST_DEVICE tensor<T, 3, 3> to_3x3(const tensor<T, 2, 2>& A) {
tensor<T,3,3> output{};
output[0][0] = A[0][0];
output[0][1] = A[0][1];
output[1][0] = A[1][0];
output[1][1] = A[1][1];
return output;
}

/**
* @brief Returns the trace of a square matrix
* @param[in] A The matrix to compute the trace of
Expand Down
2 changes: 1 addition & 1 deletion src/serac/physics/fit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FiniteElementState fit(std::integer_sequence<int, i...>, func f, mfem::ParMesh &

// signature looks like return_type(arg0_type, arg1_type);
// so this unpacks the return type
using output_space = FunctionSignature< signature >::return_type;
using output_space = typename FunctionSignature< signature >::return_type;

FiniteElementState fitted_field(mesh, output_space{}, "displacement");
fitted_field = 0.0;
Expand Down
4 changes: 2 additions & 2 deletions src/serac/physics/solid_mechanics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,8 +1635,8 @@ class SolidMechanics<order, dim, Parameters<parameter_space...>, std::integer_se
std::array<std::function<decltype((*residual_)(DifferentiateWRT<1>{}, 0.0, shape_displacement_, displacement_,
acceleration_, *parameters_[parameter_indices].state...))(double)>,
sizeof...(parameter_indices)>
d_residual_d_ = {[&](double t) {
return (*residual_)(DifferentiateWRT<NUM_STATE_VARS + 1 + parameter_indices>{}, t, shape_displacement_,
d_residual_d_ = {[&](double _t) {
return (*residual_)(DifferentiateWRT<NUM_STATE_VARS + 1 + parameter_indices>{}, _t, shape_displacement_,
displacement_, acceleration_, *parameters_[parameter_indices].state...);
}...};

Expand Down
9 changes: 2 additions & 7 deletions src/serac/physics/tests/fit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,8 @@ void stress_extrapolation_test() {
Empty internal_variables{};

sigma_J2 = fit< dim, output_space(input_space) >([&](double /*t*/, [[maybe_unused]] auto position, [[maybe_unused]] auto displacement_){
auto du_dx = get_value(get<1>(displacement_));
mat3 du_dx3 = {{
{du_dx[0][0], du_dx[0][1], 0.0},
{du_dx[1][0], du_dx[1][1], 0.0},
{0.0, 0.0, 0.0}
}};
auto stress = mat(internal_variables, du_dx3);
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);

Expand Down

0 comments on commit 61ae643

Please sign in to comment.