Advanced Multi-Physics (AMP)
On-Line Documentation
Property.h
Go to the documentation of this file.
1#ifndef included_AMP_Property
2 #define included_AMP_Property
3
4 #include "AMP/utils/ArraySize.h"
5 #include "AMP/utils/Database.h"
6 #include "AMP/utils/Units.h"
7 #include "AMP/utils/UtilityMacros.h"
8
9 #include <algorithm>
10 #include <array>
11 #include <limits>
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <string_view>
16 #include <vector>
17
18
19// Foward declare classes
20namespace AMP::LinearAlgebra {
21class Vector;
22class MultiVector;
23} // namespace AMP::LinearAlgebra
24
25
26namespace AMP::Materials {
27
28
45{
46public:
57 Property( std::string_view name,
58 const ArraySize &size = { 1 },
59 const Units &unit = Units(),
60 std::string_view source = "",
61 std::vector<std::string> args = {},
62 std::vector<std::array<double, 2>> ranges = {},
63 std::vector<Units> argUnits = {} );
64
66 virtual ~Property() {}
67
69 inline const ArraySize &size() const { return d_dim; }
70
72 inline const std::string &get_name() const { return d_name; }
73
75 inline const std::string &get_source() const { return d_source; }
76
78 inline const Units &get_units() const { return d_units; }
79
81 inline const std::vector<std::string> &get_arguments() const { return d_arguments; }
82
84 inline size_t get_number_arguments() const { return d_arguments.size(); }
85
87 inline int get_argument_index( std::string_view name ) const
88 {
89 int index = -1;
90 for ( size_t i = 0; i < d_arguments.size(); i++ ) {
91 if ( name == d_arguments[i] )
92 index = i;
93 }
94 return index;
95 }
96
98 double get_default( std::string_view name ) const;
99
101 inline const std::vector<double> &get_defaults() const { return d_defaults; }
102
104 inline void
105 set_default( std::string_view name, double value, const AMP::Units &unit = AMP::Units() )
106 {
107 int i = get_argument_index( name );
108 if ( i != -1 ) {
109 if ( !unit.isNull() )
110 value *= unit.convert( d_argUnits[i] );
111 d_defaults[i] = value;
112 }
113 }
114
116 inline void set_defaults( std::vector<double> defaults )
117 {
118 AMP_INSIST( defaults.size() == d_arguments.size(),
119 "incorrect number of defaults specified" );
120 d_defaults = std::move( defaults );
121 }
122
124 bool is_argument( std::string_view argname ) const;
125
127 virtual bool isString() const { return false; }
128
130 bool isScalar() const { return d_dim.length() == 1; }
131
133 bool isVector() const { return d_dim.ndim() == 1 && d_dim.length() > 0; }
134
136 bool isTensor() const { return d_dim.ndim() == 2; }
137
138 // converts AMP::MultiVector to a map of pointers to AMP::Vectors based on argument names
139 std::map<std::string, std::shared_ptr<AMP::LinearAlgebra::Vector>>
140 make_map( const std::shared_ptr<AMP::LinearAlgebra::MultiVector> &args,
141 const std::map<std::string, std::string> &translator ) const;
142
143
144public: // Functions dealing with the ranges of the arguments
146 const auto &get_arg_units() const { return d_argUnits; }
147
149 const auto &get_arg_ranges() const { return d_ranges; }
150
152 std::array<double, 2> get_arg_range( std::string_view argname ) const;
153
155 inline bool in_range( std::string_view argname,
156 double value,
157 const Units &unit = Units(),
158 bool throwError = false ) const;
159
161 template<class INPUT_VTYPE>
162 inline bool in_range( std::string_view argname,
163 const INPUT_VTYPE &values,
164 const Units &unit = Units(),
165 bool throwError = false ) const;
166
167
169 inline const Database &getAuxiliaryData() const { return d_auxiliaryData; }
170
172 template<class TYPE>
173 TYPE getAuxiliaryData( const std::string &key ) const;
174
176 template<class TYPE>
177 void setAuxiliaryData( const std::string &key, const TYPE &data );
178
179
180public: // Evaluators
191 template<class... Args>
192 double eval( const Units &unit = Units(), const Args &...args ) const;
193
204 double eval( const Units &unit,
205 const std::vector<std::string> &args,
206 const std::vector<double> &vec,
207 const std::vector<Units> &units = {} ) const;
208
219 template<class... Args>
220 void evalv( std::vector<double> &r, const Units &unit, const Args &...args ) const;
221
230 template<class... Args>
231 void evalv( AMP::LinearAlgebra::Vector &r, const Args &...args ) const;
232
243 template<class... Args>
244 void evalv( std::vector<std::shared_ptr<std::vector<double>>> &r,
245 const Units &unit,
246 const Args &...args ) const;
247
256 template<class... Args>
257 void evalv( std::vector<std::shared_ptr<AMP::LinearAlgebra::Vector>> &r,
258 const Args &...args ) const;
259
267 template<class... Args>
268 void evalv( AMP::Array<std::shared_ptr<std::vector<double>>> &r,
269 const Units &unit,
270 const Args &...args ) const;
271
280 template<class... Args>
281 void evalv( AMP::Array<std::shared_ptr<AMP::LinearAlgebra::Vector>> &r,
282 const Args &...args ) const;
283
294 template<class... Args>
295 void
296 evalv( AMP::Array<std::vector<double> *> &r, const Units &unit, const Args &...args ) const;
297
306 template<class... Args>
307 void evalv( AMP::Array<AMP::LinearAlgebra::Vector *> &r, const Args &...args ) const;
308
310 virtual std::string evalString() const;
311
312
313protected: // Virtual function to override to load the property
319 virtual void eval( AMP::Array<double> &result, const AMP::Array<double> &args ) const = 0;
320
321
322protected: // Internal eval/evalv/evalArg
323 // clang-format off
324 static size_t getSize( const AMP::LinearAlgebra::Vector& );
326 void evalv( const AMP::Array<double>&, AMP::Array<std::vector<double> *> &, const Units & ) const;
328 void evalArg( AMP::Array<double>&, std::string_view, const Units&, double ) const;
329 void evalArg( AMP::Array<double>&, std::string_view, const Units&, const std::vector<double>& ) const;
330 void evalArg( AMP::Array<double>&, std::string_view, const Units&, const AMP::LinearAlgebra::Vector& ) const;
331 // clang-format on
332
333
334protected: // Functions to load the arguments
335 // clang-format off
336 void evalArgs( AMP::Array<double>& ) const {}
337 void evalArgs( AMP::Array<double>&, const std::shared_ptr<AMP::LinearAlgebra::MultiVector>&, const std::map<std::string, std::string>& = {} ) const;
338 template<class VEC>
339 void evalArgs( AMP::Array<double>&, const std::map<std::string, VEC>& ) const;
340 template<class... Args>
341 void evalArgs( AMP::Array<double>&, std::string_view, double, const Args&... ) const;
342 template<class... Args>
343 void evalArgs( AMP::Array<double>&, std::string_view, const Units&, double, const Args&... ) const;
344 template<class... Args>
345 void evalArgs( AMP::Array<double>&, std::string_view, const std::vector<double>&, const Args&... ) const;
346 template<class... Args>
347 void evalArgs( AMP::Array<double>&, std::string_view, const AMP::LinearAlgebra::Vector&, const Args&... ) const;
348 template<class... Args>
349 void evalArgs( AMP::Array<double>&, std::string_view, const Units&, const std::vector<double>&, const Args&... ) const;
350 template<class... Args>
351 void evalArgs( AMP::Array<double>&, std::string_view, const Units&, const AMP::LinearAlgebra::Vector&, const Args&... ) const;
352 template<class VEC, class... Args>
353 void evalArgs( AMP::Array<double>&, std::string_view, const std::shared_ptr<VEC>&, const Args&... ) const;
354 template<class VEC, class... Args>
355 void evalArgs( AMP::Array<double>&, std::string_view, const Units&, const std::shared_ptr<VEC>&, const Args&... ) const;
356 void evalArgs( AMP::Array<double>&, const std::vector<double> &args, const std::vector<std::string> &names, const std::vector<Units> &argUnits = {} ) const;
357 // clang-format on
358
359
360protected:
361 std::string d_name;
364 std::string d_source;
365 std::vector<std::string> d_arguments;
366 std::vector<Units> d_argUnits;
367 std::vector<double> d_defaults;
368 std::vector<std::array<double, 2>> d_ranges;
369 std::map<std::string_view, size_t> d_argToIndexMap;
371
372
373protected:
374 Property() = default;
375
378
380 void checkArgs( const AMP::Array<double> &args ) const;
381
382 // Get the index for the desired argument
383 inline int get_arg_index( std::string_view name ) const
384 {
385 auto it = d_argToIndexMap.find( name );
386 if ( it == d_argToIndexMap.end() )
387 return -1;
388 return it->second;
389 }
390};
391
392
394std::unique_ptr<Property> createProperty( std::string_view key, const Database &db );
395
396
397} // namespace AMP::Materials
398
399#endif
400
401
402#include "AMP/materials/Property.hpp"
Simple class to store the array dimensions.
Definition ArraySize.h:138
constexpr uint8_t ndim() const
Return the number of dimensions.
Definition ArraySize.h:265
constexpr size_t length() const
Return the total number of elements in the array.
Definition ArraySize.h:271
Class to a database.
Definition Database.h:111
Abstraction of a discrete Vector in a linear simulation.
Definition Vector.h:54
Provides material properties of scalar type.
Definition Property.h:45
bool is_argument(std::string_view argname) const
Determine if a string is an argument.
void set_default(std::string_view name, double value, const AMP::Units &unit=AMP::Units())
Set the default.
Definition Property.h:105
bool isScalar() const
Indicator for scalar evaluator.
Definition Property.h:130
std::map< std::string, std::shared_ptr< AMP::LinearAlgebra::Vector > > make_map(const std::shared_ptr< AMP::LinearAlgebra::MultiVector > &args, const std::map< std::string, std::string > &translator) const
AMP::Database d_auxiliaryData
Database containing auxiliary data.
Definition Property.h:370
void evalv(const AMP::Array< double > &, AMP::Array< std::vector< double > * > &, const Units &) const
const std::string & get_source() const
Get the source of the information.
Definition Property.h:75
void evalv(AMP::Array< std::shared_ptr< AMP::LinearAlgebra::Vector > > &r, const Args &...args) const
Evaluate the property.
void evalArgs(AMP::Array< double > &, const std::vector< double > &args, const std::vector< std::string > &names, const std::vector< Units > &argUnits={}) const
const auto & get_arg_ranges() const
Get ranges for all arguments used in this material.
Definition Property.h:149
std::vector< std::array< double, 2 > > d_ranges
allowed ranges of arguments
Definition Property.h:368
void evalv(std::vector< std::shared_ptr< AMP::LinearAlgebra::Vector > > &r, const Args &...args) const
Evaluate the property.
Property(std::string_view name, const ArraySize &size={ 1 }, const Units &unit=Units(), std::string_view source="", std::vector< std::string > args={}, std::vector< std::array< double, 2 > > ranges={}, std::vector< Units > argUnits={})
void evalArg(AMP::Array< double > &, std::string_view, const Units &, double) const
void evalv(AMP::Array< std::vector< double > * > &r, const Units &unit, const Args &...args) const
Evaluate the property.
const std::vector< std::string > & get_arguments() const
Return the names of the arguments to eval.
Definition Property.h:81
void evalv(AMP::Array< std::shared_ptr< std::vector< double > > > &r, const Units &unit, const Args &...args) const
Evaluate the property.
const std::string & get_name() const
Return name of property.
Definition Property.h:72
bool isTensor() const
Indicator for tensor evaluator.
Definition Property.h:136
void setAuxiliaryData(const std::string &key, const TYPE &data)
Set auxiliary data.
double eval(const Units &unit, const std::vector< std::string > &args, const std::vector< double > &vec, const std::vector< Units > &units={}) const
Evaluate the property.
void evalArgs(AMP::Array< double > &, std::string_view, const std::shared_ptr< VEC > &, const Args &...) const
void evalArgs(AMP::Array< double > &, std::string_view, const Units &, const std::vector< double > &, const Args &...) const
AMP::Units d_units
default units to return
Definition Property.h:363
const ArraySize & size() const
get dimensions of evalv return value
Definition Property.h:69
std::map< std::string_view, size_t > d_argToIndexMap
map argument names to indices
Definition Property.h:369
void evalArg(AMP::Array< double > &, std::string_view, const Units &, const std::vector< double > &) const
AMP::ArraySize d_dim
size of the result
Definition Property.h:362
void evalv(AMP::Array< AMP::LinearAlgebra::Vector * > &r, const Args &...args) const
Evaluate the property.
void evalArgs(AMP::Array< double > &, std::string_view, const std::vector< double > &, const Args &...) const
virtual std::string evalString() const
Get the string value of the property.
void evalArg(AMP::Array< double > &, std::string_view, const Units &, const AMP::LinearAlgebra::Vector &) const
std::vector< Units > d_argUnits
default units for the arguments
Definition Property.h:366
void evalv(std::vector< std::shared_ptr< std::vector< double > > > &r, const Units &unit, const Args &...args) const
Evaluate the property.
int get_arg_index(std::string_view name) const
Definition Property.h:383
void evalArgs(AMP::Array< double > &, std::string_view, const Units &, const AMP::LinearAlgebra::Vector &, const Args &...) const
void evalv(AMP::LinearAlgebra::Vector &r, const Args &...args) const
Evaluate the property.
static size_t getSize(const AMP::LinearAlgebra::Vector &)
AMP::Array< double > defaultArgs(size_t) const
Create the default argument array.
const std::vector< double > & get_defaults() const
Get the defaults.
Definition Property.h:101
bool in_range(std::string_view argname, const INPUT_VTYPE &values, const Units &unit=Units(), bool throwError=false) const
Determine if a set of values are all within range or not.
std::vector< std::string > d_arguments
names of the arguments
Definition Property.h:365
void evalArgs(AMP::Array< double > &) const
Definition Property.h:336
void evalArgs(AMP::Array< double > &, std::string_view, const AMP::LinearAlgebra::Vector &, const Args &...) const
double get_default(std::string_view name) const
Get the default for the given argument (NaN if it is an invalid argument)
int get_argument_index(std::string_view name) const
Return the argument index.
Definition Property.h:87
void evalArgs(AMP::Array< double > &, std::string_view, const Units &, const std::shared_ptr< VEC > &, const Args &...) const
bool in_range(std::string_view argname, double value, const Units &unit=Units(), bool throwError=false) const
Determine if a value is within range or not.
TYPE getAuxiliaryData(const std::string &key) const
Get auxiliary data.
void checkArgs(const AMP::Array< double > &args) const
Check the argument values.
const Units & get_units() const
Return source reference.
Definition Property.h:78
void evalArgs(AMP::Array< double > &, std::string_view, double, const Args &...) const
std::array< double, 2 > get_arg_range(std::string_view argname) const
Get range for a specific argument.
std::string d_name
should be unique
Definition Property.h:361
const Database & getAuxiliaryData() const
Get auxiliary data.
Definition Property.h:169
bool isVector() const
Indicator for vector evaluator.
Definition Property.h:133
std::string d_source
reference for source data
Definition Property.h:364
const auto & get_arg_units() const
Get units for all arguments used in this material.
Definition Property.h:146
void evalArgs(AMP::Array< double > &, const std::map< std::string, VEC > &) const
void evalv(const AMP::Array< double > &, AMP::Array< AMP::LinearAlgebra::Vector * > &) const
void evalv(std::vector< double > &r, const Units &unit, const Args &...args) const
Evaluate the property.
std::vector< double > d_defaults
default values of arguments
Definition Property.h:367
void set_defaults(std::vector< double > defaults)
Set the defaults.
Definition Property.h:116
void evalArgs(AMP::Array< double > &, std::string_view, const Units &, double, const Args &...) const
static Units getUnits(const AMP::LinearAlgebra::Vector &)
double eval(const Units &unit=Units(), const Args &...args) const
Evaluate the property.
virtual void eval(AMP::Array< double > &result, const AMP::Array< double > &args) const =0
void evalArgs(AMP::Array< double > &, const std::shared_ptr< AMP::LinearAlgebra::MultiVector > &, const std::map< std::string, std::string > &={}) const
virtual ~Property()
Destructor.
Definition Property.h:66
size_t get_number_arguments() const
Return the number of arguments to eval.
Definition Property.h:84
virtual bool isString() const
Indicator for scalar evaluator.
Definition Property.h:127
Provides a class for storing units.
Definition Units.h:101
constexpr bool isNull() const
Check if unit is null.
Definition Units.h:208
constexpr double convert(const Units &unit) const
Convert the unit to a new type.
#define AMP_INSIST(EXP, MSG)
Insist error.
std::unique_ptr< Property > createProperty(std::string_view key, const Database &db)
Create a property from a database data.



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