https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
12registerMooseObject("ThermalHydraulicsApp", Sampler1DReal);
13registerMooseObject("ThermalHydraulicsApp", ADSampler1DReal);
14
15template <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
32 "Samples material properties at all quadrature points in mesh block(s)");
33
34 return params;
35}
36
37template <bool is_ad>
39 : GeneralVectorPostprocessor(parameters),
40 SamplerBase(parameters, this, _communicator),
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
58template <bool is_ad>
59void
64
65template <bool is_ad>
66void
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 const 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
109template <bool is_ad>
110void
std::array< Real, 2 > values
registerMooseObject("ThermalHydraulicsApp", Sampler1DReal)
static InputParameters validParams()
virtual void swapBackMaterials(const THREAD_ID tid)
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void mooseError(Args &&... args) const
Samples material properties at all quadrature points in mesh block(s)
virtual void execute() override
static InputParameters validParams()
std::vector< const GenericMaterialProperty< Real, is_ad > * > _material_properties
The material properties to be output.
virtual void finalize() override
Sampler1DRealTempl(const InputParameters &parameters)
Class constructor Sets up variables for output based on the properties to be output.
virtual void initialize() override
void setupVariables(const std::vector< std::string > &variable_names)
virtual void initialize()
virtual void finalize()
static InputParameters validParams()
MeshBase & mesh
auto raw_value(const Eigen::Map< T > &in)