b311480e |
1 | // Created on: 1991-05-27 |
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> |
19 | #include <Expr_ArgSinh.hxx> |
20 | #include <Expr_Division.hxx> |
21 | #include <Expr_GeneralExpression.hxx> |
22 | #include <Expr_NamedUnknown.hxx> |
23 | #include <Expr_NotEvaluable.hxx> |
7fd59977 |
24 | #include <Expr_NumericValue.hxx> |
42cf5bc1 |
25 | #include <Expr_Operators.hxx> |
7fd59977 |
26 | #include <Expr_Sinh.hxx> |
7fd59977 |
27 | #include <Expr_Square.hxx> |
7fd59977 |
28 | #include <Expr_SquareRoot.hxx> |
42cf5bc1 |
29 | #include <Expr_Sum.hxx> |
30 | #include <Standard_NumericError.hxx> |
31 | #include <Standard_Type.hxx> |
32 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
33 | |
92efcf78 |
34 | IMPLEMENT_STANDARD_RTTIEXT(Expr_ArgSinh,Expr_UnaryExpression) |
35 | |
7fd59977 |
36 | Expr_ArgSinh::Expr_ArgSinh (const Handle(Expr_GeneralExpression)& exp) |
37 | { |
38 | CreateOperand(exp); |
39 | } |
40 | |
41 | Handle(Expr_GeneralExpression) Expr_ArgSinh::ShallowSimplified () const |
42 | { |
43 | Handle(Expr_GeneralExpression) op = Operand(); |
44 | if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) { |
45 | Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op); |
46 | return new Expr_NumericValue(ASinh(valop->GetValue())); |
47 | } |
48 | if (op->IsKind(STANDARD_TYPE(Expr_Sinh))) { |
49 | return op->SubExpression(1); |
50 | } |
51 | Handle(Expr_ArgSinh) me = this; |
52 | return me; |
53 | } |
54 | |
55 | Handle(Expr_GeneralExpression) Expr_ArgSinh::Copy () const |
56 | { |
57 | return new Expr_ArgSinh(Expr::CopyShare(Operand())); |
58 | } |
59 | |
60 | Standard_Boolean Expr_ArgSinh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const |
61 | { |
62 | if (!Other->IsKind(STANDARD_TYPE(Expr_ArgSinh))) { |
63 | return Standard_False; |
64 | } |
65 | Handle(Expr_GeneralExpression) op = Operand(); |
66 | return op->IsIdentical(Other->SubExpression(1)); |
67 | } |
68 | |
69 | Standard_Boolean Expr_ArgSinh::IsLinear () const |
70 | { |
71 | if (ContainsUnknowns()) { |
72 | return Standard_False; |
73 | } |
74 | return Standard_True; |
75 | } |
76 | |
77 | Handle(Expr_GeneralExpression) Expr_ArgSinh::Derivative (const Handle(Expr_NamedUnknown)& X) const |
78 | { |
79 | if (!Contains(X)) { |
80 | return new Expr_NumericValue(0.0); |
81 | } |
82 | Handle(Expr_GeneralExpression) op = Operand(); |
83 | Handle(Expr_GeneralExpression) derop = op->Derivative(X); |
84 | |
85 | Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op)); |
86 | // X2 + 1 |
87 | Handle(Expr_Sum) thesum = sq->ShallowSimplified() + 1.0; |
88 | |
89 | // sqrt(X2 + 1) |
90 | Handle(Expr_SquareRoot) theroot = new Expr_SquareRoot(thesum->ShallowSimplified()); |
91 | |
92 | // ArgSinh'(F(X)) = F'(X)/sqrt(F(X)2+1) |
93 | Handle(Expr_Division) thediv = derop / theroot->ShallowSimplified(); |
94 | |
95 | return thediv->ShallowSimplified(); |
96 | } |
97 | |
98 | Standard_Real Expr_ArgSinh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const |
99 | { |
100 | Standard_Real val = Operand()->Evaluate(vars,vals); |
101 | return ::Log(val + ::Sqrt(::Square(val)+1.0)); |
102 | } |
103 | |
104 | TCollection_AsciiString Expr_ArgSinh::String() const |
105 | { |
106 | TCollection_AsciiString str("ASinh("); |
107 | str += Operand()->String(); |
108 | str += ")"; |
109 | return str; |
110 | } |