Can Nature be called from Mathcad, Scilab, Octave or Excel?

Nov 6, 2013 at 12:41 PM
Can Nature functions be called from Excel or Mathcad or Scilab or Octave? If this is possible, how do I install it for those packages (particularly for Excel or Mathcad)? Also, is there a list of the functions that can be called - or are they all included in the two code examples on the Documentation page?

More documentation would help enormously. I am working in industry, not academia; my brain is not as fast or as flexible as it was two or three decades ago. However, from the little documentation available, I feel Nature may be of considerable use to me in designing combustion systems for burning waste solvents with a supporting fuel.

Gerard Lardner
HDS Energy
Coordinator
Nov 16, 2013 at 9:48 PM
Hello Gerard,

It is very well possible that at some point Nature will become callable from Excel. I am considering to develop such an extension. Integration with other applications is definitely possible, but honestly I don't think I will ever manage without contribution from other developers joining the project.

At this moment the one work around this limitation is to consume Nature from PowreShell. In PowerShell the computational results can be easily redirected to the programm of interest, like e.g. Excel. The 1.0.1 release includes a new Nature PowerShell module that will allow you consuming all the functionality currently available in Nature in a simple way. If you are not yet familiar with PowerShell, please use the NaturePS.Installer.exe installer included into the download. The installer will simply copy the module to the relevant directory on your machine. The installation process opens a new PowerShell ISE window with an example you can start from. Note, that prior to using Nature from within the integrated shell, you need to set the execution policy to RemoteSigned with the following command

Set-ExecutionPolicy RemoteSigned

With respect to your question on the functions that can be called, these are easily discoverable when using from .NET code. Although I do realise that using Nature from other environments requires detailed API documentation to be created. The documentation pages will be extended prior to the next release. Currently, you can explore the available functionality by executing the following PowerShell command for getting the list of some common functions

Get-Command -Module Nature

and

help Set-Equilibrium -Full

for getting help about a particular function (in this case the Set-Equilibrium function).

Probably one of the most confusing points about Nature is that it practically does not require the user to call any function. Once the state of the ideal gas mixture is defined (either with the mixture definition script, or by setting some new temperature or pressure value, or by equilibrating the state), all the gas properties are accessible without any need to call a function. Nature will call these functions for you behind the scene and present the result on demand.

Currently a lot more functionality than the one shown in examples is already availbale. Although this functionality will be exposed in the documentation only in the next release after being verified additionally. As an example consider the SpeciesChemicalNetProductionRates property of the ideal gas mixture object. This property is about to be used extensively in modeling well stirred reactors, which is still a work in progress.

I hope the above answers your questions. Please feel free to ask any questions on how to use Nature. I am open to consider any particular usage issue and also very interested in your opinion on the library API.

Alexey
Nov 24, 2013 at 7:44 PM
Hello Alexey,

I am still struggling. When I tried to install Nature and run your example PowerExec script Example.ps1, it returned a series of errors starting with an Import-Module failure:
Import-Module : The specified module 'Nature' was not loaded because no valid module file was found in any module directory.
I then checked with Process Explorer and saw that the installer process (NaturePSinstaller.ps1) was still running - it appeared to have hung. I have tried several times since, including on another computer, and running the installer as Administrator, but always with the same result.

The computers are both Windows 7 X64; one is on a domain, the other on a home workgroup.

Gerard
Coordinator
Nov 26, 2013 at 10:03 PM
Hello Gerard,

Could you please check whether the installer had created the Nature folder containing

Nature.psm1
Nature.psd1
Nature.dll
Example.ps1

inside c:\Users[UserName]\Documents\WindowsPowerShell\Modules\
?
Or do you find it in some other location?

Alexey
Nov 27, 2013 at 3:45 PM
Edited Nov 28, 2013 at 1:12 PM
Hello Alexy,

I installed DotNET 4.5.1, as you suggested (I know; you said DotNET 4.5; but it was v4.5.1 that came down from the Microsoft website), and tried again. Still NaturePS.Installer.exe does not terminate. When I look in ProcessExplorer I see NaturePS.Installer.exe is still running, together with a PowerShell child process, even an hour later. It is the same regardless of whether I start NaturePS.Installer.exe by double-clicking on it in Windows Explorer or by calling it from a PowerShell command line.

I cannot find any folders created by NaturePS.Installer.exe in c:\Users[UserName]\Documents\WindowsPowerShell\Modules\ for any user name on the computer (I checked also the User trees for Default and for Public). Indeed, the only instance of C:[something]\WindowsPowerShell\ I can find is at C:\Windows\System32\WindowsPowerShell; the Nature files are not in that folder or in any subdirectory below it.

