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

How can write a field in openFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree34Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 31, 2014, 09:14
Default
  #21
Member
 
Ananda Kannan
Join Date: Feb 2014
Location: Göteborg, Sweden
Posts: 55
Rep Power: 12
ansubru is on a distinguished road
Hi Foamers!!

I am working with the DPMFoam solver and I have made some changes to some of the libraries that this solver depends on. I want to be able to track these changes I have made. For instance, I have a made a change to the -/llagrangian (-lagrangian/intermediate) libraries and I want to write some of these modified parameters into a file for every time step. The file that I have edited is -

Code:
src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/WallModel/WallSpringSliderDashpot/WallSpringSliderDashpot.C.
and here is the edited portion -

Code:
// Hard-coding vibrational wall
           
    scalar rho_wall = 8000; // Steel density in kg/m3
    scalar m_wall = (rho_wall*(3.14/6.0))*(p.d()*p.d()*p.d());
    //scalar Ux = 0;
    //scalar Uy = 1;
    //scalar Uz = 0;
    vector v_wa = vector(Uwx_, Uwy_, Uwz_);

    scalar tperiod = this->owner().mesh().time().timeOutputValue();

    scalar sine_factor = (1+a_*sin(2*3.14*f_*tperiod));

    vector v_w = sine_factor*v_wa;

    vector U_PW = p.U() - v_w;

    scalar r_PW_mag = mag(r_PW);

    scalar normalOverlapMag = max(pREff - r_PW_mag, 0.0);

    vector rHat_PW = r_PW/(r_PW_mag + VSMALL);

    // Effective radius
    scalar R = 0.5*p.d();

    // Effective mass
    //scalar M = p.mass()*m_wall/(p.mass() + m_wall);

    //scalar kN = (4.0/3.0)*sqrt(R)*Estar_;

    scalar etaN = alpha_*sqrt(p.mass()*kN)*pow025(normalOverlapMag);
I want to write v_w and tperiod to a file. I am quite puzzled as to how I can define these as two parameters as an IO object and subsequently write them. I have tried using the standard IO functions, but it doesnt seem to work at all (the class definition is out of scope.. and my code does not compile). Frankly i do not have a clue as to how this can be achieved.

I have tried looking into ostream functions used in other related lagrangian libraries, but I am just not able to comprehend them .

Do any of you have any suggestions??

Thanks in advance!

BR
ansubru
Kummi likes this.
ansubru is offline   Reply With Quote

Old   July 31, 2014, 09:22
Default
  #22
Senior Member
 
Dr. Alexander Vakhrushev
Join Date: Mar 2009
Posts: 250
Blog Entries: 1
Rep Power: 19
makaveli_lcf is on a distinguished road
Send a message via ICQ to makaveli_lcf
Ansubru,

for me all standard IO functions with openning and appending data to the file worked very well. You question is too general! To solve your problem you should check your compilation errors and include corresponding header files and libraries to your Lagrangian solver to resolve those errors.
__________________
Best regards,

Dr. Alexander VAKHRUSHEV

Christian Doppler Laboratory for "Metallurgical Applications of Magnetohydrodynamics"

Simulation and Modelling of Metallurgical Processes
Department of Metallurgy
University of Leoben

http://smmp.unileoben.ac.at
makaveli_lcf is offline   Reply With Quote

Old   February 12, 2017, 09:13
Default
  #23
Senior Member
 
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
Hi,

I think my question is a step further above! I have created a volScalarField in my own turbulence model using IOobject (not in createFields.H !!). The value calculated and outputted correctly using runTime.write. The problem is that I cannot find a way to time-average this scalar field using functionObject in controlDict, as it only identifies the fields constructed in createFields.H.

So, the question is how to do time-averaging for fields created outside createFields.H?!

Can I use swak4Foam for this purpose?!

Syavash
syavash is offline   Reply With Quote

Old   February 13, 2017, 08:13
Default
  #24
New Member
 
Hasan Shetabivash
Join Date: Jan 2017
Location: Montreal
Posts: 17
Rep Power: 12
hasan_shetabivash is on a distinguished road
Hi ansubru
Only objects that are registered into time object will be written automatically at specified time steps. Besides, you only can register objects that are of regIoObject type. In your case the vector class is not an regIoObject so it's impossible to register it. However, I just came up with two solutions:
1. Use Info and write your parameters into a log file.
2. Define a dictionary that includes all your parameters. You can register dictionaries and write them in specified time steps.
hasan_shetabivash is offline   Reply With Quote

