Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
UnaryExpressionImpl.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* UnaryExpressionImpl.h (C) 2000-2006 */
9/* */
10/* Implémentation d'une expression unaire. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_EXPR_UNARYEXPRESSIONIMPL_H
13#define ARCANE_EXPR_UNARYEXPRESSIONIMPL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Convert.h"
18#include "arcane/expr/ExpressionImpl.h"
19#include "arcane/expr/Expression.h"
20#include "arcane/expr/ExpressionResult.h"
21#include "arcane/expr/BadOperandException.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26ARCANE_BEGIN_NAMESPACE
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31class UnaryOperator;
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
39class ARCANE_EXPR_EXPORT UnaryExpressionImpl
40: public ExpressionImpl
41{
42 public:
43 enum eOperationType
44 {
45 UnarySubstract = 0,
46 Inverse = 1,
47 Acos = 2,
48 Asin = 3,
49 Atan = 4,
50 Ceil = 5,
51 Cos = 6,
52 Cosh = 7,
53 Exp = 8,
54 Fabs = 9,
55 Floor = 10,
56 Log = 11,
57 Log10 = 12,
58 Sin = 13,
59 Sinh = 14,
60 Sqrt = 15,
61 Tan = 16,
62 Tanh = 17,
63 NbOperationType = 18
64 };
65
66 public:
68 eOperationType operation);
69
70 public:
71 virtual void assign(IExpressionImpl*) {}
72 virtual void assign(IExpressionImpl*, IntegerConstArrayView) {}
73 virtual void apply(ExpressionResult* result);
74 virtual Integer vectorSize() const { return 0; }
75 String operationName() const { return operationName(m_operation); }
76 static String operationName(eOperationType type);
77
78 private:
79 Expression m_first;
80 eOperationType m_operation;
81};
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
90{
91 public:
92 virtual ~UnaryOperator() {}
93 virtual void evaluate(ExpressionResult* res, ArrayVariant* a)=0;
94};
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99template<class T>
101: public UnaryOperator
102{
103 public:
104 virtual void evaluate(ArrayView<T> res,
105 ArrayView<T> a)=0;
106
107 virtual void evaluate(ExpressionResult* res, ArrayVariant* a)
108 {
109 // verification de la validite de l'operation
110 Integer size = res->size();
111 if (size != a->size())
112 throw BadOperandException("DefaultUnaryOperator::evaluate");
113
114 // allocation du résultat en fonction du type de a
115 res->allocate(a->type());
116
117 // recuperation des valeurs des operandes
119 res->data()->value(res_val);
121 a->value(a_val);
122
123 // evaluation des tableaux
124 evaluate(res_val, a_val);
125 }
126};
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
131#define DEFAULT_UNARY_OP(classname,expression) \
132template<class T> \
133class classname : public DefaultUnaryOperator<T> \
134{ \
135 public:\
136 virtual void evaluate(ExpressionResult* res, ArrayVariant* a) \
137 { DefaultUnaryOperator<T>::evaluate(res,a); } \
138\
139 virtual void evaluate(ArrayView<T> res, \
140 ArrayView<T> a) \
141 { \
142 Integer size=res.size(); \
143 for (Integer i=0 ; i<size ; ++i) \
144 expression; \
145 } \
146};
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
149
150DEFAULT_UNARY_OP(UnarySubstractOperator,res[i]=-a[i])
151DEFAULT_UNARY_OP(InverseOperator,res[i]=1/a[i])
152DEFAULT_UNARY_OP(AcosOperator,res[i]=acos(Convert::toDouble(a[i])))
153DEFAULT_UNARY_OP(AsinOperator,res[i]=asin(Convert::toDouble(a[i])))
154DEFAULT_UNARY_OP(AtanOperator,res[i]=atan(Convert::toDouble(a[i])))
155DEFAULT_UNARY_OP(CeilOperator,res[i]=ceil(Convert::toDouble(a[i])))
156DEFAULT_UNARY_OP(CosOperator,res[i]=cos(Convert::toDouble(a[i])))
157DEFAULT_UNARY_OP(CoshOperator,res[i]=cosh(Convert::toDouble(a[i])))
158DEFAULT_UNARY_OP(ExpOperator,res[i]=exp(Convert::toDouble(a[i])))
159DEFAULT_UNARY_OP(FabsOperator,res[i]=fabs(Convert::toDouble(a[i])))
160DEFAULT_UNARY_OP(FloorOperator,res[i]=floor(Convert::toDouble(a[i])))
161DEFAULT_UNARY_OP(LogOperator,res[i]=log(Convert::toDouble(a[i])))
162DEFAULT_UNARY_OP(Log10Operator,res[i]=log10(Convert::toDouble(a[i])))
163DEFAULT_UNARY_OP(SinOperator,res[i]=sin(Convert::toDouble(a[i])))
164DEFAULT_UNARY_OP(SinhOperator,res[i]=sinh(Convert::toDouble(a[i])))
165DEFAULT_UNARY_OP(SqrtOperator,res[i]=sqrt(Convert::toDouble(a[i])))
166DEFAULT_UNARY_OP(TanOperator,res[i]=tan(Convert::toDouble(a[i])))
167DEFAULT_UNARY_OP(TanhOperator,res[i]=tanh(Convert::toDouble(a[i])))
168
169/*---------------------------------------------------------------------------*/
170/*---------------------------------------------------------------------------*/
171
172ARCANE_END_NAMESPACE
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177#endif
Type de base polymorphe pour les tableaux (dimension 1).
Exception sur les opérandes des opérations des expressions.
Classe de base de l'implémentation d'une expression.
Type de base polymorphe d'une expression.
Interface pour les différentes implémentations d'une expression.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Implementation d'une expression unaire.
virtual Integer vectorSize() const
Nombre d'éléments du vecteur.
Operateur unaire generique pour les expressions.
Vue constante d'un tableau de type T.
Chaîne de caractères unicode.