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 "NodalDisplacementDifferenceL2NormPD.h" 11 : #include "MooseVariable.h" 12 : #include "Function.h" 13 : 14 : registerMooseObject("PeridynamicsApp", NodalDisplacementDifferenceL2NormPD); 15 : 16 : InputParameters 17 11 : NodalDisplacementDifferenceL2NormPD::validParams() 18 : { 19 11 : InputParameters params = NodalIntegralPostprocessorBasePD::validParams(); 20 11 : params.addClassDescription("Class for computing the L2 norm of the difference between " 21 : "displacements and their analytic solutions"); 22 : 23 22 : params.addRequiredParam<std::vector<FunctionName>>( 24 : "analytic_functions", "The known analytic functions for displacements"); 25 22 : params.addRequiredParam<std::vector<NonlinearVariableName>>( 26 : "displacements", "Nonlinear variable name for the displacements"); 27 : 28 11 : return params; 29 0 : } 30 : 31 6 : NodalDisplacementDifferenceL2NormPD::NodalDisplacementDifferenceL2NormPD( 32 6 : const InputParameters & parameters) 33 6 : : NodalIntegralPostprocessorBasePD(parameters) 34 : { 35 : const std::vector<NonlinearVariableName> & nl_vnames( 36 6 : getParam<std::vector<NonlinearVariableName>>("displacements")); 37 : 38 : const std::vector<FunctionName> & func_names( 39 12 : getParam<std::vector<FunctionName>>("analytic_functions")); 40 : 41 6 : _n_disps = nl_vnames.size(); 42 6 : if (_n_disps > _dim) 43 0 : mooseError("Number of displacements components should not greater than problem dimension!"); 44 : 45 6 : if (_n_disps != func_names.size()) 46 0 : mooseError("Number of analytic_functions components should be the same as the number of " 47 : "displacements components!"); 48 : 49 18 : for (unsigned int i = 0; i < _n_disps; ++i) 50 : { 51 12 : _disp_var.push_back(&_subproblem.getStandardVariable(_tid, nl_vnames[i])); 52 12 : _funcs.push_back(&getFunctionByName(func_names[i])); 53 : } 54 6 : } 55 : 56 : Real 57 6 : NodalDisplacementDifferenceL2NormPD::getValue() const 58 : { 59 6 : return std::sqrt(NodalIntegralPostprocessorBasePD::getValue()); 60 : } 61 : 62 : Real 63 80 : NodalDisplacementDifferenceL2NormPD::computeNodalValue() 64 : { 65 : Real diff = 0; 66 240 : for (unsigned int i = 0; i < _n_disps; ++i) 67 160 : diff += (_disp_var[i]->getNodalValue(*_current_node) - _funcs[i]->value(_t, *_current_node)) * 68 160 : (_disp_var[i]->getNodalValue(*_current_node) - _funcs[i]->value(_t, *_current_node)); 69 : 70 80 : return diff; 71 : }