[ADOL-C] support for operator overloading for pdouble
Kshitij Kulshreshtha
kshitij at math.uni-paderborn.de
Wed Feb 28 05:27:35 EST 2018
Hello,
pdouble types are not meant to be added or multiplied together. One
pdouble represents one actual parameter. If you combine parameters
together, then you should either do that before converting them to
pdoubles as simple doubles, and that combined value will then always be
used, or the other possibility is to store the result of such a
combination in a variable of type adouble, which you will use in the
rest as any other adouble. The reason pdoubles cannot have overloaded
operators is that we do not trace any operations on constants in order
to keep the trace small, so these operations cannot be conducted when
computing derivatives with such a trace.
Your example should can either look like this:
const pdouble& __o_11_n = mkparam(input.o_11_n());
const pdouble& __o_22_n = mkparam(input.o_22_n());
const pdouble& __o_33_n = mkparam(input.o_33_n());
adouble __p_n = (adouble(__o_11_n) + __o_22_n + __o_33_n)/3;
Then you can use __p_n wherever you need.
Or it can look like this:
const pdouble& __p_n =
mkparam( (input.o_11_n() + input.o_22_n() + input.o_33_n())/3);
in case you only need __p_n in the rest of the code.
Best wishes
Kshitij Kulshreshtha.
On 02/28/18 10:56, hg wrote:
> Dear Adol-C developers
>
> I would like to report that the example taylor/inversexam.cpp failed
> with ADOL-C release v2.6.3, but it worked with the developer version.
> Hope the new stable release will be released soon.
>
> Additionally I would like to request to add the operator overloading for
> pdouble type. Because some material constants are formed from others and
> it would lead to a neatly code if an immediate variable of type pdouble
> is created. Right now I have to copy a lengthy expression to a lengthy
> one, leading to quite a complicated expression, which is then hard to
> debug if something happen later on.
>
> Right now if I added the pdouble, the compilation error appears:
>
> const pdouble& __o_11_n = mkparam(input.o_11_n());
> const pdouble& __o_22_n = mkparam(input.o_22_n());
> const pdouble& __o_33_n = mkparam(input.o_33_n());
>
> pdouble __p_n = (__o_11_n + __o_22_n + __o_33_n)/3;
>
>
> error: ambiguous overload for ‘operator+’ (operand types are ‘const
> pdouble’ and ‘const pdouble’)
> pdouble __p_n = (__o_11_n + __o_22_n + __o_33_n)/3;
> ^
> In file included from /home/hbui/opt/adol-c/include/adolc/adouble.h:329:0,
> from /home/hbui/opt/adol-c/include/adolc/adolc.h:28,
> from
> /home/hbui/kratos_bcn2/applications/soil_mechanics_application/constitutive_laws/smoothed_mohr_coulomb_ad_explicit_lode_angle.cpp:18:
> /home/hbui/opt/adol-c/include/adolc/param.h:105:13: note: candidate:
> adub operator+(const pdouble&, const badouble&)
> inline adub operator + ( const pdouble& a, const badouble& b)
> ^
> In file included from /home/hbui/opt/adol-c/include/adolc/param.h:58:0,
> from /home/hbui/opt/adol-c/include/adolc/adouble.h:329,
> from /home/hbui/opt/adol-c/include/adolc/adolc.h:28,
> from
> /home/hbui/kratos_bcn2/applications/soil_mechanics_application/constitutive_laws/smoothed_mohr_coulomb_ad_explicit_lode_angle.cpp:18:
> /home/hbui/opt/adol-c/include/adolc/internal/paramfunc.h:50:34: note:
> candidate: adub operator+(const badouble&, const pdouble&)
> friend ADOLC_DLL_EXPORT adub operator + ( const badouble&, const
> pdouble&);
>
>
> Best regards
> Giang Bui
>
>
>
> _______________________________________________
> ADOL-C mailing list
> ADOL-C at list.coin-or.org
> https://list.coin-or.org/mailman/listinfo/adol-c
>
--
PD. Dr. Kshitij Kulshreshtha
Institut für Mathematik,
Universität Paderborn,
Warburger Straße 100,
33098 Paderborn.
Büro: TP21.1.21
Besucheradresse:
Technologiepark 21
33098 Paderborn.
Privatanschrift:
Arnikaweg 62
33100 Paderborn.
More information about the ADOL-C
mailing list