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

Updating Boundary Conditions per time step/iteration in OF v4/v5

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 17, 2018, 01:25
Default Updating Boundary Conditions per time step/iteration in OF v4/v5
  #1
New Member
 
Join Date: Jan 2018
Posts: 4
Rep Power: 8
alexya is on a distinguished road
Hi, guys:

I just start Openfoam. I am trying to update the boundary conditions per time step or iteration. I have read through the previous threads and follow them. But it didn't make out.

while (piso.correct())
{
.........
}

forAll (p.boundaryField()[patchID], i)
{
p.boundaryField()[patchID][i] == 1.0;
}

wmake gives the error:

warning: value computed is not used [-Wunused-value]
p.boundaryField()[patchID][facej] == 1.0;

I have tried both OF v4 and v5. The previous threads use v1-3. I modify icoFoam as a template. I insert the above test code below the piso loop.



Thanks
Alex
alexya is offline   Reply With Quote

Old   January 17, 2018, 02:28
Default
  #2
New Member
 
Join Date: Jan 2018
Posts: 4
Rep Power: 8
alexya is on a distinguished road
It seems I could not access and modify the boundary values in the solver like some other threads mentioned:
change "p" to "mesh" reports error ‘class Foam::fvMesh’ has no member named ‘boundaryField’
operator "=" reports error

forAll(mesh.boundary(), patchID)
{
forAll (mesh.boundary()[patchID],facei)
{
alfa.boundaryField()[patchID][facei] = 2.0;
}
}
alexya is offline   Reply With Quote

Old   September 26, 2018, 12:30
Default
  #3
Member
 
Pavan
Join Date: Jan 2016
Posts: 53
Rep Power: 10
pvpnrao is on a distinguished road
Were you able to figure it out? I am facing the same problem
pvpnrao is offline   Reply With Quote

Old   September 26, 2018, 12:41
Default
  #4
Member
 
Pavan
Join Date: Jan 2016
Posts: 53
Rep Power: 10
pvpnrao is on a distinguished road
Quote:
Originally Posted by alexya View Post
Hi, guys:

I just start Openfoam. I am trying to update the boundary conditions per time step or iteration. I have read through the previous threads and follow them. But it didn't make out.

while (piso.correct())
{
.........
}

forAll (p.boundaryField()[patchID], i)
{
p.boundaryField()[patchID][i] == 1.0;
}

wmake gives the error:

warning: value computed is not used [-Wunused-value]
p.boundaryField()[patchID][facej] == 1.0;

I have tried both OF v4 and v5. The previous threads use v1-3. I modify icoFoam as a template. I insert the above test code below the piso loop.



Thanks
Alex
I have not tested it yet but you we can try adding
variable.correctBoundaryConditions();

after
p.boundaryField()[patchID][i] == 1.0;

and see if it works
pvpnrao is offline   Reply With Quote

Old   September 27, 2018, 06:54
Default
  #5
Senior Member
 
Join Date: Sep 2013
Posts: 353
Rep Power: 21
Bloerb will become famous soon enough
I do not understand what you are trying to achieve. boundary conditions can do that without changes. One example:
Code:
    myBoundary
    {
        type            fixedValue;
        value           uniform 1.0;
    }
is fixed in time. The boundary condition uniformFixedValue on the other is time dependend and uses function1. E.g
Code:
    myBoundary
    {
        type            uniformFixedValue;
        uniformValue    constant 1.0;
    }
or
Code:
    myBoundary
    {
        type            uniformFixedValue;
        uniformValue    table
        (
         (0 1.0)
         (5 2.0)
        );
    }
would change the value from 1.0 at time 0 to 2.0 after 5 seconds (gradually each time step).
Bloerb is offline   Reply With Quote

Old   September 27, 2018, 09:46
Default
  #6
Member
 
Pavan
Join Date: Jan 2016
Posts: 53
Rep Power: 10
pvpnrao is on a distinguished road
Bloerb

In my case, the inlet velocity is parabolic in space and pulsating in time. Thus, for the velocity boundary condition I am using:

INLET
{
type timeVaryingMappedFixedValue;
mapMethod nearest;
offset (0 0 0);
setAverage off;
perturb 0 ;
fieldTableName no;
}
The velocity distribution (at selected time steps) is saved in the folder constant/boundaryData/INLET/.

However, I also need to ensure that, in each time step, the pressure at the inlet matches a certain value. I understand we cannot simultaneously define pressure and velocity boundary condition at the inlet. Therefore, in each time step, I am trying to adjust the outlet pressure (by multiplying the fixedValue with an adjustment factor) till I achieve the required pressure at the inlet.

I want the solver (pimpleFoam) to keep iterating (within the time step) and updating the outlet pressure until the target inlet pressure is achieved.

So far, I have not succeeded in this.

Any help will be highly appreciated.

FYI: I am doing this creating a new boundary condition. I do not mind doing this from within the solver as well.
pvpnrao is offline   Reply With Quote

Old   September 30, 2018, 10:55
Default
  #7
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
Hi,


I remember, I did something similar before. You need to implement a new BC which impose a parabolic BC (it is kind of 101 tutorial for OF programming). Then U_max in your case should be Function1 type which the user can select it as a table or Sine wave (for pulsing flow) in time. In old OF versions, it was called DataEntry (or something like that). OF course ``timeVaryingMappedFixedValue`` is one solution but for me it is not needed if you know the profile analytically.


