<commit_before>//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

// MOOSE includes
#include "GeneralVectorPostprocessor.h"
#include "SamplerBase.h"
#include "BlockRestrictable.h"
#include "LineSegment.h"
#include "RayTracing.h" // Moose::elementsIntersectedByLine()
#include "Assembly.h"   // Assembly::qRule()
#include "MooseMesh.h"  // MooseMesh::getMesh()
#include "SwapBackSentinel.h"
#include "FEProblem.h"

#include "libmesh/quadrature.h" // _qrule->n_points()

// Forward Declarations
class MooseMesh;

/**
 * This is a base class for sampling material properties for the
 * integration points in all elements that are intersected by a
 * user-defined line.  The positions of those points are output in x,
 * y, z coordinates, as well as in terms of the projected positions of
 * those points along the line.  Derived classes can be created to
 * sample arbitrary types of material properties.
 */
template <typename T>
class LineMaterialSamplerBase : public GeneralVectorPostprocessor,
                                public SamplerBase,
                                public BlockRestrictable
{
public:
  static InputParameters validParams();

  /**
   * Class constructor
   * Sets up variables for output based on the properties to be output
   * @param parameters The input parameters
   */
  LineMaterialSamplerBase(const InputParameters & parameters);

  /**
   * Initialize
   * Calls through to base class's initialize()
   */
  virtual void initialize() override;

  /**
   * Finds all elements along the user-defined line, loops through them, and samples their
   * material properties.
   */
  virtual void execute() override;

  /**
   * Finalize
   * Calls through to base class's finalize()
   */
  virtual void finalize() override;

  /**
   * Reduce the material property to a scalar for output
   * @param property The material property
   * @param curr_point The point corresponding to this material property
   * @return A scalar value from this material property to be output
   */
  virtual Real getScalarFromProperty(const T & property, const Point & curr_point) = 0;

protected:
  /// The beginning of the line
  Point _start;

  /// The end of the line
  Point _end;

  /// The material properties to be output
  std::vector<const MaterialProperty<T> *> _material_properties;

  /// The mesh
  MooseMesh & _mesh;

  /// The quadrature rule
  const QBase * const & _qrule;

  /// The quadrature points
  const MooseArray<Point> & _q_point;
};

template <typename T>
InputParameters
LineMaterialSamplerBase<T>::validParams()
{
  InputParameters params = GeneralVectorPostprocessor::validParams();
  params += SamplerBase::validParams();
  params += BlockRestrictable::validParams();
  params.addRequiredParam<Point>("start", "The beginning of the line");
  params.addRequiredParam<Point>("end", "The end of the line");
  params.addRequiredParam<std::vector<std::string>>(
      "property", "Name of the material property to be output along a line");

  return params;
}

template <typename T>
LineMaterialSamplerBase<T>::LineMaterialSamplerBase(const InputParameters & parameters)
  : GeneralVectorPostprocessor(parameters),
    SamplerBase(parameters, this, _communicator),
    BlockRestrictable(this),
    _start(getParam<Point>("start")),
    _end(getParam<Point>("end")),
    _mesh(_subproblem.mesh()),
    _qrule(_subproblem.assembly(_tid).qRule()),
    _q_point(_subproblem.assembly(_tid).qPoints())
{
  std::vector<std::string> material_property_names = getParam<std::vector<std::string>>("property");
  for (unsigned int i = 0; i < material_property_names.size(); ++i)
  {
    if (!hasMaterialProperty<T>(material_property_names[i]))
      mooseError("In LineMaterialSamplerBase material property: " + material_property_names[i] +
                 " does not exist.");
    _material_properties.push_back(&getMaterialProperty<T>(material_property_names[i]));
  }

  SamplerBase::setupVariables(material_property_names);
}

template <typename T>
void
LineMaterialSamplerBase<T>::initialize()
{
  SamplerBase::initialize();
}

template <typename T><commit_msg>Throw an error if LineMaterialSamplerBase is used with distributed mesh<commit_after>//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

