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 : #ifdef NEML_ENABLED 16 : 17 : #include "NEMLStateAux.h" 18 : 19 : registerMooseObject("BlackBearApp", NEMLStateAux); 20 : 21 : InputParameters 22 54 : NEMLStateAux::validParams() 23 : { 24 54 : InputParameters params = AuxKernel::validParams(); 25 : 26 108 : params.addRequiredParam<FileName>("database", "Path to NEML XML database."); 27 108 : params.addRequiredParam<std::string>("model", "Model name in NEML database."); 28 108 : params.addRequiredParam<std::string>("state_variable", "Name to store."); 29 108 : params.addParam<MaterialPropertyName>( 30 : "state_vector", "history", "Material property storing NEML state."); 31 : 32 54 : return params; 33 0 : } 34 : 35 28 : NEMLStateAux::NEMLStateAux(const InputParameters & parameters) 36 : : AuxKernel(parameters), 37 56 : _fname(getParam<FileName>("database")), 38 56 : _mname(getParam<std::string>("model")), 39 28 : _neml_history(getMaterialProperty<std::vector<Real>>("state_vector")), 40 112 : _var_name(getParam<std::string>("state_variable")) 41 : { 42 : // Check that the file is readable 43 28 : MooseUtils::checkFileReadable(_fname); 44 : 45 : // Will throw an exception if it doesn't succeed 46 : try 47 : { 48 84 : _model = neml::parse_xml_unique(_fname, _mname); 49 : } 50 0 : catch (const neml::NEMLError & e) 51 : { 52 0 : paramError("Unable to load NEML model " + _mname + " from file " + _fname); 53 0 : } 54 : 55 : // Get the list of names from neml 56 28 : auto names = _model->report_internal_variable_names(); 57 : 58 : // Try to find the provided state_variable 59 28 : auto loc = std::find(names.begin(), names.end(), _var_name); 60 : 61 : // Check that it was in there 62 28 : if (loc == names.end()) 63 0 : mooseError("The requested state variable was not an output of the " 64 : "provided NEML model"); 65 : 66 : // Store the offset 67 28 : _offset = loc - names.begin(); 68 28 : } 69 : 70 : Real 71 13440 : NEMLStateAux::computeValue() 72 : { 73 : // Check that the vector we got has the right size for the model 74 13440 : if (_model->nstore() != _neml_history[_qp].size()) 75 0 : paramError("The size of the state_name vector provided to NEMLStateAux " 76 : "does not match the number of history variables requested " 77 : "by the NEML model itself."); 78 : 79 : // Trivial as we've done all the work in the constructor 80 13440 : return _neml_history[_qp][_offset]; 81 : } 82 : 83 : #endif // NEML_ENABLED