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

access members of strainRate()

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Tobi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 31, 2017, 04:03
Question access members of strainRate()
  #1
New Member
 
Shuang Li
Join Date: Nov 2015
Posts: 6
Rep Power: 10
victor198936 is on a distinguished road
Hi Everyone,

I'm a new OpenFoamer and I've been stopped by this problem here over the past four days so I'm keen in borrowing professional minds here.

Basically, I'm trying to access members value of strainRate() such that I can compare the value to a real number. I understand the type of strainRate() is volScalarField and there should be two readFields, internalField and boundaryField, that should be able to access. My code is below:

forAll(strainRate().internalField(),cellI)
{
if (strainRate().internalField()[cellI] < 0.17)
{
return
M;
}
else
{
return
k_*((-0.00795*log(strainRate()/m_) + 0.344)/(sqr(log(strainRate()/m_)) + 9.02*log(strainRate()/m_) + 25.0) + (-0.0128*log(strainRate()/m_) + 0.398)/(sqr(log(strainRate()/m_)) + 6.11*log(strainRate()/m_) + 14.5))/rho_;
}
}

However, when I compile the code, it said they could not find out internalField.

ShearThinning.C: In member function ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::viscosityModels::ShearThinning::calcNu() const’:
ShearThinning.C:53:1: error: ‘class Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ has no member named ‘internalField’
ShearThinning.C:55:18: error: ‘class Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ has no member named ‘internalField’

Can anyone suggest the reason and provide solution to work it out?

Appreciate in advance!
victor198936 is offline   Reply With Quote

Old   February 2, 2017, 02:15
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Dear Shuang,

based on the fact that I cannot find the ShearThinning.C file, I suppose that it is something you developed. Based on your output you are not accessing to a volScalarField you try to access to a tmp<volScalarField>. At the moment and out of the box I cannot tell which is the right way but it could be that it is:
Code:
shearRate()().internalField()[cellI]
Otherwise build a new volScalarField like:
Code:
const volScalarField& tmp = shearRate();
And use that one.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   February 2, 2017, 02:54
Default
  #3
New Member
 
Shuang Li
Join Date: Nov 2015
Posts: 6
Rep Power: 10
victor198936 is on a distinguished road
Thank you for the response Tobi.

Quite honest, I'm not quite sure the difference between volScalarField and tmp<Foam::volScalarField>. Can you elaborate more?

Also, what're the good resources/tutorials for understanding the OpenFoam programming code, structure. It's very difficult to program without understand the basic. Could you kindly suggest?

Thanks
victor198936 is offline   Reply With Quote

Old   February 2, 2017, 03:27
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
OpenFOAM is just C++. So if you want to know how things work, you should know C++. That's it. The tmp<T> is a class but not a normal class it is a template class. You can use doxygen to check out the stuff. Typing in tmp will lead you to the abstract template class tmp<T> (T stands for the abstract type, like volScalarField, scalar, volVectorField, tensors etc.). However, the tmp class does not provide any internalField() function. That's why you get the error. To get rid of the error you either extract the volScalarField and apply the internalField() function, or you can use the ref() function. However, the ref() function returns a non-const reference to the internal field. It should be also possible to take the pointer to the object with ptr() and access via pointer to to your volScalarField. E.g.
Code:
//- I dont know what shearRate is in your case, but I address it be an object for now
const volScalarField* ptrToObject = shearRate.ptr()  

forAll(ptrToObject->internalField(), cellI)
{

}
Based on the fact that (already mentioned) I don't know what you are doing, and what shearRate() stands for, I cannot give you a more accurate answer. One hint, it also can be that you just need to use what I said before:
Code:
//- Again shearRate is the object
const volScalarField* ptrToObject = shearRate();
If you do not understand what I was writing. Checkout C++ books because I will not explain how c++ works.
Good luck.
shuji_type97 likes this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Reply

Tags
strainrate()


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
Getting access to mesh (fvMesh) via object registry Chris Lucas OpenFOAM Programming & Development 18 January 15, 2024 02:57
[DesignModeler] DesignModeler Scripting: How to get Full Command Access ANT ANSYS Meshing & Geometry 53 February 16, 2020 15:13
Is there a way to access the gradient limiter in Fluent ? CFDYourself FLUENT 1 February 16, 2016 05:49
How to access the members of a "volScalarField"? u396852 OpenFOAM Programming & Development 3 November 27, 2012 06:35
Online libraries - with access to Journals momentum_waves Main CFD Forum 2 December 12, 2007 10:08


All times are GMT -4. The time now is 13:07.