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

how to output the volVectorField correctly?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By akashpatel95

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 17, 2020, 10:26
Post how to output the volVectorField correctly?
  #1
New Member
 
王子阳
Join Date: Aug 2019
Posts: 29
Rep Power: 7
wangziyang is on a distinguished road
hi everyone!

i recently try to output a volVectorField CC_ in a turbulent moedel DCMM.C

but when i complie .c programm, it show show the following error:

HTML Code:
DCmM.C: In member function ‘virtual void Foam::incompressible::LESNonlinearModels::DCMM::correct(const Foam::tmp<Foam::GeometricField<Foam::Tensor<double>, Foam::fvPatchField, Foam::volMesh>
 >&)’:DCMM.C:291:6: error: expected primary-expression before ‘)’ token
      );
my output code is as follows:
HTML Code:
void DCMM::correct
(
    const tmp<volTensorField>& gradU
)
{
    LESNonlinearModel::correct(gradU);

    updateSubGridScaleFields(gradU());

 const volVectorField CC_=CC(gradU);  // CC is a function of gradU, also is a volVectorField
       CC_
	 (
        IOobject
        (
            "CC_",
            runTime_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh_,
		
     );      //  expected primary-expression?? why?? 

}
how can i solve the problem?

i need help

thanks
wangziyang is offline   Reply With Quote

Old   February 17, 2020, 17:16
Default
  #2
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13
HPE is on a distinguished road
You try to construct CC_ twice?
HPE is offline   Reply With Quote

Old   February 17, 2020, 20:50
Default
  #3
New Member
 
王子阳
Join Date: Aug 2019
Posts: 29
Rep Power: 7
wangziyang is on a distinguished road
hi HPE

thanks for your reply!

how can i "construct" twice? i am a newer in openfoam, i can't understand what's your saying

best wishes

ziyang
wangziyang is offline   Reply With Quote

Old   February 18, 2020, 03:21
Default
  #4
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13
HPE is on a distinguished road
An object with the same name and the same type cannot be constructed more than once in its scope in C++. Pay attention to the two opers you did for CC_.
HPE is offline   Reply With Quote

Old   February 19, 2020, 17:22
Default
  #5
New Member
 
Akash Patel
Join Date: Dec 2018
Location: Champaign, IL, USA
Posts: 20
Rep Power: 7
akashpatel95 is on a distinguished road
Quote:
Originally Posted by wangziyang View Post
hi everyone!

i recently try to output a volVectorField CC_ in a turbulent moedel DCMM.C

but when i complie .c programm, it show show the following error:

HTML Code:
DCmM.C: In member function ‘virtual void Foam::incompressible::LESNonlinearModels::DCMM::correct(const Foam::tmp<Foam::GeometricField<Foam::Tensor<double>, Foam::fvPatchField, Foam::volMesh> >&)’:DCMM.C:291:6: error: expected primary-expression before ‘)’ token      );
my output code is as follows:
HTML Code:
void DCMM::correct(    const tmp<volTensorField>& gradU){    LESNonlinearModel::correct(gradU);    updateSubGridScaleFields(gradU()); const volVectorField CC_=CC(gradU);  // CC is a function of gradU, also is a volVectorField       CC_     (        IOobject        (            "CC_",            runTime_.timeName(),            mesh_,            IOobject::NO_READ,            IOobject::AUTO_WRITE        ),        mesh_,             );      //  expected primary-expression?? why?? }
how can i solve the problem?

i need help

thanks



volVectorField
CC_
(
IOobject
(
"CC_",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh_,
dimensionedVector("0",dimLength/dimTime,Zero)
);


This will create empty volVectorField defined on mesh with all fields as zero and dimension as m/s. If you need dimension less fields simply swap "dimLength/dimTime" by "dimless"


Also it seems that you have already declared volVectorField CC_ in the line above which constructs an object named CC_. You cannot create another object with same name immediately below.
akashpatel95 is offline   Reply With Quote

Old   February 25, 2020, 03:23
Smile
  #6
New Member
 
王子阳
Join Date: Aug 2019
Posts: 29
Rep Power: 7
wangziyang is on a distinguished road
thanks for your reply! akashpatel95

i will try again

best wishes

ziyang
wangziyang is offline   Reply With Quote

Old   February 25, 2020, 11:08
Default
  #7
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
Quote:
Originally Posted by wangziyang View Post
HTML Code:
DCmM.C: In member function ‘virtual void  error: expected primary-expression before ‘)’}
Well, This error, I got it a lot. It happens most of the time when you called

