posts - 64, comments - 569, trackbacks - 4

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!

Print | posted on Wednesday, November 23, 2011 4:07 PM | Filed Under [ Technical Computing ]

Feedback

Gravatar

# shooting star casino

Ad a website on net will be the perfect quest on web. Do this regularly in the side on internet. And also make us all enjoyable through your own blog posting about net.
12/14/2011 6:04 AM | shooting star casino
Gravatar

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

That tiffany sale. should you had a cafe, wouldn't it matter to you whether people knew that you simplyr restaurant existed? Sure, you need to inshapethem you had a cafe on a person basis, but this can be a slightly slow method to Discount Tiffany Rings a business. by the point you had enough customers via word of mouth, you would be into chapter 11!seo is vitalto be sure that you simplyr website finally ends up at the highest Google pages or other search engine sites. take into consideration while you spotk for thereforemething on the web. You type for your keywords and the pages appear. you most tiffany rings a look on the locations on pages one, two, perhapsthree if you are dedicated enough for your search. most likely, should you do not locatewhat you're in search of on those pages, you enter diffehirekeywords.87% of tourists finally end up on a tiffany necklace from page one. In other words, should your site doesn't finally end up on page one via special keyword searches, you're missing out on a load of possible clients. no matter what your site seems like or has to offerIF nobody can locateyou.search engines like tiffany rings sale locateyour site according to relevant keyword content. you need to perceivewhich keywords to make use of by doing keyword tiffany sale uk. you need to perceivewhere to put them (as an example, keywords in links are picked up more readily by search bots). you need to understand the wayagain and again to put them. Keyword stuffed pages and articles aren't anyw not search engine friendly.All of that is equally vitalon your article marketing endeavours. Article marketing is a time-consuming and priceyaffair. Whether you outsource your articles or write them yourself, you wish to need to tiffany uk on rightkeyword use. you wish to need to understand the wayto do keyword research to boot. should you do not, all some time, attemptand money may were wasted.Link-building is one more avenue of seo. Understanding link popularity and performing link researchis massively vitalin obtaining first page positions. Link-building is an out of this globalmethod to extfinishyour page cheap tiffany rings and narrow your audience to raised matched buyers, in order to drive the rightof traffic for your site!the netis plainly an international affair, tiffany necklace sale you be able to market your services or products to a few of the arena. despite the fact that you've got an area business, seo is vitalto be sure that you simplyr site shall be found prior to your competitors.for more cheap tiffany sale on what seo can do fotherwise you business, contact E-way today.<br />
12/22/2011 5:20 AM | city
Gravatar

# play online black jack

Your blog will be the best blog on-line I have ever before read. Basically compare and contrast your blog when using the other blog around the blog in the online world than I found that a blog is this blog best web log to another websites.
12/27/2011 7:05 AM | play online black jack
Gravatar

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

If you have enough black Tory burch handbags, maybe you want something different. The hardest thing you will have to do is to choose only one, so do not just stop at one. Snakeskin embossing is used on a variety of these backpacks and bag. We also sell some very unique evening cheap handbags. sdongp2013
1/4/2012 1:30 AM | Tory burch handbags
Gravatar

# Leonel Beaudin

Bridesmaid Dresses cheap evening dresses uk ball gowns evening dresses cheap wedding dresses short wedding dress bride gown Beach Wedding Dresses informal wedding dresses wedding dresses uk lace wedding dresses
1/10/2012 8:13 PM | wedding dress styles
Gravatar

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

Thanks for sharing. Totally impressive!
1/14/2012 1:34 AM | Moalboal
Gravatar

# nike air max 95 womens

Be easy to see the latest styles and plenty of affordable clothing and nike air max 95 fresh water and women's method is not an everyday affair, due to the pressure of recent women often do not have much time as well as to go shopping through many fashion malls, and compare different prices will make you exhausted, To be able to obtain a satisfactory goods, have to spend a lot of time, the appear of online shopping greatly reducing the inconvenience with this,air max 95 womens? now you although all of a sudden trip to a lot of goods, but in addition you can be most cost- affordable prices, very easy, just at homes, gently clicking the mouse, favorite products can get your hands in couple of days.
1/14/2012 2:33 AM | nike air max 95 womens
Gravatar

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

Totally amazing page in here. thanks for the share.
1/21/2012 1:04 AM | slim fast diet plan
Gravatar

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

Great posts in here indeed.
1/21/2012 1:05 AM | slim fast diet plan
Gravatar

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

