|
[Sponsors] |
March 15, 2014, 08:59 |
Problems creating volscalarfield
|
#1 |
Member
Join Date: Aug 2013
Posts: 60
Rep Power: 13 |
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]; } Code:
volScalarField SC ( IOobject ( "SC", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh );
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 Last edited by sur4j; March 16, 2014 at 11:32. |
|
March 15, 2014, 10:16 |
|
#2 |
Senior Member
|
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 ); Code:
volScalarField K ( IOobject ( "K", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimless/dimTime ); 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()) |
|
March 15, 2014, 10:51 |
|
#3 |
Member
Join Date: Aug 2013
Posts: 60
Rep Power: 13 |
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 11:33. |
|
March 15, 2014, 13:18 |
|
#4 |
Senior Member
|
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))); } Code:
forAll(T, cellI) { SC[cellI] = SC0[cellI] + 2/(250*(2^((100 - T[cellI])/10))); } SC0 = SC |
|
March 15, 2014, 13:36 |
|
#5 |
Member
Join Date: Aug 2013
Posts: 60
Rep Power: 13 |
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 ); |
|
March 15, 2014, 18:39 |
|
#6 |
Senior Member
|
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 ); |
|
March 16, 2014, 07:20 |
|
#7 |
Member
Join Date: Aug 2013
Posts: 60
Rep Power: 13 |
Thank you very much for your help.
When I try: Code:
forAll(T, cellI) { SC[cellI] += 2/((((T[cellI])/10))); } 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 Code:
int exp; int base; exp = ((100 - T.internalField()[cellI])/10); base = 250*(2^exp); SC.internalField()[cellI] += 2/base; 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 11:33. |
|
March 16, 2014, 07:39 |
|
#8 |
Senior Member
|
^ 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. |
|
March 16, 2014, 08:49 |
|
#9 |
Member
Join Date: Aug 2013
Posts: 60
Rep Power: 13 |
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 ..... Code:
forAll(T.internalField(), cellI) { SC.internalField()[cellI] += T.internalField()[cellI]; } |
|
March 16, 2014, 08:53 |
|
#10 |
Senior Member
|
OK. What is the meaning of that 100?
|
|
March 16, 2014, 09:18 |
|
#11 |
Member
Join Date: Aug 2013
Posts: 60
Rep Power: 13 |
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.
|
|
March 16, 2014, 09:22 |
|
#12 |
Senior Member
|
Units?
You can plot 2/250*(pow(2,((100 - T)/10))) in paraFoam using Calculator filter and see what you're adding to SC. |
|
March 16, 2014, 09:23 |
|
#13 |
Member
Join Date: Aug 2013
Posts: 60
Rep Power: 13 |
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! |
|
April 2, 2014, 22:59 |
|
#14 |
Senior Member
Dongyue Li
Join Date: Jun 2012
Location: Beijing, China
Posts: 849
Rep Power: 18 |
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 ); Code:
--> FOAM FATAL ERROR: NO_READ specified for read-constructor of object n of class IOobject |
|
April 8, 2015, 10:07 |
|
#15 |
Senior Member
|
Hi,
You error is NOT "the same" maybe it is similar. What is the type of Code:
0.75*Cds*phase2->rho()*bp/d1 |
|
Tags |
temperature, variable, volscalarfield |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Commercial meshers] Fluent3DMeshToFoam | simvun | OpenFOAM Meshing & Mesh Conversion | 50 | January 19, 2020 16:33 |
Problems running laminarSmoke | r08n | OpenFOAM Running, Solving & CFD | 1 | September 27, 2013 20:27 |
Problems with Meshing: Collapsed Cells | Emmanuel Resch | Siemens | 1 | July 30, 2007 04:02 |
Gerris software installation | mer | Main CFD Forum | 2 | November 12, 2005 09:50 |
Some problems with Star CD | Micha | Siemens | 0 | August 6, 2003 14:55 |