VTK  9.3.0
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
18 #ifndef vtkIOSSUtilities_h
19 #define vtkIOSSUtilities_h
20 
21 #include "vtkDataArraySelection.h"
22 #include "vtkDoubleArray.h"
23 #include "vtkIOSSReader.h"
24 #include "vtkLogger.h"
25 #include "vtkObject.h"
26 #include "vtkSmartPointer.h"
27 #include "vtkTypeInt32Array.h"
28 #include "vtkTypeInt64Array.h"
29 #include "vtkTypeList.h" // Needed for ArrayList definition
30 
31 // Ioss includes
32 #include <vtk_ioss.h>
33 // clang-format off
34 #include VTK_IOSS(Ioss_Region.h)
35 #include VTK_IOSS(Ioss_Transform.h)
36 #include VTK_IOSS(Ioss_StructuredBlock.h)
37 #include VTK_IOSS(Ioss_SideSet.h)
38 #include VTK_IOSS(Ioss_SideBlock.h)
39 // clang-format on
40 
41 #include <cassert>
42 #include <set>
43 
44 VTK_ABI_NAMESPACE_BEGIN
45 class vtkCellArray;
46 class vtkDataSet;
47 VTK_ABI_NAMESPACE_END
48 
49 namespace vtkIOSSUtilities
50 {
51 VTK_ABI_NAMESPACE_BEGIN
52 
54 {
59 };
60 
64 class Cache
65 {
66 public:
67  Cache();
68  ~Cache();
69 
74 
79  void ClearUnused();
80 
84  void Clear();
85 
86  vtkObject* Find(const Ioss::GroupingEntity* entity, const std::string& cachekey) const;
87  void Insert(const Ioss::GroupingEntity* entity, const std::string& cachekey, vtkObject* array);
88 
89 private:
90  Cache(const Cache&) = delete;
91  void operator=(const Cache&) = delete;
92 
93  class CacheInternals;
94  CacheInternals* Internals;
95 };
96 
102 {
103 public:
106 
111 
112 private:
113  std::ostringstream Stream;
114  std::ostream* DebugStream;
115  std::ostream* WarningStream;
116 };
117 
118 using EntityNameType = std::pair<vtkTypeUInt64, std::string>;
119 
127  vtkTypeList::Create<vtkDoubleArray, vtkTypeInt32Array, vtkTypeInt64Array>>::Result;
128 
133 std::vector<std::pair<int, double>> GetTime(const Ioss::Region* region);
134 
142 std::string GetSanitizedBlockName(const Ioss::Region* region, const std::string& name);
143 
149 template <typename EntityType>
150 void GetEntityAndFieldNames(const Ioss::Region* region, const std::vector<EntityType*>& entities,
151  std::set<EntityNameType>& entity_names, std::set<std::string>& field_names)
152 {
153  for (const auto& entity : entities)
154  {
155  const int64_t id = entity->property_exists("id") ? entity->get_property("id").get_int() : 0;
156  auto name = vtkIOSSUtilities::GetSanitizedBlockName(region, entity->name());
157  entity_names.insert(EntityNameType{ static_cast<vtkTypeUInt64>(id), name });
158 
159  Ioss::NameList attributeNames;
160  entity->field_describe(Ioss::Field::TRANSIENT, &attributeNames);
161  entity->field_describe(Ioss::Field::ATTRIBUTE, &attributeNames);
162  std::copy(
163  attributeNames.begin(), attributeNames.end(), std::inserter(field_names, field_names.end()));
164  }
165 }
169 template <>
170 void GetEntityAndFieldNames<Ioss::SideSet>(const Ioss::Region* region,
171  const std::vector<Ioss::SideSet*>& entities, std::set<EntityNameType>& entity_names,
172  std::set<std::string>& field_names);
173 
180 Ioss::EntityType GetIOSSEntityType(vtkIOSSReader::EntityType vtk_type);
181 
190 
197 vtkSmartPointer<vtkDataArray> GetData(const Ioss::GroupingEntity* entity,
198  const std::string& fieldname, Ioss::Transform* transform = nullptr, Cache* cache = nullptr,
199  const std::string& cachekey = std::string());
200 
209 int GetCellType(const Ioss::ElementTopology* topology);
210 
218 const Ioss::ElementTopology* GetElementTopology(int vtk_cell_type);
219 
231  Ioss::GroupingEntity* group_entity, int& vtk_topology_type, Cache* cache = nullptr);
232 
239  const Ioss::GroupingEntity* group_entity, Cache* cache = nullptr);
240 
247 bool IsFieldTransient(Ioss::GroupingEntity* entity, const std::string& fieldname);
248 
250 
253 std::string GetDisplacementFieldName(Ioss::GroupingEntity* nodeblock);
256 
262 
268 
274 DatabaseFormatType GetFormat(const Ioss::GroupingEntity* entity);
275 
282 std::vector<Ioss::StructuredBlock*> GetMatchingStructuredBlocks(
283  Ioss::Region* region, const std::string& blockname);
284 
285 VTK_ABI_NAMESPACE_END
286 }
287 
288 #endif
289 // VTK-HeaderTest-Exclude: vtkIOSSUtilities.h
object to represent cell connectivity
Definition: vtkCellArray.h:176
abstract class to specify dataset behavior
Definition: vtkDataSet.h:53
void Clear()
Clears the cache.
void ClearUnused()
Removes all cached entries not accessed since most recent call to ResetAccessCounts.
void ResetAccessCounts()
Call this to clear internal count for hits.
void Insert(const Ioss::GroupingEntity *entity, const std::string &cachekey, vtkObject *array)
vtkObject * Find(const Ioss::GroupingEntity *entity, const std::string &cachekey) const
A helper to instantiate on stack to temporarily redirect non-critical messages emanating from IOSS.
std::string GetMessages() const
Provides access to the accumulated messages.
abstract base class for most VTK objects
Definition: vtkObject.h:52
internal utilities for vtkIOSSReader
const Ioss::ElementTopology * GetElementTopology(int vtk_cell_type)
Returns an Ioss topology element, if possible, given a VTK cell type.
vtkSmartPointer< vtkPoints > GetMeshModelCoordinates(const Ioss::GroupingEntity *group_entity, Cache *cache=nullptr)
Read points from the group_entity.
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.
void InitializeEnvironmentForIOSS()
Must be called before using any Ioss library functions.
std::vector< Ioss::StructuredBlock * > GetMatchingStructuredBlocks(Ioss::Region *region, const std::string &blockname)
Returns collection of StructuredBlock's matching the selected blockname.
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...
DatabaseFormatType GetFormat(const Ioss::GroupingEntity *entity)
Given any GroupingEntity pointer, returns the format that the associated database is in.
std::pair< vtkTypeUInt64, std::string > EntityNameType
Ioss::EntityType GetIOSSEntityType(vtkIOSSReader::EntityType vtk_type)
For the given vtkIOSSReader::EntityType return the corresponding Ioss::EntityType.
std::vector< std::pair< int, double > > GetTime(const Ioss::Region *region)
Reads time / timestep information from a region.
int GetCellType(const Ioss::ElementTopology *topology)
Returns VTK celltype for a Ioss topology element.
std::string GetSanitizedBlockName(const Ioss::Region *region, const std::string &name)
This is primarily intended for CGNS.
bool IsFieldTransient(Ioss::GroupingEntity *entity, const std::string &fieldname)
Returns true if the field is transient.
std::string GetDisplacementFieldName(Ioss::GroupingEntity *nodeblock)
Finds a displacement field name.
vtkSmartPointer< vtkDataArray > CreateArray(const Ioss::Field &field)
Create an array for the given field.
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
DatabaseFormatType DetectType(const std::string &dbaseName)
Given a filename determines and returns the database type.
@ field
Definition: vtkX3D.h:177
@ Transform
Definition: vtkX3D.h:41
@ name
Definition: vtkX3D.h:219
@ string
Definition: vtkX3D.h:490
Remove all duplicate types from TypeList TList, storing the new list in Result.
Definition: vtkTypeList.h:110