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

icoFoam set outflow Dirichlet conditions for p during runtime

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Karman123

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 13, 2015, 05:43
Default icoFoam set outflow Dirichlet conditions for p during runtime
  #1
New Member
 
Join Date: Jan 2015
Posts: 4
Rep Power: 11
Karman123 is on a distinguished road
Hello everybody,
I am trying to set Dirichlet boundary conditions for the pressure which are unknown before runtime for the icoFoam solver at the outflow (and I am failing).
These Dirichlet values come from another calculation which depends on the solutions of icoFoam, so there is no way to do this with tableFile or csvFile.

My idea to achieve this is to create a modified version of the icoFoam Solver (called my_icoFoam).
In this new solver I edited my_icoFoam.C :
1. I created a new fvPatch for the outlet:
Code:
label outlet_patch_label = mesh.boundaryMesh().findPatchID("outlet");
const fvPatch& outlet_patch = mesh.boundary()[outlet_patch_label];
2. During runtime I tried to change the p-values at the adjacent cells:
Code:
forAll(outlet_patch, face_i){
    label curCellp = outlet_patch.faceCells()[face_i];
    p[curCellp] = value;
}
This has no effect at all.
I think the problem is that I declared the outflow boundary in the file case/0/p to:
Code:
boundaryField
{
    outlet
    {
        type            fixedValue;
        value           uniform 0;
    }
}
I know that this must be possible somehow because chtMultiRegionSimpleFoam does the same thing to couple two regions with the partitioned approach.
Any tips on what I am doing wrong or how chtMultiRegionSimpleFoam solves this probem are highly appreciated.
Karman123 is offline   Reply With Quote

Old   January 16, 2015, 07:55
Default push
  #2
New Member
 
Join Date: Jan 2015
Posts: 4
Rep Power: 11
Karman123 is on a distinguished road
Nobody with any ideas?

Im really in a dead end here, any ideas would be helpful.
Karman123 is offline   Reply With Quote

Old   January 16, 2015, 16:19
Default
  #3
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12
ssss is on a distinguished road
Maybe using groovyBC or swak4foam?

It will let you impose conditional conditions to your boundaryConditions, and you will be able to access runTime variables from it

Maybe I can help you with it which is your condition for changing the BC?
ssss is offline   Reply With Quote

Old   January 18, 2015, 15:22
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all! And welcome to the forum Karman123!

Quote:
Originally Posted by Karman123 View Post
Nobody with any ideas?
Uhm... here's an idea: A person should not simply take a pain pill for a headache that was caused by a hammer hitting one's head.

OK, joking aside, the problem here is that you might not be diagnosing properly the problem you have at hand.
Because from your description, it seems to me that you should first run icoFoam for a few iterations with a "zeroGradient" or "inletOutlet" or "outlerInlet" at the outlet; and then change the boundary type in the last iteration to "fixedValue" and continue the simulation from there. No solver coding required.

Then there is also the "mappedField" boundary type, which seems to do what you're looking for.

Better yet, have a look at the code documentation: http://www.openfoam.org/docs/cpp/ - look at the bottom of the page there, where you can find the "Boundary Conditions" link. From there you can see the various outlet boundary conditions that OpenFOAM has got and possibly one of them already does what you want to do.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   January 19, 2015, 15:27
Default
  #5
New Member
 
Join Date: Jan 2015
Posts: 4
Rep Power: 11
Karman123 is on a distinguished road
Thank you very much for your replies.
Just to give some context, I am not using OpenFOAM professionally, but as a student (for the first time) on a project, which might explain the existance of a simple solution to my problem .

The project is to couple a 1D solver I already wrote in C++ to a 3D inflow region (which I try to compute with icoFoam).
So the pressure at the outlet boundary of the icoFoam-region is calculated by my own FV Code.

Quote:
Originally Posted by ssss View Post
Maybe using groovyBC or swak4foam?

It will let you impose conditional conditions to your boundaryConditions, and you will be able to access runTime variables from it

