CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to write specific term in openfoam solver (https://www.cfd-online.com/Forums/openfoam-programming-development/223791-how-write-specific-term-openfoam-solver.html)

divyesh January 26, 2020 23:54

How to write specific term in openfoam solver
 
Hello Foamers,

I am trying to modify the laplacian foam. Here is the code for equation,

volScalarField U(a+(b*T)+(c*T*T));

fvScalarMatrix TEqn
(
fvm::ddt(T) - fvm::laplacian(U,T) - (k)
==
fvOptions(T)
);

fvOptions.constrain(TEqn);
TEqn.solve();
fvOptions.correct(T);
}

Where, a,b,c & k are constants.
Now, I want to write the value of "U" for each time step. How can I do that?

Thanks in advance

ybapat January 27, 2020 00:05

You can create volScalar field using IOObject and use AUTO_WRITE option for it. It will write at every save option. If you want to write every time step you can use write function after end of each time step. Then it will write every time step.

divyesh January 27, 2020 00:11

if (runTime.writeTime())
{

volScalarField U(a+(b*T)+(c*T*T));
(
IOobject
(
"U",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
U
);

runTime.write();
}

I tried this one, but its not working.
Solver is compiling, case is running but it is not writing "U" file.

vivek05 January 27, 2020 05:08

Quote:

Originally Posted by divyesh (Post 755672)
if (runTime.writeTime())
{

volScalarField U(a+(b*T)+(c*T*T));
(
IOobject
(
"U",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
U
);

runTime.write();
}

I tried this one, but its not working.
Solver is compiling, case is running but it is not writing "U" file.

1. Initialize U as volumetric field using IOobject like
PHP Code:

volScalarField U
    
(
    
IOobject
    
(
    
"U",
    
runTime.timeName(),
    
mesh,
    
IOobject::NO_READ,
    
IOobject::AUTO_WRITE
    
),
       
mesh,
       
dimensionSet(0,0,0,0,0,0,0),
       
"zeroGradient"
    
); 

I'm just presuming your U as dimensionless field. Do specify your dimension of U in dimension in dimensionSet

2. Now use your expression inside your solver
PHP Code:

a+(b*T)+(c*T*T) ; 

I hope this may help you:)

Best,
Vivek S

divyesh January 27, 2020 06:19

Thanks, Now its writing U for each time step.
I just change dimensions with this:

dimensionSet(0,2,-1,0,0,0,0),

But issue is, It is taking default value of time 0 uniform value.
While running the case, Value of T is non-uniform and value of U is uniform.
Any idean what is the mistake?

vivek05 January 27, 2020 07:23

Are you specifying BC's of U in 0 time folder?

If not , then your values of U should be non-uniform in internalField & calculated values at Boundary patches.

divyesh January 27, 2020 23:56

No, I am not specifying BC for U in my time 0 folder.
Look at the calculated value for U in all next time steps...

internalField uniform 77.359;

boundaryField
{
Side1
{
type zeroGradient;
}
Side2
{
type zeroGradient;
}
walls
{
type empty;
}
}

But my T is changing non-uniformally... like this

internalField nonuniform List<scalar>
50
(
571.591
559.42
547.284
535.214
523.241
511.396
499.706
488.2
476.904
465.844
455.041
444.518
434.293
424.384
414.806
405.571
396.691
388.173
380.024
372.248
364.847
357.82
351.166
344.881
338.959
333.393
328.175
323.294
318.741
314.503
310.566
306.918
303.545
300.431
297.563
294.923
292.498
290.271
288.228
286.352
284.628
283.041
281.576
280.219
278.953
277.765
276.641
275.566
274.525
273.506
)
;

boundaryField
{
Side1
{
type fixedValue;
value uniform 573;
}
Side2
{
type fixedValue;
value uniform 273;
}
walls
{
type empty;
}
}

vivek05 January 28, 2020 00:55

I think you have called U variable outside of your time loop if I am correct

Put it inside the time loop

divyesh January 28, 2020 04:07

Thanks Vivek,

Its working.


All times are GMT -4. The time now is 01:27.