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

Problems creating volscalarfield

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 5 Post By alexeym

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 15, 2014, 07:59
Default Problems creating volscalarfield
  #1
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 12
sur4j is on a distinguished road
I am trying to modify the solidDisplacementFoam solver so that it has an additional temperature dependant variable within it in the form of a scalar field, this variable has been programmed as shown in the main .C file:

Code:
forAll(T.internalField(), cellI)
{    
    float SCholder[400];

    SC[cellI] = SCholder[cellI] + 2/((2^((T.internalField()[cellI]))));
    SCholder[cellI] = SC[cellI];
}
and the scalar field is shown in the header file as:

Code:
volScalarField SC
(
    IOobject
    (
         "SC",
         runTime.timeName(),
         mesh,
         IOobject::NO_READ,
         IOobject::AUTO_WRITE
     ),
     mesh
);
Problems I am facing:
  • When I define exp and base as double or float I get an error, how do I prevent this?
  • The array SCholder's size is defined as the number of cells, when I leave this blank I get an error saying undefined array size therefore, I have had to specify it as 400 for a specific simulation, can this be defined with a variable so that I do not have to change it every time I change the No of cells in a mesh?
  • The solver compiles fine with the code shown above however, when I run it on my test case I get the following error:
Code:
--> FOAM FATAL ERROR: 
NO_READ specified for read-constructor of object SC of class IOobject

    From function regIOobject::readStream()
    in file db/regIOobject/regIOobjectRead.C at line 46.

FOAM aborting
I specified as NO_READ so that I would not have to create the initial conditions in the 0 folder because when I done this previously, the solver didn't work as expected and update SC accordingly, instead it just kept the initial conditions set for it in 0 in all time folders

Last edited by sur4j; March 16, 2014 at 10:32.
sur4j is offline   Reply With Quote

Old   March 15, 2014, 09:16
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

1. If you'd like to construct volScalarField with NO_READ, you have to use different constructor, for example:

