posts - 64, comments - 387, trackbacks - 4

Thursday, February 02, 2012

Adding an existing folder to a visual studio project

Including existing files in Visual Studio is easily performed by right clicking a folder and selecting 'add existing item', however, there is not a 'add existing folder' option.

The solution is quite simple, but not as hinted by the existence of 'add exiting item'. Simply click the 'Show all files' button at the top of the Solution Explorer and right click the folder desired and select 'include in project'.

The process is simple enough, but a bit obscure due to the presence of 'add existing item'.

posted @ Thursday, February 02, 2012 12:07 PM | Feedback (1) |

Saturday, December 03, 2011

Extrapolate Errors for p>3

Running some test cases pointed out that the extrapolation from first order Lagrange basis functions to those higher than third order cubic Lagrange basis functions were in error. The extrapolated functions had high degrees of oscillations. The bug has been reported to the developers. They have put in a check so that the first release will throw an error instead of attempting an extrapolation.

So it's back to traditional interpolation methods. Keep this in mind when viewing the code from the last two posts.

posted @ Saturday, December 03, 2011 11:45 PM | Feedback (16) | Filed Under [ Technical Computing ]

Tuesday, November 29, 2011

A C++ Interpolation Class for Tabled Data

I have wrapped the interpolation method using the Fenics Project into a template class. The class is template on the interpolation basis function so that the user may choose the order of interpolation. The class also contains an array of y values so that it may serve as a table of values. Part of this is a map to the variable name for convenience when calling for tabled values.

Since all the work goes into extrapolating to a higher basis function when the Constructor is called, lookups are cheap to retrieve. The cost should be about the level of evaluating a polynomial of the order of the interpolation level (since the weights are known).

An example of it being used:

 

    boost::shared_ptr<Vector> xs (new Vector(n));

    boost::shared_ptr<Vector> ys1 (new Vector(n));

    boost::shared_ptr<Vector> ys2 (new Vector(n));

 

    std::vector<boost::shared_ptr<Vector> > yss;

    std::vector<string> names;

 

    // Populate test data
						

    for(int i=0; i<n; i++)

    {

        xs->setitem(i,i+i*0.1);

        ys1->setitem(i,(*xs)[i]*(*xs)[i]);

        ys2->setitem(i,(*xs)[i]*(*xs)[i]*(*xs)[i]);

    }

 

    yss.push_back(ys1);

    names.push_back("squared");

 

    yss.push_back(ys2);

    names.push_back("cubed");

 

 

 

 

    InterpolationTable<Interpolate3::FunctionSpace> interpTable (xs, yss, names);

 

    std::cout << interpTable.eval(0,2.12) << "\t" << interpTable.eval("squared",2.12) << "\n";

    std::cout << interpTable.eval(1,2.12) << "\t" << interpTable.eval("cubed",2.12) << "\n";

 

 

The code listing:

 

// InterpolationTable.h

// Class for interpolating tabled values using the Fenics Project.

// Charles R. Cook  v1.0  29 Nov 2011

 

// Copyright (c) 2011 Charles R. Cook

// http://www.charlesrcook.com

//

// Permission is hereby granted, free of charge, to any person obtaining a copy

// of this software and associated documentation files (the "Software"), to

// deal in the Software without restriction, including without limitation the

// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or

// sell copies of the Software, and to permit persons to whom the Software is

// furnished to do so, subject to the following conditions:

//

// The above copyright notice and this permission notice shall be included in

// all copies or substantial portions of the Software.

//

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS

// IN THE SOFTWARE.

 

 

#ifndef _INTERPOLATIONTABLE_H

#define _INTERPOLATIONTABLE_H

 

 

#include <dolfin.h>

 

#include "Interpolate1.h"

#include "Interpolate2.h"

#include "Interpolate3.h"

#include "Interpolate4.h"

 

 

using namespace dolfin;

 

template <class TFunctionSpace>

class InterpolationTable

{

public:

    InterpolationTable(boost::shared_ptr<Vector> xs_in,

            std::vector<boost::shared_ptr<Vector> > ys_in);

