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

internalField issue!!

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 4, 2023, 06:03
Unhappy internalField issue!!
  #1
New Member
 
Eric Segalerba
Join Date: Dec 2021
Location: Italy
Posts: 24
Rep Power: 4
EricS is on a distinguished road
Hello everyone!

I'm trying to solve a problem with a gradient but I can't figure out how to get the value of a field, in this case Temperature, adjacent to a face.
So far I wrote this:


Code:
const scalarField& Tp = 
          patch().lookupPatchField<volScalarField, scalar>("T"); 
const scalarField& Tc = 
          patch().lookupPatchField<volScalarField, scalar>("T").internalField();
const scalarField& deltaInv = patch().deltaCoeffs(); 
const scalarField gradT_ = - (Tp-Tc)*deltaInv;
But if I write the size of Tp and Tc I get different values (namely 2000 and 80000).


I'm sure I'm doing something wrong with the "internalField()" member function, but ... what? Do you have an idea?

Thank you!
EricS is offline   Reply With Quote

Old   September 6, 2023, 19:12
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by EricS View Post
Hello everyone!

I'm trying to solve a problem with a gradient but I can't figure out how to get the value of a field, in this case Temperature, adjacent to a face.
So far I wrote this:


Code:
const scalarField& Tp = 
          patch().lookupPatchField<volScalarField, scalar>("T"); 
const scalarField& Tc = 
          patch().lookupPatchField<volScalarField, scalar>("T").internalField();
const scalarField& deltaInv = patch().deltaCoeffs(); 
const scalarField gradT_ = - (Tp-Tc)*deltaInv;
But if I write the size of Tp and Tc I get different values (namely 2000 and 80000).


I'm sure I'm doing something wrong with the "internalField()" member function, but ... what? Do you have an idea?

Thank you!



I'll take a not-so-wild guess here and bet that your mesh has 8000 cells in it. In which case, the value returned by internalField() is correct. If you actually wanted the values of the internal field immediately next to the patch, that would be a different method call. Instead of providing a quick answer, I'd suggest you take a look at fvPatch.H to see what the first lookupPatchField is doing. After that, you'll probably (hopefully) be motivated to look at fvPatchFIeld.H for which method you actually wanted to use. This is the best way to understand which code to write. I am confident that you will find the answer - please post it when you find it.
olesen is offline   Reply With Quote

Old   October 3, 2023, 05:51
Default
  #3
New Member
 
Eric Segalerba
Join Date: Dec 2021
Location: Italy
Posts: 24
Rep Power: 4
EricS is on a distinguished road
Hi Mark, thank you for your reply and yes, I think I found a not very efficient solution to the problem, but it works! The code I wrote is:
Code:
    // store in "Tp" the field of scalar temperature on the patch
      const scalarField& Tp(patch().lookupPatchField<volScalarField, scalar>("T")); 
                
    // store in "Tc" the field of scalar temperature in the computational domain
      const scalarField& Tc(patch().lookupPatchField<volScalarField, scalar>("T").internalField());         
    //Info << "Size of Tc: " << Tc.size() << endl;
    
    // initialize cell's temperature variable
    scalarField Tcell(Tp.size(), Zero);
        
    // distance from the face center to the cell center on patch's cells
    const scalarField& deltaInv(patch().deltaCoeffs()); 
    
    // separately calculate the homogenization coefficient "lambda_theta"        
    const scalarField Coeff(kF_/kS_*solidThickness_*deltaInv);

    // store in "cells" the labels of the cells adjacent to the face
    const labelList cells(patch().faceCells());
    
    // initialize the counter
    label cellN(0);
    forAll(cells, patchCell) {
        cellN = cells[patchCell];
        Tcell[patchCell] = Tc[cellN];
    }
Its purpose is to work with temperatures on the cells adjacent to a patch. The important part is:
Code:
    
label cellN(0);
    forAll(cells, patchCell) {
        cellN = cells[patchCell];
        Tcell[patchCell] = Tc[cellN];
    }
If anyone has ideas on how to make it more efficient please feel free to tell me how to improve it since now it is quite slow!
EricS is offline   Reply With Quote

Old   October 6, 2023, 04:53
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
If you look at polyPatch.H, you'll see there is a patchInternalList method that returns the values you are looking for.


olesen is offline   Reply With Quote

Reply

Tags
custom bc, 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
internalField condition mchehab2 OpenFOAM Running, Solving & CFD 14 November 10, 2022 13:28
twoPhaseEulerFoam confined plunging jet simulation failed ves OpenFOAM Running, Solving & CFD 2 June 17, 2020 05:08
internalField nonuniform List<vector> and internalField nonuniform List <scalar> Ferdinand OpenFOAM Pre-Processing 1 January 3, 2020 12:20
ill defined primitiveEntry starting at keyword 'value' on line 197 ChangeDictionary Struggle_Achieve OpenFOAM Pre-Processing 2 December 20, 2017 03:58
Convergence issue in natural convection problem chrisf90 FLUENT 5 March 5, 2016 08:30


All times are GMT -4. The time now is 01:17.