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

initializing a volScalarField in solvers' code

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By alimea

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 7, 2018, 06:47
Default initializing a volScalarField in solvers' code
  #1
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 291
Rep Power: 9
alimea is on a distinguished road
Hi all

I want to define a volScalarField in one of the viscous model codes. I saw this function that is set 0 for initial value of a dimensionedScalar:

Code:
virtual const dimensionedScalar etaP()
{
return (dimensionedScalar ("zeroU", dimensionSet(...), 0) )
}
but it does't work for a volScalarField :

Code:
virtual const volScalarField etaP()
{
return (volScalarField ("zeroU", dimensionSet(...), 0) )
}
this problem is in createFields file in solvers' code. When I want to define a volScalarField in createFields file, compiler doesn't allow me to set it in special value like 10 for all of the field like:

Code:
volScalarField AA = 0;
If I write

Code:
virtual const volScalarField etaP()
{
volScalarField A = dimensionedScalar ("zeroU", dimensionSet(...), 0);
return A;
}
compiler give me this error:
Quote:
error: conversion from 'Foam::dimensionedScalar {aka Foam::dimensioned<double>}' to non-scalar type 'Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}' requested
Could you plz help me to do that?

Thanks

Last edited by alimea; June 7, 2018 at 07:14. Reason: to complete it
alimea is offline   Reply With Quote

Old   June 7, 2018, 09:45
Default
  #2
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 298
Rep Power: 15
Cyp is on a distinguished road
See slides 94 to 102

Cheers,
Cyprien
Cyp is offline   Reply With Quote

Old   June 7, 2018, 10:12
Default
  #3
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 291
Rep Power: 9
alimea is on a distinguished road
Quote:
Originally Posted by Cyp View Post
See slides 94 to 102

Cheers,
Cyprien
Dear Cyprien

Thanks for your reply.

Those are very useful, but at the middle of a viscousity model code, I can't use non of them!
If I want to define as

Code:
volScalarField etaP
 (
                IOobject
                (
                    "etaP",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
	   ),
                mesh
);
the runTime and mesh objects are not defined!

If I want to use

Code:
volScalrField etaP ("etaP", 0.*p);
p or any other volScalarField isn't defined here!

So, How to do that?

Regards,
alimea is offline   Reply With Quote

Old   June 7, 2018, 10:26
Default
  #4
New Member
 
JPeternel
Join Date: Oct 2014
Posts: 19
Rep Power: 8
jpeter3 is on a distinguished road
You need to get mesh and time objects, they do not exist in every class under this names.

Maybe try to Access them through velocity field, something like:

U_.mesh() instead of mesh

and

U_.time() instead of runTime
jpeter3 is offline   Reply With Quote

Old   June 7, 2018, 10:40
Default
  #5
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 291
Rep Power: 9
alimea is on a distinguished road
Quote:
Originally Posted by jpeter3 View Post
You need to get mesh and time objects, they do not exist in every class under this names.

Maybe try to Access them through velocity field, something like:

U_.mesh() instead of mesh

and

U_.time() instead of runTime

Thanks for your reply.

could you plz explain it more?
I have written it as:

Code:
volScalarField etaP
 (
                IOobject
                (
                    "etaP",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
	   ),
                mesh
);
that runTime and mesh are not defined!
so as you mentioned I have changed them to:

Code:
volScalarField etaP
 (
                IOobject
                (
                    "etaP",
                    U_.time(),
                    U_.mesh(),
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
	   ),
                U_.mesh()
);
but it gives me this error:

Quote:

error: no matching function for call to 'Foam::IOobject::IOobject(const char [4], const Foam::Time&, const Mesh&, Foam::IOobject::readOption, Foam::IOobject::writeOption)'
),
^
Regards,
alimea is offline   Reply With Quote

Old   June 7, 2018, 10:46
Default
  #6
New Member
 
JPeternel
Join Date: Oct 2014
Posts: 19
Rep Power: 8
jpeter3 is on a distinguished road
Yes, that is exactly what I meant. Only one thing should be changed:

in original, you have written: runTime.timeName()

That is a call to function timeName() of the runTime.

So, when you replace runTime by U_.time(), you still need to call the function timeName():

...

IOobject
(
"etaP",
U_.time().timeName(),
U_.mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE
),

...
jpeter3 is offline   Reply With Quote

Old   June 7, 2018, 10:49
Default
  #7
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 291
Rep Power: 9
alimea is on a distinguished road
Quote:
Originally Posted by jpeter3 View Post
Yes, that is exactly what I meant. Only one thing should be changed:

in original, you have written: runTime.timeName()

That is a call to function timeName() of the runTime.

So, when you replace runTime by U_.time(), you still need to call the function timeName():

...

IOobject
(
"etaP",
U_.time().timeName(),
U_.mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE
),

...

Thenk you,
but it gives me again this error:

Quote:
error: no matching function for call to 'Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject, <unresolved overloaded function type>)'
);
what does it say?

Regards,
alimea is offline   Reply With Quote

Old   June 7, 2018, 11:07
Default
  #8
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 291
Rep Power: 9
alimea is on a distinguished road
Quote:
Originally Posted by jpeter3 View Post
Yes, that is exactly what I meant. Only one thing should be changed:

in original, you have written: runTime.timeName()

That is a call to function timeName() of the runTime.

So, when you replace runTime by U_.time(), you still need to call the function timeName():

...

IOobject
(
"etaP",
U_.time().timeName(),
U_.mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE
),

...
Dear JPeternel

That is solved!
I was wrong in last "mesh" component.

Thank you
jpeter3 likes this.
alimea is offline   Reply With Quote

Reply

Tags
initializing, volscalarfield

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Hypersonic and Supersonic Flow Solvers hyFoam OpenFOAM Announcements from Other Sources 26 March 14, 2021 22:52
Strange oscillations in my hydrodynamics code selig5576 Main CFD Forum 1 August 31, 2016 22:51
A question about the source code of realizableKE.C yuhai OpenFOAM Programming & Development 1 June 26, 2009 08:05
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 15:56
What is the Better Way to Do CFD? John C. Chien Main CFD Forum 54 April 23, 2001 08:10


All times are GMT -4. The time now is 17:24.