Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
CaseFunction.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* CaseFunction.cc (C) 2000-2022 */
9/* */
10/* Class managing a dataset function. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/CaseFunction.h"
15
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/NotImplementedException.h"
19#include "arcane/utils/ValueConvert.h"
20#include "arcane/utils/TraceInfo.h"
21
23
24#include "arcane/core/ISubDomain.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
38: CaseFunctionBuildInfo(sd->traceMng(), name)
39{
40}
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
47: m_trace(info.m_trace_mng)
48, m_name(info.m_name)
53, m_deltat_coef(info.m_deltat_coef)
54{
55}
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
60CaseFunction::
61~CaseFunction()
62{
63}
64
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
69setName(const String& new_name)
70{
71 if (new_name.null())
72 return;
73 m_name = new_name;
74}
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
84{
85 if (new_type == m_param_type)
86 return;
87 m_param_type = new_type;
88}
89
90/*---------------------------------------------------------------------------*/
91/*---------------------------------------------------------------------------*/
92
95{
96 if (new_type == m_value_type)
97 return;
98 m_value_type = new_type;
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
121
122/*---------------------------------------------------------------------------*/
123/*---------------------------------------------------------------------------*/
124
126checkIfValid() const
127{
128 throw NotImplementedException(A_FUNCINFO);
129}
130
131/*---------------------------------------------------------------------------*/
132/*---------------------------------------------------------------------------*/
133
134Real CaseFunction::
135_applyValueComulTransform(Real v, Real comul) const
136{
137 return v * comul;
138}
139Integer CaseFunction::
140_applyValueComulTransform(Integer v, Integer comul) const
141{
142 return v * comul;
143}
144Real3 CaseFunction::
145_applyValueComulTransform(Real3 v, Real3 comul) const
146{
147 return v * comul;
148}
149String CaseFunction::
150_applyValueComulTransform(const String& v, const String& comul) const
151{
152 ARCANE_UNUSED(v);
153 ARCANE_UNUSED(comul);
154 ARCANE_FATAL("Invalid for type 'String'");
155}
156bool CaseFunction::
157_applyValueComulTransform(bool v, bool comul) const
158{
159 ARCANE_UNUSED(v);
160 ARCANE_UNUSED(comul);
161 ARCANE_FATAL("Invalid for type 'bool'");
162}
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167template <typename ValueType> void CaseFunction::
168_applyValueTransform2(ValueType& value) const
169{
170 // Applies the transformation...
171 // For now, only a multiplicative coefficient.
172 if (m_transform_value_func.null())
173 return;
174 ValueType comul = ValueType();
175 bool is_bad = builtInGetValue(comul, m_transform_value_func);
176 if (is_bad)
177 ARCANE_FATAL("Can not convert 'comul' value '{0}'", m_transform_value_func);
178 value = _applyValueComulTransform(value, comul);
179}
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184void CaseFunction::
185_applyValueTransform(Real& value) const
186{
187 _applyValueTransform2(value);
188}
189void CaseFunction::
190_applyValueTransform(Real3& value) const
191{
192 _applyValueTransform2(value);
193}
194void CaseFunction::
195_applyValueTransform(Integer& value) const
196{
197 _applyValueTransform2(value);
198}
199void CaseFunction::
200_applyValueTransform(String& value) const
201{
202 _applyValueTransform2(value);
203}
204void CaseFunction::
205_applyValueTransform(bool& value) const
206{
207 _applyValueTransform2(value);
208}
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
213template <typename ParamType> void CaseFunction::
214_applyParamTransform2(ParamType& param) const
215{
216 // Applies the transformation...
217 // For now, only a multiplicative coefficient.
218 if (m_transform_param_func.null())
219 return;
220
221 ParamType comul = ParamType();
222 bool is_bad = builtInGetValue(comul, m_transform_param_func);
223 if (is_bad)
224 ARCANE_FATAL("Can not convert 'comul-x' value '{0}'", m_transform_param_func);
225 if (math::isZero(comul))
226 ARCANE_FATAL("The parameter 'comul-x' can not be zero");
227 param = param / comul;
228}
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
233void CaseFunction::
234_applyParamTransform(Real& value) const
235{
236 _applyParamTransform2(value);
237}
238
239/*---------------------------------------------------------------------------*/
240/*---------------------------------------------------------------------------*/
241
242void CaseFunction::
243_applyParamTransform(Integer& value) const
244{
245 _applyParamTransform2(value);
246}
247
248/*---------------------------------------------------------------------------*/
249/*---------------------------------------------------------------------------*/
250
251Ref<ICaseFunction> CaseFunction::
252toReference()
253{
255}
256
257/*---------------------------------------------------------------------------*/
258/*---------------------------------------------------------------------------*/
259
260} // End namespace Arcane
261
262/*---------------------------------------------------------------------------*/
263/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Various mathematical functions.
Information to build an instance of CaseFunction.
ARCANE_DEPRECATED_260 CaseFunctionBuildInfo(ISubDomain *sd, const String &name)
void setTransformParamFunction(const String &str) override
Sets a parameter transformation function. For now, this is just a multiplicative coefficient....
eParamType m_param_type
Parameter type (x).
bool checkIfValid() const override
Checks the validity of the function.
void setParamType(eParamType type) override
Sets the function parameter type.
String m_name
Name of the function.
void setName(const String &new_name) override
Sets the function name to new_name.
eValueType m_value_type
Value type (y).
String m_transform_param_func
Parameter transformation function.
CaseFunction(const CaseFunctionBuildInfo &info)
Constructs a dataset function.
void setValueType(eValueType type) override
Sets the function value type.
void setTransformValueFunction(const String &str) override
Sets a value transformation function. For now, this is just a multiplicative coefficient....
String m_transform_value_func
Value transformation function.
ITraceMng * m_trace
Trace manager.
eParamType
Type of a function parameter.
eValueType
Type of a function value.
virtual void value(Real param, Real &v) const =0
Value v of the option for parameter param.
Interface of the subdomain manager.
Definition ISubDomain.h:75
Class managing a 3-dimensional real vector.
Definition Real3.h:132
Reference to an instance.
bool null() const
Returns true if the string is null.
Definition String.cc:306
bool isZero(const BuiltInProxy< _Type > &a)
Tests if a value is exactly equal to zero.
-- 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.
Ref< InstanceType > makeRefFromInstance(InstanceType2 *t)
Retrieves a reference on the pointer t.