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

How does one convert a scalarField into a volScalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 17, 2005, 19:23
Default I'm trying to make a volScala
  #1
Marco Kupiainen (Kupiainen)
Guest
 
Posts: n/a
I'm trying to make a volScalarField out of a scalarField. What is the correct syntax?

best regards
Marco
  Reply With Quote

Old   February 17, 2005, 19:29
Default Bad idea: volScalarField cont
  #2
Hrvoje Jasak (Hjasak)
Guest
 
Posts: n/a
Bad idea: volScalarField contains boundary conditions in terms of patch fields and the scalar field does not. For valid constructors for a geometric field, have a look at:

OpenFOAM-1.0/src/OpenFOAM/lnInclude/GeometricField.H

Enjoy,

Hrv
arvindpj likes this.
  Reply With Quote

Old   February 18, 2005, 05:58
Default There is an example of creati
  #3
Mattijs Janssens (Mattijs)
Guest
 
Posts: n/a
There is an example of creating a temporary volScalarField in

parallelProcessing/decomposePar/decomposePar.C

where a volScalarField cellDist gets constructed for postprocessing of the domains.

Mattijs
  Reply With Quote

Old   February 18, 2005, 08:38
Default This is exactly what I'm tryi
  #4
Marco Kupiainen (Kupiainen)
Guest
 