Maybe I can help you with it which is your condition for changing the BC?
If I understood groovyBC and swak4Foam correctly, these BCs can access internal field variables.
This part
https://openfoamwiki.net/index.php/C..._other_patches
seems to be interesting to me.
If I create a new patch in my modified icoFoam solver which contains the solutions from my 1D solver I could access that new patch from the BC-file.. correct?

Quote:
Originally Posted by wyldckat View Post
Greetings to all! And welcome to the forum Karman123!

Uhm... here's an idea: A person should not simply take a pain pill for a headache that was caused by a hammer hitting one's head.

OK, joking aside, the problem here is that you might not be diagnosing properly the problem you have at hand.
Because from your description, it seems to me that you should first run icoFoam for a few iterations with a "zeroGradient" or "inletOutlet" or "outlerInlet" at the outlet; and then change the boundary type in the last iteration to "fixedValue" and continue the simulation from there. No solver coding required.

Then there is also the "mappedField" boundary type, which seems to do what you're looking for.

Better yet, have a look at the code documentation: http://www.openfoam.org/docs/cpp/ - look at the bottom of the page there, where you can find the "Boundary Conditions" link. From there you can see the various outlet boundary conditions that OpenFOAM has got and possibly one of them already does what you want to do.

Best regards,
Bruno
Since my outlet BC should change with every time step your first suggestion would not work for my problem.

I cant find any explanations on "mappedField", only the code.
I will look into that a little more.

Thanks again and other suggestions are still welcome.
Karman123 is offline   Reply With Quote

Old   January 19, 2015, 16:03
Default
  #6
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12
ssss is on a distinguished road
You could just create a volVectorField with your 1D field, and access to it from groovyBC, no need of creating a new patch.
ssss is offline   Reply With Quote

Old   January 19, 2015, 16:46
Default
  #7
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by Karman123 View Post
The project is to couple a 1D solver I already wrote in C++ to a 3D inflow region (which I try to compute with icoFoam).
So the pressure at the outlet boundary of the icoFoam-region is calculated by my own FV Code.
Quick answer: Have a look at the tutorial folder "heatTransfer/buoyantSimpleFoam/externalCoupledCavity", since it somewhat looks like that it's what you're looking for. That tutorial essentially has a boundary condition coming from an outside application, where data is transferred via file.
wyldckat is offline   Reply With Quote

Old   February 12, 2015, 13:00
Default solution
  #8
New Member
 
Join Date: Jan 2015
Posts: 4
Rep Power: 11
Karman123 is on a distinguished road
for anybody with a similar problem:

i used the solution "ssss" suggested. (I assumed coupling via file is slow)

1. install swak4foam
2. create a new solver (copy icoFoam and rename)
3. create a new volume scalar field in your createFields.H
Code:
    Info<< "Creating field for pressure coupling\n" << endl;
     volScalarField p_coupling
    (
        IOobject
        (
            "p_coupling",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        dimensionedScalar("p_coupling", dimensionSet(0,2,-2,0,0,0,0), Foam::scalar(0))
    );
4. compute your boundary value in the main function (for example icoFoam.C) and set the coupling field to its value
Code:
        double value=compute_value(...);
        dimensionedScalar value_dim
        (
            "value_dim",
            dimensionSet(0,2,-2,0,0,0,0),
            scalar(value)
        ); 
        p_coupling=value_dim;
5. create a groovyBC for your pressure in 0/p with the variable name as value expression
Code:
    outlet
    {
        type groovyBC;
        valueExpression "p_coupling";
    }
6. PROFIT

thanks again ssss without you I might still be stuck
wyldckat likes this.
Karman123 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
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 06:28
OF 1.6 | Ubuntu 9.10 (64bit) | GLIBCXX_3.4.11 not found piprus OpenFOAM Installation 22 February 25, 2010 13:43
Set the inflow condition from the outflow fanta1014 CFX 4 January 26, 2010 21:22
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08
How to set environment variables kanishka OpenFOAM Installation 1 September 4, 2005 10:15


All times are GMT -4. The time now is 11:57.