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

Replacing Uniform BC with zeroGradient

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By ngj
  • 1 Post By ngj

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 26, 2013, 08:43
Default Replacing Uniform BC with zeroGradient
  #1
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 13
sur4j is on a distinguished road
Hello,

I have a problem when writing a scalar field into the time folders. The field is initially specified as:
volScalarField mu("mu", E/(2.0*(1.0 + nu)));
Where E and nu are obtained from the test case mechanical properties file. I have used the following code to write the scalar field mu inside each time folder so that I can view the results in para view:
Code:
if(runTime.outputTime()) 
{ 
mu.write(); 
}
This is writing the output for mu in the time folders as a list which is correct however, at the bottom of the list of values for each cell there are boundary conditions set:
Code:
...LIST OF VALUES FOR EACH CELL ABOVE HERE
1.27941e+07
1.27941e+07
1.27941e+07
1.27941e+07
1.27941e+07
1.27941e+07
1.27941e+07
);
boundaryField
{
    walls
    {
        type            calculated;
        value           uniform 9.79413e+06;
    }
    frontAndBack
    {
        type            empty;
    }
}
The 9.79413e+06 uniform BC is the value calculated for mu initially inside of the header file as shown in the formula at the top of this post. This value is set automatically as the boundary condition at the walls for some reason and for the results to be correct in para view I have to manually change this to type zeroGradient. Do you know why this keeps happening and is there a way of changing it so that I dont have to manually change it to zeroGradient in every time step file?

If not, would it be possible for me to create a bash script (such as Allrun) in which a for loop and sed command is used to go through each time directory inside of the case and replace the BC with the required zeroGradient?

Thanks.
sur4j is offline   Reply With Quote

Old   January 4, 2014, 04:39
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,902
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hallo,

If you create your field in the following manner, you should obtain the effect that you are looking for:

Code:
volScalarField mu
(
    IOobject
    (
        "mu",
        mesh.time().timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar("null", E.dimensions(), 0.0),
    "zeroGradient"
);

mu.internalField() = E.internalField()/(2.0*(1.0 + nu.internalField()));
mu.correctBoundaryConditions();
Also, remember to add the line

Code:
mu.correctBoundaryConditions();
every time that you have changed the internal values.

Kind regards

Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   January 4, 2014, 17:13
Default
  #3
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 13
sur4j is on a distinguished road
Thank you so much for your help Niel, I was getting a volScalarField re-deceleration error but when I deleted the equation from the other header file where it was initialy defined the solver compiled fine.

Could you please help me with one more problem?

Inside of my main .C file I have made the variable "mu" temperature dependant and made it change in the time loop in the following way:
Code:
if(mu.internalField()[cellI]<(1.27941e+07+(deltaLame*3))){
mu.internalField()[cellI]+=deltaLame;
        mu.correctBoundaryConditions();}
Where deltaLame is an increment value defined earlier. As you can see I have had to define the initial value of mu as 1.27941e+07 and this has to be changed manually every time I change the mechanical properties, when I say:

if(mu.internalField()[cellI]<(mu+(deltaLame*3)))

I get errors, I also tried to replace mu with:

E.internalField()/(2.0*(1.0 + nu.internalField()))

But again I got a long list of errors. Could you please suggest a method for defining mu here so that I do not have to manually replace and recompile the solver when I change the variable it is dependant on?

Your help is greatly appreciated. Thank you.
sur4j is offline   Reply With Quote

Old   January 5, 2014, 04:24
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,902
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Good morning,

You could merely create another volScalarField called muLimit, and then make the comparison in the if-statement on a cell per cell basis. This would also allow you to have a spatially varying limit.

Kind regards,

Niels
sur4j likes this.
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   February 9, 2014, 12:25
Default
  #5
Member
 
Join Date: Aug 2013
Posts: 60
Rep Power: 13
sur4j is on a distinguished road
I am now adding a time and temperature dependant thermal conductivity, I have modified the code in the main .C file and it works as expected however, I now have the same problem with DT in the readThermalProperties file as I did for mu and lambda, I mean in the output file in the time step folder the boundary field value is set as uniform at the wall as shown in the first post above.

I have the following code in the readThermalProperties file:
Code:
volScalarField DT
(
    IOobject
    (
        "DT",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar("0", dimensionSet(0, 2, -1 , 0, 0), 0.0)
);
If I add "zeroGradien" as shown:
Code:
.....................
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar("0", dimensionSet(0, 2, -1 , 0, 0), 0.0)
    "zeroGradient"
);
I get the following error when compiling the solver with wmake:
Code:
sk@sk-VirtualBox:~/OpenFOAM/sk-2.2.2/applications/solvers/cureFoam$ wmake
Making dependency list for source file cureFoam.C
SOURCE=cureFoam.C ;  g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam222/src/finiteVolume/lnInclude -ItractionDisplacement/lnInclude -IlnInclude -I. -I/opt/openfoam222/src/OpenFOAM/lnInclude -I/opt/openfoam222/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linuxGccDPOpt/cureFoam.o
In file included from cureFoam.C:50:0:
readThermalProperties.H: In function ‘int main(int, char**)’:
readThermalProperties.H:44:5: error: expected ‘)’ before string constant
readSolidDisplacementFoamControls.H:3:11: warning: unused variable ‘nCorr’ [-Wunused-variable]
readSolidDisplacementFoamControls.H:5:8: warning: unused variable ‘convergenceTolerance’ [-Wunused-variable]
make: *** [Make/linuxGccDPOpt/cureFoam.o] Error 1
Also I did not have to use the "DT.correctBoundaryConditions();" after this code yet it still updates as expected in the time step folder, is this code required?

Thank you.
sur4j is offline   Reply With Quote

Old   February 9, 2014, 14:08
Default
  #6
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,902
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hallo,

You get an error, because you lack a ",", before the "zeroGradient" part.

Kind regards,

Niels
sur4j likes this.
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj 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
Inlet patch problems martyn88 OpenFOAM Running, Solving & CFD 6 April 21, 2017 19:34
T Junction Stability ignacio OpenFOAM Running, Solving & CFD 5 May 2, 2013 11:44
[swak4Foam] Air Conditioned room groovyBC Sebaj OpenFOAM Community Contributions 7 October 31, 2012 15:16
Need help with boundary conditions: open to atmosphere Wolle OpenFOAM 2 April 11, 2011 08:32
Pressure instability with rhoSimpleFoam daniel_mills OpenFOAM Running, Solving & CFD 44 February 17, 2011 18:08


All times are GMT -4. The time now is 06:34.