NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
LabeledAxisAccessor.h
1// Copyright 2024, UChicago Argonne, LLC
2// All Rights Reserved
3// Software Name: NEML2 -- the New Engineering material Model Library, version 2
4// By: Argonne National Laboratory
5// OPEN SOURCE LICENSE (MIT)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23// THE SOFTWARE.
24
25#pragma once
26
27#include <vector>
28#include <iosfwd>
29#include <string>
30
31namespace neml2
32{
33// Reserved subaxis names
34inline const std::string STATE = "state";
35inline const std::string OLD_STATE = "old_state";
36inline const std::string FORCES = "forces";
37inline const std::string OLD_FORCES = "old_forces";
38inline const std::string RESIDUAL = "residual";
39inline const std::string PARAMETERS = "parameters";
40
41// Reserved subaxis names
42std::vector<std::string> reserved_subaxis_names();
43
56{
57public:
59
60 template <typename... S>
61 LabeledAxisAccessor(const char * name, S &&... names)
62 {
63 validate_item_name(name);
64 _item_names.emplace_back(name);
65
66 (validate_item_name(names), ...);
67 (_item_names.emplace_back(std::forward<S>(names)), ...);
68 }
69
70 template <typename... S>
71 LabeledAxisAccessor(const std::string & name, S &&... names)
72 {
73 validate_item_name(name);
74 _item_names.emplace_back(name);
75
76 (validate_item_name(names), ...);
77 (_item_names.emplace_back(std::forward<S>(names)), ...);
78 }
79
80 template <typename Container,
81 typename = typename std::enable_if_t<
82 !std::is_convertible_v<Container, std::string> &&
83 std::is_convertible_v<typename std::iterator_traits<
84 decltype(std::declval<Container>().begin())>::value_type,
85 std::string> &&
86 std::is_convertible_v<typename std::iterator_traits<
87 decltype(std::declval<Container>().end())>::value_type,
88 std::string>>>
89 LabeledAxisAccessor(const Container & c)
90 {
91 _item_names = std::vector<std::string>(c.begin(), c.end());
92 for (const auto & name : _item_names)
93 validate_item_name(name);
94 }
95
96 using iterator = std::vector<std::string>::iterator;
97 using const_iterator = std::vector<std::string>::const_iterator;
98
105 iterator begin() { return iterator(_item_names.begin()); }
106 iterator end() { return iterator(_item_names.end()); }
107 const_iterator begin() const { return const_iterator(_item_names.begin()); }
108 const_iterator end() const { return const_iterator(_item_names.end()); }
110
111 explicit operator std::vector<std::string>() const;
112
113 const std::vector<std::string> & vec() const { return _item_names; }
114
115 std::string str() const;
116
117 bool empty() const;
118
119 size_t size() const;
120
121 const std::string & operator[](size_t i) const;
122
124 LabeledAxisAccessor with_suffix(const std::string & suffix) const;
125
128
131
133 LabeledAxisAccessor slice(int64_t n) const;
134
136 LabeledAxisAccessor slice(int64_t n1, int64_t n2) const;
137
139 LabeledAxisAccessor remount(const LabeledAxisAccessor & axis, int64_t n = 1) const;
140
142 bool start_with(const LabeledAxisAccessor & axis) const;
143
146 bool is_state() const;
147 bool is_old_state() const;
148 bool is_force() const;
149 bool is_old_force() const;
150 bool is_residual() const;
151 bool is_parameter() const;
153
156
158 LabeledAxisAccessor old() const;
159
160private:
162 void validate_item_name(const std::string &) const;
163
164 std::vector<std::string> _item_names;
165};
166
168bool operator==(const LabeledAxisAccessor & a, const LabeledAxisAccessor & b);
169
171bool operator!=(const LabeledAxisAccessor & a, const LabeledAxisAccessor & b);
172
177bool operator<(const LabeledAxisAccessor & a, const LabeledAxisAccessor & b);
178
183std::ostream & operator<<(std::ostream & os, const LabeledAxisAccessor & accessor);
184
187
188} // namespace neml2
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:56
bool is_old_force() const
Definition LabeledAxisAccessor.cxx:142
LabeledAxisAccessor(const std::string &name, S &&... names)
Definition LabeledAxisAccessor.h:71
size_t size() const
Definition LabeledAxisAccessor.cxx:58
bool is_parameter() const
Definition LabeledAxisAccessor.cxx:154
bool is_state() const
Definition LabeledAxisAccessor.cxx:124
const_iterator begin() const
Definition LabeledAxisAccessor.h:107
std::vector< std::string >::iterator iterator
Definition LabeledAxisAccessor.h:96
LabeledAxisAccessor append(const LabeledAxisAccessor &axis) const
Append another accessor.
Definition LabeledAxisAccessor.cxx:78
LabeledAxisAccessor current() const
Returns the "current" counterpart.
Definition LabeledAxisAccessor.cxx:160
LabeledAxisAccessor prepend(const LabeledAxisAccessor &axis) const
Prepend another accessor.
Definition LabeledAxisAccessor.cxx:84
LabeledAxisAccessor(const char *name, S &&... names)
Definition LabeledAxisAccessor.h:61
bool empty() const
Definition LabeledAxisAccessor.cxx:52
bool start_with(const LabeledAxisAccessor &axis) const
Check if this accessor begins with another accessor.
Definition LabeledAxisAccessor.cxx:118
LabeledAxisAccessor with_suffix(const std::string &suffix) const
Append a suffix to the final item name.
Definition LabeledAxisAccessor.cxx:70
LabeledAxisAccessor remount(const LabeledAxisAccessor &axis, int64_t n=1) const
A combination of slice and prepend.
Definition LabeledAxisAccessor.cxx:112
LabeledAxisAccessor old() const
Returns the "old" counterpart.
Definition LabeledAxisAccessor.cxx:172
LabeledAxisAccessor(const Container &c)
Definition LabeledAxisAccessor.h:89
bool is_residual() const
Definition LabeledAxisAccessor.cxx:148
iterator end()
Definition LabeledAxisAccessor.h:106
bool is_force() const
Definition LabeledAxisAccessor.cxx:136
const_iterator end() const
Definition LabeledAxisAccessor.h:108
iterator begin()
Definition LabeledAxisAccessor.h:105
std::vector< std::string >::const_iterator const_iterator
Definition LabeledAxisAccessor.h:97
LabeledAxisAccessor slice(int64_t n) const
Remove the leading n items from the labels.
Definition LabeledAxisAccessor.cxx:92
std::string str() const
Definition LabeledAxisAccessor.cxx:46
bool is_old_state() const
Definition LabeledAxisAccessor.cxx:130
const std::vector< std::string > & vec() const
Definition LabeledAxisAccessor.h:113
const std::string & operator[](size_t i) const
Definition LabeledAxisAccessor.cxx:64
Definition DiagnosticsInterface.cxx:30
const std::string OLD_STATE
Definition LabeledAxisAccessor.h:35
LabeledAxisAccessor SubaxisName
Definition LabeledAxisAccessor.h:186
const std::string STATE
Definition LabeledAxisAccessor.h:34
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
bool operator==(const LabeledAxis &a, const LabeledAxis &b)
Definition LabeledAxis.cxx:503
const std::string OLD_FORCES
Definition LabeledAxisAccessor.h:37
bool operator!=(const LabeledAxis &a, const LabeledAxis &b)
Definition LabeledAxis.cxx:509
const std::string RESIDUAL
Definition LabeledAxisAccessor.h:38
const std::string FORCES
Definition LabeledAxisAccessor.h:36
LabeledAxisAccessor VariableName
Definition LabeledAxisAccessor.h:185
const std::string PARAMETERS
Definition LabeledAxisAccessor.h:39
std::ostream & operator<<(std::ostream &os, const EnumSelection &es)
Definition EnumSelection.cxx:32
bool operator<(const LabeledAxisAccessor &a, const LabeledAxisAccessor &b)
The (strict) smaller than operator is created so as to use LabeledAxisAccessor in sorted data structu...
Definition LabeledAxisAccessor.cxx:207
std::vector< std::string > reserved_subaxis_names()
Definition LabeledAxisAccessor.cxx:34