CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   How does one convert a scalarField into a volScalarField (https://www.cfd-online.com/Forums/openfoam-solving/58838-how-does-one-convert-scalarfield-into-volscalarfield.html)

Marco Kupiainen (Kupiainen) February 17, 2005 18:23

I'm trying to make a volScala
 
I'm trying to make a volScalarField out of a scalarField. What is the correct syntax?

best regards
Marco

Hrvoje Jasak (Hjasak) February 17, 2005 18:29

Bad idea: volScalarField cont
 
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

Mattijs Janssens (Mattijs) February 18, 2005 04:58

There is an example of creati
 
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

Marco Kupiainen (Kupiainen) February 18, 2005 07:38

This is exactly what I'm tryi
 
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?

Eugene de Villiers (Eugene) February 18, 2005 07:41

Try delta.internalField()
 
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.

Marco Kupiainen (Kupiainen) February 18, 2005 07:45

error: no suitable conversion
 
error: no suitable conversion function from "const Foam::scalarField" to "double" exists
delta.internalField() = 0.65*::pow(mesh.V(), 1.0/3.0);

Eugene de Villiers (Eugene) February 18, 2005 07:52

Sorry delta.internalField(
 
Sorry

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

Henry Weller (Henry) February 18, 2005 07:53

remove the :: delta.intern
 
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.

Henry Weller (Henry) February 18, 2005 07:55

You don't need the Foam:: if
 
You don't need the Foam:: if you are operating within the Foam namespace.

Hrvoje Jasak (Hjasak) February 18, 2005 08:36

... but sometimes when helps
 
... but sometimes when helps if the compiler gets confused, e.g. with min and max function templates from STL.

Hrv

xiao May 19, 2008 02:20

This is partially what I tried
 
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

su_junwei May 19, 2008 20:23

Hi Heng It doesn't seem tha
 
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

xiao May 19, 2008 21:10

Hi Junwei, Thanks for your
 
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

su_junwei May 19, 2008 22:04

Dear Heng When constructing
 
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

xiao May 19, 2008 23:51

Hi Junwei, Thanks for your
 
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

su_junwei May 20, 2008 01:57

Hi Heng Just try gammaI
 
Hi Heng

Just try

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

Su Junwei

suredross June 2, 2008 11:01

hi Su, i also need to just wr
 
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

su_junwei June 2, 2008 21:01

Hi Davey If you just want
 
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

suredross June 3, 2008 04:55

Hi Su, i just had a look at t
 
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

su_junwei June 3, 2008 05:19

Hi davey The laplacianFo
 
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


All times are GMT -4. The time now is 21:37.