CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Efficient way of programming for fvc::grad()

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By dlahaye
  • 1 Post By msaravia

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 16, 2018, 13:33
Question Efficient way of programming for fvc::grad()
  #1
Senior Member
 
krishna kant
Join Date: Feb 2016
Location: Hyderabad, India
Posts: 133
Rep Power: 10
kk415 is on a distinguished road
Hello All


I am new to OpenFoam. I have this small portion of code in my solver. I think right now it is working in a very efficient. Can anyone suggest me any more efficient way of doing the same thing.


CODE


forAll(solidRegions[0].cells(), cellI)
{
vector r=solidRegions[0].C()[cellI]-fluidRegions[0].C()[celladd_to_src[cellI]];
Us[cellI]=Uf[celladd_to_src[cellI]];
Us[cellI].component(0)=Us[cellI].component(0)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(0)*r.component(0);
Us[cellI].component(1)=Us[cellI].component(1)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(1)*r.component(0);
Us[cellI].component(2)=Us[cellI].component(2)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(2)*r.component(0);
Us[cellI].component(0)=Us[cellI].component(0)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(3)*r.component(1);
Us[cellI].component(1)=Us[cellI].component(1)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(4)*r.component(1);
Us[cellI].component(2)=Us[cellI].component(2)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(5)*r.component(1);
Us[cellI].component(0)=Us[cellI].component(0)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(6)*r.component(2);
Us[cellI].component(1)=Us[cellI].component(1)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(7)*r.component(2);
Us[cellI].component(2)=Us[cellI].component(2)+fvc::grad(Uf)()[celladd_to_src[cellI]].component(8)*r.component(2);
Tf[celladd_to_src[cellI]]=0;
}
kk415 is offline   Reply With Quote

Old   September 18, 2018, 04:57
Default
  #2
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 798
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Possibly it helps to look into Chapter 9 of Moukalled, Manga and Darwish, The finite volume method in computational fluid dynamics, Springer 2015 , http://www.springer.com/gp/book/9783319168739
kk415 likes this.
dlahaye is offline   Reply With Quote

Old   September 20, 2018, 11:01
Default
  #3
Member
 
Martin
Join Date: Dec 2011
Posts: 40
Rep Power: 14
msaravia is on a distinguished road
If I am right you need to update Us as:

Code:
Us += fvc::grad(Uf).T() & r
Writing this would probably be faster, in your loop you are evaluating the gradient several times and you should do it only once.
kk415 likes this.
msaravia is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenFOAM programming training, 19./20. Feb. 2018 thg OpenFOAM Announcements from Other Sources 0 February 8, 2018 07:04
Additional Programming Course November 2016 thg OpenFOAM Announcements from Other Sources 0 October 20, 2016 17:23
How can i make a parallel programming in OpenFOAM? jignesh_thaker2007 OpenFOAM Running, Solving & CFD 3 July 2, 2014 10:37
A book for a beginner wanting to learn programming frank Main CFD Forum 9 May 13, 2014 00:15
Rheolef 6.3: a free and efficient C++ finite element library saramito Main CFD Forum 0 October 23, 2012 03:42


All times are GMT -4. The time now is 03:38.