    InterpolationTable(boost::shared_ptr<Vector> xs_in,

            std::vector<boost::shared_ptr<Vector> > ys_in,

            std::vector<std::string> names_in);

    double eval(int index, double x);

    double eval(std::string name, double x);

 

    // These vectors contain the raw data

    boost::shared_ptr<Vector> xs;

    boost::shared_ptr<std::vector<boost::shared_ptr<Vector> > > ys;

 

    // The mesh (defined as nodes at x locations)

    boost::shared_ptr<Mesh> mesh;

 

    boost::shared_ptr<Interpolate1::FunctionSpace> V1;

    boost::shared_ptr<TFunctionSpace> V2;

 

    boost::shared_ptr<std::vector<Function> > fy1;

    boost::shared_ptr<std::vector<Function> > fy2;

 

    boost::shared_ptr<std::vector<std::string> > Names;

 

private:

    void Setup(boost::shared_ptr<Vector> xs_in,

            std::vector<boost::shared_ptr<Vector> > ys_in);

    boost::shared_ptr<std::map<std::string,int> > mapping;

 

};

 

template <class TFunctionSpace>

double InterpolationTable<TFunctionSpace>::eval(

        std::string name, double x)

{

    if((*Names).size()==0)

        throw ("names not defined");

 

    // check key exists in map

    if ((*mapping).find(name) == (*mapping).end() )

        throw ("name was not found");

 

 

    int index = (*mapping)[name];

 

    return eval(index, x);

 

}

 

template <class TFunctionSpace>

double InterpolationTable<TFunctionSpace>::eval(

        int index, double x)

{

    if(index >= (*ys).size())

        throw ("index out of range");

 

    if(x < mesh->coordinates()[0] ||

            x > mesh->coordinates()[(*mesh).num_cells()])

        throw ("x location out of range");

 

    return (*fy2)[index](x);

 

}

 

 

template <class TFunctionSpace>

void InterpolationTable<TFunctionSpace>::Setup(

        boost::shared_ptr<Vector> xs_in,

        std::vector<boost::shared_ptr<Vector> > ys_in)

{

 

    // copy the x locations in

    xs = xs_in;

 

    // copy the data in

    for (uint i=0; i<ys_in.size(); i++)

    {

        (*ys)[i] = ys_in[i];

    }

 

    // Setup the mesh to interpolate on

    // Note the count is the number of elements, not nodes

    //  when the interval is constructed

    for(uint i=0; i<xs->size(); i++)

        mesh->coordinates()[i] = (*xs)[i];

 

    // Setup the Function space(s)

    for (uint i=0; i<ys->size(); i++)

    {

        Function fv1(V1,(*ys)[i]);

        fy1->push_back(fv1);

 

        Function fv2(V2);

        fv2.extrapolate(fv1);

 

        fy2->push_back(fv2);

 

    }

}

 

template <class TFunctionSpace>

InterpolationTable<TFunctionSpace>::InterpolationTable(boost::shared_ptr<Vector> xs_in,

        std::vector<boost::shared_ptr<Vector> > ys_in,

        std::vector<std::string> names_in) :

            xs(new Vector(xs_in->size())),

            ys(new std::vector<boost::shared_ptr<Vector> > (ys_in.size())),

            mesh(new Interval(xs_in->size()-1,0,1)),

            V1(new Interpolate1::FunctionSpace(mesh)),

            V2(new TFunctionSpace(mesh)),

            fy1(new std::vector<Function>),

            fy2(new std::vector<Function>),

            Names(new std::vector<std::string>),

            mapping(new std::map<std::string, int>)

{

 

    Setup(xs_in, ys_in);

 

    (*Names) = names_in;

 

    for(uint i=0; i < (*Names).size(); i++)

        (*mapping)[(*Names)[i]] = i;

 

}

 

 

template <class TFunctionSpace>

InterpolationTable<TFunctionSpace>::InterpolationTable(boost::shared_ptr<Vector> xs_in,

        std::vector<boost::shared_ptr<Vector> > ys_in) :

            xs(new Vector(xs_in->size())),

            ys(new std::vector<boost::shared_ptr<Vector> > (ys_in.size())),

            mesh(new Interval(xs_in->size()-1,0,1)),

            V1(new Interpolate1::FunctionSpace(mesh)),

            V2(new TFunctionSpace(mesh)),

            fy1(new std::vector<Function>),

            fy2(new std::vector<Function>),

            Names(new std::vector<std::string>),

            mapping(new std::map<std::string, int>)

 

