https://mooseframework.inl.gov
Sampler1DReal.C
Go to the documentation of this file.
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 "Sampler1DReal.h"
11 
12 registerMooseObject("ThermalHydraulicsApp", Sampler1DReal);
13 registerMooseObject("ThermalHydraulicsApp", ADSampler1DReal);
14 
15 template <bool is_ad>
18 {
20  params += SamplerBase::validParams();
22 
23  params.addRequiredParam<std::vector<std::string>>(
24  "property", "Names of the material properties to be output along a line");
25 
26  // This parameter exists in BlockRestrictable, but it is made required here
27  // because it is undesirable to use the default, which is to add all blocks.
28  params.addRequiredParam<std::vector<SubdomainName>>(
29  "block", "The list of block ids (SubdomainID) for which this object will be applied");
30 
31  params.addClassDescription(
32  "Samples material properties at all quadrature points in mesh block(s)");
33 
34  return params;
35 }
36 
37 template <bool is_ad>
39  : GeneralVectorPostprocessor(parameters),
40  SamplerBase(parameters, this, _communicator),
41  BlockRestrictable(this),
42  _mesh(_subproblem.mesh()),
43  _qrule(_assembly.qRule()),
44  _q_point(_assembly.qPoints())
45 {
46  std::vector<std::string> material_property_names = getParam<std::vector<std::string>>("property");
47  for (unsigned int i = 0; i < material_property_names.size(); ++i)
48  {
49  if (!hasGenericMaterialProperty<Real, is_ad>(material_property_names[i]))
50  mooseError("The material property '" + material_property_names[i] + "' does not exist.");
51  _material_properties.push_back(
52  &getGenericMaterialProperty<Real, is_ad>(material_property_names[i]));
53  }
54 
55  SamplerBase::setupVariables(material_property_names);
56 }
57 
58 template <bool is_ad>
59 void
61 {
63 }
64 
65 template <bool is_ad>
66 void
68 {
69  std::vector<Real> values(_material_properties.size());
70 
71  std::unordered_set<unsigned int> needed_mat_props;
72  const auto & mp_deps = getMatPropDependencies();
73  needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
74  _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
75 
76  ConstElemRange & elem_range = *(_mesh.getActiveLocalElementRange());
77  for (typename ConstElemRange::const_iterator el = elem_range.begin(); el != elem_range.end();
78  ++el)
79  {
80  const Elem * elem = *el;
81 
82  if (elem->processor_id() != processor_id())
83  continue;
84 
85  if (!hasBlocks(elem->subdomain_id()))
86  continue;
87 
88  _subproblem.setCurrentSubdomainID(elem, _tid);
89  _subproblem.prepare(elem, _tid);
90  _subproblem.reinitElem(elem, _tid);
91 
92  // Set up Sentinel class so that, even if reinitMaterials() throws, we
93  // still remember to swap back during stack unwinding.
94  SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterials, _tid);
95  _fe_problem.reinitMaterials(elem->subdomain_id(), _tid);
96 
97  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
98  {
99  for (unsigned int j = 0; j < _material_properties.size(); ++j)
100  values[j] = MetaPhysicL::raw_value((*_material_properties[j])[qp]);
101 
102  // use the "x" coordinate as the "id"; at this time, it is not used for anything
103  addSample(_q_point[qp], _q_point[qp](0), values);
104  }
105  }
106  _fe_problem.clearActiveMaterialProperties(_tid);
107 }
108 
109 template <bool is_ad>
110 void
112 {
114 }
virtual void initialize()
MeshBase & mesh
auto raw_value(const Eigen::Map< T > &in)
virtual void execute() override
Definition: Sampler1DReal.C:67
std::vector< const GenericMaterialProperty< Real, is_ad > * > _material_properties
The material properties to be output.
Definition: Sampler1DReal.h:45
void addRequiredParam(const std::string &name, const std::string &doc_string)
StoredRange< MeshBase::const_element_iterator, const Elem *> ConstElemRange
static InputParameters validParams()
virtual void initialize() override
Definition: Sampler1DReal.C:60
registerMooseObject("ThermalHydraulicsApp", Sampler1DReal)
void setupVariables(const std::vector< std::string > &variable_names)
static InputParameters validParams()
Sampler1DRealTempl(const InputParameters &parameters)
Class constructor Sets up variables for output based on the properties to be output.
Definition: Sampler1DReal.C:38
static InputParameters validParams()
virtual void finalize()
virtual void swapBackMaterials(const THREAD_ID tid)
virtual void finalize() override
static InputParameters validParams()
Definition: Sampler1DReal.C:17
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
Samples material properties at all quadrature points in mesh block(s)
Definition: Sampler1DReal.h:27
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")