CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Replacing Uniform BC with zeroGradient (https://www.cfd-online.com/Forums/openfoam-programming-development/127930-replacing-uniform-bc-zerogradient.html)

sur4j December 26, 2013 08:43

Replacing Uniform BC with zeroGradient
 
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.

ngj January 4, 2014 04:39

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

sur4j January 4, 2014 17:13

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.

ngj January 5, 2014 04:24

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 February 9, 2014 12:25

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.

ngj February 9, 2014 14:08

Hallo,

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

Kind regards,

Niels


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