|
[Sponsors] |
December 17, 2019, 21:20 |
several volscalarfield named Y[i]
|
#1 |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Dear Friends
How can I define two(or several) volscalarfield named Y[i] with two members Y[1] and Y[2]? Many thanks Farzad |
|
December 18, 2019, 10:54 |
|
#2 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
Sounds similar to what is done for reacting solvers. So, something like this should be helpful :
Code:
PtrList<volScalarField> Y(2); // forAll (Y, i) { Y.set ( i, new volScalarField ( IOobject ( "Yi", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), i ) ); } |
|
December 18, 2019, 11:59 |
thanks
|
#3 |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Dear Caelan
Thanks for your response. I did what you have said and I got this error; ./createFields.H:132:9: error: no matching function for call to ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject, Foam::label&)’ ) ^ could you please check this error too? Thanks, Farzad |
|
December 18, 2019, 12:26 |
|
#4 | |
Senior Member
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21 |
Quote:
The correct way of constructing a volScalarField: PtrList<volScalarField> Y(2); // forAll (Y, i) { Y.set ( i, new volScalarField ( IOobject ( "Yi", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar("name", correct_dimension, initial_value) ) ); } |
||
December 18, 2019, 13:12 |
|
#5 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
Thanks to Daniel, who corrected my code snippet. I should have included that "i" was a placeholder that must be replaced with correct info to instantiate a volScalarField.
Caelan |
|
December 18, 2019, 13:44 |
|
#6 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Dear Daniel
thanks, it worked. I have two other questions which is related to previous question; 1- If I want to put general initial condition instead of a number for whole domain what should I do? 2- I want to use Y[1] and Y[2] in below equation, but it give me error; forAll(Y, i) { volScalarField& Yi = Y[i]; volScalarField& gammai = gamma[i]; fvScalarMatrix YEqn ( fvm::ddt(Yi) + fvm::div(alphaPhic,Yi) - fvm::laplacian(gammai, Yi) == kinematicCloud.SYi(i, Yi) ); YEqn.relax(); YEqn.solve(mesh.solver("Yi")); Yi.max(0.0); } } error; --> FOAM FATAL ERROR: Field name Yi not found in schemes From function bool Foam::cloudSolution::semiImplicit(const Foam::word&) const in file clouds/Templates/KinematicCloud/cloudSolution/cloudSolution.C at line 217. FOAM aborting Is it related to kinematicCloud.SYi(i, Yi)??? Thanks, Farzad Quote:
|
||
December 18, 2019, 18:26 |
|
#7 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
As for 1), you can likely edit the fields once you create them with something like :
Code:
forAll(Y[i], celli) { if (<insert condition here>) { Y[i][celli] = <insert value here> } } Caelan |
|
December 19, 2019, 13:12 |
|
#8 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Dear Caelan
Thanks for your reply. I want to do something like this(could you please check it if it is feasible?); First I want to read two fields named Yinit0 and Yinit1 from 0 folder using below code lines; Code:
label N = 2; PtrList<volScalarField> Yinit(N); forAll (Yinit, i) { word nameYiniti ("Yinit" + name(i)); ( new volScalarField ( IOobject ( nameYiniti, runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ) ); } Code:
PtrList<volScalarField> Y(N); // forAll (Y, i) { Y.set ( i, new volScalarField ( IOobject ( "Yi", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar("Y", dimless, 0.0) ) ); } What should I do? and what should I do to red lines in above code? Thanks Farzad Quote:
|
||
December 19, 2019, 13:29 |
|
#9 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
Can you not do something like this?
Code:
Y[0] = Y0init; Y[1] = Y1init; |
|
December 19, 2019, 13:39 |
|
#10 |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Dear Caelan
I will do that right away, but what should I do to these below lines? Code:
mesh, dimensionedScalar("name", correct_dimension, initial_value) Code:
Y[0] = Y0init; Y[1] = Y1init; |
|
December 19, 2019, 13:43 |
|
#11 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
As established previously you cannot omit it. However, all of the necessary info is explained in that line. You just need to fill in the blanks (correct dimensions, (dummy) initial value).
Caelan |
|
December 19, 2019, 13:49 |
|
#12 |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Dear Caelan
I did what you suggested me; Code:
label N = 2; PtrList<volScalarField> Yinit(N); forAll (Yinit, i) { word nameYiniti ("Yinit" + name(i)); ( new volScalarField ( IOobject ( nameYiniti, runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ) ); } Code:
PtrList<volScalarField> Y(N); // forAll (Y, i) { Y.set ( i, new volScalarField ( IOobject ( "Yi", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar("Y", dimless, 0.0) ) ); } Code:
In file included from /home/thomas/OpenFOAM/OpenFOAM-6/src/OpenFOAM/lnInclude/postProcess.H:135:0, from DPMFoamBFD.C:59: ./createFields.H: In function ‘int main(int, char**)’: ./createFields.H:140:8: error: ‘Yinit0’ was not declared in this scope Y[0] = Yinit0; ^ In file included from DPMFoamBFD.C:66:0: createFields.H:140:8: error: ‘Yinit0’ was not declared in this scope Y[0] = Yinit0; |
|
December 19, 2019, 13:55 |
|
#13 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
I wrote it following the code you wanted, but you declared the init vars as part of a Ptr list. So you need to access the individual fields as e.g. :
Code:
Y[0] = Yinit[0]; |
|
December 19, 2019, 14:11 |
|
#14 |
Senior Member
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21 |
Well I'm not getting what exactly you are trying to do here...
If Y[i] is supposed to be initialized immediately from Yinit[i] which is being read from the case 0 directory, then why not defining Y[i] using IOobject::MUST_READ at first place? I think you already know that this piece of code is defining Y[i] and initilize it with an initial dimension and value that can be altered any where in the code. Code:
PtrList<volScalarField> Y(N); forAll (Y, i) { Y.set ( i, new volScalarField ( IOobject ( "Y" + name(i), runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar("Y", dimless, 0.0) ) ); } Code:
PtrList<volScalarField> Y(N); // forAll (Y, i) { Y.set ( i, new volScalarField ( IOobject ( "Y" + name(i), runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), Yinit[i], Yinit[i].boundaryField().types() ) ); } In the above code, I assumed that Yinit[i] which is being read from the disk is providing correct boundary conditions. |
|
December 19, 2019, 14:30 |
|
#15 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Dear Daniel
What I am trying to do is this; I want to create two volScalarFields Y[0] and Y[1] which must be read from Y0 and Y1 respectively(from 0 folder). So what are you saying me is that both creating volScalarField and Reading can be done with a just 1 piece of code? Could you please give me this piece of code(meanwhile I am trying to do it myself). Farzad Quote:
|
||
December 19, 2019, 15:23 |
|
#16 | |
Senior Member
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21 |
Quote:
Code:
PtrList<volScalarField> Y(N); Code:
forAll (Y, i) { Y.set ( i, new volScalarField ( IOobject ( "Y" + name(i), runTime.timeName(), mesh, IOobject::AUTO_READ, IOobject::AUTO_WRITE ), mesh ) ); } |
||
December 19, 2019, 15:51 |
|
#17 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Dear Daniel
It worked and I pass that error. Thanks! Just for researchers who are looking to our conversation there is typo which the correct one is in below; Code:
forAll (Y, i) { Y.set ( i, new volScalarField ( IOobject ( "Y" + name(i), runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ) ); } Quote:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
y+ and u+ values with low-Re RANS turbulence models: utility + testcase | florian_krause | OpenFOAM | 114 | August 23, 2023 06:37 |
Near wall treatment in k-omega SST | Arnoldinho | OpenFOAM Running, Solving & CFD | 38 | March 8, 2017 14:48 |
[OpenFOAM] Native ParaView Reader Bugs | tj22 | ParaView | 270 | January 4, 2016 12:39 |
writing execFlowFunctionObjects | immortality | OpenFOAM Post-Processing | 30 | September 15, 2013 07:16 |
Problem with compile the setParabolicInlet | ivanyao | OpenFOAM Running, Solving & CFD | 6 | September 5, 2008 21:50 |