Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline mikekaganski  
#1 Posted : 12 February 2015 07:58:22(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Hello!

I'm making a wrapper for CoolProp library (yes, I know that Ian promised to do it, but I'm afraid there's no activity there, and I thought like helping them).

My plugin implements numeric evaluation (IPluginMathNumericEvaluation).
Everything seem OK when I simply return unitless numbers.
But when I try to assign units to the result (it is a physical properties library), it becomes complicated.

I use SMath.Manager.UnitsManager.GetCurrentUnitName() to get current built-in units names; I use SMath.Manager.Converter.ToTerms() and SMath.Math.Symbolic.Converter.ToMItem() to make proper MItem to assign to resulting TNumber's obj.Units. But it seems I do it wrong.

When the unit current name (e.g. 'K, 'm, 'J) is one-letter, it works OK. The returning result may be displayed by user using different units (say, 'F, 'in, 'kJ).
But if the unit current name is multiletter (say, 'mol, or ('J in Russian locale) 'Дж), the result is displayed correctly, but cannot be normally converted to different units; SMath handles the plugin-assigned unit as a "blob" and makes funny transformations to show "'mol/'{m^3}" as "'kmol/{m^3}".

This is the first problem.
The second is when I make functions that return strings. There seem to be no "string" type in SMath. Instead, strings are a kind of TDouble with isText set to true. I make string results as

new SMath.Math.Numeric.TDouble("\"" + String + "\"" );

This produces a number with isText properly set to true.
But when such a function is used inside other that requests textual arguments, an error is emitted that says "Here must be a string!".

What is wrong with the code?

I attach the plugin source code here. The test file debug.sm is in the solution's root directory. The solution is made with VS 2013 Community. After building the debug version, it tries to copy plugin and CoolProp DLLs to SMath's user plugins directory. It should already exist (%appdata%\SMath\extensions\plugins\ca92ef03-c7da-4888-98ad-528482733e2f\1.0.0.0\). I haven't yet considered how the plugin should install and register itself; this is a work to do...

Thank you very much for attention, and even more for help!
File Attachment(s):
coolprop_wrapper.zip (1,862kb) downloaded 46 time(s).
Best regards,
Mike Kaganski
thanks 1 user thanked mikekaganski for this useful post.
on 13/02/2015(UTC)

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline uni  
#2 Posted : 12 February 2015 10:33:59(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,493
Man
Russian Federation

Was thanked: 1274 time(s) in 745 post(s)
Если Давид оперативно не ответит, то можно по-русски пообщаться на эту тему на русском форуме. Мне здесь нужно вникать, давно не занимался.
Russia ☭ forever
Viacheslav N. Mezentsev
Offline Davide Carpi  
#3 Posted : 12 February 2015 14:11:32(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,639
Man
Italy
Location: Italy

Was thanked: 1323 time(s) in 873 post(s)
Nice work Good

My experience with numeric interface is limited to a couple of plugins, but I've not noticed obvious errors; therefore I've tried a "mixed approach" like in the GPCWrapper (code written with numeric library and I/O handled with lowlevel evaluation) and as you can see from the attachment this works fine, thus the core of your work basically it works (and the issue probably is in the IPluginMathNumericEvaluation.NumericEvaluation, or maybe we are missing something else...)

The implementation is a little bit naive, just to make the test

- input arguments are not preprocessed (overriden with values taken from your debug file)
- units in some cases uses new MItem() instead of unit(uname()) (this approach seems better but I don't have idea if it works with localizations)

Edited by user 12 February 2015 16:58:16(UTC)  | Reason: Not specified

File Attachment(s):
coolprop_wrapper.zip (1,929kb) downloaded 41 time(s).
Davide Carpi attached the following image(s):
2015-02-12 11_50_39-SMath Studio Desktop - [debug.sm_].png
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 12/02/2015(UTC)
Offline mikekaganski  
#4 Posted : 12 February 2015 17:37:52(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Thank you Davide!

I seem to have solved the units problem.
Unfortunately, the new MItem(string) doesn't handle localization; thus I had to keep using the long way.
It turned out that it is crucial to call Expression.SimplifyEx() upon MItem. And taking into account that there's no context in numeric evaluation available (or I miss it), I had to split all the units to basic SI parts (e.g. Pa -> kg/{m*s^2}). Then the units work as intended, and localization works.

The second problem (text that is "not text"Wink seem to be over my skills; hope that someone could shed some light there.

Other than that (unimportant?) issue, the plugin is ready to use. I post the source here, in case someone could make some suggestions.

I don't know how to install it properly; is there some procedure for that?

I don't intend to support it in the future. I'll handle it to CoolProp library makers, and if they wish, they will merge it with their other wrappers and (hopefully) keep it in sync with the library.

Thanks again!
File Attachment(s):
coolprop_wrapper.zip (1,869kb) downloaded 42 time(s).
Best regards,
Mike Kaganski
Offline Davide Carpi  
#5 Posted : 12 February 2015 19:30:40(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,639
Man
Italy
Location: Italy

Was thanked: 1323 time(s) in 873 post(s)
You're welcome Good

Probably Andrey knows a better way to handle units, but your approach seems it works Biggrin

Usually to develop plugins I (manually) copy the libraries to the Plugins directory of the executable, thus I can use the automatic numbering without looking in the %APPDATA% folder (but this may be matter of taste)

I've uploaded a copy in the EM (marked as Beta Version 0.1.*) that should install all that is needed without additional efforts from the users.

BTW I have no idea on what could be different from the Viacheslav plugin CoolProp for PTC Mathcad, any hint to provide documentation/improvements is welcome.


EDIT: Code uploaded in the SVN repository (CoolPropWrapper), to make it easily available for further changes.

Edited by user 12 February 2015 20:33:14(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 13/02/2015(UTC)
Offline mikekaganski  
#6 Posted : 13 February 2015 01:23:20(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Thanks again!

Different is that this is native SMath plugin, that doesn't depend on Mathcad EFI, only on the CoolProp library itself. It may be used both with 32- and 64-bit .NET (as the CoolProp library is available for both 32-bit and 64-bit).

Now I need to analyze the comments that Vyacheslav has made in Russian topic. Maybe I need to use a different approach to simplify units handling (Vyacheslav suggested using ExpressionEvaluation instead of NumericEvaluation). Though initially I tried to follow that path, and it seemed to me that it was more complicated.
Best regards,
Mike Kaganski
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.