VTK  9.7.1
vtkIOSSUtilities.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 vtkIOSSUtilities_h
4 #define vtkIOSSUtilities_h
5 
20 #include "vtkDataArraySelection.h"
21 #include "vtkDoubleArray.h"
22 #include "vtkIOSSReader.h"
23 #include "vtkLogger.h"
24 #include "vtkObject.h"
25 #include "vtkSmartPointer.h"
26 #include "vtkTypeInt32Array.h"
27 #include "vtkTypeInt64Array.h"
28 #include "vtkTypeList.h" // Needed for ArrayList definition
29 
30 // Ioss includes
31 #include <vtk_ioss.h>
32 // clang-format off
33 #include VTK_IOSS(Ioss_Region.h)
34 #include VTK_IOSS(Ioss_Transform.h)
35 #include VTK_IOSS(Ioss_StructuredBlock.h)
36 #include VTK_IOSS(Ioss_SideSet.h)
37 // clang-format on
38 
39 #include <cassert>
40 #include <set>
41 
42 VTK_ABI_NAMESPACE_BEGIN
43 class vtkCellArray;
44 class vtkDataSet;
45 VTK_ABI_NAMESPACE_END
46 
47 namespace vtkIOSSUtilities
48 {
49 VTK_ABI_NAMESPACE_BEGIN
50 
52 {
57 };
58 
62 class Cache
63 {
64 public:
65  Cache();
66  ~Cache();
67 
71  void ResetAccessCounts();
72 
77  void ClearUnused();
78 
82  void Clear();
83 
84  vtkObject* Find(const Ioss::GroupingEntity* entity, const std::string& cachekey) const;
85  void Insert(const Ioss::GroupingEntity* entity, const std::string& cachekey, vtkObject* array);
86 
87 private:
88  Cache(const Cache&) = delete;
89  void operator=(const Cache&) = delete;
90 
91  class CacheInternals;
92  CacheInternals* Internals;
93 };
94 
100 {
101 public:
104 
108  std::string GetMessages() const;
109 
110 private:
111  std::ostringstream Stream;
112  std::ostream* OutputStream;
113  std::ostream* DebugStream;
114  std::ostream* WarningStream;
115 };
116 
117 using EntityNameType = std::pair<vtkTypeUInt64, std::string>;
118 
125 using ArrayList = typename vtkTypeList::Unique<
127 
132 std::vector<std::pair<int, double>> GetTime(const Ioss::Region* region);
133 
141 std::string GetSanitizedBlockName(const Ioss::Region* region, const std::string& name);
142 
148 template <typename EntityType>
149 void GetEntityAndFieldNames(const Ioss::Region* region, const std::vector<EntityType*>& entities,
150  std::set<EntityNameType>& entity_names, std::set<std::string>& field_names)
151 {
152  for (const auto& entity : entities)
153  {
154  const int64_t id = entity->property_exists("id") ? entity->get_property("id").get_int() : 0;
155  auto name = vtkIOSSUtilities::GetSanitizedBlockName(region, entity->name());
156  entity_names.insert(EntityNameType{ static_cast<vtkTypeUInt64>(id), name });
157 
158  Ioss::NameList attributeNames;
159  entity->field_describe(Ioss::Field::TRANSIENT, &attributeNames);
160  entity->field_describe(Ioss::Field::ATTRIBUTE, &attributeNames);
161  std::copy(
162  attributeNames.begin(), attributeNames.end(), std::inserter(field_names, field_names.end()));
163  }
164 }
165 
169 void GetGlobalFieldNames(const Ioss::Region* region, std::set<std::string>& field_names);
170 
174 template <>
175 void GetEntityAndFieldNames<Ioss::SideSet>(const Ioss::Region* region,
176  const std::vector<Ioss::SideSet*>& entities, std::set<EntityNameType>& entity_names,
177  std::set<std::string>& field_names);
178 
185 Ioss::EntityType GetIOSSEntityType(vtkIOSSReader::EntityType vtk_type);
186 
195 
202 vtkSmartPointer<vtkDataArray> GetData(const Ioss::GroupingEntity* entity,
203  const std::string& fieldname, Ioss::Transform* transform = nullptr, Cache* cache = nullptr,
204  const std::string& cachekey = std::string());
205 
214 int GetCellType(const Ioss::ElementTopology* topology);
215 
223 const Ioss::ElementTopology* GetElementTopology(int vtk_cell_type);
224 
236  Ioss::GroupingEntity* group_entity, int& vtk_topology_type, Cache* cache = nullptr);
237 
244  const Ioss::GroupingEntity* group_entity, Cache* cache = nullptr);
245 
252 bool IsFieldTransient(const Ioss::GroupingEntity* entity, const std::string& fieldname);
253 
255 
258 std::string GetDisplacementFieldName(Ioss::GroupingEntity* nodeblock);
261 
267 
272 DatabaseFormatType DetectType(const std::string& dbaseName);
273 
279 DatabaseFormatType GetFormat(const Ioss::GroupingEntity* entity);
280 
287 std::vector<Ioss::StructuredBlock*> GetMatchingStructuredBlocks(
288  Ioss::Region* region, const std::string& blockname);
289 
290 VTK_ABI_NAMESPACE_END
291 }
292 
293 #endif
294 // VTK-HeaderTest-Exclude: vtkIOSSUtilities.h
std::string GetSanitizedBlockName(const Ioss::Region *region, const std::string &name)
This is primarily intended for CGNS.
abstract base class for most VTK objects
Definition: vtkObject.h:52
Remove all duplicate types from TypeList TList, storing the new list in Result.
Definition: vtkTypeList.h:117
Ioss::EntityType GetIOSSEntityType(vtkIOSSReader::EntityType vtk_type)
For the given vtkIOSSReader::EntityType return the corresponding Ioss::EntityType.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
void GetGlobalFieldNames(const Ioss::Region *region, std::set< std::string > &field_names)
Reads global fields from the region and populates field_names.
std::vector< Ioss::StructuredBlock * > GetMatchingStructuredBlocks(Ioss::Region *region, const std::string &blockname)
Returns collection of StructuredBlock's matching the selected blockname.
void Insert(const Ioss::GroupingEntity *entity, const std::string &cachekey, vtkObject *array)
DatabaseFormatType GetFormat(const Ioss::GroupingEntity *entity)
Given any GroupingEntity pointer, returns the format that the associated database is in...
typename vtkTypeList::detail::CreateImpl< Ts... >::type Create
Definition: vtkTypeList.h:171
vtkObject * Find(const Ioss::GroupingEntity *entity, const std::string &cachekey) const
std::string GetDisplacementFieldName(Ioss::GroupingEntity *nodeblock)
Finds a displacement field name.
const Ioss::ElementTopology * GetElementTopology(int vtk_cell_type)
Returns an Ioss topology element, if possible, given a VTK cell type.
void Clear()
Clears the cache.
vtkSmartPointer< vtkDataArray > GetData(const Ioss::GroupingEntity *entity, const std::string &fieldname, Ioss::Transform *transform=nullptr, Cache *cache=nullptr, const std::string &cachekey=std::string())
Returns a VTK array for a given field (fieldname) on the chosen block (or set) entity.
int GetCellType(const Ioss::ElementTopology *topology)
Returns VTK celltype for a Ioss topology element.
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
std::string GetMessages() const
Provides access to the accumulated messages.
object to represent cell connectivity
Definition: vtkCellArray.h:177
vtkSmartPointer< vtkPoints > GetMeshModelCoordinates(const Ioss::GroupingEntity *group_entity, Cache *cache=nullptr)
Read points from the group_entity.
std::vector< std::pair< int, double > > GetTime(const Ioss::Region *region)
Reads time / timestep information from a region.
void GetEntityAndFieldNames(const Ioss::Region *region, const std::vector< EntityType * > &entities, std::set< EntityNameType > &entity_names, std::set< std::string > &field_names)
Populates entitySelection with available entity block (or set) names and populates fieldSelection wit...
bool IsFieldTransient(const Ioss::GroupingEntity *entity, const std::string &fieldname)
Returns true if the field is transient.
void ResetAccessCounts()
Call this to clear internal count for hits.
internal utilities for vtkIOSSReader
A helper to instantiate on stack to temporarily redirect non-critical messages emanating from IOSS...
vtkSmartPointer< vtkDataArray > CreateArray(const Ioss::Field &field)
Create an array for the given field.
void InitializeEnvironmentForIOSS()
Must be called before using any Ioss library functions.
DatabaseFormatType DetectType(const std::string &dbaseName)
Given a filename determines and returns the database type.
std::pair< vtkTypeUInt64, std::string > EntityNameType
void ClearUnused()
Removes all cached entries not accessed since most recent call to ResetAccessCounts.