IOSS 2.0
Loading...
Searching...
No Matches
Ioss_VariableType.h
Go to the documentation of this file.
1// Copyright(C) 1999-2024 National Technology & Engineering Solutions
2// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3// NTESS, the U.S. Government retains certain rights in this software.
4//
5// See packages/seacas/LICENSE for details
6
7#pragma once
8
9#include "Ioss_CodeTypes.h"
10#include "Ioss_Utils.h"
11#include <cstring> // for strncmp
12#include <functional> // for less
13#include <map> // for map, map<>::value_compare
14#include <string> // for string, operator<
15#include <vector> // for vector
16
17#include "ioss_export.h"
18
19namespace Ioss {
20 struct Basis;
21 struct QuadraturePoint;
22 class VariableType;
23} // namespace Ioss
24
25namespace Ioss {
26 using VariableTypeMap = std::map<std::string, VariableType *, std::less<>>;
27 using VTM_ValuePair = VariableTypeMap::value_type;
28
29 class IOSS_EXPORT Registry
30 {
31 friend class VariableType;
32
33 public:
34 void insert(const Ioss::VTM_ValuePair &value, bool delete_me);
35 IOSS_NODISCARD VariableTypeMap::iterator begin() { return m_registry.begin(); }
36 IOSS_NODISCARD VariableTypeMap::iterator end() { return m_registry.end(); }
37 IOSS_NODISCARD VariableTypeMap::iterator find(const std::string &type)
38 {
39 return m_registry.find(type);
40 }
41
42 ~Registry();
43
44 private:
45 std::map<std::string, std::string> customFieldTypes;
47 std::vector<Ioss::VariableType *> m_deleteThese;
48 };
49
50 struct IOSS_EXPORT Suffix
51 {
52 explicit Suffix(const char *new_data) : m_data(new_data) {}
53 explicit Suffix(std::string new_data) : m_data(std::move(new_data)) {}
54 IOSS_NODISCARD bool operator==(const std::string &str) const
55 {
56 return Utils::str_equal(m_data, str);
57 }
58 IOSS_NODISCARD bool operator!=(const std::string &str) const
59 {
60 return !Utils::str_equal(m_data, str);
61 }
62 IOSS_NODISCARD bool is_uppercase() const { return isalpha(m_data[0]) && isupper(m_data[0]); }
63
64 std::string m_data{};
65 };
66
67 /** \brief A generic variable type
68 */
69 class IOSS_EXPORT VariableType
70 {
71 public:
72 enum class Type {
73 UNKNOWN,
74 SCALAR,
75 STANDARD,
76 COMPOSED,
77 COMPOSITE,
78 CONSTRUCTED,
79 ELEMENT,
80 NAMED_SUFFIX,
81 BASIS,
82 QUADRATURE
83 };
84
85 static void alias(const std::string &base, const std::string &syn);
86 static int describe(NameList *names);
87 IOSS_NODISCARD static NameList describe();
88
89 // Return a list of types that have been defined
90 // externally... Basically a subset of the types in the
91 // `Registry::m_deleteThese` list...
92 IOSS_NODISCARD static std::vector<Ioss::VariableType *>
93 external_types(Ioss::VariableType::Type type);
94
95 static bool create_named_suffix_type(const std::string &type_name,
96 const Ioss::NameList &suffices);
97
98 // Backward compatibility...
99 [[deprecated("Use create_named_suffix_type")]] static bool
100 create_named_suffix_field_type(const std::string &type_name, const Ioss::NameList &suffices)
101 {
102 return create_named_suffix_type(type_name, suffices);
103 }
104
105 static bool create_basis_type(const std::string &type_name, const Ioss::Basis &basis);
106 static bool create_quadrature_type(const std::string &type_name,
107 const std::vector<Ioss::QuadraturePoint> &quad_points);
108 static bool get_field_type_mapping(const std::string &field, std::string *type);
109 static bool add_field_type_mapping(const std::string &raw_field, const std::string &raw_type);
110
111 VariableType(const VariableType &) = delete;
113 virtual ~VariableType() = default;
114
115 virtual void print() const;
116
117 IOSS_NODISCARD int component_count() const;
118
119 // Override this function if the derived class has no suffices
120 // For example, a 'vector_2d' has suffices "x" and "y"
121 // A 'quad4' has no suffices...
122 IOSS_NODISCARD virtual int suffix_count() const;
123 IOSS_NODISCARD std::string name() const;
124 IOSS_NODISCARD virtual Type type() const = 0;
125 IOSS_NODISCARD virtual std::string type_string() const = 0;
126
127 IOSS_NODISCARD static std::string numeric_label(int which, int ncomp, const std::string &name);
128 IOSS_NODISCARD virtual std::string label(int which, char suffix_sep = '_') const = 0;
129 IOSS_NODISCARD virtual std::string label_name(const std::string &base, int which,
130 char suffix_sep1 = '_', char suffix_sep2 = '_',
131 bool suffices_uppercase = false) const;
132 IOSS_NODISCARD virtual bool match(const std::vector<Suffix> &suffices) const;
133
134 IOSS_NODISCARD static const VariableType *factory(const std::string &raw_name, int copies = 1);
135 IOSS_NODISCARD static const VariableType *factory(const std::string &raw_name,
136 const std::string &secondary);
137 IOSS_NODISCARD static const VariableType *factory(const std::vector<Suffix> &suffices,
138 bool ignore_realn_fields = false);
139
140 static Registry &registry();
141
142 protected:
143 VariableType(const std::string &type, int comp_count, bool delete_me = false);
144
145 private:
146 const std::string name_{};
147 int componentCount{};
148
149 static bool build_variable_type(const std::string &raw_type);
150 };
151} // namespace Ioss
152inline std::string Ioss::VariableType::name() const { return name_; }
153
154inline int Ioss::VariableType::component_count() const { return componentCount; }
155
156inline int Ioss::VariableType::suffix_count() const { return componentCount; }
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
Definition Ioss_VariableType.h:30
IOSS_NODISCARD VariableTypeMap::iterator begin()
Definition Ioss_VariableType.h:35
IOSS_NODISCARD VariableTypeMap::iterator find(const std::string &type)
Definition Ioss_VariableType.h:37
std::map< std::string, std::string > customFieldTypes
Definition Ioss_VariableType.h:45
Ioss::VariableTypeMap m_registry
Definition Ioss_VariableType.h:46
IOSS_NODISCARD VariableTypeMap::iterator end()
Definition Ioss_VariableType.h:36
std::vector< Ioss::VariableType * > m_deleteThese
Definition Ioss_VariableType.h:47
A generic variable type.
Definition Ioss_VariableType.h:70
const std::string name_
Definition Ioss_VariableType.h:146
VariableType & operator=(const VariableType &)=delete
static bool create_named_suffix_field_type(const std::string &type_name, const Ioss::NameList &suffices)
Definition Ioss_VariableType.h:100
Type
Definition Ioss_VariableType.h:72
VariableType(const VariableType &)=delete
virtual IOSS_NODISCARD std::string label(int which, char suffix_sep='_') const =0
IOSS_NODISCARD std::string name() const
Definition Ioss_VariableType.h:152
virtual IOSS_NODISCARD int suffix_count() const
Definition Ioss_VariableType.h:156
virtual ~VariableType()=default
IOSS_NODISCARD int component_count() const
Definition Ioss_VariableType.h:154
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
VariableTypeMap::value_type VTM_ValuePair
Definition Ioss_VariableType.h:27
Ioss::NameList NameList
Definition Ioss_ChangeSetFactory.h:25
std::map< std::string, VariableType *, std::less<> > VariableTypeMap
Definition Ioss_VariableType.h:26
Definition Ioss_BasisVariableType.h:30
Definition Ioss_VariableType.h:51
IOSS_NODISCARD bool is_uppercase() const
Definition Ioss_VariableType.h:62
IOSS_NODISCARD bool operator==(const std::string &str) const
Definition Ioss_VariableType.h:54
Suffix(std::string new_data)
Definition Ioss_VariableType.h:53
IOSS_NODISCARD bool operator!=(const std::string &str) const
Definition Ioss_VariableType.h:58
Suffix(const char *new_data)
Definition Ioss_VariableType.h:52