Sacado Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Sacado_Fad_StaticStorage.hpp
Go to the documentation of this file.
1
// @HEADER
2
// ***********************************************************************
3
//
4
// Sacado Package
5
// Copyright (2006) Sandia Corporation
6
//
7
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8
// the U.S. Government retains certain rights in this software.
9
//
10
// This library is free software; you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as
12
// published by the Free Software Foundation; either version 2.1 of the
13
// License, or (at your option) any later version.
14
//
15
// This library is distributed in the hope that it will be useful, but
16
// WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
// Lesser General Public License for more details.
19
//
20
// You should have received a copy of the GNU Lesser General Public
21
// License along with this library; if not, write to the Free Software
22
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23
// USA
24
// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25
// (etphipp@sandia.gov).
26
//
27
// ***********************************************************************
28
// @HEADER
29
30
#ifndef SACADO_FAD_STATICSTORAGE_HPP
31
#define SACADO_FAD_STATICSTORAGE_HPP
32
33
#include "
Sacado_ConfigDefs.h
"
34
35
#ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
36
37
#include "
Sacado_Fad_Exp_StaticStorage.hpp
"
38
39
namespace
Sacado
{
40
namespace
Fad
{
41
42
template
<
typename
T,
int
N>
43
using
StaticStorage
=
Exp::StaticStorage<T,N>
;
44
45
}
46
}
47
48
#else
49
50
#include "
Sacado_ConfigDefs.h
"
51
#include "
Sacado_StaticArrayTraits.hpp
"
52
53
namespace
Sacado
{
54
55
namespace
Fad
{
56
58
62
template
<
typename
T,
int
Num>
63
class
StaticStorage
{
64
65
public
:
66
67
typedef
T
value_type
;
68
70
template
<
typename
S>
71
SACADO_INLINE_FUNCTION
72
StaticStorage
(
const
S & x,
SACADO_ENABLE_VALUE_CTOR_DECL
) :
73
val_
(x),
sz_
(0) {}
74
76
79
SACADO_INLINE_FUNCTION
80
StaticStorage
(
const
int
sz,
const
T
& x,
const
DerivInit
zero_out =
InitDerivArray
) :
81
val_
(x),
sz_
(sz) {
82
#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
83
if
(sz > Num)
84
throw
"StaticStorage::StaticStorage() Error: Supplied derivative dimension exceeds maximum length."
;
85
#endif
86
if
(zero_out ==
InitDerivArray
)
87
ss_array<T>::zero
(
dx_
,
sz_
);
88
}
89
91
SACADO_INLINE_FUNCTION
92
StaticStorage
(
const
StaticStorage
& x) :
93
val_
(x.
val_
),
sz_
(x.
sz_
) {
94
//ss_array<T>::copy(x.dx_, dx_, sz_);
95
for
(
int
i=0; i<
sz_
; i++)
96
dx_
[i] = x.
dx_
[i];
97
}
98
100
SACADO_INLINE_FUNCTION
101
~StaticStorage
() {}
102
104
SACADO_INLINE_FUNCTION
105
StaticStorage
&
operator=
(
const
StaticStorage
& x) {
106
if
(
this
!= &x) {
107
val_
= x.
val_
;
108
sz_
= x.
sz_
;
109
//ss_array<T>::copy(x.dx_, dx_, sz_);
110
for
(
int
i=0; i<
sz_
; i++)
111
dx_
[i] = x.
dx_
[i];
112
}
113
return
*
this
;
114
}
115
117
SACADO_INLINE_FUNCTION
118
int
size
()
const
{
return
sz_
;}
119
121
SACADO_INLINE_FUNCTION
122
int
length
()
const
{
return
Num; }
123
125
SACADO_INLINE_FUNCTION
126
void
resize
(
int
sz) {
127
#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
128
if
(sz > Num)
129
throw
"StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length."
;
130
#endif
131
sz_
= sz;
132
}
133
135
139
SACADO_INLINE_FUNCTION
140
void
resizeAndZero
(
int
sz) {
141
#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
142
if
(sz > Num)
143
throw
"StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length."
;
144
#endif
145
if
(sz >
sz_
)
146
ss_array<T>::zero
(
dx_
+
sz_
, sz-
sz_
);
147
sz_
= sz;
148
}
149
151
155
SACADO_INLINE_FUNCTION
156
void
expand
(
int
sz) {
157
#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
158
if
(sz > Num)
159
throw
"StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length."
;
160
#endif
161
if
(sz >
sz_
)
162
ss_array<T>::zero
(
dx_
+
sz_
, sz-
sz_
);
163
sz_
= sz;
164
}
165
166
168
SACADO_INLINE_FUNCTION
169
void
zero
() {
ss_array<T>::zero
(
dx_
,
sz_
); }
170
172
SACADO_INLINE_FUNCTION
173
const
T
&
val
()
const
{
return
val_
; }
174
176
SACADO_INLINE_FUNCTION
177
T
&
val
() {
return
val_
; }
178
180
SACADO_INLINE_FUNCTION
181
const
T
*
dx
()
const
{
return
dx_
;}
182
184
SACADO_INLINE_FUNCTION
185
T
dx
(
int
i)
const
{
return
sz_
?
dx_
[i] :
T
(0.); }
186
188
SACADO_INLINE_FUNCTION
189
T
&
fastAccessDx
(
int
i) {
return
dx_
[i];}
190
192
SACADO_INLINE_FUNCTION
193
const
T
&
fastAccessDx
(
int
i)
const
{
return
dx_
[i];}
194
195
protected
:
196
198
T
val_
;
199
201
T
dx_
[Num];
202
204
int
sz_
;
205
206
};
// class StaticStorage
207
208
}
// namespace Fad
209
210
}
// namespace Sacado
211
212
#endif
// SACADO_NEW_FAD_DESIGN_IS_DEFAULT
213
214
#endif
// SACADO_FAD_STATICSTORAGE_HPP
Sacado_ConfigDefs.h
SACADO_INLINE_FUNCTION
#define SACADO_INLINE_FUNCTION
Definition
Sacado_ConfigDefs.h:110
Sacado_Fad_Exp_StaticStorage.hpp
SACADO_ENABLE_VALUE_CTOR_DECL
#define SACADO_ENABLE_VALUE_CTOR_DECL
Definition
Sacado_SFINAE_Macros.hpp:67
Sacado_StaticArrayTraits.hpp
T
#define T
Definition
Sacado_rad.hpp:573
Sacado::Fad::Exp::StaticStorage
Derivative array storage class using static memory allocation.
Definition
Sacado_Fad_Exp_StaticStorage.hpp:50
Sacado::Fad::StaticStorage
Derivative array storage class using static memory allocation.
Definition
Sacado_Fad_StaticStorage.hpp:63
Sacado::Fad::StaticStorage::StaticStorage
SACADO_INLINE_FUNCTION StaticStorage(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Default constructor.
Definition
Sacado_Fad_StaticStorage.hpp:72
Sacado::Fad::StaticStorage::dx
SACADO_INLINE_FUNCTION T dx(int i) const
Returns derivative component i with bounds checking.
Definition
Sacado_Fad_StaticStorage.hpp:185
Sacado::Fad::StaticStorage::resize
SACADO_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
Definition
Sacado_Fad_StaticStorage.hpp:126
Sacado::Fad::StaticStorage< ValueT, Num >::value_type
ValueT value_type
Definition
Sacado_Fad_StaticStorage.hpp:67
Sacado::Fad::StaticStorage< ValueT, Num >::sz_
int sz_
Definition
Sacado_Fad_StaticStorage.hpp:204
Sacado::Fad::StaticStorage< ValueT, Num >::val_
ValueT val_
Definition
Sacado_Fad_StaticStorage.hpp:198
Sacado::Fad::StaticStorage::dx
SACADO_INLINE_FUNCTION const T * dx() const
Returns derivative array.
Definition
Sacado_Fad_StaticStorage.hpp:181
Sacado::Fad::StaticStorage::val
SACADO_INLINE_FUNCTION const T & val() const
Returns value.
Definition
Sacado_Fad_StaticStorage.hpp:173
Sacado::Fad::StaticStorage::fastAccessDx
SACADO_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
Definition
Sacado_Fad_StaticStorage.hpp:189
Sacado::Fad::StaticStorage::resizeAndZero
SACADO_INLINE_FUNCTION void resizeAndZero(int sz)
Resize the derivative array to sz.
Definition
Sacado_Fad_StaticStorage.hpp:140
Sacado::Fad::StaticStorage::expand
SACADO_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
Definition
Sacado_Fad_StaticStorage.hpp:156
Sacado::Fad::StaticStorage::size
SACADO_INLINE_FUNCTION int size() const
Returns number of derivative components.
Definition
Sacado_Fad_StaticStorage.hpp:118
Sacado::Fad::StaticStorage::length
SACADO_INLINE_FUNCTION int length() const
Returns array length.
Definition
Sacado_Fad_StaticStorage.hpp:122
Sacado::Fad::StaticStorage::val
SACADO_INLINE_FUNCTION T & val()
Returns value.
Definition
Sacado_Fad_StaticStorage.hpp:177
Sacado::Fad::StaticStorage::StaticStorage
SACADO_INLINE_FUNCTION StaticStorage(const StaticStorage &x)
Copy constructor.
Definition
Sacado_Fad_StaticStorage.hpp:92
Sacado::Fad::StaticStorage< ValueT, Num >::dx_
ValueT dx_[Num]
Definition
Sacado_Fad_StaticStorage.hpp:201
Sacado::Fad::StaticStorage::StaticStorage
SACADO_INLINE_FUNCTION StaticStorage(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz.
Definition
Sacado_Fad_StaticStorage.hpp:80
Sacado::Fad::StaticStorage::~StaticStorage
SACADO_INLINE_FUNCTION ~StaticStorage()
Destructor.
Definition
Sacado_Fad_StaticStorage.hpp:101
Sacado::Fad::StaticStorage::operator=
SACADO_INLINE_FUNCTION StaticStorage & operator=(const StaticStorage &x)
Assignment.
Definition
Sacado_Fad_StaticStorage.hpp:105
Sacado::Fad::StaticStorage::zero
SACADO_INLINE_FUNCTION void zero()
Zero out derivative array.
Definition
Sacado_Fad_StaticStorage.hpp:169
Sacado::Fad::StaticStorage::fastAccessDx
SACADO_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
Definition
Sacado_Fad_StaticStorage.hpp:193
Sacado::Fad
Namespace for forward-mode AD classes.
Definition
Sacado_Fad_Exp_DFad.hpp:38
Sacado
Definition
Sacado_mpl_apply.hpp:39
Sacado::DerivInit
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors.
Definition
Sacado_Traits.hpp:70
Sacado::InitDerivArray
@ InitDerivArray
Initialize the derivative array.
Definition
Sacado_Traits.hpp:72
Sacado::ss_array::zero
static SACADO_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
Definition
Sacado_StaticArrayTraits.hpp:54
Generated by
1.17.0