|
[Sponsors] |
How does one convert a scalarField into a volScalarField |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 17, 2005, 19:23 |
I'm trying to make a volScala
|
#1 |
Guest
Posts: n/a
|
I'm trying to make a volScalarField out of a scalarField. What is the correct syntax?
best regards Marco |
|
February 17, 2005, 19:29 |
Bad idea: volScalarField cont
|
#2 |
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 |
|
February 18, 2005, 05:58 |
There is an example of creati
|
#3 |
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 |
|
February 18, 2005, 08:38 |
This is exactly what I'm tryi
|
#4 |
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? |
|
February 18, 2005, 08:41 |
Try
delta.internalField()
|
#5 |
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. |
|
February 18, 2005, 08:45 |
error: no suitable conversion
|
#6 |
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); |
|
February 18, 2005, 08:52 |
Sorry
delta.internalField(
|
#7 |
Guest
Posts: n/a
|
Sorry
delta.internalField() =0.65*Foam::pow(mesh.V(),1.0/3.0); |
|
February 18, 2005, 08:53 |
remove the ::
delta.intern
|
#8 |
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. |
|
February 18, 2005, 08:55 |
You don't need the Foam:: if
|
#9 |
Guest
Posts: n/a
|
You don't need the Foam:: if you are operating within the Foam namespace.
|
|
February 18, 2005, 09:36 |
... but sometimes when helps
|
#10 |
Guest
Posts: n/a
|
... but sometimes when helps if the compiler gets confused, e.g. with min and max function templates from STL.
Hrv |
|
May 19, 2008, 03:20 |
This is partially what I tried
|
#11 |
Member
Heng Xiao
Join Date: Mar 2009
Location: Zurich, Switzerland
Posts: 58
Rep Power: 17 |
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 |
|
May 19, 2008, 21:23 |
Hi Heng
It doesn't seem tha
|
#12 |
Senior Member
|
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 |
|
May 19, 2008, 22:10 |
Hi Junwei,
Thanks for your
|
#13 |
Member
Heng Xiao
Join Date: Mar 2009
Location: Zurich, Switzerland
Posts: 58
Rep Power: 17 |
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 |
|
May 19, 2008, 23:04 |
Dear Heng
When constructing
|
#14 |
Senior Member
|
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 |
|
May 20, 2008, 00:51 |
Hi Junwei,
Thanks for your
|
#15 |
Member
Heng Xiao
Join Date: Mar 2009
Location: Zurich, Switzerland
Posts: 58
Rep Power: 17 |
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 |
|
May 20, 2008, 02:57 |
Hi Heng
Just try
gammaI
|
#16 |
Senior Member
|
Hi Heng
Just try gammaIO_ ( IOobject ( "gamma", runTime_.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), scalarField(mesh.nCells(),1.0) ); Su Junwei |
|
June 2, 2008, 12:01 |
hi Su,
i also need to just wr
|
#17 |
Member
davey david
Join Date: Mar 2009
Posts: 54
Rep Power: 17 |
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 |
|
June 2, 2008, 22:01 |
Hi Davey
If you just want
|
#18 |
Senior Member
|
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 |
|
June 3, 2008, 05:55 |
Hi Su,
i just had a look at t
|
#19 |
Member
davey david
Join Date: Mar 2009
Posts: 54
Rep Power: 17 |
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 |
|
June 3, 2008, 06:19 |
Hi davey
The laplacianFo
|
#20 |
Senior Member
|
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 |
|
|
|
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 |