diff --git a/python/wrap/compute.cpp b/python/wrap/compute.cpp index 50de974..1647a73 100644 --- a/python/wrap/compute.cpp +++ b/python/wrap/compute.cpp @@ -1,46 +1,52 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "computes.hh" #include "wrap.hh" /* -------------------------------------------------------------------------- */ namespace tamaas { namespace wrap { using namespace py::literals; void wrapCompute(py::module& mod) { auto compute_mod = mod.def_submodule("compute"); compute_mod.def( "eigenvalues", [](model_type type, Grid& eigs, const Grid& field) { eigenvalues(type, eigs, field); }, "model_type"_a, "eigenvalues_out"_a, "field"_a); compute_mod.def("von_mises", [](model_type type, Grid& vm, const Grid& field) { vonMises(type, vm, field); }, "model_type"_a, "von_mises"_a, "field"_a); + compute_mod.def( + "deviatoric", + [](model_type type, Grid& dev, const Grid& field) { + deviatoric(type, dev, field); + }, + "model_type"_a, "deviatoric"_a, "field"_a); } } // namespace wrap } // namespace tamaas diff --git a/src/core/computes.cpp b/src/core/computes.cpp index 062d466..467fe6a 100644 --- a/src/core/computes.cpp +++ b/src/core/computes.cpp @@ -1,35 +1,39 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "computes.hh" namespace tamaas { void eigenvalues(model_type type, GridBase& eigs, const GridBase& field) { applyCompute(type, eigs, field); } void vonMises(model_type type, GridBase& eigs, const GridBase& field) { applyCompute(type, eigs, field); } +void deviatoric(model_type type, GridBase& dev, + const GridBase& field) { + applyCompute(type, dev, field); +} } // namespace tamaas diff --git a/src/core/computes.hh b/src/core/computes.hh index 44fb5c2..5705687 100644 --- a/src/core/computes.hh +++ b/src/core/computes.hh @@ -1,89 +1,101 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef EIGENVALUES_HH #define EIGENVALUES_HH /* -------------------------------------------------------------------------- */ #include "grid.hh" #include "loop.hh" #include "model_type.hh" #include "ranges.hh" #include "static_types.hh" #include namespace tamaas { namespace compute { /// Compute eigenvalues of a symmetric matrix field struct Eigenvalues { template static void call(Grid& eigs, const Grid& field) { Loop::loop([](auto eig, auto f) { eig = eigenvalues(f); }, range>(eigs), range>(field)); } }; /// Compute von Mises stress on a tensor field struct VonMises { template static void call(Grid& vm, const Grid& stress) { Loop::loop( [](Real& vm, auto sigma) { SymMatrix dev; dev.deviatoric(sigma, 3); vm = std::sqrt(1.5) * dev.l2norm(); }, vm, range>(stress)); } }; + +/// Compute deviatoric of tensor field +struct Deviatoric { + template + static void call(Grid& dev, const Grid& field) { + Loop::loop([](auto s, auto sigma) { s.deviatoric(sigma, 3); }, + range>(dev), + range>(field)); + } +}; } // namespace compute template void applyCompute(model_type type, GridBase& result, const GridBase& field) { #define APPLY_CASE(_, __, type) \ case type: { \ constexpr UInt dim = model_type_traits::dimension; \ const auto& f = dynamic_cast&>(field); \ auto& e = dynamic_cast&>(result); \ Compute::template call(e, f); \ break; \ } switch (type) { BOOST_PP_SEQ_FOR_EACH(APPLY_CASE, ~, (model_type::volume_2d)); default: - TAMAAS_EXCEPTION("Model type " << type - << " not yet suported for field computation"); + TAMAAS_EXCEPTION("Model type " + << type << " not yet suported for field computation"); } #undef APPLY_CASE } void eigenvalues(model_type type, GridBase& eigs, const GridBase& field); void vonMises(model_type type, GridBase& eigs, const GridBase& field); +void deviatoric(model_type type, GridBase& dev, + const GridBase& field); } // namespace tamaas #endif /* EIGENVALUES_HH */