Posts: n/a
This is exactly what I'm trying to do...
volScalarField delta
(
IOobject
(
"delta",
runTime.timeName(),
runTime,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("cellDist", dimless, 0),
zeroGradientFvPatchScalarField::typeName
);

forAll(mesh,celli)
{
delta[celli] = 0.65*pow(mesh[celli].V(), 1.0/3.0);
}

but I get the syntax wrong in
delta[celli] = 0.65*pow(mesh[celli].V(), 1.0/3.0);
what should it say?
  Reply With Quote

Old   February 18, 2005, 08:41
Default Try delta.internalField()
  #5
Eugene de Villiers (Eugene)
Guest
 
Posts: n/a
Try

delta.internalField()=0.65*::pow(mesh.V(),1.0/3.0);

The functionality to use only the cuberoot of the cell volume for the LES length scale is already built into the code via the LESdeltas class.
  Reply With Quote

Old   February 18, 2005, 08:45
Default error: no suitable conversion
  #6
Marco Kupiainen (Kupiainen)
Guest
 
Posts: n/a
error: no suitable conversion function from "const Foam::scalarField" to "double" exists
delta.internalField() = 0.65*::pow(mesh.V(), 1.0/3.0);
  Reply With Quote

Old   February 18, 2005, 08:52
Default Sorry delta.internalField(
  #7
Eugene de Villiers (Eugene)
Guest
 
Posts: n/a
Sorry

delta.internalField()
=0.65*Foam::pow(mesh.V(),1.0/3.0);
  Reply With Quote

Old   February 18, 2005, 08:53
Default remove the :: delta.intern
  #8
Henry Weller (Henry)
Guest
 
Posts: n/a
remove the ::

delta.internalField() = 0.65*pow(mesh.V(), 1.0/3.0);

otherwise you are trying to call the lower-level c pow function which operates on doubles and floats.
  Reply With Quote

Old   February 18, 2005, 08:55
Default You don't need the Foam:: if
  #9
Henry Weller (Henry)
Guest
 
Posts: n/a
You don't need the Foam:: if you are operating within the Foam namespace.
  Reply With Quote

Old   February 18, 2005, 09:36
Default ... but sometimes when helps
  #10
Hrvoje Jasak (Hjasak)
Guest
 
Posts: n/a
... but sometimes when helps if the compiler gets confused, e.g. with min and max function templates from STL.

Hrv
  Reply With Quote

Old   May 19, 2008, 03:20
Default This is partially what I tried
  #11
Member
 
Heng Xiao
Join Date: Mar 2009
Location: Zurich, Switzerland
Posts: 58
Rep Power: 17
xiao is on a distinguished road
This is partially what I tried to to. Is it possible to set up a "scalarField" to automatically write itself into files (as the filed p and U do)? Anybody could give some help?

Indeed, when you don't have any boundary conditions and boundary fields, it is not necessary to have a volScalarField.

Best,
Heng
xiao is offline   Reply With Quote

Old   May 19, 2008, 21:23
Default Hi Heng It doesn't seem tha
  #12
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 20
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
Hi Heng

It doesn't seem that ScalarField can write itself into a file.

To make a object auto writing, one have to register it using regIOobject.

try dimensionedField or use the internalField() of volScalarField

volScalarField temp
(
IOobject
(
"temp",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh
dimensionedScalar("zero", dimensionSet(0,0,0,0,0,0,0), 0.0),
zeroGradientFvPatchField<scalar>::typeName
)

scalarField &sf=temp.internalField();
sf=....

Su Junwei
su_junwei is offline   Reply With Quote

Old   May 19, 2008, 22:10
Default Hi Junwei, Thanks for your
  #13
Member
 
Heng Xiao
Join Date: Mar 2009
Location: Zurich, Switzerland
Posts: 58
Rep Power: 17
xiao is on a distinguished road
Hi Junwei,

Thanks for your reply. I tried this approach, and it worked.

In the .H file, I have:

volScalarField gamma_; // Solid volume fraction of the cell

In the initialization list of the constructor:
gamma_
(
IOobject
(
"gamma",
runTime_.timeName(),
U_.db(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
).

In the code, I directly change gamma_.internalField(), or as you said, I can do:
scalarField & sf=gamma_.internalField();
and then change "sf" directly.

This worked nicely. It writes to the file gamma, which can be read by paraFoam. The field can thus be visualized.

A previous version was:

scalarIOField gamma_;

and

gamma_
(
IOobject
(
"gamma",
runTime_.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
scalarField((mesh_.nCells(), 1.0),
)

which was suggested by Prof. Jasak. This also works, and writes to file correctly. However, paraFoam does not read it correctly. (It seems the paraView only read volScalarField, or pointScalarField, or like that. It does not read the "primititve fileds" like "scalarField", or its IO version, "scalarIOField.

An even earlier try was:

In the .H file:

scalarField gamma_; // Solid volume fraction of the cell
scalarIOField gammaIO_; // Volume fraction field with IO

In the constructor initialization list:
gamma_(mesh_.nCells(), 1.0),
gammaIO_
(
IOobject
(
"gamma",
runTime_.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
gamma_
)

it compiled and writed into files, but the values written to the file are always the initial value (1.0), although gamma_ has been updated in the code.

I still don't quite understand why, since gamma_ is supposed to be a "reference" to the field in "gamma_IO".

Have you any idea why this did not work?

Anyway, I hope the three tries above would be helpful for someone who find the same problem in the future.

Heng
xiao is offline   Reply With Quote

Old   May 19, 2008, 23:04
Default Dear Heng When constructing
  #14
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 20
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
Dear Heng

When constructing the gammaIO_, you used the values of gamma_ to initiate gammaIO_, not its "reference". So the values in gammaIO_ are only copies of those in gamma_;

So although gamma_ has been updated in the code, the copy of it didn't change.

if you want to write the temporal values for gamma_ update gammaIO_ using
gammaIO_=gamma_;
or
using gammIO_ directly, deleting all gamma_ s.

Su Junwei
su_junwei is offline   Reply With Quote

Old   May 20, 2008, 00:51
Default Hi Junwei, Thanks for your
  #15
Member
 
Heng Xiao
Join Date: Mar 2009
Location: Zurich, Switzerland
Posts: 58
Rep Power: 17
xiao is on a distinguished road
Hi Junwei,

Thanks for your reply. It indeed answered my question! I was thinking along the same track, and I tried to initialize gammaIO with a "reference" to gamma, then gammaIO has a reference to gamma, and there would be no need to update both gammaIO AND gamma. Just updating gamma is enough ...

but I did not (and still do not) know how to achieve this, particularly because gammaIO needs to be initialized in the initialization list of a constructor since it is a class member of another class. (Have you any hints?)
I thought about:
gammaIO_
(
IOobject
(
"gamma",
runTime_.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
tmp<scalarfield> & gammaTmp
)

but did not succeed. I guess one needs to use "new" to allocate space for gammaTmp?

As you said, another way to avoid "double" updating (i.e. change both gammaIO and gamma) is to use only gammaIO, and delete all gamma.

Anyway, thanks very much for your discussion! It has been very helpful.
The IO related stuff is very hard for me as I just learned OpenFOAM a month ago, and there is very little discussion in the user guide or programmer's guide. Well, after this struggle, I certainly learned some basics though...

How did you learned this aspect of foam when you first came to it?

Heng
xiao is offline   Reply With Quote

Old   May 20, 2008, 02:57
Default Hi Heng Just try gammaI
  #16
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 20
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
Hi Heng

Just try

gammaIO_
(
IOobject
(
"gamma",
runTime_.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
scalarField(mesh.nCells(),1.0)
);

Su Junwei
vcvedant likes this.
su_junwei is offline   Reply With Quote

Old   June 2, 2008, 12:01
Default hi Su, i also need to just wr
  #17
Member
 
davey david
Join Date: Mar 2009
Posts: 54
Rep Power: 17
suredross is on a distinguished road
hi Su,
i also need to just write a solver for the laplace equation and only solve for the electrical field(p,u,not needed).how do i go about it?also which 'code' are you referring to in your posts.i seem to get lost..any help?

cheers
davey
suredross is offline   Reply With Quote

Old   June 2, 2008, 22:01
Default Hi Davey If you just want
  #18
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 20
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
Hi Davey

If you just want to solve laplace equation only, please refer to the solver of "laplacianFoam" in the dir "~/OpenFOAM 1.4/OpenFOAM-1.4.1/applications/solver/basic/laplacianFoam"

In the post above, I referred the code of the class "GeometricField".

When I can't find the solution to a problem, I usually search the relative topics in this forum, or refer to the OpenFOAM programmer's C++ documentation on the local PC, or on the site
http://foam.sourceforge.net/doc/Doxy...l/classes.html

Su Junwei
su_junwei is offline   Reply With Quote

Old   June 3, 2008, 05:55
Default Hi Su, i just had a look at t
  #19
Member
 
davey david
Join Date: Mar 2009
Posts: 54
Rep Power: 17
suredross is on a distinguished road
Hi Su,
i just had a look at the laplacian solver.in my case ,there is a uniform electric field,so the eqn reads:

( fvm::laplacian (psi) == Null).

now comparing and contrasting with the eqn in the laplace foam,i am confused as to how to reconcile the two equations?any help?

davey
suredross is offline   Reply With Quote

Old   June 3, 2008, 06:19
Default Hi davey The laplacianFo
  #20
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 20
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
Hi davey


The laplacianFoam solver has the temporal terms but in your solver doesn't

Actually, steady flow can be solved using unsteady flow solver with long simulation time.

what is your boundary condition of your case?
the uniform electic field may concern with you boundary condition adopted in your case

Su Junwei
su_junwei 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
How to sum up scalarField wese OpenFOAM Running, Solving & CFD 2 August 19, 2019 18:30
How to set up an AUTO_WRITE scalarField xiao OpenFOAM Running, Solving & CFD 9 July 22, 2010 04:23
max for scalarField maka OpenFOAM Bugs 9 February 19, 2009 10:43
ScalarField division maka OpenFOAM Pre-Processing 2 August 27, 2007 06:10
[CGNS] Computing a cellcentered scalarField from a vertexcentered scalarField mbeaudoin OpenFOAM Meshing & Mesh Conversion 10 February 22, 2007 08:43


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