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

several volscalarfield named Y[i]

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 1 Post By clapointe
  • 1 Post By Daniel_Khazaei
  • 1 Post By clapointe
  • 1 Post By clapointe
  • 1 Post By clapointe
  • 1 Post By Daniel_Khazaei

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 17, 2019, 20:20
Default several volscalarfield named Y[i]
  #1
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
Dear Friends

How can I define two(or several) volscalarfield named Y[i] with two members
Y[1] and Y[2]?

Many thanks
Farzad
farzadmech is offline   Reply With Quote

Old   December 18, 2019, 09:54
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
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
        )
    );
}
Caelan
farzadmech likes this.
clapointe is offline   Reply With Quote

Old   December 18, 2019, 10:59
Default thanks
  #3
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
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
farzadmech is offline   Reply With Quote

Old   December 18, 2019, 11:26
Default
  #4
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
Quote:
Originally Posted by farzadmech View Post
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

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)
)
);
}
farzadmech likes this.
Daniel_Khazaei is offline   Reply With Quote

Old   December 18, 2019, 12:12
Default
  #5
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
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
farzadmech likes this.
clapointe is offline   Reply With Quote

Old   December 18, 2019, 12:44
Default
  #6
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
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:
Originally Posted by Daniel_Khazaei View Post
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)
)
);
}
farzadmech is offline   Reply With Quote

Old   December 18, 2019, 17:26
Default
  #7
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
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>
    }
}
For 2), I am not sure what you are trying to do but it does appear to have a problem with your use of the kinematicCloud source term.

Caelan
farzadmech likes this.
clapointe is offline   Reply With Quote

Old   December 19, 2019, 12:12
Default
  #8
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
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
            )
        );		
    }
Then as I learnt from this thread, I can create two fields named Y[1] and Y[2] as below;

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)       
         )
    );
}
Now I want to put Y[0]=Yinit0 and Y[1]=Yinit1.
What should I do? and what should I do to red lines in above code?


Thanks
Farzad






Quote:
Originally Posted by clapointe View Post
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>
    }
}
For 2), I am not sure what you are trying to do but it does appear to have a problem with your use of the kinematicCloud source term.

Caelan
farzadmech is offline   Reply With Quote

Old   December 19, 2019, 12:29
Default
  #9
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Can you not do something like this?

Code:
Y[0] = Y0init;
Y[1] = Y1init;
Caelan
clapointe is offline   Reply With Quote

Old   December 19, 2019, 12:39
Default
  #10
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
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)
Here we have given name, dimension and value. Should I omit it(How? it gives me error), or should I keep it and just put

Code:
Y[0] = Y0init;
Y[1] = Y1init;
Farzad



Quote:
Originally Posted by clapointe View Post
Can you not do something like this?

Code:
Y[0] = Y0init;
Y[1] = Y1init;
Caelan
farzadmech is offline   Reply With Quote

Old   December 19, 2019, 12:43
Default
  #11
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
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
clapointe is offline   Reply With Quote

Old   December 19, 2019, 12:49
Default
  #12
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
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
            )
        );		
    }
cccccccccccccccccccccccccccccccccccccccccccccccccc cccccccccccccc
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)       
        )
    );
}
cccccccccccccccccccccccccccccccccccccccccccccccccc cccccccccccccc
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;

Quote:
Originally Posted by clapointe View Post
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
farzadmech is offline   Reply With Quote

Old   December 19, 2019, 12:55
Default
  #13
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
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];
Caelan
farzadmech likes this.
clapointe is offline   Reply With Quote

Old   December 19, 2019, 13:11
Default
  #14
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
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)       
        )
    );
}
If for some unknown reason you need to define Y[i] as NO_READ and then initialize it with Yinit[i], you can always do:

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()
        )
    );
}
Be-careful, as if you need to solve for Y[i] anywhere in the code then you have to apply physical boundary conditions.
In the above code, I assumed that Yinit[i] which is being read from the disk is providing correct boundary conditions.
farzadmech likes this.
Daniel_Khazaei is offline   Reply With Quote

Old   December 19, 2019, 13:30
Default
  #15
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
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:
Originally Posted by Daniel_Khazaei View Post
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)       
        )
    );
}
If for some unknown reason you need to define Y[i] as NO_READ and then initialize it with Yinit[i], you can always do:

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()
        )
    );
}
Be-careful, as if you need to solve for Y[i] anywhere in the code then you have to apply physical boundary conditions.
In the above code, I assumed that Yinit[i] which is being read from the disk is providing correct boundary conditions.
farzadmech is offline   Reply With Quote

Old   December 19, 2019, 14:23
Default
  #16
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
Quote:
Originally Posted by farzadmech View Post
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
This will create a list of pointers that hold memory address of your volScalarField objects:

Code:
PtrList<volScalarField> Y(N);
Now you can initialize this list using:
Code:
forAll (Y, i)
{
    Y.set
    (
        i,
        new volScalarField
        (
            IOobject
            (
                "Y" + name(i),
                runTime.timeName(),
                mesh,
                IOobject::AUTO_READ,
                IOobject::AUTO_WRITE
            ),
            mesh
        )
    );
}
This will create N number of volScalarFields that reads Y0...YN from case/0 directory.
Daniel_Khazaei is offline   Reply With Quote

Old   December 19, 2019, 14:51
Default
  #17
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
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:
Originally Posted by Daniel_Khazaei View Post
This will create a list of pointers that hold memory address of your volScalarField objects:

Code:
PtrList<volScalarField> Y(N);
Now you can initialize this list using:
Code:
forAll (Y, i)
{
    Y.set
    (
        i,
        new volScalarField
        (
            IOobject
            (
                "Y" + name(i),
                runTime.timeName(),
                mesh,
                IOobject::AUTO_READ,
                IOobject::AUTO_WRITE
            ),
            mesh
        )
    );
}
This will create N number of volScalarFields that reads Y0...YN from case/0 directory.
farzadmech 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
y+ and u+ values with low-Re RANS turbulence models: utility + testcase florian_krause OpenFOAM 114 August 23, 2023 05:37
Near wall treatment in k-omega SST Arnoldinho OpenFOAM Running, Solving & CFD 38 March 8, 2017 13:48
[OpenFOAM] Native ParaView Reader Bugs tj22 ParaView 270 January 4, 2016 11:39
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 06:16
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 20:50


All times are GMT -4. The time now is 05:57.