<commit_before>#ifndef DIAGTENSOR_H
#define DIAGTENSOR_H

#include "ColumnMajorMatrix.h"
#include "MaterialProperty.h"
#include <cmath>
#include "libmesh.h"

class DiagTensor
{
public:
  DiagTensor() :
      _xx(0),
      _yy(0),
      _zz(0)
    {}
  explicit
  
  DiagTensor(Real init) :
      _xx(init),
      _yy(init),
      _zz(init)
    {}
  DiagTensor(Real xx, Real yy, Real zz) :
      _xx(xx),
      _yy(yy),
      _zz(zz)
    {}
  explicit

  DiagTensor(const ColumnMajorMatrix & cmm) :
      _xx( cmm.numEntries() == 9 ? cmm.rawData()[0] : 0 ),
      _yy( cmm.numEntries() == 9 ? cmm.rawData()[4] : 0 ),
      _zz( cmm.numEntries() == 9 ? cmm.rawData()[8] : 0 )
    {
      if (cmm.numEntries() != 9)
      {
        mooseError("Cannot create DiagTensor from ColumnMajorMatrix.  Wrong number of entries.");
      }
    }
  explicit

  DiagTensor(std::vector<Real> &init_list) :
      _xx(init_list[0]),
      _yy(init_list[1]),
      _zz(init_list[2])
      
    {
      // test the length to make sure it's 3 long
      if(init_list.size() != 3)
        mooseError("please enter a vector with 3 entries.");
    }
  
  DiagTensor(const DiagTensor &a)
    {
      *this = a;
    }
  
  
  ~DiagTensor() {}
  

  Real rowDot(const unsigned int r,
              const libMesh::TypeVector<Real> & v) const
    {
      mooseAssert(LIBMESH_DIM == 3, "Incompatible sizes");
      if (0 == r)
      {
        return _xx * v(0) ;
      }
      else if (1 == r)
      {
        return  _yy * v(1) ;
      }
      else if (2 == r)
      {
        return  _zz * v(2);
      }
      else
      {
        mooseError( "Incorrect row" );
      }
      return 0;
    }
  
  libMesh::TypeVector<Real> operator*(const libMesh::TypeVector<Real> & v) const 
    {
      libMesh::TypeVector<Real> r_val(v);
      
      r_val(0) = _xx * v(0);
      r_val(1) = _yy * v(1);
      r_val(2) = _zz * v(2);
      return r_val;
    }
  
  Real trace() const
  {
    return _xx + _yy + _zz;
  }
  
  Real component( unsigned int i ) const
    {
      if (0 == i)
      {
        return _xx;
      }
      else if (1 == i)
      {
      return _yy;
      }
      else if (2 == i)
      {
        return _zz;
      }
      else
      {
        mooseError( "Invalid entry requested for DiagTensor" );
      }
      return 0;
    }
  Real xx() const
    {
      return _xx;
    }
  Real yy() const
    {
      return _yy;
    }
  Real zz() const
    {
    return _zz;
    }
  Real & operator()(const unsigned i, const unsigned j)
    {
      Real * rVal(NULL);
      if (0 == i)
      {
        if (0 == j)
        {
          rVal = &_xx;
        }
      }
      else if (1 == i)
      {
      if (1 == j)
      {
        rVal = &_yy;
      }
      }
      else if (2 == i)
      {
      if (2 == j)
      {
        rVal = &_zz;
      }
      }
      if (!rVal)
      {
        mooseError( "Index must be 0, 1, or 2" );
      }
    return *rVal;
    }
  
  Real doubleContraction( const DiagTensor & rhs ) const
    {
      return _xx*rhs._xx + _yy*rhs._yy + _zz*rhs._zz;
    }
  

  void xyz( Real xx, Real yy,Real zz )
    {
      _xx = xx;
      _yy = yy;
      _zz = zz;
    }
  void xx( Real xx )
    {
      _xx = xx;
    }
  void yy( Real yy )
    {
      _yy = yy;
    }
  void zz( Real zz )
    {
      _zz = zz;
    }
  
  void zero()
    {
      _xx = _yy = _zz =  0;
    }
  void identity()
    {
      _xx = _yy = _zz = 1.0;
    }
  void addDiag( Real value )<commit_msg>added to DiagTensor Class and modified PressureDiffusionHSTMP<commit_after>#ifndef DIAGTENSOR_H
#define DIAGTENSOR_H

#include "ColumnMajorMatrix.h"
#include "MaterialProperty.h"
#include <cmath>
#include "libmesh.h"

class DiagTensor
{
public:
  DiagTensor() :
      _xx(0),
      _yy(0),
      _zz(0)
    {}
  explicit
  
  DiagTensor(Real init) :
      _xx(init),
      _yy(init),
      _zz(init)
    {}
  DiagTensor(Real xx, Real yy, Real zz) :
      _xx(xx),
      _yy(yy),
      _zz(zz)
    {}
  explicit

  DiagTensor(const ColumnMajorMatrix & cmm) :
      _xx( cmm.numEntries() == 9 ? cmm.rawData()[0] : 0 ),
      _yy( cmm.numEntries() == 9 ? cmm.rawData()[4] : 0 ),
      _zz( cmm.numEntries() == 9 ? cmm.rawData()[8] : 0 )
    {
      if (cmm.numEntries() != 9)
      {
        mooseError("Cannot create DiagTensor from ColumnMajorMatrix.  Wrong number of entries.");
      }
    }
  explicit

  DiagTensor(std::vector<Real> &init_list) :
      _xx(init_list[0]),
      _yy(init_list[1]),
      _zz(init_list[2])
      
    {
      // test the length to make sure it's 3 long
      if(init_list.size() != 3)
        mooseError("please enter a vector with 3 entries.");
    }
  
  DiagTensor(const DiagTensor &a)
    {
      *this = a;
    }
  
  
  ~DiagTensor() {}
  

  Real rowDot(const unsigned int r,
              const libMesh::TypeVector<Real> & v) const
    {
      mooseAssert(LIBMESH_DIM == 3, "Incompatible sizes");
      if (0 == r)
      {
        return _xx * v(0) ;
      }
      else if (1 == r)
      {
        return  _yy * v(1) ;
      }
      else if (2 == r)
      {
        return  _zz * v(2);
      }
      else
      {
        mooseError( "Incorrect row" );
      }
      return 0;
    }
  
  libMesh::TypeVector<Real> operator*(const libMesh::TypeVector<Real> & v) const 
    {
      libMesh::TypeVector<Real> r_val(v);
      
      r_val(0) = _xx * v(0);
      r_val(1) = _yy * v(1);
      r_val(2) = _zz * v(2);
      return r_val;
    }
  
  Real trace() const
  {
    return _xx + _yy + _zz;
  }
  
  Real component( unsigned int i ) const
    {
      if (0 == i)
      {
        return _xx;
      }
      else if (1 == i)
      {
      return _yy;
      }
      else if (2 == i)
      {
        return _zz;
      }
      else
      {
        mooseError( "Invalid entry requested for DiagTensor" );
      }
      return 0;
    }
  Real xx() const
    {
      return _xx;
    }
  Real yy() const
    {
      return _yy;
    }
  Real zz() const
    {
    return _zz;
    }
  Real & operator()(const unsigned i, const unsigned j)
    {
      Real * rVal(NULL);
      if (0 == i)
      {
        if (0 == j)
        {
          rVal = &_xx;
        }
      }
      else if (1 == i)
      {
      if (1 == j)
      {
        rVal = &_yy;
      }
      }
      else if (2 == i)
      {
      if (2 == j)
      {
        rVal = &_zz;
      }
      }
      if (!rVal)
      {
        mooseError( "Index must be 0, 1, or 2" );
      }
    return *rVal;
    }
  
  Real doubleContraction( const DiagTensor & rhs ) const
    {
      return _xx*rhs._xx + _yy*rhs._yy + _zz*rhs._zz;
    }
  

  void assign( unsigned int i, Real val ) 
    {
      if (0 == i)
      {
        _xx= val;
      }
      else if (1 == i)
      {
        _yy=val;
      }
      else if (2 == i)
      {
         _zz=val;
      }
      else
      {
        mooseError( "Invalid entry requested for DiagTensor" );
      }
    }
  
  void xyz( Real xx, Real yy,Real zz )
    {
      _xx = xx;
      _yy = yy;
      _zz = zz;
    }
  void xx( Real xx )
    {
      _xx = xx;
    }
  void yy( Real yy )
    {
      _yy = yy;
    }
  void zz( Real zz )
    {
      _zz = zz;
    }
  
  void zero()
    {
      _xx = _yy = _zz =  0;
    }
  void identity()
    {
      _xx = _yy = _zz = 1.0;
    }
  void addDiag( Real value )
{'fraction_non_alphanumeric': 0.13391877058177826, 'fraction_numerical': 0.013858397365532382, 'mean_word_length': 1.4476158495634655, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6417939', 'n_tokens_mistral': 2850, 'n_tokens_neox': 2797, 'n_words': 655}