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 "NodalNormalsEvaluator.h" 11 : 12 : // MOOSE includes 13 : #include "AuxiliarySystem.h" 14 : #include "MooseVariableFE.h" 15 : #include "NodalNormalsPreprocessor.h" 16 : 17 : registerMooseObject("MooseApp", NodalNormalsEvaluator); 18 : 19 : InputParameters 20 14640 : NodalNormalsEvaluator::validParams() 21 : { 22 14640 : InputParameters params = NodalUserObject::validParams(); 23 14640 : params.addClassDescription( 24 : "Helper object to compute nodal normal values via the NodalNormals input block."); 25 14640 : params.set<bool>("_dual_restrictable") = true; 26 29280 : params.set<std::vector<SubdomainName>>("block") = {"ANY_BLOCK_ID"}; 27 14640 : return params; 28 14640 : } 29 : 30 195 : NodalNormalsEvaluator::NodalNormalsEvaluator(const InputParameters & parameters) 31 195 : : NodalUserObject(parameters), _aux(_fe_problem.getAuxiliarySystem()) 32 : { 33 195 : } 34 : 35 : void 36 415328 : NodalNormalsEvaluator::execute() 37 : { 38 : 39 415328 : if (_current_node->processor_id() == processor_id()) 40 : { 41 415328 : if (_current_node->n_dofs(_aux.number(), 42 415328 : _fe_problem 43 830656 : .getVariable(_tid, 44 : "nodal_normal_x", 45 : Moose::VarKindType::VAR_AUXILIARY, 46 : Moose::VarFieldType::VAR_FIELD_STANDARD) 47 415328 : .number()) > 0) 48 : { 49 313584 : std::scoped_lock lock(NodalNormalsPreprocessor::_nodal_normals_mutex); 50 : 51 : dof_id_type dof_x = 52 313584 : _current_node->dof_number(_aux.number(), 53 313584 : _fe_problem 54 627168 : .getVariable(_tid, 55 : "nodal_normal_x", 56 : Moose::VarKindType::VAR_AUXILIARY, 57 : Moose::VarFieldType::VAR_FIELD_STANDARD) 58 : .number(), 59 : 0); 60 : dof_id_type dof_y = 61 313584 : _current_node->dof_number(_aux.number(), 62 313584 : _fe_problem 63 627168 : .getVariable(_tid, 64 : "nodal_normal_y", 65 : Moose::VarKindType::VAR_AUXILIARY, 66 : Moose::VarFieldType::VAR_FIELD_STANDARD) 67 : .number(), 68 : 0); 69 : dof_id_type dof_z = 70 313584 : _current_node->dof_number(_aux.number(), 71 313584 : _fe_problem 72 627168 : .getVariable(_tid, 73 : "nodal_normal_z", 74 : Moose::VarKindType::VAR_AUXILIARY, 75 : Moose::VarFieldType::VAR_FIELD_STANDARD) 76 : .number(), 77 : 0); 78 : 79 313584 : NumericVector<Number> & sln = _aux.solution(); 80 313584 : Real nx = sln(dof_x); 81 313584 : Real ny = sln(dof_y); 82 313584 : Real nz = sln(dof_z); 83 : 84 313584 : Real n = std::sqrt((nx * nx) + (ny * ny) + (nz * nz)); 85 313584 : if (std::abs(n) >= 1e-13) 86 : { 87 : // divide by n only if it is not close to zero to avoid NaNs 88 76448 : sln.set(dof_x, nx / n); 89 76448 : sln.set(dof_y, ny / n); 90 76448 : sln.set(dof_z, nz / n); 91 : } 92 313584 : } 93 : } 94 415328 : } 95 : 96 : void 97 5784 : NodalNormalsEvaluator::initialize() 98 : { 99 5784 : _aux.solution().close(); 100 5784 : } 101 : 102 : void 103 5302 : NodalNormalsEvaluator::finalize() 104 : { 105 5302 : _aux.solution().close(); 106 5302 : }