Code:
myFunction(a,b, )
(There is a comma => so before the ')', we expect another primary expression, which is missing.)


What you should do is something like, as akashpatel95 said:

Quote:
Originally Posted by akashpatel95 View Post
Code:
volVectorField
       CC_
     (
        IOobject
        (
            "CC_",
            runTime_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
         mesh_,
         dimensionedVector("0",dimLength/dimTime,Zero)
        );
Then you fill it

Code:
//then, you fill it with the output of your function

CC_=CC(gradU);


//then you write it manually

CC_.write(); // this write directly the fields, so most of the time at each time step => to use only in the debugging steps
frobaux is offline   Reply With Quote

Old   February 27, 2020, 00:00
Post output the field every 0.001s
  #8
New Member
 
王子阳
Join Date: Aug 2019
Posts: 29
Rep Power: 7
wangziyang is on a distinguished road
thanks for your reply! frobaux

it works well according to your guidance!

but i want to output the CC_ fields based on ControlDict , for example, output CC_ every 0.001s

i try to insert the code " if (runTime.writeTime())" ,but produce the error

"error: ‘runTime’ was not declared in this scope
if (runTime.outputTime())"

i think i may be need insert the "creatTime.H" and "writeTime.H"

how can i output the field every 0.001s?

best wishes

ziyang
wangziyang is offline   Reply With Quote

Old   February 27, 2020, 00:33
Default
  #9
New Member
 
Akash Patel
Join Date: Dec 2018
Location: Champaign, IL, USA
Posts: 20
Rep Power: 7
akashpatel95 is on a distinguished road
Quote:
Originally Posted by wangziyang View Post
i try to insert the code " if (runTime.writeTime())" ,but produce the error
First you need to create runTime object using
Foam::Time runTime(Foam::Time::controlDictName, args);

Then, you can use it like this (This will make sure that your CC_ field is only written when you want according to controlDict, in this case, every 0.001 seconds).

if(runTime.write()) {
CC_.write();
}
__________________
We are developing an open-source software for constructing reduced order models for your CFD simulations in OpenFOAM that runs several magnitude faster. Visit the link below to learn more.
AccelerateCFD - OpenFOAM based reduced order model solver for CFD using Proper Orthogonal Decomposition.
akashpatel95 is offline   Reply With Quote

Old   February 27, 2020, 05:56
Default
  #10
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
Well, I'm not sure of that but

- if you used the IOobject::AUTO_WRITE options, it should work automatically according to the main parameters of your controlDict (writeControl and writeInterval)
- you can also add a subdictionnary in your controlDict file
Code:
functions
{

     myOutputObject
    {
        type writeObjects;
        functionObjectLibs ( "libutilityFunctionObjects.so" );
        objects
        (
                "CC_"
        );
        writeControl     adjustableRunTime;
        writeInterval    0.001;
    
    }
}
The third possibility is the solution given by akashpatel95.: You recreate a runTime.



But where is that part of code located/ called?
frobaux is offline   Reply With Quote

Old   February 27, 2020, 09:11
Post
  #11
New Member
 
王子阳
Join Date: Aug 2019
Posts: 29
Rep Power: 7
wangziyang is on a distinguished road
Quote:
Originally Posted by frobaux View Post
Well, I'm not sure of that but

- if you used the IOobject::AUTO_WRITE options, it should work automatically according to the main parameters of your controlDict (writeControl and writeInterval)
- you can also add a subdictionnary in your controlDict file
Code:
functions
{

     myOutputObject
    {
        type writeObjects;
        functionObjectLibs ( "libutilityFunctionObjects.so" );
        objects
        (
                "CC_"
        );
        writeControl     adjustableRunTime;
        writeInterval    0.001;
    
    }
}
The third possibility is the solution given by akashpatel95.: You recreate a runTime.



But where is that part of code located/ called?
Thanks very much for your reply!akashpatel95 and frobaux

my code is in a new SGS turbulent model.

The code i present to you is a part of DCNM .C programm (this new turbulent model)

the code is as follows:
Code:
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void DCNM::correct
(
    const tmp<volTensorField>& gradU
)
{
	{
 //int main(int argc, char *argv[])
 // #include "setRootCase.H"
 //  #include "createTime.H"
	
      volVectorField     CC_    
	 (
        IOobject
        (
            "CC_",
            runTime_.timeName(),
            mesh_,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
            mesh_,
            dimensionedVector ("CC_",dimless,vector(0,0,0))
     );
            CC_=CC(gradU); // CC is a function of gradU, it has been calculated in private member function section

	    Foam::Time runTime(Foam::Time::controlDictName, args);

	if(runTime.write())
           {
	      CC_.write();
           }  
             
   } 
	
   
    LESNonlinearModel::correct(gradU);

    updateSubGridScaleFields(gradU());

}
but the code will make a error according the suggestion of akashpatel95,

Code:
  error: ‘args’ was not declared in this scope
   Foam::Time runTime(Foam::Time::controlDictName, args);
i think my output code is in tubulence model source program, so it can't use the "AUTO_WRITE",

and i also think akashpatel95's advice is right, but how can i solve the error ?

do i need insert any code to my program?

best wishes!

ziyang
wangziyang is offline   Reply With Quote

Old   February 27, 2020, 09:43
Default
  #12
Member
 
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7
raumpolizei is on a distinguished road
Hey, if this inside a turbulence model, you should be able to access the Time object with the following line (no need to create a new Time object, it is already present so lets use it):
Code:
const Time& t = this->time();
Regarding the writing part, try to use something like this(check the extended source code guide for more information):
Code:
if(t.writeTime()) // or t.outputTime()
{
    CC_.write();
}
raumpolizei is offline   Reply With Quote

Old   February 27, 2020, 12:34
Default
  #13
New Member
 
Akash Patel
Join Date: Dec 2018
Location: Champaign, IL, USA
Posts: 20
Rep Power: 7
akashpatel95 is on a distinguished road
Quote:
Originally Posted by wangziyang View Post
my code is in a new SGS turbulent model.
If your code is inside a turbulence model, then you cannot create runTime object. The syntax I provided for runTime is for process happening inside main() function.

I think for source code, AUTO_WRITE should work just fine while declaring volVectorField
frobaux likes this.
__________________
We are developing an open-source software for constructing reduced order models for your CFD simulations in OpenFOAM that runs several magnitude faster. Visit the link below to learn more.
AccelerateCFD - OpenFOAM based reduced order model solver for CFD using Proper Orthogonal Decomposition.
akashpatel95 is offline   Reply With Quote

Old   February 27, 2020, 13:34
Default
  #14
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
Well, args is not defined in your scope.



Did you try to add what I suggest in your controlDict?


Not sure because I'm also quite a beginer in openFoam, but you have acess to time trough db or mesh_, so maybe try

Code:
if(db().time().write()) // or mesh_.time().write()
{
   ...
}
frobaux is offline   Reply With Quote

Old   March 10, 2020, 00:09
Default my view
  #15
New Member
 
王子阳
Join Date: Aug 2019
Posts: 29
Rep Power: 7
wangziyang is on a distinguished road
hi! frobaux and akashpate95

very thanks for your reply, and i also very sorry the late reply

according to your suggestions, i have solve my question, i want to share the solution here

first, it shoulid note that i work in of2.3, my purpose is to output the volVectorField CC_ in turbulence model program (eg Smagorinsky.C)


the first step, in priviate member faction, i insert the cord as followsin "updateSubGridScaleFields" part)

CC_=CC(gradU);
CC_.correctBoundaryConditions();

and i also define a volVectorField named CC in this part,and it will return the value to CC.

the second part, in Constructors part, insert the CC_ write code.(the code is memtioned before)

the last part,in Member faction part, insert the code " CC_=CC(gradU); "

meanwhile, in .H programe , CC and CC_ should declare.

ziyang

best wishes!
wangziyang is offline   Reply With Quote

Reply

Tags
ioobject


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
Projected area to output parameters Daniil85 Fluent UDF and Scheme Programming 1 March 16, 2016 16:44
CGNS Output file parameters ant0wn SU2 1 August 19, 2013 15:47
[ANSYS Meshing] ICEM output precision papis ANSYS Meshing & Geometry 4 July 9, 2013 10:54
[Other] Output Format of MetaMesh t42 OpenFOAM Meshing & Mesh Conversion 0 August 3, 2007 05:28
Output from the Monitor point command swapnil CFX 0 November 20, 2002 23:08


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