Advanced Multi-Physics (AMP)
On-Line Documentation
ScalarProperty.h
Go to the documentation of this file.
1#ifndef included_AMP_ScalarProperty
2#define included_AMP_ScalarProperty
3
4#include "AMP/materials/Property.h"
5
6#include <cstring>
7
8
9// Forward declares
10namespace AMP {
11class MathExpr;
12}
13
14
15namespace AMP::Materials {
16
17
18// Helper function
19std::vector<std::array<double, 2>> getDefaultRanges( std::vector<std::array<double, 2>> ranges,
20 const std::vector<std::string> &vars );
21
23class StringProperty final : public Property
24{
25public:
26 StringProperty( std::string_view name, std::string value, std::string_view source = "" );
27 bool isString() const override { return true; }
28 std::string evalString() const override { return d_value; }
29 void eval( AMP::Array<double> &, const AMP::Array<double> & ) const override;
30
31private:
32 std::string d_value;
33};
34
35
37class ScalarProperty final : public Property
38{
39public:
40 ScalarProperty( std::string_view name,
41 double value,
42 const AMP::Units &unit = AMP::Units(),
43 std::string_view source = "" );
44 ScalarProperty( std::string_view name,
46 const AMP::Units &unit = AMP::Units(),
47 std::string_view source = "" );
48 void eval( AMP::Array<double> &result, const AMP::Array<double> & ) const override;
49 inline const AMP::Array<double> &getValue() const { return d_value; }
50
51private:
53};
54
55
58{
59public:
61 PolynomialProperty( std::string_view name,
62 std::string_view source,
63 const AMP::Units &unit = {},
64 std::vector<double> params = {},
65 std::vector<std::string> args = {},
66 std::vector<std::array<double, 2>> ranges = {},
67 std::vector<AMP::Units> argUnits = {} );
68 void eval( AMP::Array<double> &result, const AMP::Array<double> &args ) const override;
69
70private:
71 std::vector<double> d_p;
72};
73
74
76class InterpolatedProperty final : public Property
77{
78public:
79 InterpolatedProperty( std::string_view name,
80 const AMP::Units &unit,
81 const std::string &var_name,
82 std::vector<double> x,
83 std::vector<double> y,
84 const std::array<double, 2> range,
85 const AMP::Units &argUnit,
86 double default_value,
87 std::string_view source = "",
88 std::string_view method = "linear" );
89 void eval( AMP::Array<double> &result, const AMP::Array<double> & ) const override;
90
91private:
92 std::vector<double> d_x;
93 std::vector<double> d_y;
95};
96
97
100{
101public:
103 EquationProperty( std::string_view name,
104 std::shared_ptr<const MathExpr> eq,
105 const AMP::Units &unit = {},
106 std::vector<std::array<double, 2>> ranges = {},
107 std::vector<AMP::Units> argUnits = {},
108 std::string_view source = "" );
109 EquationProperty( std::string_view name,
110 const std::string &expression,
111 const AMP::Units &unit = {},
112 std::vector<std::string> args = {},
113 std::vector<std::array<double, 2>> ranges = {},
114 std::vector<AMP::Units> argUnits = {},
115 std::string_view source = "" );
116 void eval( AMP::Array<double> &result, const AMP::Array<double> &args ) const override;
117
118private:
119 std::shared_ptr<const MathExpr> d_eq;
120};
121
122
124template<class... Args>
126{
127public:
128 FunctionProperty( std::string_view name,
129 std::function<double( Args... )> fun,
130 const AMP::Units &unit = {},
131 std::vector<std::string> args = {},
132 std::vector<std::array<double, 2>> ranges = {},
133 std::vector<AMP::Units> argUnits = {},
134 const std::vector<double> &default_values = {},
135 std::string_view source = "" )
136 : Property( std::move( name ),
137 { 1 },
138 unit,
139 std::move( source ),
140 std::move( args ),
141 getDefaultRanges( std::move( ranges ), args ),
142 std::move( argUnits ) ),
143 d_fun( fun )
144 {
145 AMP_ASSERT( get_number_arguments() == sizeof...( Args ) );
146 set_defaults( default_values );
147 }
148 void eval( AMP::Array<double> &result, const AMP::Array<double> &args ) const override
149 {
150 constexpr std::size_t N = sizeof...( Args );
151 static_assert( N <= 5, "More than 5 arguments is not supported yet" );
152 if constexpr ( N == 0 ) {
153 result.fill( d_fun() );
154 return;
155 }
156 for ( size_t i = 0; i < result.length(); i++ ) {
157 const double *x = &args( 0, i );
158 if constexpr ( N == 1 )
159 result( i ) = d_fun( x[0] );
160 else if constexpr ( N == 2 )
161 result( i ) = d_fun( x[0], x[1] );
162 else if constexpr ( N == 3 )
163 result( i ) = d_fun( x[0], x[1], x[2] );
164 else if constexpr ( N == 4 )
165 result( i ) = d_fun( x[0], x[1], x[2], x[3] );
166 else if constexpr ( N == 5 )
167 result( i ) = d_fun( x[0], x[1], x[2], x[3], x[4] );
168 }
169 }
170
171private:
172 std::function<double( Args... )> d_fun;
173};
174
175
176} // namespace AMP::Materials
177
178#endif
ARRAY_INLINE void fill(const TYPE &y)
Definition Array.h:351
ARRAY_INLINE size_t length() const
Return the size of the Array.
Definition Array.h:389
Equation based property class.
void eval(AMP::Array< double > &result, const AMP::Array< double > &args) const override
EquationProperty(std::string_view name, const std::string &expression, const AMP::Units &unit={}, std::vector< std::string > args={}, std::vector< std::array< double, 2 > > ranges={}, std::vector< AMP::Units > argUnits={}, std::string_view source="")
std::shared_ptr< const MathExpr > d_eq
EquationProperty(std::string_view name, std::shared_ptr< const MathExpr > eq, const AMP::Units &unit={}, std::vector< std::array< double, 2 > > ranges={}, std::vector< AMP::Units > argUnits={}, std::string_view source="")
Function based property class.
void eval(AMP::Array< double > &result, const AMP::Array< double > &args) const override
FunctionProperty(std::string_view name, std::function< double(Args...)> fun, const AMP::Units &unit={}, std::vector< std::string > args={}, std::vector< std::array< double, 2 > > ranges={}, std::vector< AMP::Units > argUnits={}, const std::vector< double > &default_values={}, std::string_view source="")
std::function< double(Args...)> d_fun
Interpolated property class.
void eval(AMP::Array< double > &result, const AMP::Array< double > &) const override
InterpolatedProperty(std::string_view name, const AMP::Units &unit, const std::string &var_name, std::vector< double > x, std::vector< double > y, const std::array< double, 2 > range, const AMP::Units &argUnit, double default_value, std::string_view source="", std::string_view method="linear")
Polynomial based property class.
PolynomialProperty(std::string_view name, std::string_view source, const AMP::Units &unit={}, std::vector< double > params={}, std::vector< std::string > args={}, std::vector< std::array< double, 2 > > ranges={}, std::vector< AMP::Units > argUnits={})
void eval(AMP::Array< double > &result, const AMP::Array< double > &args) const override
Provides material properties of scalar type.
Definition Property.h:45
void set_defaults(std::vector< double > defaults)
Set the defaults.
Definition Property.h:116
size_t get_number_arguments() const
Return the number of arguments to eval.
Definition Property.h:84
Scalar property class (fixed value)
ScalarProperty(std::string_view name, double value, const AMP::Units &unit=AMP::Units(), std::string_view source="")
const AMP::Array< double > & getValue() const
ScalarProperty(std::string_view name, AMP::Array< double > value, const AMP::Units &unit=AMP::Units(), std::string_view source="")
AMP::Array< double > d_value
void eval(AMP::Array< double > &result, const AMP::Array< double > &) const override
String property class.
std::string evalString() const override
Get the string value of the property.
bool isString() const override
Indicator for scalar evaluator.
void eval(AMP::Array< double > &, const AMP::Array< double > &) const override
StringProperty(std::string_view name, std::string value, std::string_view source="")
Provides a class for storing units.
Definition Units.h:101
#define AMP_ASSERT(EXP)
Assert error.
std::vector< std::array< double, 2 > > getDefaultRanges(std::vector< std::array< double, 2 > > ranges, const std::vector< std::string > &vars)



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:40.
Comments on this page