VTK  9.4.20241108
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
11VTK_ABI_NAMESPACE_BEGIN
12
13class vtkDoubleArray;
14
17class VTKFILTERSCELLGRID_EXPORT vtkDGOperationBase
18{
19public:
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
34template <typename InputIterator, typename OutputIterator>
36{
37public:
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
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
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
148 {
149 TLOp.Local()(this->InIter, this->OutIter, begin, end);
150 }
151 };
152
153protected:
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
166VTK_ABI_NAMESPACE_END
167#endif // vtkDGOperation_h
168// VTK-HeaderTest-Exclude: vtkDGOperation.h
A function defined over the physical domain of a vtkCellGrid.
Visualization data composed of cells of arbitrary type.
Definition vtkCellGrid.h:49
Base class for a discontinuous Galerkin cells of all shapes.
Definition vtkDGCell.h:44
A base class for operator evaluators.
Encapsulate the state required to evaluate DG cell-attributes.
Invoke an operator on DG cells/sides.
bool Prepare(vtkDGCell *cellType, vtkCellAttribute *cellAttribute, vtkStringToken operationName, bool includeShape=true)
Prepare this instance of vtkDGOperation to evaluate operationName on the given cellType and cellAttri...
EvaluatorMap Evaluators
int GetNumberOfResultComponents() const
Return the number of values generated per tuple each time an input cell-id and parameter-value are ev...
OpEval GetEvaluatorForSideSpec(vtkDGCell *cell, int sideSpecId)
Return a function that can be called on the named sideSpecId.
EvaluatorMap::const_iterator FindEvaluator(RangeKey cellKey, const EvaluatorMap &evaluators)
Return the first iterator to an entry of evaluators that covers cellKey.
std::map< RangeKey, OpEvalEntry > EvaluatorMap
Container for functions that evaluate data on a single vtkDGCell::Source instance.
vtkDGOperation(vtkDGCell *cellType, vtkCellAttribute *cellAttribute, vtkStringToken operationName)
vtkDGCellRangeEvaluator< InputIterator, OutputIterator > OpEval
The signature for a function that evaluates iterators over a range.
vtkDGOperation()=default
Construct an operation object.
void AddSource(vtkCellGrid *grid, vtkDGCell *cellType, std::size_t sideSpecIdx, vtkCellAttribute *cellAtt, const vtkCellAttribute::CellTypeInfo &cellTypeInfo, vtkDGOperatorEntry &op, bool includeShape)
bool Evaluate(InputIterator &inIter, OutputIterator &outIter, vtkTypeUInt64 begin=0, vtkTypeUInt64 end=~0)
Evaluate the prepared operator on the given cellIds at the given rst parameters, storing results in t...
vtkDGOperation(const SelfType &other)
void PrintSelf(std::ostream &os, vtkIndent indent)
A record for a basis in a function space that is specific to one cell shape.
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition vtkIndent.h:108
Thread local storage for VTK objects.
T & Local()
This needs to be called mainly within a threaded execution path.
Represent a string by its integer hash.
A range of cell IDs handled by a vtkDGCell::Source instance.
bool ContainedBy(const RangeKey &other) const
bool operator<(const RangeKey &other) const
bool Contains(vtkTypeUInt64 cellId) const
A vtkSMPTools worker class for evaluating an operation across a range of cells.
void operator()(vtkIdType begin, vtkIdType end)
Worker(InputIterator &inIter, OutputIterator &outIter, vtkDGCell *dgCell, vtkCellAttribute *cellAtt, vtkStringToken opName)
vtkSMPThreadLocal< vtkDGOperation< InputIterator, OutputIterator > > TLOp
OutputIterator & OutIter
#define VTK_ALWAYS_EXPORT
Definition vtkCompiler.h:65
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:315