LCOV - code coverage report
Current view: top level - models - ForwardEulerTimeIntegration.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.7 % 38 36
Test Date: 2025-06-29 01:25:44 Functions: 66.7 % 12 8

            Line data    Source code
       1              : // Copyright 2024, UChicago Argonne, LLC
       2              : // All Rights Reserved
       3              : // Software Name: NEML2 -- the New Engineering material Model Library, version 2
       4              : // By: Argonne National Laboratory
       5              : // OPEN SOURCE LICENSE (MIT)
       6              : //
       7              : // Permission is hereby granted, free of charge, to any person obtaining a copy
       8              : // of this software and associated documentation files (the "Software"), to deal
       9              : // in the Software without restriction, including without limitation the rights
      10              : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      11              : // copies of the Software, and to permit persons to whom the Software is
      12              : // furnished to do so, subject to the following conditions:
      13              : //
      14              : // The above copyright notice and this permission notice shall be included in
      15              : // all copies or substantial portions of the Software.
      16              : //
      17              : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      18              : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      19              : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      20              : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      21              : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      22              : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      23              : // THE SOFTWARE.
      24              : 
      25              : #include "neml2/models/ForwardEulerTimeIntegration.h"
      26              : #include "neml2/tensors/Scalar.h"
      27              : #include "neml2/tensors/Vec.h"
      28              : #include "neml2/tensors/SR2.h"
      29              : #include "neml2/tensors/SSR4.h"
      30              : 
      31              : namespace neml2
      32              : {
      33              : template <typename T>
      34              : OptionSet
      35            6 : ForwardEulerTimeIntegration<T>::expected_options()
      36              : {
      37            6 :   OptionSet options = Model::expected_options();
      38            6 :   options.doc() =
      39              :       "Perform forward Euler time integration defined as \\f$ s = s_n + (t - t_n) \\dot{s} "
      40              :       "\\f$, where \\f$s\\f$ is the variable being integrated, \\f$\\dot{s}\\f$ is the variable "
      41              :       "rate, and \\f$t\\f$ is time. Subscripts \\f$n\\f$ denote quantities from the previous time "
      42              :       "step.";
      43              : 
      44           12 :   options.set_output("variable");
      45           12 :   options.set("variable").doc() = "Variable being integrated";
      46              : 
      47           12 :   options.set_input("rate");
      48            6 :   options.set("rate").doc() = "Variable rate of change";
      49              : 
      50           18 :   options.set_input("time") = VariableName(FORCES, "t");
      51            6 :   options.set("time").doc() = "Time";
      52              : 
      53            6 :   return options;
      54            0 : }
      55              : 
      56              : template <typename T>
      57            4 : ForwardEulerTimeIntegration<T>::ForwardEulerTimeIntegration(const OptionSet & options)
      58              :   : Model(options),
      59            4 :     _s(declare_output_variable<T>("variable")),
      60            4 :     _sn(declare_input_variable<T>(_s.name().old())),
      61            8 :     _ds_dt(options.get<VariableName>("rate").empty()
      62           16 :                ? declare_input_variable<T>(_s.name().with_suffix("_rate"))
      63            4 :                : declare_input_variable<T>("rate")),
      64            4 :     _t(declare_input_variable<Scalar>("time")),
      65            8 :     _tn(declare_input_variable<Scalar>(_t.name().old()))
      66              : {
      67            4 : }
      68              : 
      69              : template <typename T>
      70              : void
      71            3 : ForwardEulerTimeIntegration<T>::diagnose() const
      72              : {
      73            3 :   Model::diagnose();
      74            3 :   diagnostic_assert_state(_s);
      75            3 :   diagnostic_assert_state(_ds_dt);
      76            3 :   diagnostic_assert_force(_t);
      77            3 : }
      78              : 
      79              : template <typename T>
      80              : void
      81            5 : ForwardEulerTimeIntegration<T>::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
      82              : {
      83            5 :   if (out)
      84            4 :     _s = _sn + _ds_dt * (_t - _tn);
      85              : 
      86            5 :   if (dout_din)
      87              :   {
      88            1 :     auto I = T::identity_map(_ds_dt.options());
      89              : 
      90            1 :     _s.d(_ds_dt) = I * (_t - _tn);
      91              : 
      92            1 :     if (currently_solving_nonlinear_system())
      93            0 :       return;
      94              : 
      95            1 :     _s.d(_sn) = I;
      96            1 :     _s.d(_t) = _ds_dt;
      97            1 :     _s.d(_tn) = -_ds_dt;
      98            1 :   }
      99              : }
     100              : 
     101              : #define REGISTER(T)                                                                                \
     102              :   using T##ForwardEulerTimeIntegration = ForwardEulerTimeIntegration<T>;                           \
     103              :   register_NEML2_object(T##ForwardEulerTimeIntegration);                                           \
     104              :   template class ForwardEulerTimeIntegration<T>
     105              : REGISTER(Scalar);
     106              : REGISTER(Vec);
     107              : REGISTER(SR2);
     108              : } // namespace neml2
        

Generated by: LCOV version 2.0-1