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

Update Cell Values Outside of Boundary Code

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 8, 2024, 06:57
Default Update Cell Values Outside of Boundary Code
  #1
New Member
 
Kuzey Can Derman
Join Date: Oct 2022
Posts: 12
Rep Power: 4
NorthCFD is on a distinguished road
Hello,

I am trying to change the value of a variable in updateFields.H inside solver folder for a purpose.

Problem is when I try to print the values of this variable in boundary condition file (in p) to check ıf it is correct, it prints all zero meaning I failed.

What may be the problem ?

createFields:
Code:
volScalarField checkVol
(
    IOobject
    (
        "checkVol",
        runTime.timeName(),
        mesh,
  	IOobject::NO_READ,
	IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar("checkVol", dimless, 0.0 )
);
updateFields:
Code:
  forAll(checkVol, facei) {
    checkVol[facei] = 250;
  }
boundary condition:
Code:
    const fvPatchField<scalar>& checkVol=
        patch().lookupPatchField<volScalarField, scalar>("checkVol");

    forAll(checkVol, checki) {

      Info << "checkVol: " << checkVol[checki] << endl;
    }
I added every line with checkVol, sorry couldn't include whole code.

Any help is appreciated.
NorthCFD is offline   Reply With Quote

Old   March 10, 2024, 16:19
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Your choice of variable names is a bit misleading. If you write this:
Code:
 forAll(checkVol, celli)
{
    checkVol[celli] = 250;

}
It is at least clear that you are only touching the volume values. The boundary patch values can either be something that you are prescribing yourself (eg, inlet, wall, etc) or simply a "calculated" or zeroGradient value. You need to ensure that all of those types of patches know about which changes you just made to the volume (internal field) values:
Code:
checkVol.correctBoundaryCondtions();
Let us know how you get on with that.
olesen is offline   Reply With Quote

Old   March 12, 2024, 06:10
Default
  #3
New Member
 
Kuzey Can Derman
Join Date: Oct 2022
Posts: 12
Rep Power: 4
NorthCFD is on a distinguished road
Thanks for the response Olesen.

Sorry that I gave a hard to understand code, this was because, I tried to give a template of what I am doing since there are few more things with similar variables and I had restrictions.

To answer you, checkVol is a not a boundary value itself like p or U but a intermediate step for calculating U and p, think it like phi or gamma. checkVol value is calculated inside another updateCheck.h file just before updateFields.H. So no need to call correctBoudnaryCondition function.

The problem is after it is calculated and assigned in that updateCheck.h file as previously mentioned, its values can be printed out. But when trying to print its values inside p boundary condition, it gives all zeros for it.
NorthCFD is offline   Reply With Quote

Old   March 13, 2024, 05:27
Default
  #4
New Member
 
Kuzey Can Derman
Join Date: Oct 2022
Posts: 12
Rep Power: 4
NorthCFD is on a distinguished road
UPDATE !!!

I was using lookupPatchField to retrieve checkVol which was giving me zeros, I changed inital to 225 instead. Then it started to print out 225s instead of zeros. This concluded that it was just giving initial values and no other intermediate processes were done (unless some other function that turns the values to initials but seems unlikely).

Then I tried to use the lookupObject to retrieve whole field instead of that single patch. This way it gave me 250 like it was supposed to (as I was changing values to 250 in updateFields, just arbitary value).

From now on I can use these values and my problem is fixed for now. BUT this raises new questions to me.
-Why did lookupObject worked as intended but lookupPatchField not?
-Isn't lookupPatchField is similar to lookupObject but the difference is it just gives the values on these patches instead of whole domain?

Thanks.
NorthCFD is offline   Reply With Quote

Old   March 14, 2024, 16:02
Default
  #5
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
You concluded that you do not need to call correctBoundaryConditions() despite my attempt to describe why it is necessary and what it does.
For what it's worth, I think that I have a somewhat better than basic knowledge of OpenFOAM and that my suggestion may have some merit.
olesen is offline   Reply With Quote

Old   March 15, 2024, 02:44
Default
  #6
New Member
 
Kuzey Can Derman
Join Date: Oct 2022
Posts: 12
Rep Power: 4
NorthCFD is on a distinguished road
It was inappropriate to not try what you said and just continue, after asking a question here. I understand and am sorry about that.

I changed part of my code back and tried what you said. Added checkVol.correctBoundaryCondition() inside updateFields. And it doesn't work.

My code is not well written in "OpenFOAM way", probably that is the issue.
NorthCFD is offline   Reply With Quote

Reply

Tags
boundary condition, programing


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
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 12:04
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 08:38
[swak4Foam] About groovyBC to set distributed fixedGradient values for each cell boundary patch nwpukaka OpenFOAM Community Contributions 6 August 12, 2014 07:34
parallel code samiam1000 SU2 3 March 25, 2013 05:55
Convective Heat Transfer - Heat Exchanger Mark CFX 6 November 15, 2004 16:55


All times are GMT -4. The time now is 16:46.