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 |
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 |
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 |
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? |
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. |
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); |
Sorry
delta.internalField(
Sorry
delta.internalField() =0.65*Foam::pow(mesh.V(),1.0/3.0); |
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. |
You don't need the Foam:: if
You don't need the Foam:: if you are operating within the Foam namespace.
|
... but sometimes when helps
... but sometimes when helps if the compiler gets confused, e.g. with min and max function templates from STL.
Hrv |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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. |