{

 

    Setup(xs_in, ys_in);

 

}

 

 

 

#endif /* _INTERPOLATIONTABLE_H */

 

posted @ Tuesday, November 29, 2011 12:27 PM | Feedback (8) | Filed Under [ Technical Computing ]

Wednesday, November 23, 2011

Interpolation/Curve Fitting in C++ with the Fenics Project in 1D, 2D and 3D

My recent research has been with the Fenics Project, which is an amazing finite element project. In general it provides the tools needed to solve differential equations with the finite element method. For some examples check out their website and view the demos and applications (my interest is in CFD).

In my particular code I need to interpolate tabulated properties (steam tables) with some reasonable level of accuracy. The solution in MATLAB is straight forward, call interp1:

y_i = interp1(xs, ys, x_i, 'cubic');

 

Where xs and ys are vectors of known x and y values and y_i is the interpolated value at x_i.

The code I am working on is already using the Fenics Project to solve a set of PDEs, so I wanted to see if I could use it for the interpolation as well through the finite element's basis functions. As the title of this post indicates, it can be done and here is how through a code snippet.

In C++…

// Setup data vectors

Vector xs(n);

Vector ys(n);

 

// Populate test data (this would be the tabulated data)

for(int i=0; i<n; i++)

{

    xs.setitem(i,i+i*0.1);

    ys.setitem(i,xs[i]*xs[i]);

}

 

 

// Setup the mesh to interpolate on

// Note the count is the number of elements, not nodes.

// there are general n-1 elements than nodes.

Interval mesh (n-1,0,1);

for(int i=0; i<n; i++)

    mesh.coordinates()[i] = xs[i];

 

 

// create the function space of order one.

// this is done so that dof maps directly to

// data points. This provides a linear interpolation.

Interpolate1::FunctionSpace V (mesh);

 

// copy the data into the function space

Function fy (V, ys);

 

 

// Create quadratic function space (quadratic interpolation)

Interpolate2::FunctionSpace V2 (mesh);

Function fy2 (V2);

 

// 'fit' to the quadratic basis functions through least squares

fy2.extrapolate(fy);

 

// The fitted function is now available in fy2 as a quadratic fit

std::cout << "O(1): " << fy(2)

        << "\tO(2): " << fy2(2)

        << "\n";

 

 

Note that two UFL files (form files) are needed for this snippet.

 

Interpolate1.ufl

# First order (linear) lagrange elements (polynomials)

element = FiniteElement("Lagrange", interval, 1)

 

 

Interpolate2.ufl

# Second order lagrange elements (polynomials)

element = FiniteElement("Lagrange", interval, 2)

 

To create higher order fitting you can change the element to be of the desired order (instead of 2).

The very nice feature of interpolation through this method is that it will work in two dimensions and three dimensions as well. To do so, the elements would be updated to 2-d or 3-d element types instead of 'interval' (say triangle or tetrahedral). Too cool!

posted @ Wednesday, November 23, 2011 4:07 PM | Feedback (22) | Filed Under [ Technical Computing ]

Tuesday, November 22, 2011

A bit more on the personal side …

The posts so far have been rather technical in nature, but this post is a bit different. It's a bit more personal as I am sharing my recent engagement to my amazing fiancée Kristy.

It's an exciting time and I can't wait to see what's down the road for us. We have started planning for the wedding which is roughly two years out. The process is being well documented on her blog, I Do Times Two.

 


image source

posted @ Tuesday, November 22, 2011 8:42 PM | Feedback (11) |

Monday, June 20, 2011

Update Summer 2011

I have been lax in updating posts on the blog.  Mostly this is because I have been transitioning from web development to my Ph.D. research work in Aerospace Engineering over the last two or so years.  The topic of the blog thus far has been mostly web development related, with less significant posts on the topic recently.

