https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Sampler1DBase.h
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#pragma once
11
12// MOOSE includes
14#include "SamplerBase.h"
15#include "BlockRestrictable.h"
16#include "Assembly.h"
17#include "MooseMesh.h"
18#include "SwapBackSentinel.h"
19#include "FEProblem.h"
20
21// libMesh includes
22#include "libmesh/quadrature.h"
23
24// Forward Declarations
25class MooseMesh;
26
34template <typename T>
36 public SamplerBase,
38{
39public:
46
51 virtual void initialize() override;
52
56 virtual void execute() override;
57
62 virtual void finalize() override;
63
70 virtual Real getScalarFromProperty(const T & property, const Point & curr_point) = 0;
71
72protected:
74 std::vector<const MaterialProperty<T> *> _material_properties;
75
78
80 const QBase * const & _qrule;
81
84
85public:
87};
88
89template <typename T>
91 : GeneralVectorPostprocessor(parameters),
92 SamplerBase(parameters, this, _communicator),
94 _mesh(_subproblem.mesh()),
95 _qrule(_assembly.qRule()),
96 _q_point(_assembly.qPoints())
97{
98 std::vector<std::string> material_property_names = getParam<std::vector<std::string>>("property");
99 for (unsigned int i = 0; i < material_property_names.size(); ++i)
100 {
101 if (!hasMaterialProperty<T>(material_property_names[i]))
102 mooseError("In Sampler1DBase material property: " + material_property_names[i] +
103 " does not exist.");
104 _material_properties.push_back(&getMaterialProperty<T>(material_property_names[i]));
105 }
106
107 SamplerBase::setupVariables(material_property_names);
108}
109
110template <typename T>
111void
116
117template <typename T>
118void
120{
121 std::vector<Real> values(_material_properties.size());
122
123 std::unordered_set<unsigned int> needed_mat_props;
124 const auto & mp_deps = getMatPropDependencies();
125 needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
126 _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
127
128 const ConstElemRange & elem_range = *(_mesh.getActiveLocalElementRange());
129 for (typename ConstElemRange::const_iterator el = elem_range.begin(); el != elem_range.end();
130 ++el)
131 {
132 const Elem * elem = *el;
133
134 if (elem->processor_id() != processor_id())
135 continue;
136
137 if (!hasBlocks(elem->subdomain_id()))
138 continue;
139
140 _subproblem.setCurrentSubdomainID(elem, _tid);
141 _subproblem.prepare(elem, _tid);
142 _subproblem.reinitElem(elem, _tid);
143
144 // Set up Sentinel class so that, even if reinitMaterials() throws, we
145 // still remember to swap back during stack unwinding.
146 SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterials, _tid);
147 _fe_problem.reinitMaterials(elem->subdomain_id(), _tid);
148
149 for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
150 {
151 for (unsigned int j = 0; j < _material_properties.size(); ++j)
152 values[j] = getScalarFromProperty((*_material_properties[j])[qp], _q_point[qp]);
153
154 // use the "x" coordinate as the "id"; at this time, it is not used for anything
155 addSample(_q_point[qp], _q_point[qp](0), values);
156 }
157 }
158 _fe_problem.clearActiveMaterialProperties(_tid);
159}
160
161template <typename T>
162void
const double T
std::array< Real, 2 > values
virtual void swapBackMaterials(const THREAD_ID tid)
const InputParameters & parameters() const
void mooseError(Args &&... args) const
This is a base class for sampling material properties for the integration points in all elements in a...
MooseMesh & _mesh
The mesh.
static InputParameters validParams()
const QBase *const & _qrule
The quadrature rule.
Sampler1DBase(const InputParameters &parameters)
Class constructor Sets up variables for output based on the properties to be output.
const MooseArray< Point > & _q_point
The quadrature points.
virtual void execute() override
Loops through all elements in a block and samples their material properties.
virtual void initialize() override
Initialize Calls through to base class's initialize()
virtual Real getScalarFromProperty(const T &property, const Point &curr_point)=0
Reduce the material property to a scalar for output.
std::vector< const MaterialProperty< T > * > _material_properties
The material properties to be output.
virtual void finalize() override
Finalize Calls through to base class's finalize()
void setupVariables(const std::vector< std::string > &variable_names)
virtual void initialize()
virtual void finalize()
MeshBase & mesh