b311480e |
1 | // Created on: 1991-05-28 |
2 | // Created by: Arnaud BOUZY |
3 | // Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <Expr.hxx> |
7fd59977 |
19 | #include <Expr_Division.hxx> |
20 | #include <Expr_Exponential.hxx> |
42cf5bc1 |
21 | #include <Expr_GeneralExpression.hxx> |
22 | #include <Expr_LogOfe.hxx> |
23 | #include <Expr_NamedUnknown.hxx> |
24 | #include <Expr_NotEvaluable.hxx> |
25 | #include <Expr_NumericValue.hxx> |
7fd59977 |
26 | #include <Expr_Operators.hxx> |
42cf5bc1 |
27 | #include <Standard_NumericError.hxx> |
28 | #include <Standard_Type.hxx> |
29 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
30 | |
92efcf78 |
31 | IMPLEMENT_STANDARD_RTTIEXT(Expr_LogOfe,Expr_UnaryExpression) |
32 | |
7fd59977 |
33 | Expr_LogOfe::Expr_LogOfe(const Handle(Expr_GeneralExpression)& exp) |
34 | { |
35 | CreateOperand(exp); |
36 | } |
37 | |
38 | Handle(Expr_GeneralExpression) Expr_LogOfe::ShallowSimplified () const |
39 | { |
40 | Handle(Expr_GeneralExpression) myexp = Operand(); |
41 | if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) { |
42 | Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp); |
43 | return new Expr_NumericValue(Log(myNVexp->GetValue())); |
44 | } |
45 | if (myexp->IsKind(STANDARD_TYPE(Expr_Exponential))) { |
46 | return myexp->SubExpression(1); |
47 | } |
48 | Handle(Expr_LogOfe) me = this; |
49 | return me; |
50 | } |
51 | |
52 | Handle(Expr_GeneralExpression) Expr_LogOfe::Copy () const |
53 | { |
54 | return new Expr_LogOfe(Expr::CopyShare(Operand())); |
55 | } |
56 | |
57 | Standard_Boolean Expr_LogOfe::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const |
58 | { |
59 | if (Other->IsKind(STANDARD_TYPE(Expr_LogOfe))) { |
60 | Handle(Expr_GeneralExpression) myexp = Operand(); |
61 | return myexp->IsIdentical(Other->SubExpression(1)); |
62 | } |
63 | return Standard_False; |
64 | } |
65 | |
66 | Standard_Boolean Expr_LogOfe::IsLinear () const |
67 | { |
68 | return !ContainsUnknowns(); |
69 | } |
70 | |
71 | Handle(Expr_GeneralExpression) Expr_LogOfe::Derivative (const Handle(Expr_NamedUnknown)& X) const |
72 | { |
73 | if (!Contains(X)) { |
74 | return new Expr_NumericValue(0.0); |
75 | } |
76 | Handle(Expr_GeneralExpression) myexp = Operand(); |
77 | Handle(Expr_GeneralExpression) myder = myexp->Derivative(X); |
78 | Handle(Expr_Division) thediv = myder / Expr::CopyShare(myexp); |
79 | return thediv->ShallowSimplified(); |
80 | } |
81 | |
82 | Standard_Real Expr_LogOfe::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const |
83 | { |
84 | return ::Log(Operand()->Evaluate(vars,vals)); |
85 | } |
86 | |
87 | TCollection_AsciiString Expr_LogOfe::String() const |
88 | { |
89 | TCollection_AsciiString str("Ln("); |
90 | str += Operand()->String(); |
91 | str += ")"; |
92 | return str; |
93 | } |