LCOV - code coverage report
Current view: top level - src/actions - CavityPressureAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 0 38 0.0 %
Date: 2025-07-25 05:00:39 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 "CavityPressureAction.h"
      11             : #include "Factory.h"
      12             : #include "FEProblem.h"
      13             : #include "Conversion.h"
      14             : 
      15             : registerMooseAction("SolidMechanicsApp", CavityPressureAction, "add_bc");
      16             : 
      17             : InputParameters
      18           0 : CavityPressureAction::validParams()
      19             : {
      20           0 :   InputParameters params = Action::validParams();
      21           0 :   params.addRequiredParam<std::vector<BoundaryName>>(
      22             :       "boundary", "The list of boundary IDs from the mesh where the pressure will be applied");
      23           0 :   params.addRequiredParam<std::vector<VariableName>>("displacements",
      24             :                                                      "The nonlinear displacement variables");
      25           0 :   params.addParam<std::vector<AuxVariableName>>(
      26             :       "save_in", {}, "Auxiliary variables to save the displacement residuals");
      27           0 :   params.addParam<std::string>("output", "The name to use for the cavity pressure value");
      28           0 :   params.addParam<bool>(
      29           0 :       "use_displaced_mesh", true, "Whether to use displaced mesh in the boundary condition");
      30           0 :   params.addParam<bool>("use_automatic_differentiation",
      31           0 :                         false,
      32             :                         "Flag to use automatic differentiation (AD) objects when possible");
      33           0 :   params.addParam<std::vector<TagName>>("extra_vector_tags",
      34             :                                         "The extra tags for the vectors this Kernel should fill");
      35           0 :   params.addParam<std::vector<TagName>>(
      36             :       "absolute_value_vector_tags",
      37             :       "The tags for the vectors this residual object should fill with the "
      38             :       "absolute value of the residual contribution");
      39           0 :   params.addClassDescription("Action to setup cavity pressure boundary condition");
      40           0 :   return params;
      41           0 : }
      42             : 
      43           0 : CavityPressureAction::CavityPressureAction(const InputParameters & params)
      44           0 :   : Action(params), _use_ad(getParam<bool>("use_automatic_differentiation"))
      45             : {
      46           0 : }
      47             : 
      48             : void
      49           0 : CavityPressureAction::act()
      50             : {
      51           0 :   auto displacements = getParam<std::vector<VariableName>>("displacements");
      52           0 :   auto save_in = getParam<std::vector<AuxVariableName>>("save_in");
      53             : 
      54           0 :   unsigned int ndisp = displacements.size();
      55           0 :   if (save_in.size() > 0 && save_in.size() != ndisp)
      56           0 :     mooseError("Number of save_in variables should equal to the number of displacement variables ",
      57             :                ndisp);
      58             : 
      59           0 :   std::string ad_prepend = "";
      60           0 :   if (_use_ad)
      61             :     ad_prepend = "AD";
      62             : 
      63           0 :   std::string kernel_name = ad_prepend + "Pressure";
      64             : 
      65           0 :   InputParameters params = _factory.getValidParams(kernel_name);
      66           0 :   params.applyParameters(parameters());
      67             : 
      68           0 :   params.set<PostprocessorName>("postprocessor") =
      69           0 :       isParamValid("output") ? getParam<std::string>("output") : _name;
      70             : 
      71           0 :   for (unsigned int i = 0; i < ndisp; ++i)
      72             :   {
      73           0 :     params.set<NonlinearVariableName>("variable") = displacements[i];
      74           0 :     if (!save_in.empty())
      75           0 :       params.set<std::vector<AuxVariableName>>("save_in") = {save_in[i]};
      76           0 :     std::string unique_kernel_name = _name + "_" + Moose::stringify(i);
      77             : 
      78           0 :     _problem->addBoundaryCondition(kernel_name, unique_kernel_name, params);
      79             :   }
      80           0 : }

Generated by: LCOV version 1.14