|
[Sponsors] |
January 31, 2017, 05:03 |
access members of strainRate()
|
#1 |
New Member
Shuang Li
Join Date: Nov 2015
Posts: 6
Rep Power: 11 |
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! |
|
February 2, 2017, 03:15 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
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] Code:
const volScalarField& tmp = shearRate();
__________________
Keep foaming, Tobias Holzmann |
|
February 2, 2017, 03:54 |
|
#3 |
New Member
Shuang Li
Join Date: Nov 2015
Posts: 6
Rep Power: 11 |
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 |
|
February 2, 2017, 04:27 |
|
#4 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
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) { } Code:
//- Again shearRate is the object const volScalarField* ptrToObject = shearRate(); Good luck.
__________________
Keep foaming, Tobias Holzmann |
|
Tags |
strainrate() |
|
|
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 03:57 |
[DesignModeler] DesignModeler Scripting: How to get Full Command Access | ANT | ANSYS Meshing & Geometry | 53 | February 16, 2020 16:13 |
Is there a way to access the gradient limiter in Fluent ? | CFDYourself | FLUENT | 1 | February 16, 2016 06:49 |
How to access the members of a "volScalarField"? | u396852 | OpenFOAM Programming & Development | 3 | November 27, 2012 07:35 |
Online libraries - with access to Journals | momentum_waves | Main CFD Forum | 2 | December 12, 2007 11:08 |