https://mooseframework.inl.gov
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
25 class MooseMesh;
26 
34 template <typename T>
36  public SamplerBase,
37  public BlockRestrictable
38 {
39 public:
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 
72 protected:
74  std::vector<const MaterialProperty<T> *> _material_properties;
75 
78 
80  const QBase * const & _qrule;
81 
84 
85 public:
87 };
88 
89 template <typename T>
91  : GeneralVectorPostprocessor(parameters),
92  SamplerBase(parameters, this, _communicator),
93  BlockRestrictable(this),
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 
110 template <typename T>
111 void
113 {
115 }
116 
117 template <typename T>
118 void
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  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 
161 template <typename T>
162 void
164 {
166 }
virtual void initialize()
MooseMesh & _mesh
The mesh.
Definition: Sampler1DBase.h:77
virtual Real getScalarFromProperty(const T &property, const Point &curr_point)=0
Reduce the material property to a scalar for output.
MeshBase & mesh
const QBase *const & _qrule
The quadrature rule.
Definition: Sampler1DBase.h:80
StoredRange< MeshBase::const_element_iterator, const Elem *> ConstElemRange
This is a base class for sampling material properties for the integration points in all elements in a...
Definition: Sampler1DBase.h:35
std::vector< const MaterialProperty< T > * > _material_properties
The material properties to be output.
Definition: Sampler1DBase.h:74
void setupVariables(const std::vector< std::string > &variable_names)
virtual void initialize() override
Initialize Calls through to base class&#39;s initialize()
virtual void finalize() override
Finalize Calls through to base class&#39;s finalize()
virtual void finalize()
virtual void swapBackMaterials(const THREAD_ID tid)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Sampler1DBase(const InputParameters &parameters)
Class constructor Sets up variables for output based on the properties to be output.
Definition: Sampler1DBase.h:90
void mooseError(Args &&... args) const
const InputParameters & parameters() const
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
static InputParameters validParams()
const MooseArray< Point > & _q_point
The quadrature points.
Definition: Sampler1DBase.h:83
virtual void execute() override
Loops through all elements in a block and samples their material properties.