NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
BufferStore.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 <memory>
28
29#include "neml2/jit/types.h"
30
31namespace neml2
32{
33class NEML2Object;
34template <typename T>
35struct TensorName;
36class TensorValueBase;
37template <typename T>
38class TensorBase;
39
42{
43public:
44 BufferStore(NEML2Object * object);
45
46 BufferStore(const BufferStore &) = delete;
48 BufferStore & operator=(const BufferStore &) = delete;
50 virtual ~BufferStore() = default;
51
54 const std::map<std::string, std::unique_ptr<TensorValueBase>> & named_buffers() const
55 {
56 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
57 return const_cast<BufferStore *>(this)->named_buffers();
58 }
59 std::map<std::string, std::unique_ptr<TensorValueBase>> & named_buffers();
61
63 const TensorValueBase & get_buffer(const std::string & name) const
64 {
65 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
66 return const_cast<BufferStore *>(this)->get_buffer(name);
67 }
68
69 TensorValueBase & get_buffer(const std::string & name);
70
71protected:
77 virtual void send_buffers_to(const TensorOptions & options);
78
92 template <typename T, typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
93 const T & declare_buffer(const std::string & name, const T & rawval);
94
106 template <typename T, typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
107 const T & declare_buffer(const std::string & name, const TensorName<T> & tensorname);
108
121 template <typename T, typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
122 const T & declare_buffer(const std::string & name, const std::string & input_option_name);
123
125 void assign_buffer_stack(jit::Stack & stack);
126
128 jit::Stack collect_buffer_stack() const;
129
130private:
131 NEML2Object * _object;
132
134 std::map<std::string, std::unique_ptr<TensorValueBase>> _buffer_values;
135};
136
137} // namespace neml2
virtual ~BufferStore()=default
BufferStore(const BufferStore &)=delete
void assign_buffer_stack(jit::Stack &stack)
Assign stack to buffers.
Definition BufferStore.cxx:118
const T & declare_buffer(const std::string &name, const T &rawval)
Declare a buffer.
Definition BufferStore.cxx:64
const std::map< std::string, std::unique_ptr< TensorValueBase > > & named_buffers() const
Definition BufferStore.h:54
const TensorValueBase & get_buffer(const std::string &name) const
}@
Definition BufferStore.h:63
virtual void send_buffers_to(const TensorOptions &options)
Send all buffers to options.
Definition BufferStore.cxx:56
jit::Stack collect_buffer_stack() const
Collect stack from buffers.
Definition BufferStore.cxx:142
BufferStore & operator=(const BufferStore &)=delete
BufferStore & operator=(BufferStore &&)=delete
BufferStore(BufferStore &&)=delete
BufferStore(NEML2Object *object)
Definition BufferStore.cxx:34
The base class of all "manufacturable" objects in the NEML2 library.
Definition NEML2Object.h:42
NEML2's enhanced tensor type.
Definition TensorBase.h:49
The base class to allow us to set up a polymorphic container of Tensors. The concrete definitions wil...
Definition TensorValue.h:39
Definition DiagnosticsInterface.cxx:30
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
c10::TensorOptions TensorOptions
Definition types.h:63
The name of a tensor object that can be referenced in the input files.
Definition TensorName.h:46