Old   February 13, 2017, 17:21
Default
  #25
New Member
 
Hasan Shetabivash
Join Date: Jan 2017
Location: Montreal
Posts: 17
Rep Power: 12
hasan_shetabivash is on a distinguished road
Dear syavash,

You can use functionObjects for all registered fields. In order to check that your field is registered and available, use banana trick described in the following link.
https://openfoamwiki.net/index.php/T...gisteredObject
hasan_shetabivash is offline   Reply With Quote

Old   March 15, 2017, 15:19
Default
  #26
Member
 
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 10
linyanx is on a distinguished road
Quote:
Originally Posted by vigneshTG View Post
Thanks Alex !! You pointed it out, i wrote the definition of surface tension term before alpha definition. Now i corrected it and it works !!

Thank you very much !!
Hi Vignesh,

After reading your problem and solution, I have a quick question regarding the volVectorField that you've gotten, named volVectorField 'ST'. How can you implement this volVectorField term into the equation that you want to solve? Like, for example, UEqn.H in interFoam. I want to add the force vector term into the UEqn.H, written as 'interpolate(F)'. But the system will always complain about the format of this vector term.

Hence, I guess you may know this after reading your post. Really appreciate your help for any hints.

Regards,
Linyan
linyanx is offline   Reply With Quote

Old   May 7, 2018, 20:33
Default runTime_.outputTime() at converged time step
  #27
New Member
 
sethu
Join Date: Oct 2011
Posts: 7
Rep Power: 14
Sethu is on a distinguished road
Quote:
Originally Posted by su_junwei View Post
Hi Sven

you can test the following code

if(runTime_.outputTime())
{
hybrid_.write();
}

Junwei
Dear Su Junwei.,

runTime_.outputTime() works fine. But, if my solution is converged and when it is not in output interval, the VolScalarFileld is not written. (e.g: writeInterval 100; It is writing it for every 100 iterations. But when my solution is converged at 357 iteration, the volScalarField is not written)


Im using the latest OF version (5.0)


The following is my code,

if(runTime.outputTime())
{
volScalarField FFR
(
IOobject
(
"FFR",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
p/max(p)
);
FFR.write();
//runTime.write();
}

Am I missing something in the code.??
Sethu is offline   Reply With Quote

Old   December 11, 2019, 11:57
Default
  #28
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 6
sippanspojk is on a distinguished road
Hi all,

First of all - thanks for a very informative and good thread!


I am doing something similar - I am doing some computations on the pressure values for each face for some patches and I want to create a field from these values that I can visualize in paraview.

I created a volScalarField in createFields.H like:
Code:
volScalarField myField
    (
        IOobject
        (
            "myField",
            mesh.time().timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        dimensionedScalar("myField", dimEnergy/dimVolume, 0.0)
    )
and it compiles fine and I also get a "myField" output for each write interval. At the moment it is just an empty field, since I am not using it anywhere so my obvious question is - how do I fill this field with my values?


I have already written a functionObject that reads the pressure values for the faces of some specified patches, does some computations and saves them to a List<double>. Is it possible to reach my "myField" from my functionObject and save my values there instead or do I need to move my computations over to the solver? Furthermore, is it possible to create a field for only some faces?

btw, I am using pimpleFoam.


I am grateful for any help on this.

Cheers,
David

Last edited by sippanspojk; December 11, 2019 at 13:25.
sippanspojk 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
Critical errors during OpenFoam installation in OpenSuse 11.0 amscosta OpenFOAM 5 May 1, 2009 14:06
Problem installing OpenFOAM 1.5 installation on RHEL 4. vwsj84 OpenFOAM Installation 4 April 23, 2009 04:48
2009 OpenFOAM Summer School in Zagreb, Croatia hjasak OpenFOAM Announcements from Other Sources 0 March 27, 2009 12:08
Adventure of fisrst openfoam installation on Ubuntu 710 jussi OpenFOAM Installation 0 April 24, 2008 14:25
OpenFOAM Training and Workshop Hrvoje Jasak Main CFD Forum 0 October 7, 2005 07:14


All times are GMT -4. The time now is 08:38.