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 "PolycrystalEBSD.h" 11 : #include "EBSDReader.h" 12 : 13 : registerMooseObject("PhaseFieldApp", PolycrystalEBSD); 14 : 15 : InputParameters 16 304 : PolycrystalEBSD::validParams() 17 : { 18 304 : InputParameters params = PolycrystalUserObjectBase::validParams(); 19 304 : params.addClassDescription("Object for setting up a polycrystal structure from an EBSD Datafile"); 20 608 : params.addParam<unsigned int>("phase", "The phase to use for all queries."); 21 608 : params.addParam<UserObjectName>("ebsd_reader", "EBSD Reader for initial condition"); 22 304 : return params; 23 0 : } 24 : 25 152 : PolycrystalEBSD::PolycrystalEBSD(const InputParameters & parameters) 26 : : PolycrystalUserObjectBase(parameters), 27 204 : _phase(isParamValid("phase") ? getParam<unsigned int>("phase") : libMesh::invalid_uint), 28 152 : _ebsd_reader(getUserObject<EBSDReader>("ebsd_reader")), 29 304 : _node_to_grain_weight_map(_ebsd_reader.getNodeToGrainWeightMap()) 30 : { 31 152 : } 32 : 33 : void 34 234206 : PolycrystalEBSD::getGrainsBasedOnPoint(const Point & point, 35 : std::vector<unsigned int> & grains) const 36 : { 37 234206 : const EBSDAccessFunctors::EBSDPointData & d = _ebsd_reader.getData(point); 38 : 39 : // See if we are in a phase that we are actually tracking 40 234206 : if (_phase != libMesh::invalid_uint && _phase != d._phase) 41 : { 42 8154 : grains.resize(0); 43 8154 : return; 44 : } 45 : 46 : // Get the ids from the EBSD reader 47 226052 : const auto global_id = _ebsd_reader.getGlobalID(d._feature_id); 48 226052 : const auto local_id = _ebsd_reader.getAvgData(global_id)._local_id; 49 : 50 226052 : grains.resize(1); 51 401904 : grains[0] = _phase != libMesh::invalid_uint ? local_id : global_id; 52 : } 53 : 54 : unsigned int 55 2432327 : PolycrystalEBSD::getNumGrains() const 56 : { 57 2432327 : if (_phase != libMesh::invalid_uint) 58 743127 : return _ebsd_reader.getGrainNum(_phase); 59 : else 60 1689200 : return _ebsd_reader.getGrainNum(); 61 : } 62 : 63 : Real 64 2432200 : PolycrystalEBSD::getNodalVariableValue(unsigned int op_index, const Node & n) const 65 : { 66 : // Make sure the _current_node is in the node_to_grain_weight_map (return error if not in map) 67 2432200 : const auto it = _node_to_grain_weight_map.find(n.id()); 68 : 69 2432200 : if (it == _node_to_grain_weight_map.end()) 70 0 : mooseError("The following node id is not in the node map: ", n.id()); 71 : 72 : // Increment through all grains at node_index (these are global IDs if consider_phase is false and 73 : // local IDs otherwise) 74 2432200 : const auto num_grains = getNumGrains(); 75 59268774 : for (MooseIndex(num_grains) index = 0; index < num_grains; ++index) 76 : { 77 : // If the current order parameter index (_op_index) is equal to the assigned index 78 : // (_assigned_op), 79 : // set the value from node_to_grain_weight_map 80 : auto grain_index = 81 57321366 : _phase != libMesh::invalid_uint ? _ebsd_reader.getGlobalID(_phase, index) : index; 82 : mooseAssert(grain_index < it->second.size(), "grain_index out of range"); 83 57321366 : auto value = (it->second)[grain_index]; 84 57321366 : if (_grain_to_op.at(index) == op_index && value > 0.0) 85 484792 : return value; 86 : } 87 : 88 1947408 : return 0.0; 89 : } 90 : 91 : Real 92 124432 : PolycrystalEBSD::getVariableValue(unsigned int op_index, const Point & p) const 93 : { 94 : std::vector<unsigned int> grain_ids; 95 124432 : getGrainsBasedOnPoint(p, grain_ids); 96 : 97 124432 : if (grain_ids.empty()) 98 : return -1.0; 99 : 100 : mooseAssert(grain_ids.size() == 1, "Expected only one grain at point in EBSDReader"); 101 123958 : auto index = grain_ids[0]; 102 : 103 123958 : return _grain_to_op.at(index) == op_index ? 1.0 : 0.0; 104 124432 : }