VTK  9.7.1
vtkDGOperation.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 #ifndef vtkDGOperation_h
4 #define vtkDGOperation_h
5 
6 #include "vtkCompiler.h" // For VTK_ALWAYS_EXPORT.
7 #include "vtkDGCell.h" // For vtkDGCell::Source used in API.
8 #include "vtkDGOperationStateEntry.h" // For API.
9 #include "vtkSMPThreadLocal.h" // For API.
10 
11 VTK_ABI_NAMESPACE_BEGIN
12 
13 class vtkDoubleArray;
14 
17 class VTKFILTERSCELLGRID_EXPORT vtkDGOperationBase
18 {
19 public:
21  struct VTKFILTERSCELLGRID_EXPORT RangeKey
22  {
23  vtkTypeUInt64 Begin;
24  vtkTypeUInt64 End;
25  bool Contains(vtkTypeUInt64 cellId) const;
26  bool ContainedBy(const RangeKey& other) const;
27  bool operator<(const RangeKey& other) const;
28  };
29 };
30 
34 template <typename InputIterator, typename OutputIterator>
36 {
37 public:
47  using EvaluatorMap = std::map<RangeKey, OpEvalEntry>;
48 
53  vtkDGOperation() = default;
54  vtkDGOperation(const SelfType& other);
56  vtkDGCell* cellType, vtkCellAttribute* cellAttribute, vtkStringToken operationName);
57 
58  void PrintSelf(std::ostream& os, vtkIndent indent);
59 
80  bool Prepare(vtkDGCell* cellType, vtkCellAttribute* cellAttribute, vtkStringToken operationName,
81  bool includeShape = true);
82 
93  bool Evaluate(InputIterator& inIter, OutputIterator& outIter, vtkTypeUInt64 begin = 0,
94  vtkTypeUInt64 end = ~0);
95 
111  OpEval GetEvaluatorForSideSpec(vtkDGCell* cell, int sideSpecId);
112 
115  int GetNumberOfResultComponents() const { return this->NumberOfResultComponents; }
116 
120  {
121  InputIterator& InIter;
122  OutputIterator& OutIter;
123  vtkDGCell* DGCell{ nullptr };
124  vtkCellAttribute* CellAtt{ nullptr };
126 
127  Worker(InputIterator& inIter, OutputIterator& outIter, vtkDGCell* dgCell,
128  vtkCellAttribute* cellAtt, vtkStringToken opName)
129  : InIter(inIter)
130  , OutIter(outIter)
131  , DGCell(dgCell)
132  , CellAtt(cellAtt)
133  , OpName(opName)
134  {
135  }
136 
138 
139  void Initialize()
140  {
141  if (!TLOp.Local().Prepare(this->DGCell, this->CellAtt, this->OpName))
142  {
143  throw std::runtime_error("Could not initialize operation for evaluation.");
144  }
145  }
146 
147  void operator()(vtkIdType begin, vtkIdType end)
148  {
149  TLOp.Local()(this->InIter, this->OutIter, begin, end);
150  }
151  };
152 
153 protected:
154  void AddSource(vtkCellGrid* grid, vtkDGCell* cellType, std::size_t sideSpecIdx,
155  vtkCellAttribute* cellAtt, const vtkCellAttribute::CellTypeInfo& cellTypeInfo,
156  vtkDGOperatorEntry& op, bool includeShape);
157 
159  typename EvaluatorMap::const_iterator FindEvaluator(
160  RangeKey cellKey, const EvaluatorMap& evaluators);
161 
162  int NumberOfResultComponents{ 0 };
164 };
165 
166 VTK_ABI_NAMESPACE_END
167 #endif // vtkDGOperation_h
168 // VTK-HeaderTest-Exclude: vtkDGOperation.h
A vtkSMPTools worker class for evaluating an operation across a range of cells.
T & Local()
This needs to be called mainly within a threaded execution path.
OutputIterator & OutIter
A range of cell IDs handled by a vtkDGCell::Source instance.
std::function< void(InputIterator &inIter, OutputIterator &outIter, vtkTypeUInt64 begin, vtkTypeUInt64 end)> vtkDGCellRangeEvaluator
Signature for a method to evaluate data on a single vtkDGCell::Source instance.
int vtkIdType
Definition: vtkType.h:363
std::map< RangeKey, OpEvalEntry > EvaluatorMap
Container for functions that evaluate data on a single vtkDGCell::Source instance.
dynamic, self-adjusting array of double
Invoke an operator on DG cells/sides.
EvaluatorMap Evaluators
Visualization data composed of cells of arbitrary type.
Definition: vtkCellGrid.h:48
a simple class to control print indentation
Definition: vtkIndent.h:28
A base class for operator evaluators.
A function defined over the physical domain of a vtkCellGrid.
InputIterator & InIter
vtkDGCellRangeEvaluator< vtkDGArraysInputAccessor, vtkDGArrayOutputAccessor > OpEval
The signature for a function that evaluates iterators over a range.
bool VTKCOMMONCORE_EXPORT operator<(const std::string &a, const vtkStringToken &b)
Base class for a discontinuous Galerkin cells of all shapes.
Definition: vtkDGCell.h:43
Thread local storage for VTK objects.
Encapsulate the state required to evaluate DG cell-attributes.
Represent a string by its integer hash.
A record for a basis in a function space that is specific to one cell shape.
int GetNumberOfResultComponents() const
Return the number of values generated per tuple each time an input cell-id and parameter-value are ev...
#define VTK_ALWAYS_EXPORT
Definition: vtkCompiler.h:65
Worker(InputIterator &inIter, OutputIterator &outIter, vtkDGCell *dgCell, vtkCellAttribute *cellAtt, vtkStringToken opName)
vtkSMPThreadLocal< vtkDGOperation< InputIterator, OutputIterator > > TLOp
void operator()(vtkIdType begin, vtkIdType end)