LCOV - code coverage report
Current view: top level - include/userobjects - EBSDReader.h (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 7 7 100.0 %
Date: 2025-09-04 07:55:36 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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             : #pragma once
      11             : 
      12             : #include "EulerAngleProvider.h"
      13             : #include "EBSDAccessFunctors.h"
      14             : 
      15             : /**
      16             :  * A GeneralUserObject that reads an EBSD file and stores the centroid
      17             :  * data in a data structure which indexes on element centroids.
      18             :  *
      19             :  * Grains are indexed through multiple schemes:
      20             :  *  * feature_id   The grain number in the EBSD data file
      21             :  *  * global_id    The index into the global average data (contiguously numbered)
      22             :  *                 This is also called "(global) grain ID"
      23             :  *  * local_id     The index into the per-phase grain list. (contiguously numbered and only
      24             :  *                 unique when combined with phase number)
      25             :  *                 This is also called "(local) grain ID"
      26             :  *
      27             :  * Phases are referred to using the numbers in the EBSD data file. In case the phase number in the
      28             :  * data file
      29             :  * starts at 1 the phase 0 will simply contain no grains.
      30             :  */
      31             : class EBSDReader : public EulerAngleProvider, public EBSDAccessFunctors
      32             : {
      33             : public:
      34             :   static InputParameters validParams();
      35             : 
      36             :   EBSDReader(const InputParameters & params);
      37             :   virtual ~EBSDReader();
      38             : 
      39             :   virtual void readFile();
      40             : 
      41         134 :   virtual void initialize() {}
      42         134 :   virtual void execute() {}
      43         134 :   virtual void finalize() {}
      44             : 
      45             :   /**
      46             :    * Get the requested type of data at the point p.
      47             :    */
      48             :   const EBSDPointData & getData(const Point & p) const;
      49             : 
      50             :   /**
      51             :    * Get the requested type of average data for (global) grain number i.
      52             :    */
      53             :   const EBSDAvgData & getAvgData(unsigned int i) const;
      54             : 
      55             :   /**
      56             :    * Get the requested type of average data for a given phase and (local) grain.
      57             :    */
      58             :   const EBSDAvgData & getAvgData(unsigned int phase, unsigned int local_id) const;
      59             : 
      60             :   /**
      61             :    * EulerAngleProvider interface implementation to fetch a triplet of Euler angles
      62             :    */
      63             :   virtual const EulerAngles & getEulerAngles(unsigned int) const;
      64             : 
      65             :   /**
      66             :    * Return the total number of grains
      67             :    */
      68             :   virtual unsigned int getGrainNum() const;
      69             : 
      70             :   /**
      71             :    * Return the total number of phases
      72             :    */
      73      319131 :   virtual unsigned int getPhaseNum() const { return _global_id.size(); }
      74             : 
      75             :   /**
      76             :    * Return the number of grains in a given phase
      77             :    */
      78             :   virtual unsigned int getGrainNum(unsigned int phase) const;
      79             : 
      80             :   /// Return the EBSD feature id for a given phase and phase (local) grain number
      81             :   unsigned int getFeatureID(unsigned int phase, unsigned int local_id) const
      82             :   {
      83             :     return _avg_data[_global_id[phase][local_id]]._feature_id;
      84             :   }
      85             :   /// Return the EBSD feature id for a given (global) grain number
      86             :   unsigned int getFeatureID(unsigned int global_id) const
      87             :   {
      88      501948 :     return _avg_data[global_id]._feature_id;
      89             :   }
      90             : 
      91             :   /// Return the (global) grain id for a given phase and (local) grain number
      92    26173533 :   virtual unsigned int getGlobalID(unsigned int phase, unsigned int local_id) const
      93             :   {
      94    26173533 :     return _global_id[phase][local_id];
      95             :   }
      96             :   /// Return the (global) grain id for a given feature_id
      97             :   virtual unsigned int getGlobalID(unsigned int feature_id) const;
      98             : 
      99             :   /// Factory function to return a point functor specified by name
     100             :   MooseSharedPointer<EBSDPointDataFunctor>
     101             :   getPointDataAccessFunctor(const MooseEnum & field_name) const;
     102             :   /// Factory function to return a average functor specified by name
     103             :   MooseSharedPointer<EBSDAvgDataFunctor>
     104             :   getAvgDataAccessFunctor(const MooseEnum & field_name) const;
     105             : 
     106             :   /**
     107             :    * Returns a map consisting of the node index followd by
     108             :    * a vector of all grain weights for that node. Needed by ReconVarIC
     109             :    */
     110             :   const std::map<dof_id_type, std::vector<Real>> & getNodeToGrainWeightMap() const;
     111             : 
     112             :   /**
     113             :    * Returns a map consisting of the node index followd by
     114             :    * a vector of all phase weights for that node. Needed by ReconPhaseVarIC
     115             :    */
     116             :   const std::map<dof_id_type, std::vector<Real>> & getNodeToPhaseWeightMap() const;
     117             : 
     118             :   /// Maps need to be updated when the mesh changes
     119             :   void meshChanged();
     120             : 
     121             : protected:
     122             :   ///@{ MooseMesh Variables
     123             :   MooseMesh & _mesh;
     124             :   NonlinearSystemBase & _nl;
     125             :   ///@}
     126             : 
     127             :   ///@{ Variables needed to determine reduced order parameter values
     128             :   unsigned int _grain_num;
     129             :   Point _bottom_left;
     130             :   Point _top_right;
     131             :   Point _range;
     132             :   ///@}
     133             : 
     134             :   /// number of additional custom data columns
     135             :   unsigned int _custom_columns;
     136             : 
     137             :   /// Logically three-dimensional data indexed by geometric points in a 1D vector
     138             :   std::vector<EBSDPointData> _data;
     139             : 
     140             :   /// Averages by (global) grain ID
     141             :   std::vector<EBSDAvgData> _avg_data;
     142             : 
     143             :   /// Euler Angles by (global) grain ID
     144             :   std::vector<EulerAngles> _avg_angles;
     145             : 
     146             :   /// map from feature_id to global_id
     147             :   std::map<unsigned int, unsigned int> _global_id_map;
     148             : 
     149             :   /// global ID for given phases and grains
     150             :   std::vector<std::vector<unsigned int>> _global_id;
     151             : 
     152             :   /// Map of grain weights per node
     153             :   std::map<dof_id_type, std::vector<Real>> _node_to_grain_weight_map;
     154             : 
     155             :   /// Map of phase weights per node
     156             :   std::map<dof_id_type, std::vector<Real>> _node_to_phase_weight_map;
     157             : 
     158             :   /// current timestep. Maps are only rebuild on mesh change during time step zero
     159             :   const int & _time_step;
     160             : 
     161             :   /// Dimension of the problem domain
     162             :   unsigned int _mesh_dimension;
     163             : 
     164             :   /// number of bins for each quaternion component
     165             :   unsigned int _bins;
     166             : 
     167             :   /// L_norm value for averaging
     168             :   unsigned int _L_norm;
     169             : 
     170             :   /// The number of values in the x, y and z directions.
     171             :   unsigned _nx, _ny, _nz;
     172             : 
     173             :   /// The spacing of the values in x, y and z directions.
     174             :   Real _dx, _dy, _dz;
     175             : 
     176             :   /// Grid origin
     177             :   Real _minx, _miny, _minz;
     178             : 
     179             :   /// Maximum grid extent
     180             :   Real _maxx, _maxy, _maxz;
     181             : 
     182             :   /// Computes a global index in the _data array given an input *centroid* point
     183             :   unsigned indexFromPoint(const Point & p) const;
     184             : 
     185             :   /// Transfer the index into the _avg_data array from given index
     186             :   unsigned indexFromIndex(unsigned int var) const;
     187             : 
     188             :   /// Build grain and phase weight maps
     189             :   void buildNodeWeightMaps();
     190             : };

Generated by: LCOV version 1.14