1 // Created on: 1991-05-28
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #define No_Standard_RangeError
19 #define No_Standard_OutOfRange
22 #include <Expr_UnaryFunction.ixx>
23 #include <Expr_InvalidFunction.hxx>
24 #include <Expr_Array1OfNamedUnknown.hxx>
25 #include <Expr_Array1OfGeneralExpression.hxx>
26 #include <Expr_FunctionDerivative.hxx>
27 #include <Expr_Product.hxx>
28 #include <Expr_Operators.hxx>
31 Expr_UnaryFunction::Expr_UnaryFunction (const Handle(Expr_GeneralFunction)& func, const Handle(Expr_GeneralExpression)& exp)
33 if (func->NbOfVariables() != 1) {
34 Expr_InvalidFunction::Raise();
40 Handle(Expr_GeneralFunction) Expr_UnaryFunction::Function () const
45 Handle(Expr_GeneralExpression) Expr_UnaryFunction::ShallowSimplified () const
47 Handle(Expr_GeneralExpression) op = Operand();
48 if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
49 Handle(Expr_NumericValue) nval = Handle(Expr_NumericValue)::DownCast(op);
50 TColStd_Array1OfReal tabval(1,1);
51 tabval(1) = nval->GetValue();
52 Expr_Array1OfNamedUnknown vars(1,1);
53 vars(1) = myFunction->Variable(1);
54 Standard_Real res = myFunction->Evaluate(vars,tabval);
55 return new Expr_NumericValue(res);
57 Handle(Expr_UnaryFunction) me = this;
61 Handle(Expr_GeneralExpression) Expr_UnaryFunction::Copy () const
63 return new Expr_UnaryFunction(myFunction,Expr::CopyShare(Operand()));
66 Standard_Boolean Expr_UnaryFunction::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
68 if (!Other->IsKind(STANDARD_TYPE(Expr_UnaryFunction))) {
69 return Standard_False;
71 Handle(Expr_UnaryFunction) fother = Handle(Expr_UnaryFunction)::DownCast(Other);
72 Handle(Expr_GeneralExpression) otherexp = fother->Operand();
73 if (otherexp->IsIdentical(Operand())) {
74 if (myFunction->IsIdentical(fother->Function())) {
78 return Standard_False;
81 Standard_Boolean Expr_UnaryFunction::IsLinear () const
83 if (!ContainsUnknowns()) {
86 if (!Operand()->IsLinear()) {
87 return Standard_False;
89 return myFunction->IsLinearOnVariable(1);
92 Handle(Expr_GeneralExpression) Expr_UnaryFunction::Derivative (const Handle(Expr_NamedUnknown)& X) const
94 Handle(Expr_NamedUnknown) myvar = myFunction->Variable(1);
95 Handle(Expr_GeneralExpression) myop = Operand();
96 Handle(Expr_GeneralExpression) myexpder = myop->Derivative(X);
97 Handle(Expr_GeneralFunction) myfuncder = myFunction->Derivative(myvar);
98 Handle(Expr_UnaryFunction) firstpart = new Expr_UnaryFunction(myfuncder,Expr::CopyShare(myop));
99 Handle(Expr_Product) resu = firstpart->ShallowSimplified() * myexpder;
100 return resu->ShallowSimplified();
103 Standard_Real Expr_UnaryFunction::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
105 Expr_Array1OfNamedUnknown varsfunc(1,1);
106 varsfunc(1) = myFunction->Variable(1);
107 TColStd_Array1OfReal valsfunc(1,1);
108 valsfunc(1) = Operand()->Evaluate(vars,vals);
109 return myFunction->Evaluate(varsfunc,valsfunc);
112 TCollection_AsciiString Expr_UnaryFunction::String() const
114 TCollection_AsciiString res = myFunction->GetStringName();
116 res += Operand()->String();