I’ve decided to transition the blog into my current focus, research, as my personal focus has also shifted (it is a personal blog after all).  As part of this I have updated the blog engine itself (subtext).  Many thanks to those at subtext for maintaining a blog so well that after three years of update neglect an automated update script goes flawlessly!

Over the past couple of years I have worked with gravity currents for my Masters research in Aerospace Engineering.  Some of the research effort was spent in Davos, Switzerland at WSL SFL (Summer 2010).  I earned my MS this last May (2011), and am starting a new research project for my Ph.D. on Cryogenic Thermal and Fluid Physics.  My focus is as one might imagine computational.  I’m looking forward to delving deeply into the topic over the next few years.

More to come!

posted @ Monday, June 20, 2011 3:18 PM | Feedback (6) | Filed Under [ Web Programming School ]

Tuesday, January 18, 2011

Skype an IIS Gotcha

 

I was getting the following error after installing IIS and starting a new Web Site in Windows 7

 

---------------------------

Internet Information Services (IIS) Manager

---------------------------

The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

---------------------------

OK

---------------------------

 

And in the System Event Log:

 

The World Wide Web Publishing Service (WWW Service) did not register the URL prefix http://something.local:80/ for site 1. The site has been disabled. The data field contains the error number.

 

It turns out Skype automatically listens to port 80 and 443. Change this is the advanced settings of Skype to fix the issue.

posted @ Tuesday, January 18, 2011 9:22 PM | Feedback (6) | Filed Under [ Web Programming ]

Wednesday, January 12, 2011

Digital Spring Cleaning

It's a new year, a new spring semester, and my school, the University of Florida, gave us a nice present. They have obtained a site license for Windows 7 Ultimate and Office 2010 Professional Plus for the students and faculty. We can obtain each for just $15. Combined with our MSDNAA account for engineering students, this makes just about everything made by Microsoft free for the Engineering students.

The spur of new software and a clean start motivated me to put some time into some early spring cleaning on my primary computer, a desktop replacement laptop.

One of my first steps was to install Office 2010, which was met with a nice installation 1402 setup error regarding the registry entries for the installer. The solution for me was to simply over right the permissions of those keys from the Components level down. More explicitly, run regedit as an administrator. Find the key hklm\software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components and right click Components, select permissions, advanced, the owner tab, and change the owner to Administrators and check the checkbox for replace on all sub containers. Click okay and the problem should be solved if it was the same problem I had. Note that this is a nice little trick for resurrecting rights to a set of files on disk as well. Well, trick may be over glorifying it…

With Office installed I did an upgrade anytime upgrade to Windows 7 Ultimate. The process couldn't be any simpler, just click start and search for 'upgrade' and click any time upgrade. Enter your key and wait for fifteen minutes or so (and the reboot).

After the upgrade I had finished my changes to Windows, so I ran Windows update a few times after un-hiding hidden updates (I had a few hidden that failed previously due to Office 2007). Be sure to re-check for updates after installing updates, some updates don't show until their dependencies are installed.

Now for my 'superficial' security, I updated Microsoft Security Essentials and ran a Quick Scan. Neat, no viruses or spy-ware… As an aside, the best security for a computer is a smart user and conversely nothing more dangerous than a 'risky' user.

With Windows up-to-date and scanned I next chose to clean up the hard drive. One tool I find essential for this is TreeSize Free, which has a new version. First I updated the version, which was a nice improvement over the last, and started a full scan of my drive. Space for me is still at a premium because of the 130GB SSD; for me every GB matters.

  • The scan reminded me of some games I had installed and no longer played. The games Left 4 Dead and Left 4 Dead 2 were huge on disk, so I removed them without issue through Steam.
  • It also pointed out that my Outlook files were excessively large and needed to be compacted. To do so, right click a mail folder in Outlook 2010 (the main folder for an account) select Data File Properties, and go to Advanced. Then choose Compact now. I did this for each of my accounts. Note that it takes a few minutes for a large account.
  • My Google application data was in excess of a Gig and needed to be cleared. I started Chrome, went to options, under the hood and clicked 'Clear browsing data…'
  • The same was true for Internet Explorer. I went to Internet Options and deleted my browsing History.
  • I manually emptied my 'Temp' folders. They can, by definition, be deleted at will (I killed the contents, not the folder).
  • I deleted the contents of my 'Downloads' folder, good for many Gigabytes.
  • Note that if you a running a Vista Service Pack you can save some space in WinSXS.
  • I deleted C:\Dell, where Dell loves to extract software.
  • Finally don't forget to empty the Recycling bin.

