LCOV - code coverage report
Current view: top level - src/actions - DisplacementGradientsAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 0 48 0.0 %
Date: 2025-09-04 07:55:36 Functions: 0 3 0.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             : #include "DisplacementGradientsAction.h"
      11             : #include "Factory.h"
      12             : #include "FEProblem.h"
      13             : 
      14             : #include "libmesh/string_to_enum.h"
      15             : 
      16             : registerMooseAction("PhaseFieldApp", DisplacementGradientsAction, "add_kernel");
      17             : 
      18             : registerMooseAction("PhaseFieldApp", DisplacementGradientsAction, "add_material");
      19             : 
      20             : registerMooseAction("PhaseFieldApp", DisplacementGradientsAction, "add_variable");
      21             : 
      22             : InputParameters
      23           0 : DisplacementGradientsAction::validParams()
      24             : {
      25           0 :   InputParameters params = Action::validParams();
      26           0 :   params.addClassDescription("Set up variables, kernels, and materials for a the displacement "
      27             :                              "gradients and their elastic free energy derivatives for non-split "
      28             :                              "Cahn-Hilliard problems.");
      29           0 :   params.addRequiredParam<std::vector<VariableName>>("displacements",
      30             :                                                      "Vector of displacement variables");
      31           0 :   params.addRequiredParam<std::vector<VariableName>>("displacement_gradients",
      32             :                                                      "Vector of displacement gradient variables");
      33           0 :   params.addParam<Real>(
      34           0 :       "scaling", 1.0, "Specifies a scaling factor to apply to the displacement gradient variables");
      35           0 :   params.addParam<std::vector<SubdomainName>>(
      36             :       "block", {}, "Block restriction for the variables and kernels");
      37           0 :   return params;
      38           0 : }
      39             : 
      40           0 : DisplacementGradientsAction::DisplacementGradientsAction(const InputParameters & params)
      41             :   : Action(params),
      42           0 :     _displacements(getParam<std::vector<VariableName>>("displacements")),
      43           0 :     _displacement_gradients(getParam<std::vector<VariableName>>("displacement_gradients"))
      44             : {
      45           0 : }
      46             : 
      47             : void
      48           0 : DisplacementGradientsAction::act()
      49             : {
      50           0 :   unsigned int ngrad = _displacement_gradients.size();
      51             : 
      52           0 :   if (_current_task == "add_variable")
      53             :   {
      54             :     // Loop through the gij variables
      55           0 :     Real scaling = getParam<Real>("scaling");
      56           0 :     for (unsigned int i = 0; i < ngrad; ++i)
      57             :     {
      58           0 :       auto var_params = _factory.getValidParams("MooseVariable");
      59           0 :       var_params.set<MooseEnum>("family") = "LAGRANGE";
      60           0 :       var_params.set<MooseEnum>("order") = "FIRST";
      61           0 :       var_params.set<std::vector<Real>>("scaling") = {scaling};
      62           0 :       var_params.applySpecificParameters(_pars, {"block"});
      63             : 
      64             :       // Create displacement gradient variables
      65           0 :       _problem->addVariable("MooseVariable", _displacement_gradients[i], var_params);
      66           0 :     }
      67             :   }
      68           0 :   else if (_current_task == "add_material")
      69             :   {
      70           0 :     InputParameters params = _factory.getValidParams("StrainGradDispDerivatives");
      71           0 :     params.set<std::vector<VariableName>>("displacement_gradients") = _displacement_gradients;
      72           0 :     params.applySpecificParameters(parameters(), {"block"});
      73           0 :     _problem->addMaterial("StrainGradDispDerivatives", "strain_grad_disp_derivatives", params);
      74           0 :   }
      75           0 :   else if (_current_task == "add_kernel")
      76             :   {
      77           0 :     unsigned int ndisp = _displacements.size();
      78           0 :     if (ndisp * ndisp != ngrad)
      79           0 :       paramError("displacement_gradients",
      80             :                  "Number of displacement gradient variables must be the square of the number of "
      81             :                  "displacement variables.");
      82             : 
      83             :     // Loop through the displacements
      84             :     unsigned int i = 0;
      85           0 :     for (unsigned int j = 0; j < ndisp; ++j)
      86           0 :       for (unsigned int k = 0; k < ndisp; ++k)
      87             :       {
      88           0 :         InputParameters params = _factory.getValidParams("GradientComponent");
      89           0 :         params.set<NonlinearVariableName>("variable") = _displacement_gradients[i];
      90           0 :         params.set<std::vector<VariableName>>("v") = {_displacements[j]};
      91           0 :         params.set<unsigned int>("component") = k;
      92           0 :         _problem->addKernel(
      93           0 :             "GradientComponent", _displacement_gradients[i] + "_grad_kernel", params);
      94           0 :         ++i;
      95           0 :       }
      96             :   }
      97             :   else
      98           0 :     mooseError("Internal error.");
      99           0 : }

Generated by: LCOV version 1.14