This is a really good post. Must admit that you are amongst the best bloggers I have read. Thanks for posting this informative article.
1/25/2012 3:00 AM | Lennox Humidifier
Gravatar

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

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your posts. Any way I'll be subscribing to your feed and I hope you post again soon..
1/25/2012 4:33 AM | home energy audit
Gravatar

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

I like your blog post. Keep on writing this type of great stuff. I'll make sure to follow up on your blog in the future.
1/25/2012 6:15 AM | local solicitors
Gravatar

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

You made some good points .I did a little research on the topic and found that most people agree with your blog. Thanks.
1/25/2012 6:17 AM | Escort Service Las Vegas
Gravatar

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

I would like to share it with all my friends and hope they will like it too.
1/27/2012 12:47 AM | MyTicketin Rodeo Tickets
Gravatar

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

All the information on how to get your dream house is there for you on this blog. Take a look and and you will find all that you need to know.
1/27/2012 5:29 AM | Link Building India
Gravatar

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

This is a really good post. Must admit that you are amongst the best bloggers I have read. Thanks for posting this informative article.
1/27/2012 5:31 AM | www.profitbysearch.com
Gravatar

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

I read your post and I found it amazing .Your thought process is wonderful. The way you express yourself is awesome.
1/27/2012 5:32 AM | Ruby Sinatra Development
Gravatar

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

I have heard about these problems in corporate websites,Offshore Software development might help you to deal with them.
1/27/2012 5:39 AM | DVD Duplication Service
Gravatar

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

Wow, story share looks like a cool application,I got some additional information on it from software development India.
1/27/2012 5:47 AM | www.seoindia.pro
Gravatar

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

Excellent read, I just passed this onto a colleague who was doing a little research on this topic....
Gravatar

# find a solicitor uk

Some interesting and well researched information on cameras. I'll put a link to this site on my blog. Thank you!
1/30/2012 7:57 AM | find a solicitor uk
Gravatar

# Cfd Trading

This is a really good read for me, Must admit that you are one of the best bloggers I have read. Thanks for posting this informative article.
1/30/2012 8:06 AM | Cfd Trading
Gravatar

# emaar mgf new project gurgaon

This is my first visit here. I found some really interesting stuff in your blog especially this discussion. Keep up the good work.
2/9/2012 5:23 AM | Yogendra Bisht
Gravatar

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

I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that's at the other blogs. Thanks for sharing this.
2/20/2012 11:28 PM | flower delivery in dubai
Gravatar

# re: A bit more on the personal side …

Lots of timepieces have an finish of life indicator, which helps you to understand when to replace the battery. It only takes a couple of minutes every day to keep your timepieces searching wonderful...invest the time.The innovative frames perfectly portray the mind blowing skills of its Italian craftsmen and supply elegance and style for the wearer. louis vuitton speedy are many of the main components that prompt persons to personal a pair of louis vuitton sale shades. Besides being fashionable, these designer louis vuitton artsy sunglasses supply 100% UV protection.As designs changed to become extra fashionable, you will find people who have to have extra than a pair from the traditional sunglasses. Traditionally, individuals who have eyesight difficulties happen to be required to make use of a pair with the clip ons to cover their prescription eyeglasses.louis vuitton neverfull normally provides the assurance of superior excellent. To keep pace using the altering trends, these louis vuitton luggage are the very best bet. Even Hollywood celebs appreciate donning these masterpieces.
2/21/2012 9:14 PM | louis vuitton sale
Gravatar

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

The truth is that louis vuitton store is actually actually quite simple to care for a luxury timepiece. Most of these models are extremely comparable and will require exactly the same attention, so whether or not you own a Louis vuitton sale bags or any other d esigner piece...these tips will help you to keep you watch looking and running like new.Louis vuitton outlet is synonymous with ultra fashionable and trendy accessories. One of the oldest brands within the fashion world, from the fashion hub - Italy, Louis vuitton is loved and admired by fashion lovers for its diverse and distinctive designs.Whether or not you're element with the globe of high fashion or the average shopper, most of us are familiar with all the name of Gucci. The Home of louis vuitton outlet store, commonly referred to as Gucci, was begun in 1921 by Gucio Gucci in Florence, Italy. louis vuitton factory outlet was identified, for the duration of it early beginnings, for producing top quality leather goods for example high fashion luggage and shoes.
2/21/2012 9:32 PM | tresor paris bracelets

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 2 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET