NEML2 2.0.0
Loading...
Searching...
No Matches
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 <iostream>
29
30#include <c10/util/SmallVector.h>
31#include <c10/util/ArrayRef.h>
32
33namespace neml2
34{
35// Reserved subaxis names
36inline const std::string STATE = "state";
37inline const std::string OLD_STATE = "old_state";
38inline const std::string FORCES = "forces";
39inline const std::string OLD_FORCES = "old_forces";
40inline const std::string RESIDUAL = "residual";
41inline const std::string PARAMETERS = "parameters";
42
43// Reserved subaxis names
44std::vector<std::string> reserved_subaxis_names();
45
58{
59public:
61
62 template <typename... S>
63 LabeledAxisAccessor(const char * name, S &&... names)
64 {
65 validate_item_name(name);
66 _item_names.push_back(name);
67
68 (validate_item_name(names), ...);
69 (_item_names.push_back(names), ...);
70 }
71
72 template <typename... S>
73 LabeledAxisAccessor(const std::string & name, S &&... names)
74 {
75 validate_item_name(name);
76 _item_names.push_back(name);
77
78 (validate_item_name(names), ...);
79 (_item_names.push_back(names), ...);
80 }
81
82 template <typename Container,
83 typename = typename std::enable_if_t<
84 !std::is_convertible_v<Container, std::string> &&
85 std::is_convertible_v<typename std::iterator_traits<
86 decltype(std::declval<Container>().begin())>::value_type,
87 std::string> &&
88 std::is_convertible_v<typename std::iterator_traits<
89 decltype(std::declval<Container>().end())>::value_type,
90 std::string>>>
92 {
93 _item_names.append(c.begin(), c.end());
94 for (const auto & name : _item_names)
95 validate_item_name(name);
96 }
97
98 using iterator = c10::SmallVector<std::string>::iterator;
99 using const_iterator = c10::SmallVector<std::string>::const_iterator;
100
107 iterator begin() { return iterator(_item_names.begin()); }
108 iterator end() { return iterator(_item_names.end()); }
109 const_iterator begin() const { return const_iterator(_item_names.begin()); }
110 const_iterator end() const { return const_iterator(_item_names.end()); }
112
113 explicit operator std::vector<std::string>() const;
114
115 const c10::SmallVector<std::string> & vec() const { return _item_names; }
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
134
137
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 c10::SmallVector<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
185using VariableName = LabeledAxisAccessor;
187
188} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:54
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:58
bool is_old_force() const
Definition LabeledAxisAccessor.cxx:134
LabeledAxisAccessor(const std::string &name, S &&... names)
Definition LabeledAxisAccessor.h:73
size_t size() const
Definition LabeledAxisAccessor.cxx:50
bool is_parameter() const
Definition LabeledAxisAccessor.cxx:146
bool is_state() const
Definition LabeledAxisAccessor.cxx:116
const_iterator begin() const
Definition LabeledAxisAccessor.h:109
c10::SmallVector< std::string >::const_iterator const_iterator
Definition LabeledAxisAccessor.h:99
LabeledAxisAccessor append(const LabeledAxisAccessor &axis) const
Append another accessor.
Definition LabeledAxisAccessor.cxx:70
LabeledAxisAccessor current() const
Returns the "current" counterpart.
Definition LabeledAxisAccessor.cxx:152
LabeledAxisAccessor prepend(const LabeledAxisAccessor &axis) const
Prepend another accessor.
Definition LabeledAxisAccessor.cxx:76
LabeledAxisAccessor(const char *name, S &&... names)
Definition LabeledAxisAccessor.h:63
bool empty() const
Definition LabeledAxisAccessor.cxx:44
bool start_with(const LabeledAxisAccessor &axis) const
Check if this accessor begins with another accessor.
Definition LabeledAxisAccessor.cxx:110
LabeledAxisAccessor with_suffix(const std::string &suffix) const
Append a suffix to the final item name.
Definition LabeledAxisAccessor.cxx:62
LabeledAxisAccessor remount(const LabeledAxisAccessor &axis, int64_t n=1) const
A combination of slice and prepend.
Definition LabeledAxisAccessor.cxx:104
LabeledAxisAccessor old() const
Returns the "old" counterpart.
Definition LabeledAxisAccessor.cxx:164
LabeledAxisAccessor(const Container &c)
Definition LabeledAxisAccessor.h:91
c10::SmallVector< std::string >::iterator iterator
Definition LabeledAxisAccessor.h:98
bool is_residual() const
Definition LabeledAxisAccessor.cxx:140
iterator end()
Definition LabeledAxisAccessor.h:108
bool is_force() const
Definition LabeledAxisAccessor.cxx:128
const_iterator end() const
Definition LabeledAxisAccessor.h:110
iterator begin()
Definition LabeledAxisAccessor.h:107
LabeledAxisAccessor slice(int64_t n) const
Remove the leading n items from the labels.
Definition LabeledAxisAccessor.cxx:84
const c10::SmallVector< std::string > & vec() const
Definition LabeledAxisAccessor.h:115
bool is_old_state() const
Definition LabeledAxisAccessor.cxx:122
const std::string & operator[](size_t i) const
Definition LabeledAxisAccessor.cxx:56
Definition CrossRef.cxx:31
bool operator!=(const TraceableSize &lhs, const TraceableSize &rhs)
Definition types.cxx:66
const std::string OLD_STATE
Definition LabeledAxisAccessor.h:37
const std::string STATE
Definition LabeledAxisAccessor.h:36
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
LabeledAxisAccessor VariableName
Definition parser_utils.h:33
const std::string OLD_FORCES
Definition LabeledAxisAccessor.h:39
const std::string RESIDUAL
Definition LabeledAxisAccessor.h:40
const std::string FORCES
Definition LabeledAxisAccessor.h:38
const std::string PARAMETERS
Definition LabeledAxisAccessor.h:41
std::ostream & operator<<(std::ostream &os, const EnumSelection &es)
Definition EnumSelection.cxx:31
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:199
std::vector< std::string > reserved_subaxis_names()
Definition LabeledAxisAccessor.cxx:32
bool operator==(const TraceableSize &lhs, const TraceableSize &rhs)
Definition types.cxx:60