// MOOSE includes
#include "GeneralVectorPostprocessor.h"
#include "SamplerBase.h"
#include "BlockRestrictable.h"
#include "LineSegment.h"
#include "RayTracing.h" // Moose::elementsIntersectedByLine()
#include "Assembly.h"   // Assembly::qRule()
#include "MooseMesh.h"  // MooseMesh::getMesh()
#include "SwapBackSentinel.h"
#include "FEProblem.h"

#include "libmesh/quadrature.h" // _qrule->n_points()

// Forward Declarations
class MooseMesh;

/**
 * This is a base class for sampling material properties for the
 * integration points in all elements that are intersected by a
 * user-defined line.  The positions of those points are output in x,
 * y, z coordinates, as well as in terms of the projected positions of
 * those points along the line.  Derived classes can be created to
 * sample arbitrary types of material properties.
 */
template <typename T>
class LineMaterialSamplerBase : public GeneralVectorPostprocessor,
                                public SamplerBase,
                                public BlockRestrictable
{
public:
  static InputParameters validParams();

  /**
   * Class constructor
   * Sets up variables for output based on the properties to be output
   * @param parameters The input parameters
   */
  LineMaterialSamplerBase(const InputParameters & parameters);

  /**
   * Initialize
   * Calls through to base class's initialize()
   */
  virtual void initialize() override;

  /**
   * Finds all elements along the user-defined line, loops through them, and samples their
   * material properties.
   */
  virtual void execute() override;

  /**
   * Finalize
   * Calls through to base class's finalize()
   */
  virtual void finalize() override;

  /**
   * Reduce the material property to a scalar for output
   * @param property The material property
   * @param curr_point The point corresponding to this material property
   * @return A scalar value from this material property to be output
   */
  virtual Real getScalarFromProperty(const T & property, const Point & curr_point) = 0;

protected:
  /// The beginning of the line
  Point _start;

  /// The end of the line
  Point _end;

  /// The material properties to be output
  std::vector<const MaterialProperty<T> *> _material_properties;

  /// The mesh
  MooseMesh & _mesh;

  /// The quadrature rule
  const QBase * const & _qrule;

  /// The quadrature points
  const MooseArray<Point> & _q_point;
};

template <typename T>
InputParameters
LineMaterialSamplerBase<T>::validParams()
{
  InputParameters params = GeneralVectorPostprocessor::validParams();
  params += SamplerBase::validParams();
  params += BlockRestrictable::validParams();
  params.addRequiredParam<Point>("start", "The beginning of the line");
  params.addRequiredParam<Point>("end", "The end of the line");
  params.addRequiredParam<std::vector<std::string>>(
      "property", "Name of the material property to be output along a line");

  return params;
}

template <typename T>
LineMaterialSamplerBase<T>::LineMaterialSamplerBase(const InputParameters & parameters)
  : GeneralVectorPostprocessor(parameters),
    SamplerBase(parameters, this, _communicator),
    BlockRestrictable(this),
    _start(getParam<Point>("start")),
    _end(getParam<Point>("end")),
    _mesh(_subproblem.mesh()),
    _qrule(_subproblem.assembly(_tid).qRule()),
    _q_point(_subproblem.assembly(_tid).qPoints())
{
  _mesh.errorIfDistributedMesh("LineMaterialSamplerBase");

  std::vector<std::string> material_property_names = getParam<std::vector<std::string>>("property");
  for (unsigned int i = 0; i < material_property_names.size(); ++i)
  {
    if (!hasMaterialProperty<T>(material_property_names[i]))
      mooseError("In LineMaterialSamplerBase material property: " + material_property_names[i] +
                 " does not exist.");
    _material_properties.push_back(&getMaterialProperty<T>(material_property_names[i]));
  }

  SamplerBase::setupVariables(material_property_names);
}

template <typename T>
void
LineMaterialSamplerBase<T>::initialize()
{
  SamplerBase::initialize();
}

template <typename T>
{'fraction_non_alphanumeric': 0.11045987376014428, 'fraction_numerical': 0.001352569882777277, 'mean_word_length': 4.155723416618245, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, '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': '3834407', 'n_tokens_mistral': 2549, 'n_tokens_neox': 2503, 'n_words': 753}