The only place I can find the various files is in the folder where I placed them when I extracted them from the zip file, i.e. Nature.dll and NaturePS.Installer.exe are in C:\Users\GLardner.HDS\Desktop\Nature\, and Example.ps1, Nature.psd1 and Nature.psm1 are in C:\Users\GLardner.HDS\Desktop\Nature\Nature.

It's the same on both computers I have tried installing it on.

Regards,

Gerard
Coordinator
Nov 27, 2013 at 9:26 PM
Edited Nov 27, 2013 at 9:43 PM
Hello Gerard,

From your description it seems that the installer failed to start. When working as expected, you would be guided through the installation process with a simple wizard UI. Most probably it is a permissions issue and I will try to figure out how to fix this. Sorry for the inconvenience.
For now, to save your time, I would suggest to execute the installation steps manually as follows

1) Install PowerShell 4.0 from http://www.microsoft.com/en-us/download/details.aspx?id=40855
(Although version 3 seems to be sufficient, I am not 100% sure it is fully compatible with the library)

2) Open the PowerShell prompt (the Windows PowerShell application) and execute the following command
Set-ExecutionPolicy RemoteSigned
Answer Yes, on the question “Do you want to change the execution policy?”.

Image

3) Create the Modules folder under the
c:\Users\GLardner.HDS\Documents\WindowsPowerShell 
directory, if does not exist already.

4) Copy the Nature module (Nature folder with its content, found in the zip file) into
 c:\Users\GLardner.HDS\Documents\WindowsPowerShell\Modules\
As the result you should have the
c:\Users\GLardner.HDS\Documents\WindowsPowerShell\Modules\Nature\ 
directory containing files

Nature.psm1
Nature.psd1
Example.ps1
Nature.dll


5) Open the Windows PowerShell ISE application. Using the applications File-menu open the
c:\Users\GLardner.HDS\Documents\WindowsPowerShell\Modules\Nature\Example.ps1
file and run the script pressing F5.

Image

If all goes fine, executing the script will open a new window with a sortable/filterable table showing H2O, CO2, O2, C3H8 and Temperature as functions of the equivalence ratio.

Image

With the File->New option you can create new scripts and try other examples from the documentation (by simply copy/paste).

At this point, please do not forget to add

Import-Module Nature

at the beginning of each script you create. When all is settled, I'll explain how to automate the import, so that Nature gets imported automatically every time you open Windows PowerShell ISE

I hope the above will work out well for you.

Regards,

Alexey
Nov 28, 2013 at 1:09 PM
Edited Nov 28, 2013 at 1:13 PM
Partial success at last!

My computer had Windows PowerShell v2 installed. By installing v4, as well as DotNET 4.5.1 previously, I was able to get the installer user interface to appear, but it still crashed ("Program stopped running").

I went through the manual installation steps as you describe. The first step (Set-ExecutionPolicy RemoteSigned) failed, but worked when I ran PowerShell as Administrator. I had to create the folders c:\Users\GLardner.HDS\Documents\WindowsPowerShell and c:\Users\GLardner.HDS\Documents\WindowsPowerShell\Modules before I could copy the Nature folder into it.

Incidentally, once I had done the installation manually, I tried again to run the installer; this time it did run to completion, and created the file C:\Users\GLardner.HDS\Documents\WindowsPowerShell\profile.ps1.
  • Perhaps you should include a test in the installer to check that DotNET 4.5 and PowerShell v4 are present
  • Does your installer assume that the folder C:\Users\GLardner.HDS\Documents\WindowsPowerShell\ will be present, and has no process if it is not present? Should it always be present? Maybe thiat is another check the installer should make
I copied the folders as you describe, and ran the example script. After a relatively long wait (about a minute), I got the same table as you show above (the values are the same - Great!), but I also got a lot of errors, about 49 in total, all of the type:
out-file : Access to the path 'C:\Windows\system32\0' is denied.
At C:\Users\GLardner.HDS\Documents\WindowsPowerShell\Modules\Nature\Nature.psm1:143 char:12
+         if($PSCmdlet.MyInvocation.PipelineLength > 0){ $Mixture }
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Out-File], UnauthorizedAccessException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
Looks like a permissions error.

Thanks for all your continuing help.

Regards,

Gerard
Coordinator
Nov 28, 2013 at 7:29 PM
Hello Gerard,

Yes, PowerShell version 2 is installed by default with Windows 7. But because of Nature relies on some specific features of the .NET framework 4.5, it is required to upgrade PowerShell to the version 4.0 (or at minimum to 3.0) prior to using the Nature PS module.