I then simply cleaned up my Desktop. There is something to be said of keeping things looking clean. It reminds me of a mechanic saying the best way to make a customer feel like their car is running better is to clean their windshield. My desktop is my windshield, and it is clean. I also cleaned the actual screen.

My next focus was on bringing software up to date. My favorite text editor, Notepad2, was a version behind and needed to be updated. Note that I replace Window's notepad with Notepad2 by replacing the file in the Window's directory. This is probably not the best practice, but it's worked great for me for years. Note to do so you have to take ownership of the original notepad file and add modify rights for yourself.

I also installed the newest versions of Pidgin, Adobe Reader (through help update), Sumatra PDF, Winamp, and Dropbox (yes, that's a referral link. It gives both you and me extra space).

I then checked Dell for new drivers for my laptop. I chose to let it check my service tag because it's simply easier than flipping the laptop. I also downloaded and installed new video drivers from NVIDIA. They added some 3D Vision links to my start menu… not too thrilled about that, but oh well.

Next I checked the Windows logs for any errors that have been occurring. This is perhaps the most important maintenance step imho. Right click computer in the start menu, select manage, and expand the Event Viewer under System Tools and then Windows Logs, Application. I looked through my events, filtering for Warnings, Critical and Errors. These results will vary heavily between computers so Google will be your friend. Try to search by unique things in the error, such as file names, error numbers and the like. Inspection of my logs pointed out that I had to do the following

After checking the logs I went back to removing bloat and uninstalled old Applications I no longer needed.

To increase login performance I ran msconfig and removed some applications from startup (Almost everything).

Along the same vein I then stopped unnecessary services by running services.msc. Note that the important thing is to change the startup type to manual on optional services. I made services by Apple 'Manual' for example (Bonjour being one of them). Starting iTunes will re-enable these services.

Note that I did not run Disk Defrag as I have a SSD, which in general should not be defragged.

Finally, I ran a Full Backup of my Machine.

A final reboot and the machine is running like new for the new year.

 

 

 

 

 

 

posted @ Wednesday, January 12, 2011 8:41 AM | Feedback (15) |

Thursday, December 09, 2010

Cygwin to Empower Windows

Over the past two years I have been working heavily in the LINUX world. For software development I love it, package distribution to obtain dependencies and the free tools make development really nice. Moving back to the Windows has been a bit frustrating as many tools I have come to use are missing. A simple solution has been to install Cygwin, which is 'like' a package manager for Windows, and add the binary location to Cygwin to my PATH variable. Now I can use linux commands such as 'ls' and 'ssh' from CMD. Or better yet, use Cygwin to have BASH on my Windows machines.

Cygwin is available here: http://www.cygwin.com/

Don't let the circa 1998 web design fool you; the project is still very active.

posted @ Thursday, December 09, 2010 11:55 AM | Feedback (7) |

Friday, October 01, 2010

Generating a Symbolic Vector in Matlab

Matlab's symbolic toolbox is great for abstracting algebraic operations. For example, generating Lagrange basis functions. However, when generalizing an operation of order n, n symbolic variables are needed. Creating n symbolic variables in Matlab isn't as obvious as creating a static set of symbols. For example:

 

syms x y

 

vs.

 

syms x1 x2 x3 xn

 

Fortunately the function sym takes a string argument and returns the symbolic variable. This way we can build a string for each xi, and append the resulting variable into a container such as a vector. Generating n symbolic variables can be done like so

 

% generate xi symbolic values

xi = [];

for (i=1:n)

t = sym(['x' int2str(i)]);

xi = [xi; t];

end

 

 

We now have a symbolic vector with n variables

posted @ Friday, October 01, 2010 7:59 PM | Feedback (3) |

Powered by:
Powered By Subtext Powered By ASP.NET