14#include "arcane/utils/ValueConvert.h"
15#include "arcane/utils/ITraceMng.h"
16#include "arcane/utils/FatalErrorException.h"
18#include "arcane/core/CaseTable.h"
19#include "arcane/core/CaseTableParams.h"
21#include "arcane/core/ISubDomain.h"
32template <
class T>
void
35 bool is_bad = builtInGetValue(v, s);
37 ARCANE_FATAL(
"Table '{0}' index={1} : can not convert value '{2}' to type '{3}'",
38 table->name(), index, s, typeToName(v));
48, m_param_list(nullptr)
53 m_use_fast_search = v.value() == 0;
69_isValidIndex(
Integer index)
const
85 if (_isValidIndex(
id))
97 m_param_list->toString(
id, str);
106 _findValueAndApplyTransform(param, v);
112 _findValueAndApplyTransform(param, v);
118 _findValueAndApplyTransform(param, v);
124 _findValueAndApplyTransform(param, v);
130 _findValueAndApplyTransform(param, v);
136 _findValueAndApplyTransform(param, v);
142 _findValueAndApplyTransform(param, v);
148 _findValueAndApplyTransform(param, v);
154 _findValueAndApplyTransform(param, v);
160 _findValueAndApplyTransform(param, v);
169 return m_param_list->setValue(
id, str);
178 if (_isValidIndex(
id))
179 return _setValue(
id, str);
193 if (builtInGetValue(v, value_str)) {
196 variant.setValueAll(v);
200 if (builtInGetValue(v, value_str)) {
203 variant.setValueAll(v);
207 if (builtInGetValue(v, value_str)) {
210 variant.setValueAll(v);
228 bool type_changed = (new_type !=
paramType());
231 m_param_list->setType(new_type);
243 eError err = m_param_list->appendValue(param);
264 m_param_list->toString(n - 1, param_str);
265 m_param_list->appendValue(param_str);
270 for (
Integer i = n; i > id; --i) {
271 m_param_list->toString(i - 1, param_str);
272 m_param_list->setValue(i, param_str);
283 if (!_isValidIndex(
id))
287 m_param_list->removeValue(
id);
296 return m_param_list->nbElement();
311template <
class U,
class V>
void CaseTable::
312_findValueAndApplyTransform(U param, V& avalue)
const
314 _findValue(param, avalue);
315 _applyValueTransform(avalue);
321template <
typename U> Real
322_curveLinear(Real current_value, Real next_value, U t)
324 return (Real)(current_value + (next_value - current_value) * t);
326template <
typename U>
Real3
327_curveLinear(
Real3 current_value,
Real3 next_value, U t)
329 return current_value + (next_value - current_value) * t;
336template <
typename U>
bool
337_curveLinear(
bool,
bool, U)
341template <
typename U>
String
357template <
typename ParamType,
typename ValueType>
void CaseTable::
358_findValue(ParamType param,
ValueType& avalue)
const
360 _applyParamTransform(param);
367 Int32 iend = nb_elem;
368 if (m_use_fast_search)
369 m_param_list->getRange(param, i0, iend);
371 for (
Integer i = i0; i < iend; ++i) {
373 ParamType current_begin_value;
374 m_param_list->value(i, current_begin_value);
377 if ((i + 1) == nb_elem) {
378 _verboseBuiltInGetValue(
this, i, avalue, current_value_str);
383 if (
math::isEqual(current_begin_value, param) || param < current_begin_value) {
384 _verboseBuiltInGetValue(
this, i, avalue, current_value_str);
389 ParamType next_begin_value;
390 m_param_list->value(i + 1, next_begin_value);
394 _verboseBuiltInGetValue(
this, i, avalue, next_value_str);
399 if (param > current_begin_value && param < next_begin_value) {
402 _verboseBuiltInGetValue(
this, i, current_value, current_value_str);
404 avalue = current_value;
408 _verboseBuiltInGetValue(
this, i, next_value, next_value_str);
409 ParamType diff = next_begin_value - current_begin_value;
412 ParamType t = (param - current_begin_value) / diff;
413 avalue = _curveLinear<ParamType>(current_value, next_value, t);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Various mathematical functions.
Information to build an instance of CaseFunction.
ICaseFunction::eParamType m_param_type
Parameter type (x).
void setParamType(eParamType type) override
Sets the function parameter type.
CaseFunction(const CaseFunctionBuildInfo &info)
Constructs a dataset function.
String name() const override
function name
eValueType valueType() const override
Function value type.
eParamType paramType() const override
Function parameter type.
virtual eError setValue(Integer id, const String &value)
Modifies the value of element id.
virtual eError appendElement(const String ¶m, const String &value)
Adds an element to the table.
virtual void setParamType(eParamType type)
Sets the function parameter type.
virtual void insertElement(Integer id)
Inserts a couple (parameter,value) into the function.
eCurveType
Type of the table curve.
@ CurveLinear
Piecewise linear curve.
@ CurveConstant
Piecewise constant curve.
virtual Integer nbElement() const
Number of elements in the function.
CaseTable(const CaseFunctionBuildInfo &info, eCurveType curve_type)
Constructs a lookup table from the data set.
virtual void removeElement(Integer id)
Removes a couple (parameter,value) from the function.
eError
Types of errors returned by the class.
@ ErrCanNotConvertValueToRightType
Indicates that converting the value to the desired type is impossible.
eCurveType m_curve_type
Curve type.
virtual void value(Real param, Real &v) const
Value v of the option for parameter param.
virtual eError setParam(Integer id, const String &value)
Modifies the parameter of element id.
virtual bool checkIfValid() const
Checks the validity of the function.
virtual void paramToString(Integer id, String ¶m) const
The i-th parameter in the string str.
virtual void valueToString(Integer id, String &str) const
The i-th value in the string str.
UniqueArray< SmallVariant > m_value_list
List of values.
Template class for converting a type.
eParamType
Type of a function parameter.
eValueType
Type of a function value.
@ ValueInteger
Integer type value.
@ ValueReal
Real type value.
@ ValueBool
Boolean type value.
Class managing a 3-dimensional real vector.
Class managing a polymorphic type.
Unicode character string.
Integer toInteger(Real r)
Converts a Real to Integer.
bool isZero(const BuiltInProxy< _Type > &a)
Tests if a value is exactly equal to zero.
constexpr __host__ __device__ bool isEqual(const _Type &a, const _Type &b)
Tests the bit-by-bit equality between two values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.