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

How to write specific term in openfoam solver

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By ybapat
  • 1 Post By divyesh

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 26, 2020, 23:54
Default How to write specific term in openfoam solver
  #1
New Member
 
divyesh's Avatar
 
Divyesh Variya
Join Date: May 2018
Location: INDIA
Posts: 16
Rep Power: 7
divyesh is on a distinguished road
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
divyesh is offline   Reply With Quote

Old   January 27, 2020, 00:05
Default
  #2
Senior Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 15
ybapat is on a distinguished road
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 likes this.
ybapat is offline   Reply With Quote

Old   January 27, 2020, 00:11
Default
  #3
New Member
 
divyesh's Avatar
 
Divyesh Variya
Join Date: May 2018
Location: INDIA
Posts: 16
Rep Power: 7
divyesh is on a distinguished road
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.
divyesh is offline   Reply With Quote

Old   January 27, 2020, 05:08
Smile
  #4
Member
 
Vivek
Join Date: Mar 2018
Location: India
Posts: 54
Rep Power: 8
vivek05 is on a distinguished road
Quote:
Originally Posted by divyesh View Post
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
vivek05 is offline   Reply With Quote

Old   January 27, 2020, 06:19
Default
  #5
New Member
 
divyesh's Avatar
 
Divyesh Variya
Join Date: May 2018
Location: INDIA
Posts: 16
Rep Power: 7
divyesh is on a distinguished road
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?
divyesh is offline   Reply With Quote

Old   January 27, 2020, 07:23
Default
  #6
Member
 
Vivek
Join Date: Mar 2018
Location: India
Posts: 54
Rep Power: 8
vivek05 is on a distinguished road
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.
vivek05 is offline   Reply With Quote

Old   January 27, 2020, 23:56
Default
  #7
New Member
 
divyesh's Avatar
 
Divyesh Variya
Join Date: May 2018
Location: INDIA
Posts: 16
Rep Power: 7
divyesh is on a distinguished road
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;
}
}
divyesh is offline   Reply With Quote

Old   January 28, 2020, 00:55
Default
  #8
Member
 
Vivek
Join Date: Mar 2018
Location: India
Posts: 54
Rep Power: 8
vivek05 is on a distinguished road
I think you have called U variable outside of your time loop if I am correct

Put it inside the time loop
vivek05 is offline   Reply With Quote

Old   January 28, 2020, 04:07
Default
  #9
New Member
 
divyesh's Avatar
 
Divyesh Variya
Join Date: May 2018
Location: INDIA
Posts: 16
Rep Power: 7
divyesh is on a distinguished road
Thanks Vivek,

Its working.
vivek05 likes this.
divyesh 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
Map of the OpenFOAM Forum - Understanding where to post your questions! wyldckat OpenFOAM 10 September 2, 2021 05:29
[ANSYS Meshing] Help with element size sandri_92 ANSYS Meshing & Geometry 14 November 14, 2018 07:54
Domain Reference Pressure and mass flow inlet boundary AdidaKK CFX 75 August 20, 2018 05:37
How to add this term to openfoam solver rapierrz OpenFOAM Programming & Development 10 February 28, 2015 12:30
Can't get data from OpenFoam to external solver using externalCoupled perry OpenFOAM Running, Solving & CFD 4 May 26, 2014 08:09


All times are GMT -4. The time now is 19:39.