LCOV - code coverage report
Current view: top level - user_tensors - FillRot.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.3 % 30 28
Test Date: 2025-06-29 01:25:44 Functions: 100.0 % 3 3

            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/user_tensors/FillRot.h"
      26              : #include "neml2/misc/assertions.h"
      27              : #include "neml2/tensors/functions/sqrt.h"
      28              : 
      29              : namespace neml2
      30              : {
      31              : register_NEML2_object(FillRot);
      32              : 
      33              : OptionSet
      34            2 : FillRot::expected_options()
      35              : {
      36            2 :   OptionSet options = UserTensorBase::expected_options();
      37            2 :   options.doc() = "Construct a Rot from a vector of Scalars.";
      38              : 
      39            4 :   options.set<std::vector<TensorName<Scalar>>>("values");
      40            4 :   options.set("values").doc() = "Scalars used to fill the Rot";
      41              : 
      42            4 :   options.set<std::string>("method") = "modified";
      43            2 :   options.set("method").doc() = "Fill method, options are 'modified' and 'standard'.";
      44              : 
      45            2 :   return options;
      46            0 : }
      47              : 
      48           17 : FillRot::FillRot(const OptionSet & options)
      49              :   : UserTensorBase(options),
      50           34 :     Rot(fill(options.get<std::vector<TensorName<Scalar>>>("values"),
      51           68 :              options.get<std::string>("method")))
      52              : 
      53              : {
      54           17 : }
      55              : 
      56              : Rot
      57           17 : FillRot::fill(const std::vector<TensorName<Scalar>> & values, const std::string & method) const
      58              : {
      59           17 :   auto * f = factory();
      60           17 :   neml_assert(f, "Internal error: factory != nullptr");
      61              : 
      62           17 :   if (method == "modified")
      63              :   {
      64           16 :     neml_assert(values.size() == 3,
      65              :                 "Number of values must be 3, but ",
      66           16 :                 values.size(),
      67              :                 " values are provided.");
      68           16 :     return Rot::fill(values[0].resolve(f), values[1].resolve(f), values[2].resolve(f));
      69              :   }
      70              : 
      71            1 :   if (method == "standard")
      72              :   {
      73            1 :     neml_assert(values.size() == 3,
      74              :                 "Number of values must be 3, but ",
      75            1 :                 values.size(),
      76              :                 " values are provided.");
      77            2 :     auto ns = values[0].resolve(f) * values[0].resolve(f) +
      78            2 :               values[1].resolve(f) * values[1].resolve(f) +
      79            3 :               values[2].resolve(f) * values[2].resolve(f);
      80            1 :     auto v = neml2::sqrt(ns + 1.0) + 1.0;
      81            1 :     return Rot::fill(values[0].resolve(f) / v, values[1].resolve(f) / v, values[2].resolve(f) / v);
      82            1 :   }
      83              : 
      84            0 :   throw NEMLException("Unknown Rot fill type " + method);
      85              : }
      86              : } // namespace neml2
        

Generated by: LCOV version 2.0-1