diff --git a/python/wrap/solvers.cpp b/python/wrap/solvers.cpp index 0d2f111..de0a7ad 100644 --- a/python/wrap/solvers.cpp +++ b/python/wrap/solvers.cpp @@ -1,141 +1,142 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-19 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 "beck_teboulle.hh" #include "condat.hh" #include "contact_solver.hh" #include "ep_solver.hh" #include "epic.hh" #include "kato.hh" #include "kato_saturated.hh" #include "polonsky_keer_rey.hh" #include "polonsky_keer_tan.hh" #include "wrap.hh" /* -------------------------------------------------------------------------- */ namespace tamaas { namespace wrap { /* -------------------------------------------------------------------------- */ using namespace py::literals; class PyEPSolver : public EPSolver { public: using EPSolver::EPSolver; void solve() override { PYBIND11_OVERLOAD_PURE(void, EPSolver, solve); } void updateState() override { PYBIND11_OVERLOAD(void, EPSolver, updateState); } }; /* -------------------------------------------------------------------------- */ void wrapSolvers(py::module& mod) { py::class_(mod, "ContactSolver") // .def(py::init&, Real>(), "model"_a, // "surface"_a, "tolerance"_a) .def("setMaxIterations", &ContactSolver::setMaxIterations, "max_iter"_a) .def("setDumpFrequency", &ContactSolver::setDumpFrequency, "dump_freq"_a) .def("addFunctionalTerm", &ContactSolver::addFunctionalTerm) .def("solve", py::overload_cast>(&ContactSolver::solve), "target_force"_a) .def("solve", py::overload_cast(&ContactSolver::solve), "target_normal_pressure"_a); py::class_ pkr(mod, "PolonskyKeerRey"); pkr.def(py::init&, Real, PolonskyKeerRey::type, PolonskyKeerRey::type>(), "model"_a, "surface"_a, "tolerance"_a, "primal_type"_a, "constraint_type"_a, py::keep_alive<1, 2>(), py::keep_alive<1, 3>()) .def("computeError", &PolonskyKeerRey::computeError); py::enum_(pkr, "type") .value("gap", PolonskyKeerRey::gap) .value("pressure", PolonskyKeerRey::pressure) .export_values(); py::class_(mod, "KatoSaturated") .def(py::init&, Real, Real>(), "model"_a, - "surface"_a, "tolerance"_a, "pmax"_a); + "surface"_a, "tolerance"_a, "pmax"_a) + .def_property("pmax", &KatoSaturated::getPMax, &KatoSaturated::setPMax); py::class_ kato(mod, "Kato"); kato.def(py::init&, Real, Real>(), "model"_a, "surface"_a, "tolerance"_a, "mu"_a, py::keep_alive<1, 2>(), py::keep_alive<1, 3>()) .def("solve", &Kato::solve, "p0"_a, "proj_iter"_a = 50) .def("solveRelaxed", &Kato::solveRelaxed, "g0"_a) .def("solveRegularized", &Kato::solveRegularized, "p0"_a, "r"_a = 0.01) .def("computeCost", &Kato::computeCost, "use_tresca"_a = false); py::class_ bt(mod, "BeckTeboulle"); bt.def(py::init&, Real, Real>(), "model"_a, "surface"_a, "tolerance"_a, "mu"_a, py::keep_alive<1, 2>(), py::keep_alive<1, 3>()) .def("solve", &BeckTeboulle::solve, "p0"_a) .def("computeCost", &BeckTeboulle::computeCost); py::class_ cd(mod, "Condat"); cd.def(py::init&, Real, Real>(), "model"_a, "surface"_a, "tolerance"_a, "mu"_a, py::keep_alive<1, 2>(), py::keep_alive<1, 3>()) .def("solve", &Condat::solve, "p0"_a, "grad_step"_a = 0.9) .def("computeCost", &Condat::computeCost); py::class_ pkt(mod, "PolonskyKeerTan"); pkt.def(py::init&, Real, Real>(), "model"_a, "surface"_a, "tolerance"_a, "mu"_a, py::keep_alive<1, 2>(), py::keep_alive<1, 3>()) .def("solve", &PolonskyKeerTan::solve, "p0"_a) .def("solveTresca", &PolonskyKeerTan::solveTresca, "p0"_a) .def("computeCost", &PolonskyKeerTan::computeCost, "use_tresca"_a = false); py::class_(mod, "EPSolver") .def(py::init(), "residual"_a) .def("solve", &EPSolver::solve) .def("getStrainIncrement", &EPSolver::getStrainIncrement, py::return_value_policy::reference_internal) .def("getResidual", &EPSolver::getResidual, py::return_value_policy::reference_internal) .def("updateState", &EPSolver::updateState); py::class_(mod, "EPICSolver") .def(py::init(), "contact_solver"_a, "elasto_plastic_solver"_a, "tolerance"_a = 1e-10, "relaxation"_a = 0.3) .def("solve", &EPICSolver::solve, "force"_a) .def("solve", [](EPICSolver& solver, Real pressure) { return solver.solve(std::vector{pressure}); }, "normal_pressure"_a) .def("acceleratedSolve", [](EPICSolver& solver, Real pressure) { return solver.acceleratedSolve(std::vector{pressure}); }, "normal_pressure"_a); } } // namespace wrap } // namespace tamaas diff --git a/src/solvers/kato_saturated.hh b/src/solvers/kato_saturated.hh index 2ddf3bd..9cb1143 100644 --- a/src/solvers/kato_saturated.hh +++ b/src/solvers/kato_saturated.hh @@ -1,62 +1,72 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-19 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 KATO_SATURATED_HH #define KATO_SATURATED_HH /* -------------------------------------------------------------------------- */ #include "polonsky_keer_rey.hh" +#include /* -------------------------------------------------------------------------- */ namespace tamaas { /* -------------------------------------------------------------------------- */ /// Polonsky-Keer algorithm with saturation of the pressure class KatoSaturated : public PolonskyKeerRey { public: /// Constructor KatoSaturated(Model& model, const GridBase& surface, Real tolerance, - Real pmax); + Real pmax); ~KatoSaturated() override = default; public: /// Mean on unsaturated constraint zone Real meanOnUnsaturated(const GridBase& field) const override; /// Compute squared norm Real computeSquaredNorm(const GridBase& field) const override; /// Update search direction void updateSearchDirection(Real factor) override; /// Compute critical step Real computeCriticalStep(Real target = 0) override; /// Update primal and check non-admissible state bool updatePrimal(Real step) override; /// Compute error/stopping criterion Real computeError() override; /// Enfore mean value constraint void enforceMeanValue(Real mean) override; /// Enforce contact constraints on final state void enforceAdmissibleState() override; + /// Access to pmax + Real getPMax() const { return pmax; } + /// Set pax + void setPMax(Real p) { + if (p <= 0) + pmax = std::numeric_limits::max(); + else + pmax = p; + } protected: - Real pmax; ///< saturation pressure + Real pmax = std::numeric_limits::max(); ///< saturation pressure }; } // namespace tamaas #endif // KATO_SATURATED_HH