Code:
    volScalarField p
    (
        IOobject
        (
            "p",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        p_rgh + rho*gh
    );
here volScalarField is created using another fields, or

Code:
volScalarField K
(
    IOobject
    (
        "K",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimless/dimTime
);
here just dimensions are specified.

2. You create SCholder array inside the loop, so it won't be available after you exit the loop. Do you plan to use it outside forAll macro? And if you need dynamically allocated array, you can use Field type. Something like:

Code:
Field SCholder(SC.size())
alexeym is offline   Reply With Quote

Old   March 15, 2014, 09:51
Default
  #3
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 12
sur4j is on a distinguished road
Thank you for your reply however, I am now confused on how I need to implement this in the solver. The code is in the time loop so every time step it will run through all nodes and will calculate:
base = (((T.internalField()[cellI])))
and then calculate SC by looking at the previous SC and adding 2/base onto this. It will then update SCholder so that on the next time loop the code can see the previous SC, SCholder is not used anywhere else in the code.

Could you please guide me on how I should add this to the solver?

Last edited by sur4j; March 16, 2014 at 10:33.
sur4j is offline   Reply With Quote

Old   March 15, 2014, 12:18
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
From your post I did not get why you need two fields: SC and SCholder. If SC is just recalculated on every time step by addition certain values to it, why not just do this:

Code:
forAll(T, cellI)
{
    SC[cellI] += 2/(250*(2^((100 - T[cellI])/10)));
}
though if you really need to keep values of SC (maybe it is modified somewhere else), create SC0 as you create SC and then:

Code:
forAll(T, cellI)
{
    SC[cellI] = SC0[cellI] + 2/(250*(2^((100 - T[cellI])/10)));
}
SC0 = SC
As a description of the problem is rather vague, I'm not quite sure that my reply is relevant to what you're looking for.
alexeym is offline   Reply With Quote

Old   March 15, 2014, 12:36
Default
  #5
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 12
sur4j is on a distinguished road
Thank you very much, that simplifies things for me. The part I am stuck with is the creation of the volScalarField for this case so that I can view the SC results from my simulation, I do not understand how to set up the constructor. I currently have:

Code:
volScalarField SC
(
    IOobject
    (
         "SC",
         runTime.timeName(),
         mesh,
         IOobject::NO_READ,
         IOobject::AUTO_WRITE
     ),
     mesh//but I dont know what to put down here
);
SC is a percentage therefore it has no units and should start at 0.
sur4j is offline   Reply With Quote

Old   March 15, 2014, 17:39
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Then you can create the field with

Code:
volScalarField SC
(
    IOobject
    (
        "SC",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimless // as SC units are percents
);
this is an invocation of the following constructor - http://foam.sourceforge.net/docs/cpp...0d8f8a5fec0dc8, and it is friendly with NO_READ option.
alexeym is offline   Reply With Quote

Old   March 16, 2014, 06:20
Default
  #7
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 12
sur4j is on a distinguished road
Thank you very much for your help.

When I try:
Code:
forAll(T, cellI) {     
SC[cellI] += 2/((((T[cellI])/10))); 
}
I get the following error when using the wmake command on the solver:
Code:
Making dependency list for source file cureFoam.C
SOURCE=cureFoam.C ;  g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam222/src/finiteVolume/lnInclude -ItractionDisplacement/lnInclude -IlnInclude -I. -I/opt/openfoam222/src/OpenFOAM/lnInclude -I/opt/openfoam222/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linuxGccDPOpt/cureFoam.o
cureFoam.C: In function ‘int main(int, char**)’:
cureFoam.C:81:50: error: invalid operands of types ‘int’ and ‘double’ to binary ‘operator^’
readSolidDisplacementFoamControls.H:3:11: warning: unused variable ‘nCorr’ [-Wunused-variable]
readSolidDisplacementFoamControls.H:5:8: warning: unused variable ‘convergenceTolerance’ [-Wunused-variable]
make: *** [Make/linuxGccDPOpt/cureFoam.o] Error 1
When I change the solver code to:
Code:
int exp;
int base;
    exp = ((100 - T.internalField()[cellI])/10);
    base = 250*(2^exp);
    SC.internalField()[cellI] += 2/base;
It compiles fine but when I run this on a test case I only get the first cell value and every other cell value stays 0, this value in the first cell is also constant in all time step folders.

How do I get this to work with doubles rather than integers and also why is it only calculating the first cell and why is it constant in all time step folders?

Last edited by sur4j; March 16, 2014 at 10:33.
sur4j is offline   Reply With Quote

Old   March 16, 2014, 06:39
Default
  #8
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym


^ operator in C/C++ is something different (http://en.wikipedia.org/wiki/Operato...wise_operators)

If you need exponentiation, you have to use pow (http://www.cplusplus.com/reference/cmath/pow/) function.

I did not pay attention to this as I thought expression you'd like to add to SC is valid.
alexeym is offline   Reply With Quote

Old   March 16, 2014, 07:49
Default
  #9
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 12
sur4j is on a distinguished road
Thanks

It compiles fine now with but I am still having the same problem with only a single value appearing and only for the first cell in all time step files:
Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "67";
    object      SC;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 0 0 0 0];

internalField   nonuniform List<scalar> 
400
(
6.17207e-264
0
0
0
0
0
0
0
.....
It works as expected and populates all cells in the time step folders if I use the following code for example:
Code:
forAll(T.internalField(), cellI)
{ 
SC.internalField()[cellI] += T.internalField()[cellI];
}
So it is definitely a problem with the code in the forAll loop in the main .C file, I cant figure out why this is happening and any help from you with this would be greatly appreciated. Thanks.
sur4j is offline   Reply With Quote

Old   March 16, 2014, 07:53
Default
  #10
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
OK. What is the meaning of that 100?
alexeym is offline   Reply With Quote

Old   March 16, 2014, 08:18
Default
  #11
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 12
sur4j is on a distinguished road
It is the temperature at which the reaction starts, I had tested this in excel a while back and it worked fine, just having problems adding it into openfoam.
sur4j is offline   Reply With Quote

Old   March 16, 2014, 08:22
Default
  #12
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Units?

You can plot 2/250*(pow(2,((100 - T)/10))) in paraFoam using Calculator filter and see what you're adding to SC.
alexeym is offline   Reply With Quote

Old   March 16, 2014, 08:23
Default
  #13
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 12
sur4j is on a distinguished road
Ahh sorry about this, messed up on the brackets

Closed the denominator in brackets and works fine now. Thank you very much for your help!
sur4j is offline   Reply With Quote

Old   April 2, 2014, 21:59
Default
  #14
Senior Member
 
Dongyue Li
Join Date: Jun 2012
Location: Beijing, China
Posts: 838
Rep Power: 17
sharonyue is on a distinguished road
Hi guys,

Im facing the same "NO READ" problem.

In twoPhaseEulerFoam, just like k-Epsilon model in this solver. I make the drag model very simple so I dump the template and make the GidaspowSchillerNaumann model into the main code. But its alike with the original one.

Post all the code is tough, but something wrong is here:

Code:
volScalarField K
    (
        IOobject
        (
            "K",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        0.75*Cds*phase2->rho()*bp/d1
        //0.75*Cds*phase2->rho()*Ur*bp/d1
    );
This can be compiled with no error. But when I run the case:
Code:
--> FOAM FATAL ERROR: 
NO_READ specified for read-constructor of object n of class IOobject
Any ideas?
sharonyue is offline   Reply With Quote

Old   April 8, 2015, 09:07
Default
  #15
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

You error is NOT "the same" maybe it is similar. What is the type of

Code:
0.75*Cds*phase2->rho()*bp/d1
?
alexeym is offline   Reply With Quote

Reply

Tags
temperature, variable, volscalarfield


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
[Commercial meshers] Fluent3DMeshToFoam simvun OpenFOAM Meshing & Mesh Conversion 50 January 19, 2020 15:33
Problems running laminarSmoke r08n OpenFOAM Running, Solving & CFD 1 September 27, 2013 19:27
Problems with Meshing: Collapsed Cells Emmanuel Resch Siemens 1 July 30, 2007 03:02
Gerris software installation mer Main CFD Forum 2 November 12, 2005 08:50
Some problems with Star CD Micha Siemens 0 August 6, 2003 13:55


All times are GMT -4. The time now is 06:31.