LCOV - code coverage report
Current view: top level - include/neml2/actions - NEML2Action.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fa5e60 Lines: 7 8 87.5 %
Date: 2026-06-24 08:03:36 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include <memory>
      13             : 
      14             : #ifdef NEML2_ENABLED
      15             : #include "neml2/models/Model.h"
      16             : #endif
      17             : 
      18             : #include "Action.h"
      19             : #include "NEML2Utils.h"
      20             : #include "DerivativeMaterialPropertyNameInterface.h"
      21             : 
      22             : class NEML2ActionCommon;
      23             : 
      24             : /**
      25             :  * Action to set up NEML2 objects.
      26             :  */
      27             : class NEML2Action : public Action, public DerivativeMaterialPropertyNameInterface
      28             : {
      29             : public:
      30             :   static InputParameters validParams();
      31             : 
      32             :   NEML2Action(const InputParameters &);
      33             : 
      34             :   virtual void act() override;
      35             : 
      36             : protected:
      37             :   const NEML2ActionCommon & getCommonAction() const;
      38             : 
      39             : #ifdef NEML2_ENABLED
      40             : 
      41          24 :   const FileName & fname() const { return _fname; }
      42             : 
      43             :   struct VariableMapping
      44             :   {
      45             :     std::string name;
      46             :     NEML2Utils::MOOSEIOType moose_type;
      47             :     neml2::TensorType neml2_type;
      48             :     std::size_t history_order;
      49             :   };
      50             : 
      51             :   struct ParameterMapping
      52             :   {
      53             :     std::string name;
      54             :     NEML2Utils::MOOSEIOType moose_type;
      55             :     neml2::TensorType neml2_type;
      56             :   };
      57             : 
      58             :   struct DerivativeMapping
      59             :   {
      60             :     std::string name;
      61             :     std::string y;
      62             :     std::string x;
      63             :   };
      64             : 
      65             :   /// Set up MOOSE-NEML2 input variable mappings
      66             :   void setupInputMappings(const neml2::Model &);
      67             : 
      68             :   /// Set up MOOSE-NEML2 output variable mappings
      69             :   void setupOutputMappings(const neml2::Model &);
      70             : 
      71             :   /// Set up MOOSE-NEML2 model parameter mappings
      72             :   void setupParameterMappings(const neml2::Model &);
      73             : 
      74             :   /// Set up MOOSE-NEML2 derivative mappings
      75             :   void setupDerivativeMappings(const neml2::Model &);
      76             : 
      77             :   /// Set up MOOSE-NEML2 parameter derivative mappings
      78             :   void setupParameterDerivativeMappings(const neml2::Model &);
      79             : 
      80             :   /// Infer the MOOSE IO type from the variable name and type
      81             :   NEML2Utils::MOOSEIOType inferMOOSEIOType(const neml2::VariableName & name,
      82             :                                            const neml2::TensorType & type) const;
      83             : 
      84             :   /// Name of the NEML2 input file
      85             :   FileName _fname;
      86             : 
      87             :   /// List of cli-args
      88             :   std::vector<std::string> _cli_args;
      89             : 
      90             :   /// The neml2 model
      91             :   std::shared_ptr<neml2::Model> _model;
      92             : 
      93             :   /// MOOSE-NEML2 input variable mappings
      94             :   std::vector<VariableMapping> _inputs;
      95             : 
      96             :   /// MOOSE-NEML2 model parameter mappings
      97             :   std::vector<ParameterMapping> _params;
      98             : 
      99             :   /// MOOSE-NEML2 output variable mappings
     100             :   std::vector<VariableMapping> _outputs;
     101             : 
     102             :   /// MOOSE-NEML2 derivative mappings
     103             :   std::vector<DerivativeMapping> _derivs;
     104             : 
     105             :   /// MOOSE-NEML2 parameter derivative mappings
     106             :   std::vector<DerivativeMapping> _param_derivs;
     107             : 
     108             : #endif
     109             :   /// Name of the NEML2Executor user object
     110             :   const UserObjectName _executor_name;
     111             : 
     112             :   /// Name of the NEML2BatchIndexGenerator user object
     113             :   const UserObjectName _idx_generator_name;
     114             : 
     115             :   /// Blocks this sub-block action applies to
     116             :   const std::vector<SubdomainName> _block;
     117             : 
     118             :   /// Input variables to skip (i.e., not to set up mappings for)
     119             :   std::vector<std::string> _skip_input_variables;
     120             : 
     121             :   /// Material property initial conditions
     122             :   std::map<MaterialPropertyName, MaterialPropertyName> _initialize_output_values;
     123             : 
     124             :   /// Material property additional outputs
     125             :   std::map<MaterialPropertyName, std::vector<OutputName>> _export_output_targets;
     126             : 
     127             : private:
     128             : #ifdef NEML2_ENABLED
     129             :   /// Get parameter lists for mapping between MOOSE and NEML2 quantities
     130             :   template <typename EnumType, typename T>
     131             :   std::tuple<std::vector<EnumType>, std::vector<T>>
     132          48 :   getInputParameterMapping(const std::string & source_opt, const std::string & name_opt) const
     133             :   {
     134          48 :     const auto moose_types = getParam<MultiMooseEnum>(source_opt).getSetValueIDs<EnumType>();
     135          48 :     const auto neml2_names = getParam<std::vector<T>>(name_opt);
     136             : 
     137          48 :     if (moose_types.size() != neml2_names.size())
     138           0 :       paramError(source_opt, source_opt, " must have the same length as ", name_opt);
     139             : 
     140          96 :     return {moose_types, neml2_names};
     141          48 :   }
     142             : 
     143             :   /// Print a summary of the NEML2 model
     144             :   void printSummary() const;
     145             : #endif
     146             : 
     147             :   /// Get the maximum length of all MOOSE names (for printing purposes)
     148             :   std::size_t getLongestMOOSEName() const;
     149             : };

Generated by: LCOV version 1.14