LCOV - code coverage report
Current view: top level - src/actions - EqualValueEmbeddedConstraintAction.C (source / functions) Hit Total Coverage
Test: idaholab/blackbear: b15b36 Lines: 45 45 100.0 %
Date: 2025-07-18 16:15:14 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /****************************************************************/
       2             : /*               DO NOT MODIFY THIS HEADER                      */
       3             : /*                       BlackBear                              */
       4             : /*                                                              */
       5             : /*           (c) 2017 Battelle Energy Alliance, LLC             */
       6             : /*                   ALL RIGHTS RESERVED                        */
       7             : /*                                                              */
       8             : /*          Prepared by Battelle Energy Alliance, LLC           */
       9             : /*            Under Contract No. DE-AC07-05ID14517              */
      10             : /*            With the U. S. Department of Energy               */
      11             : /*                                                              */
      12             : /*            See COPYRIGHT for full restrictions               */
      13             : /****************************************************************/
      14             : 
      15             : #include "EqualValueEmbeddedConstraintAction.h"
      16             : #include "Conversion.h"
      17             : #include "FEProblem.h"
      18             : #include "Factory.h"
      19             : #include "MooseMesh.h"
      20             : 
      21             : #include "libmesh/string_to_enum.h"
      22             : // #include <algorithm>
      23             : 
      24             : registerMooseAction("BlackBearApp", EqualValueEmbeddedConstraintAction, "add_constraint");
      25             : 
      26             : InputParameters
      27          18 : EqualValueEmbeddedConstraintAction::validParams()
      28             : {
      29          18 :   InputParameters params = Action::validParams();
      30          18 :   params.addClassDescription("Sets up constraint on primary and secondary variables on "
      31             :                              "primary and secondary block");
      32          36 :   params.addRequiredParam<std::vector<SubdomainName>>(
      33             :       "primary", "The list of ids of the primary block (subdomain)");
      34          36 :   params.addRequiredParam<std::vector<SubdomainName>>(
      35             :       "secondary", "The list of ids of the secondary block (subdomain) ");
      36          36 :   params.addParam<std::vector<VariableName>>(
      37             :       "primary_variable",
      38             :       {},
      39             :       "The list of variables on the primary side (defaults to the specified value of 'variable')");
      40          36 :   params.addRequiredParam<std::vector<NonlinearVariableName>>(
      41             :       "variable", "The list of variables on the secondary side");
      42          36 :   MooseEnum formulation("kinematic penalty", "kinematic");
      43          36 :   params.addParam<MooseEnum>(
      44             :       "formulation", formulation, "Formulation used to enforce the constraint");
      45          36 :   params.addRequiredParam<Real>(
      46             :       "penalty",
      47             :       "Penalty parameter used in constraint enforcement for kinematic and penalty formulations.");
      48          18 :   return params;
      49          18 : }
      50             : 
      51          18 : EqualValueEmbeddedConstraintAction::EqualValueEmbeddedConstraintAction(
      52          18 :     const InputParameters & params)
      53             :   : Action(params),
      54          18 :     _primary(getParam<std::vector<SubdomainName>>("primary")),
      55          36 :     _secondary(getParam<std::vector<SubdomainName>>("secondary")),
      56          36 :     _primary_var(getParam<std::vector<VariableName>>("primary_variable")),
      57          36 :     _variable(getParam<std::vector<NonlinearVariableName>>("variable")),
      58          36 :     _formulation(getParam<MooseEnum>("formulation").getEnum<Formulation>()),
      59          54 :     _penalty(getParam<Real>("penalty"))
      60             : {
      61          18 :   if (_primary_var.size() == 0)
      62          45 :     for (unsigned int i = 0; i < _variable.size(); ++i)
      63          60 :       _primary_var.push_back(_variable[i]);
      64           3 :   else if (_primary_var.size() != _variable.size())
      65           3 :     mooseError("Sizes of 'primary_variable' and 'variable' must match.");
      66          15 : }
      67             : 
      68             : void
      69          15 : EqualValueEmbeddedConstraintAction::act()
      70             : {
      71          15 :   const std::string constraint_name = "EqualValueEmbeddedConstraint";
      72             : 
      73             :   SubdomainName pb, sb;
      74          45 :   for (size_t i = 0; i < _variable.size(); i++)
      75          60 :     for (size_t p = 0; p < _primary.size(); p++)
      76          90 :       for (size_t s = 0; s < _secondary.size(); s++)
      77             :       {
      78         120 :         std::string unique_constraint_name = constraint_name + "_" + _variable[i] + "_" +
      79         120 :                                              "_primary_" + Moose::stringify(p) + "_secondary_" +
      80          60 :                                              Moose::stringify(s);
      81          60 :         InputParameters params = _factory.getValidParams(constraint_name);
      82         300 :         params.applyParameters(parameters(),
      83             :                                {"primary", "secondary", "primary_variable", "variable"});
      84         120 :         params.set<SubdomainName>("primary") = _primary[p];
      85         120 :         params.set<SubdomainName>("secondary") = _secondary[s];
      86         120 :         params.set<NonlinearVariableName>("variable") = _variable[i];
      87         180 :         params.set<std::vector<VariableName>>("primary_variable") = {_primary_var[i]};
      88          60 :         params.set<Real>("penalty") = _penalty;
      89         180 :         params.set<MooseEnum>("formulation") = getParam<MooseEnum>("formulation");
      90          60 :         _problem->addConstraint(constraint_name, unique_constraint_name, params);
      91          60 :       }
      92         135 : }

Generated by: LCOV version 1.14