If you are solving incompressible flow, I cannot see the point of adjusting or iterating to active a certain pressure value. Only pressure gradient matters, not the absolute value.


Your code probably doestn't work on OF-4 > because you need to use ``boundaryFieldRef()`` which returns a reference not a constant reference. Check this thread [LINK]



Best wishes,
Hassan
__________________
@HIKassem | HassanKassem.me
hk318i is offline   Reply With Quote

Old   September 30, 2018, 22:10
Lightbulb
  #8
Member
 
Pavan
Join Date: Jan 2016
Posts: 53
Rep Power: 10
pvpnrao is on a distinguished road
Hassan


Thank you very much. I am still pretty much stuck at the same place. Please see below:



Quote:
Originally Posted by hk318i View Post

I remember, I did something similar before. You need to implement a new BC which impose a parabolic BC (it is kind of 101 tutorial for OF programming). Then U_max in your case should be Function1 type which the user can select it as a table or Sine wave (for pulsing flow) in time. In old OF versions, it was called DataEntry (or something like that). OF course ``timeVaryingMappedFixedValue`` is one solution but for me it is not needed if you know the profile analytically.

I think I got the velocity boundary condition at the inlet workig as per my requirement.


Quote:
Originally Posted by hk318i View Post
If you are solving incompressible flow, I cannot see the point of adjusting or iterating to active a certain pressure value. Only pressure gradient matters, not the absolute value.

True, but I am trying to simulate the blood flow in arteries and I need to make sure both pressure and velocity at the inlet are attaining a stupulated value. These values have been recorded during experiments.


So witinin each time loop I need to satisfy velocity and pressure at the inlet. As I mentioned earlier, I have defined the velocity BC at inlet and I am trying the achieve the required inlet pressure by dynamically changing the oulet pressure. I am trying to tweak pimpleFoam slover to suit my requirement.
But, even after assiging the new pressures at the begining of each "pimple loop", the area averaged pressure at the inlet is not changing (after each pimple loop).

The area averaged pressure (at inlet) is only chaanging upon the completion of time loop.
Can you suggest a way where I can upadate the oulet pressures after each pimple loop so that the subsequent pimple loop runs with updated outlet pressures. Here is my code


while (pimple.loop())
{
#include "ResistanceHeader.H"
#include "UEqn.H"
// --- Pressure corrector loop
while (pimple.correct())
{
#include "pEqn.H"
}
if (pimple.turbCorr())
{
laminarTransport.correct();
turbulence->correct();
}
p.correctBoundaryConditions()
}
runTime.write();
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;

The ResistanceHeader.H file contains the following code
const label& OUT1patchId = mesh.boundaryMesh().findPatchID("OUT1");
/ /Calculating area of the outlet
scalar OUT1Area = gSum(mesh.boundary()[OUT1patchId].magSf());
// Calculating radius of the outlet in cm, that is why rad_1 is getting multiplied by 100
scalar OUT1rad_1 = Foam::sqrt(OUT1Area/(constant::mathematical:i))*100;
scalar OUT1PVR_1 = 1; scalar OUT1PVR_2 = 1;
scalar OUT1PVR_3 = 1;
if (OUT1Count== 1)
{
OUT1PVR_1 = (Rnew)*((-1.589e5)*Foam:ow(OUT1rad_1, 7.0) + (1.361e6)*Foam:ow(OUT1rad_1, 6.0) + (-4.778e6)*Foam:ow(OUT1rad_1, 5.0) + (8.864e6)*Foam:ow(OUT1rad_1, 4.0) + (-9.328e6)*Foam:ow(OUT1rad_1, 3.0) + (5.548e6)*Foam:ow(OUT1rad_1, 2.0) + (-1.737e6)*Foam:ow(OUT1rad_1, 1.0) + (2.318e5));
OUT1PVR_3 = OUT1PVR_1;
}
if (OUT1Count>1)
{
OUT1PVR_2 = OUT1PVR_1;
OUT1PVR_3 = Rnew * OUT1PVR_2;
OUT1PVR_1 = OUT1PVR_3;
}
scalar OUT1Pressure = ((OUT1PVR * gSum(phi.boundaryField()[OUT1patchId])) + PCWP)/blood_density;
p.boundaryFieldRef()[OUT1patchId] = OUT1Pressure;


The last line in the above code is supposed to update the boundary field but for some reason I do not see it upadating the values after each pimple loop


Quote:
Originally Posted by hk318i View Post
Your code probably doestn't work on OF-4 > because you need to use ``boundaryFieldRef()`` which returns a reference not a constant reference. Check this thread [LINK]
This fixed the compilation errors, but I cannot see updated boundary conditions after each pimple loop.

Please let me know how to fix these problems. Particularly, how to force pimplefoam to update the boundary condition after each pimple loop.
pvpnrao 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
bash script for pseudo-parallel usage of reconstructPar kwardle OpenFOAM Post-Processing 42 May 8, 2024 00:17
AMI speed performance danny123 OpenFOAM 21 October 24, 2020 05:13
My radial inflow turbine Abo Anas CFX 27 May 11, 2018 02:44
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 07:20
dynamic Mesh is faster than MRF???? sharonyue OpenFOAM Running, Solving & CFD 14 August 26, 2013 08:47


All times are GMT -4. The time now is 04:00.