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

boundary condition that depends on another field

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 23, 2019, 18:46
Default boundary condition that depends on another field
  #1
New Member
 
Join Date: Mar 2019
Posts: 8
Rep Power: 7
gryphaea1635 is on a distinguished road
Hi everyone,

I have two volScalarFields, theta, and alpha.CO2. I want alpha.CO2 at a wall to have a value that depends on the value of theta at the wall.

I've set theta as 0.5 everywhere at the boundary in the solver file at the end of the while loop:

Code:
...
while(pimple.correct())
{
     #include "pEqn.H"
}

if (pimple.turbCorr())
{
     turbulence.correct();
}
}

//End of while(pimple.loop())
//Set theta as 0.5 on the boundary

forAll(mesh.boundary(), patchID){
     forAll (mesh.boundary()[patchID],facei)
     {
          theta.boundaryFieldRef()[patchID][facei]=0.5;
     }
}

runTime.write();

Info<< "ExecutionTime = "
     << runTime.elapsedCpuTime()
     ...
Then, I'm using the boundary condition to try to set alpha.CO2 to 1 at the boundary, by adding 0.5 to the value of theta (0.5):

Code:
walls                                                                           
{                                                                                      
        type codedFixedValue; 
        value uniform 0;                                                          
        name wallAdsorption;                                                                
        code    #{                                                            
           const fvPatch& boundaryPatch = patch();                                             
           const fvBoundaryMesh& boundaryMesh = boundaryPatch.boundaryMesh();
           const fvMesh& mesh = boundaryMesh.mesh();                                           
           const vectorField& Cf = boundaryPatch.Cf();
           scalarField& field = *this;
           field=patchInternalField();                                                         
           const volScalarField& theta = mesh.lookupObject<volScalarField>("theta");
            forAll(Cf, faceI){
                        field[faceI]=0.5+theta[faceI];
                }
    #};

        }
Yet after running the solver, the the boundary and plotting their values at the boundary with paraview, both alpha.CO2 and theta seem to have a value of 0.5 at the wall. Is there something I'm doing wrong?

Thanks!
gryphaea1635 is offline   Reply With Quote

Old   November 25, 2019, 03:38
Default
  #2
Member
 
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7
raumpolizei is on a distinguished road
Short answer: Issue seems to be your codedFixedValue code. You are accessing your volScalarField with a faceid and this will get you the cell value with the id faceid. The solution to that problem is already there (in your first code snippet. There, the boundary faces, no cells, are accessed correctly). Something like that could work:
Code:
const label patchid = mesh.boundaryField().findPatchID(this->name()); // could work, not sure though

const volScalarField& theta(mesh.lookupObject<volScalarField>("theta"));
const auto& thetaPatchField = theta.boundaryField()[patchid];

forAll(field, facei) // face loop

{
    field[facei] = 0.5 + thetaPatchField[i];

}
Cheers, RP
raumpolizei is offline   Reply With Quote

Old   November 25, 2019, 14:13
Default
  #3
New Member
 
Join Date: Mar 2019
Posts: 8
Rep Power: 7
gryphaea1635 is on a distinguished road
Thanks for the response! Unfortunately, I'm still having some issues.

I put your code into alpha.CO2:
Code:
const fvPatch& boundaryPatch = patch();
                const fvBoundaryMesh& boundaryMesh = boundaryPatch.boundaryMesh();
                const fvMesh& mesh = boundaryMesh.mesh();
                const vectorField& Cf = boundaryPatch.Cf();                                                                             scalarField& field = *this;                                                                                             field=patchInternalField();
                const label patchid = mesh.boundaryField().findPatchID(this->name());
                const volScalarField& theta((mesh.lookupObject<volScalarField>("theta")));
                const auto& thetaPatchField = theta.boundaryField()[patchid];
                forAll(field, facei) {                                                                                                                               
                         field[facei] = 0.5+thetaPatchField[i];
                }
However, after running the code, I got an error that said:
Code:
error: 'const class Foam::fvMesh' has no member named 'boundaryField'
error: 'class Foam::wallAdsorptionFixedValueFvPatchScalarField' has no member named 'name'
error: 'i' was not declared in this scope
warning: unused variable 'Cf'
If I replace "thetaPatchField[i]" with "thetaPatchField[facei]", the third error message goes away, but since I'm new to OpenFOAM I'm not sure if that would do what I want it to do.
Also, how should I fix the first two error messages? Should I be replacing "name" with something?
gryphaea1635 is offline   Reply With Quote

Old   November 26, 2019, 03:43
Default
  #4
Member
 
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7
raumpolizei is on a distinguished road
Hey,

which version of OF are you using?

Yes, of course this is not compiling, my bad. Just wrote without compiling and thought you would only take the hints out of that pseudo-like code..
Try to use mesh.boundary().findPatchID(this->patch().name()) instead of mesh.boundaryField... and like you suggested 'i' is not defined in your code so replace it with 'facei' in the loop. (+ delete the line with Cf, it looks like it is not used anywhere, see compiler warning message).

Cheers, RP
raumpolizei 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
Wind turbine simulation Saturn CFX 60 July 17, 2024 06:45
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 08:38
Radiation in semi-transparent media with surface-to-surface model? mpeppels CFX 11 August 22, 2019 08:30
External Radiation Boundary Condition (Two sided wall), Grid Interface CFD XUE FLUENT 0 July 8, 2010 07:49
vorticity boundary condition bearcharge Main CFD Forum 0 May 14, 2010 12:32


All times are GMT -4. The time now is 03:20.