The Nature PowerShell module installer is not a native Windows setup program, but just a a simple UI application that relies on the .NET Framework 4.5 itself (this system requirement is mentioned on the documentation page of the Nature project). If the current PowerShell version is below 4.0, the installer should guide the user through the PowerShell upgrade process. After PowerShell is upgraded, the installer simply copies the module into the dedicated directory (the step you've done manually).

Apparently I've failed to oversee all possible complications and will need to correct the process to ensure the smooth installation experience. To be honest I am still a bit puzzled about the difficulties you've faced. I'd tried the installer on a couple of machines and “unfortunately” all went smoothly. I will try to reproduce the issue on a virtual machine and hopefully will resolve it for the following release or a patch.

As for the error you see when executing the example script, can you reproduce the problem even when running the example as Administrator and/or also in both x86 and the standard PowerShell ISE? This script is supposed to not access anything on the file system, unless you've set the $viewInExcel variable to $true. So I am a bit confused with the error you are getting. The fact that the error was displayed 49 times is due to the equivalence ratio being varied from 0.1 till 10 with the step of 10% that in total results in 49 chemical mixtures being equilibrated.

I hope the rest of examples from the documentation work for you fine. Did you already tried to export the results into Excel? I'll try to reproduce the issues you have encountered and will let you know on the outcome as soon as possible.

Regards,

Alexey
Nov 29, 2013 at 1:49 AM
Edited Nov 29, 2013 at 1:50 AM
Hello Alexy,

I have not had time to try all your suggestions, but I did try again to install Nature on my home laptop (which is on a home workgroup, not on a domain), also running Windows 7 X64. First I installed Windows PowerShell 4, having previously installed DotNET 4.5.1.

I tried running the NaturePS.installer: no go. I tried running it again from a PowerShell window, with PowerShell running as Administrator; Success. Why? I have administrator rights, but NaturePS.Install needed to be run as an actual Administrator, not as a user with administrator rights.

I tried running Example.ps1 in PowerShell ISE: I got the same errors as I reported yesterday. I tried again, running PowerShell ISE as Administrator: Success; Example.ps1 ran without errors. Same if I ran Example.ps1 in PowerShell (not PowerShell ISE); success without errors only if PowerShell is running as Administrator.

It's quite slow (Example.ps1, running in PowerShell ISE); 42 seconds on my laptop, an elderly Dell Precision with a 2-core Centrino CPU running at 2.5 GHz and with 8 GB RAM, regardless of whether PowerShell ISE is run as Administrator (Example.ps1 runs without errors) or not as Administrator (runs with errors).

So it looks like both the installer needs to be run as Administrator and your PowerShell example code needs to be run in an instance of PowerShell running as Administrator. Then all is well, at least on this unmanaged (not on a domain) home laptop.

I'll try to export the results to Excel tomorrow (later today - got to go to bed now, it's almost 2 am!)

Again, thanks for all the help.

Best regards,

Gerard
Nov 29, 2013 at 10:59 AM
Edited Nov 29, 2013 at 11:00 AM
I've now been able to run Nature and Example.ps1 without errors on my work computer (it is part of a domain and is strictly managed) by running PowerShell as Administrator. If I try running PowerShell not as administrator, even though I, the logged in user, have administrator rights, then I get the same 49 errors as I reported yesterday.

Regards,

Gerard
Coordinator
Nov 30, 2013 at 2:44 PM
Hello Gerard,

Thanks for all your efforts and patience. I am glad you've managed, athough not ideal way. Your input helps me to improve the code.

I've found what exactly went wrong when the WindowsPowershell directory is missing in the User..\Documents folder. The fixed installer has been uploaded to the release Downloads (see NaturePS.Installer.v2.exe). This installer fixes a couple of other issues I've discovered playing with the restricted accounts. The first one is related to the OS Regional settings (Numbers format). Nature requires the “.” decimal symbol. When the regional settings specify another symbol (e.g. “,”) the module fails to invoke the Nature functions correctly, resulting in a number of errors. The second one is that the Set-MachNumber cmdlet was not imported from the Nature module. This cmdlet allows modeling shock compression processes in ideal gas mixtures.

I am still trying to reproduce the permissions issue you described. When I run the installer under a restricted account, it still succeds. Also the ISE program runs fine without the Administrator mode. To not bring other users into troubles, I've updated the documentation so that running the installer and the PowerShell apps is recommended in the “as Administrator” mode.

Please be aware of the fact that the modules slow startup has nothing to do with the Nature library. Normally, when executing from other hosts than PowerShell, loading the model takes about few seconds. And when loading from the local file system rather than Internet (as it is done in examples specifying the GRI3 URLs), the startup takes even shorter. I can only guess why in PowerShell loading takes so long. However you've probably already noticed that all the following calls, including loading new ModelObjects, goes pretty fast.

Don't hesitate to contact me if you have further question.

Regards,

Alexey