How to update a volScalarField's values
Hi!
I have a question concerning how to update a volScalarField. Imagine the following problem: You have a volScalarField T for the temperature (with values applied to it). You now have another volScalarField X which is meant to consist of values depending on the respective temperatures. How do I implement an update for X which looks up the temperature of each element and then updates the value in terms of special conditions. With that I mean a procedure of this sort: Code:
if (T<100) |
There are several ways to do it. One of them:
Code:
forAll(X, cellI) { |
There are many examples in the source code, see e.g.:
https://github.com/OpenFOAM/OpenFOAM.../hePsiThermo.C Here a simplified example: Say you get your temperature field like this: Code:
const volScalarField& T = thermo.T(); Code:
scalarField& TCells = T.internalField(); |
Thanks! :)
EDIT: Btw - is there a difference between writing "celli" and "cellI" (i.e. upper- / lowercase letter)? |
Quote:
The variable celli is a 'label' (i.e. a integer) defined in forAll, which is a macro that sets up the for loop. So, you can call the variable whatever you want, you just need to be consistent. ;) |
Allright thanks...
I'd like to add another more "practical" question here. Things now work fine and I define a temperature field which then is analyzed to determine the solid fraction in the respective cells. What I'd like to know is how to write the new volScalarField for the fraction solid into the "0 folder". I create the fraction solid field like this: Code:
volScalarField fracSol I now would like to know how I also can write the calculated fracSol into the 0 folder i.e. the fraction solid field for the initial temperatures. This also would come in handy when postprocessing the project in ParaFoam as there now is no fracSol field in time step 0 and it is a bit tedious to go to timestep 1 and activate the field plus once again any time you accidentally rewind to timestep 0 as it then gets unloaded (because there's no data for it in step 0)... I already tried to simply put a runtime.write() command before progressing time in the time loop but this didn't do the trick. I guess one usually would approach this problem with the setfields utility but as far as I know one here is limited to the premade functions like defining a block in which the variable get set to a certain value... |
you can force the writing of a field at any time with
Code:
fracSol.write(); |
Thanks - if I can come up with enough self-motivation after having finished my master thesis I might write a beginners tutorial so people won't have such a hard time figuring out such "mundane" things like this... ;)
|
Hello Foamers,
My problem is almost similar. I have two volScalarFields T (temperature) and k (thermal conductivity). volScalarField k depends upon volScalarField T with the following expression: Quote:
I need to update the value (k) thermal conductivity for every time step based on Temperature (T). I have followed the above comments and compiled the new FOAM successfully. However, k returns constant value for every time step after solving the expression. For verification, I am hereby mentioning the source (.C) and createFields.H files. Quote:
Quote:
Thank you |
Quote:
Code:
fvScalarMatrix TEqn Code:
IOobject::AUTO_WRITE |
All times are GMT -4. The time now is 00:07. |