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 "CommonSolidMechanicsAction.h" 11 : #include "QuasiStaticSolidMechanicsPhysics.h" 12 : #include "ActionWarehouse.h" 13 : #include "FEProblemBase.h" 14 : #include "Factory.h" 15 : 16 : registerMooseAction("SolidMechanicsApp", CommonSolidMechanicsAction, "meta_action"); 17 : 18 : registerMooseAction("SolidMechanicsApp", CommonSolidMechanicsAction, "add_variable"); 19 : 20 : InputParameters 21 4802 : CommonSolidMechanicsAction::validParams() 22 : { 23 4802 : InputParameters params = QuasiStaticSolidMechanicsPhysicsBase::validParams(); 24 4802 : params.addClassDescription("Store common solid mechanics parameters"); 25 4802 : return params; 26 0 : } 27 : 28 4802 : CommonSolidMechanicsAction::CommonSolidMechanicsAction(const InputParameters & parameters) 29 4802 : : Action(parameters) 30 : { 31 4802 : } 32 : 33 : void 34 9582 : CommonSolidMechanicsAction::act() 35 : { 36 : 37 : // check if sub-blocks block are found which will use the common parameters 38 9582 : auto actions = _awh.getActions<QuasiStaticSolidMechanicsPhysicsBase>(); 39 9582 : if (actions.size() == 0) 40 2 : mooseWarning("Common parameters are supplied, but not used in ", parameters().blockLocation()); 41 : 42 : // Add disp-variables 43 9580 : if (_current_task == "add_variable") 44 : { 45 : // We set these variables first with the "common" (not nested) level parameters 46 9564 : bool do_add_variables = getParam<bool>("add_variables"); 47 14346 : auto displacement_variables = getParam<std::vector<VariableName>>("displacements"); 48 : bool add_variables_block_restricted = true; 49 : std::set<SubdomainName> add_variables_blocks; 50 4782 : bool scaling_set = isParamValid("scaling"); 51 4782 : Real scaling_value = (scaling_set) ? getParam<Real>("scaling") : 1.0; 52 : 53 : // Check all nested sub-actions and update the variables keeping track of each selection 54 9660 : for (const auto & action : actions) 55 : { 56 9756 : if (action->getParam<bool>("add_variables")) 57 : { 58 : // this sub-action wants the disp-variables added. 59 : do_add_variables = true; 60 13446 : const auto v = action->getParam<std::vector<VariableName>>("displacements"); 61 4482 : if (v.size() > 0) 62 : { 63 4482 : if (displacement_variables.size() == 0) 64 0 : displacement_variables.insert(displacement_variables.end(), v.begin(), v.end()); 65 4482 : else if (displacement_variables != v) 66 0 : paramError("displacements", 67 : "The vector of displacement variables of the actions differ."); 68 : } 69 : 70 : // with block-restriction? 71 17928 : if (add_variables_block_restricted && action->isParamValid("block") && 72 13446 : action->getParam<std::vector<SubdomainName>>("block").size()) 73 : { 74 924 : auto action_blocks = action->getParam<std::vector<SubdomainName>>("block"); 75 : mooseAssert(action_blocks.size(), "Block restriction must not be empty"); 76 308 : add_variables_blocks.insert(action_blocks.cbegin(), action_blocks.cend()); 77 308 : } 78 : else 79 : add_variables_block_restricted = false; 80 : 81 : // scaling? 82 17928 : if (action->getParam<bool>("add_variables") && action->isParamValid("scaling")) 83 : { 84 12 : const auto scaling = action->getParam<Real>("scaling"); 85 : 86 : // sanity-check 87 6 : if (scaling_set && scaling_value != scaling) 88 0 : paramError("scaling", "The scaling parameter of the actions differ."); 89 : 90 : // set local scaling variables 91 : scaling_set = true; 92 : scaling_value = scaling; 93 : } 94 4482 : } 95 : } 96 : 97 : // add the disp-variables, if desired 98 4782 : if (do_add_variables) 99 : { 100 4386 : auto params = _factory.getValidParams("MooseVariable"); 101 : // determine necessary order 102 4386 : const bool second = _problem->mesh().hasSecondOrderElements(); 103 : 104 12872 : params.set<MooseEnum>("order") = second ? "SECOND" : "FIRST"; 105 8772 : params.set<MooseEnum>("family") = "LAGRANGE"; 106 4386 : if (add_variables_block_restricted && add_variables_blocks.size() > 0) 107 : { 108 212 : std::vector<SubdomainName> blks(add_variables_blocks.begin(), add_variables_blocks.end()); 109 212 : params.set<std::vector<SubdomainName>>("block") = blks; 110 212 : } 111 4386 : if (scaling_set && scaling_value != 1) 112 12 : params.set<std::vector<Real>>("scaling") = {scaling_value}; 113 : 114 : // Loop through the displacement variables 115 : const auto n = displacement_variables.size(); 116 4386 : if (n == 0) 117 0 : paramError("displacements", "The vector of displacement variables is not set."); 118 4386 : if (n != _problem->mesh().dimension()) 119 0 : paramError("displacements", 120 : "The number of displacement variables differs from the number of dimensions of " 121 : "the mesh."); 122 : 123 16210 : for (const auto & disp : displacement_variables) 124 : // Create displacement variables 125 23648 : _problem->addVariable("MooseVariable", disp, params); 126 4386 : } 127 4782 : } 128 9580 : }