|
[Sponsors] |
Snippet for redefining fixedGradient boundary condition for a patch inside solver |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 6, 2018, 05:54 |
|
#41 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34 |
Try the following:
Code:
const polyPatchList& patches = mesh.boundaryMesh(); forAll(patches,patchI) { if (patches[patchI].name() == "midup") { fixedGradientFvPatchScalarField& gradcMinusPatch = refCast<fixedGradientFvPatchScalarField>(cMinus.boundaryField()[patchI]); scalarField& gradcMinusField = gradcMinusPatch.gradient(); forAll(gradcMinusField, faceI) { if (cMinus.boundaryField()[patchI][faceI] < 0) { // Set gradient for this face to zero gradcMinusField[faceI] = 0; } else { // Set gradient for this face to some calculated value; I assume eKbT, Dinv, and currentj are all scalars (not scalarFields) gradcMinusField[faceI] = eKbT*cMinus.boundaryField()[patchI][faceI]*Ue.boundaryField()[patchI].snGrad()[faceI] + Dinv*currentj; } } } } Philip Last edited by bigphil; April 7, 2018 at 11:29. Reason: Fix: changed "forAll(patchI, faceI)" to "forAll(gradcMinusField, faceI)" |
|
April 6, 2018, 13:53 |
|
#42 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Many Thanks Philip
I am working on your proposed snippet and appologize for the caused confusions. I had read that page, but maybe I need to re-read again Regards |
|
April 6, 2018, 16:07 |
|
#43 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Philip,
thanks for your reply. I think the second forAll loop Code:
forAll(patchI, faceI){ if(cMinus.boundaryField()[patchI][faceI] < 0){ gradcMinusField [faceI] = 0; } else{ gradcMinusField [faceI] = eKbT * cMinus.boundaryField()[patchI][faceI] * Ue.boundaryField() [patchI][faceI].snGrad() + Dinv * currentj; //3.13e13; //midup } } Code:
Boundary.H: In function ‘int main(int, char**)’: /home/babak/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/UList.H:394:36: error: request for member ‘size’ in ‘patchI’, which is of non-class type ‘Foam::label {aka int}’ for (Foam::label i=0; i<(list).size(); i++) ^ Boundary.H:18:4: note: in expansion of macro ‘forAll’ forAll(patchI, faceI){ ^ In file included from interFoamEHDIon5New.C:97:0: Boundary.H:16:17: warning: unused variable ‘gradcMinusField’ [-Wunused-variable] scalarField& gradcMinusField = gradcMinusPatch.gradient(); ^ In file included from interFoamEHDIon5New.C:77:0: /home/babak/OpenFOAM/OpenFOAM-2.1.x/src/finiteVolume/lnInclude/readTimeControls.H:38:8: warning: unused variable ‘maxDeltaT’ [-Wunused-variable] scalar maxDeltaT = ^ make: *** [Make/linux64GccDPOpt/interFoamEHDIon5New.o] Error 1 |
|
April 7, 2018, 11:33 |
|
#44 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34 |
Sorry, "forAll(patchI, faceI)" should have been "forAll(gradcMinusField, faceI)": I have editted this in my previous post.
Also, for your second error, please be careful, you have written: Code:
else { gradcMinusField [faceI] = eKbT*cMinus.boundaryField()[patchI][faceI]*Ue.boundaryField()[patchI][faceI].snGrad() + Dinv * currentj; } Code:
else { gradcMinusField[faceI] = eKbT*cMinus.boundaryField()[patchI][faceI]*Ue.boundaryField()[patchI].snGrad()[faceI] + Dinv*currentj; } |
|
April 7, 2018, 11:38 |
|
#45 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34 |
Actually, as "snGrad()" constructs and returns the full patch field, it will be more efficient to store the snGrad as follows:
Code:
const polyPatchList& patches = mesh.boundaryMesh(); forAll(patches,patchI) { if (patches[patchI].name() == "midup") { fixedGradientFvPatchScalarField& gradcMinusPatch = refCast<fixedGradientFvPatchScalarField>(cMinus.boundaryField()[patchI]); scalarField& gradcMinusField = gradcMinusPatch.gradient(); const scalarField UeSnGrad = Ue.boundaryField()[patchI].snGrad(); forAll(gradcMinusField, faceI) { if (cMinus.boundaryField()[patchI][faceI] < 0) { // Set gradient for this face to zero gradcMinusField[faceI] = 0; } else { // Set gradient for this face to some calculated value; I assume eKbT, Dinv, and currentj are all scalars (not scalarFields) gradcMinusField[faceI] = eKbT*cMinus.boundaryField()[patchI][faceI]*UeSnGrad[faceI] + Dinv*currentj; } } } } |
|
April 7, 2018, 17:48 |
|
#46 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Thank you philip for the comments.
I understood the points you raised in the snippet. The code compiles successfully. I am running my cases in parallel. Do I need to add reduce function after the last line of each section (after gradcMinusField=.. and gradcPlusField=.. lines) to make sure that the master processor gets the correct value?? sth like this: Code:
reduce(gradcMinusField = maxOp<scalar>()); Last edited by babakflame; April 8, 2018 at 01:02. |
|
April 9, 2018, 06:13 |
|
#47 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34 |
Without seeing the rest of your code, I cannot say whether you need to explicitly perform a parallel sync; however, from looking at your code snippet, the only terms that might need it are those you have defined before the code snippet e.g. eKbT, Dinv, currentj.
How do you calculate these terms? |
|
April 9, 2018, 14:19 |
|
#48 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Philip,
These terms are all constant scalars (eKbT, Dinv) or constant outward vector (currentj) with known values given in the case folder (defined this way in createFields.H file) Regards Last edited by babakflame; April 9, 2018 at 16:01. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem with cyclic boundaries in Openfoam 1.5 | fs82 | OpenFOAM | 37 | November 29, 2024 11:15 |
Wind turbine simulation | Saturn | CFX | 60 | July 17, 2024 06:45 |
Error finding variable "THERMX" | sunilpatil | CFX | 8 | April 26, 2013 08:00 |
[blockMesh] Cyclic BC's: Possible face ordering problem? (Channel flow) | sega | OpenFOAM Meshing & Mesh Conversion | 3 | September 28, 2010 13:46 |
[Gmsh] Import gmsh msh to Foam | adorean | OpenFOAM Meshing & Mesh Conversion | 24 | April 27, 2005 09:19 |