LCOV - code coverage report
Current view: top level - include/neml2/actions - NEML2Action.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 9 11 81.8 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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             : 
      20             : class NEML2ActionCommon;
      21             : 
      22             : /**
      23             :  * Action to set up NEML2 objects.
      24             :  */
      25             : class NEML2Action : public Action
      26             : {
      27             : public:
      28             :   static InputParameters validParams();
      29             : 
      30             :   NEML2Action(const InputParameters &);
      31             : 
      32             :   virtual void act() override;
      33             : 
      34             : protected:
      35             :   const NEML2ActionCommon & getCommonAction() const;
      36             : 
      37             : #ifdef NEML2_ENABLED
      38             : 
      39          22 :   const FileName & fname() const { return _fname; }
      40             : 
      41             :   enum class MOOSEIOType
      42             :   {
      43             :     MATERIAL,
      44             :     VARIABLE,
      45             :     POSTPROCESSOR
      46             :   };
      47             : 
      48             :   struct MOOSEIO
      49             :   {
      50             :     const std::string name;
      51             :     const MOOSEIOType type;
      52             :   };
      53             : 
      54             :   struct NEML2IO
      55             :   {
      56             :     const neml2::VariableName name;
      57             :     const neml2::TensorType type;
      58             :   };
      59             : 
      60             :   struct NEML2Param
      61             :   {
      62             :     const std::string name;
      63             :     const neml2::TensorType type;
      64             :   };
      65             : 
      66             :   struct VariableMapping
      67             :   {
      68             :     const MOOSEIO moose;
      69             :     const NEML2IO neml2;
      70             :   };
      71             : 
      72             :   struct ParameterMapping
      73             :   {
      74             :     const MOOSEIO moose;
      75             :     const NEML2Param neml2;
      76             :   };
      77             : 
      78             :   struct DerivativeMapping
      79             :   {
      80             :     const MOOSEIO moose;
      81             :     const struct NEML2Derivative
      82             :     {
      83             :       const NEML2IO y;
      84             :       const NEML2IO x;
      85             :     } neml2;
      86             :   };
      87             : 
      88             :   struct ParameterDerivativeMapping
      89             :   {
      90             :     const MOOSEIO moose;
      91             :     const struct NEML2Derivative
      92             :     {
      93             :       const NEML2IO y;
      94             :       const NEML2Param x;
      95             :     } neml2;
      96             :   };
      97             : 
      98             :   /// Set up MOOSE-NEML2 input variable mappings
      99             :   void setupInputMappings(const neml2::Model &);
     100             : 
     101             :   /// Set up MOOSE-NEML2 model parameter mappings
     102             :   void setupParameterMappings(const neml2::Model &);
     103             : 
     104             :   /// Set up MOOSE-NEML2 output variable mappings
     105             :   void setupOutputMappings(const neml2::Model &);
     106             : 
     107             :   /// Set up MOOSE-NEML2 derivative mappings
     108             :   void setupDerivativeMappings(const neml2::Model &);
     109             : 
     110             :   /// Set up MOOSE-NEML2 parameter derivative mappings
     111             :   void setupParameterDerivativeMappings(const neml2::Model &);
     112             : 
     113             :   /// Name of the NEML2 input file
     114             :   FileName _fname;
     115             : 
     116             :   /// List of cli-args
     117             :   std::vector<std::string> _cli_args;
     118             : 
     119             :   /// The neml2 model
     120             :   std::shared_ptr<neml2::Model> _model;
     121             : 
     122             :   /// MOOSE-NEML2 input variable mappings
     123             :   std::vector<VariableMapping> _inputs;
     124             : 
     125             :   /// MOOSE-NEML2 model parameter mappings
     126             :   std::vector<ParameterMapping> _params;
     127             : 
     128             :   /// MOOSE-NEML2 output variable mappings
     129             :   std::vector<VariableMapping> _outputs;
     130             : 
     131             :   /// MOOSE-NEML2 derivative mappings
     132             :   std::vector<DerivativeMapping> _derivs;
     133             : 
     134             :   /// MOOSE-NEML2 parameter derivative mappings
     135             :   std::vector<ParameterDerivativeMapping> _param_derivs;
     136             : 
     137             : #endif
     138             :   /// Name of the NEML2Executor user object
     139             :   const UserObjectName _executor_name;
     140             : 
     141             :   /// Name of the NEML2BatchIndexGenerator user object
     142             :   const UserObjectName _idx_generator_name;
     143             : 
     144             :   /// Blocks this sub-block action applies to
     145             :   const std::vector<SubdomainName> _block;
     146             : 
     147             :   /// Material property initial conditions
     148             :   std::map<MaterialPropertyName, MaterialPropertyName> _initialize_output_values;
     149             : 
     150             :   /// Material property additional outputs
     151             :   std::map<MaterialPropertyName, std::vector<OutputName>> _export_output_targets;
     152             : 
     153             : private:
     154             : #ifdef NEML2_ENABLED
     155             :   /// Get parameter lists for mapping between MOOSE and NEML2 quantities
     156             :   template <typename EnumType, typename T1, typename T2>
     157             :   std::tuple<std::vector<EnumType>, std::vector<T1>, std::vector<T2>>
     158         110 :   getInputParameterMapping(const std::string & moose_type_opt,
     159             :                            const std::string & moose_name_opt,
     160             :                            const std::string & neml2_name_opt) const
     161             :   {
     162         110 :     const auto moose_types = getParam<MultiMooseEnum>(moose_type_opt).getSetValueIDs<EnumType>();
     163         110 :     const auto moose_names = getParam<std::vector<T1>>(moose_name_opt);
     164         110 :     const auto neml2_names = getParam<std::vector<T2>>(neml2_name_opt);
     165             : 
     166         110 :     if (moose_types.size() != moose_names.size())
     167           0 :       paramError(moose_name_opt, moose_name_opt, " must have the same length as ", moose_type_opt);
     168         110 :     if (moose_names.size() != neml2_names.size())
     169           0 :       paramError(moose_name_opt, moose_name_opt, " must have the same length as ", neml2_name_opt);
     170             : 
     171         220 :     return {moose_types, moose_names, neml2_names};
     172         110 :   }
     173             : 
     174             :   /// Print a summary of the NEML2 model
     175             :   void printSummary() const;
     176             : #endif
     177             : 
     178             :   /// Get the maximum length of all MOOSE names (for printing purposes)
     179             :   std::size_t getLongestMOOSEName() const;
     180             : };

Generated by: LCOV version 1.14