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

CodedSource controlled by a different region

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 28, 2020, 20:53
Default CodedSource controlled by a different region
  #1
New Member
 
Alex
Join Date: May 2020
Posts: 2
Rep Power: 0
malydilnar is on a distinguished road
Hey all, ive been stuck at this problem for a while and am looking for your insight. I have a multi region conjugate heat transfer problem where I have a heater generating heat in its own region (Through scalar coded source / semi implicit source). I want to be able to turn the heater on/off based on the temperature read in a cell in a different region. (Thermostat controlling the heater)

The problem is it seems like I can only access the mesh inside the region the fvoptions file lives in for the coded source (The heater). Therefore I cant pull the temperature of a specific cell in a different region to use for my thermostat control.

This is my coded source so far, its really just copied parts from other forum users so far. The thermostat if conditions aren't there yet, because I need to figure out how to get the conditional thermostat into the coded source first.

Code:
test
{
    type          scalarCodedSource;

    active          true;

    name    sourceTime;



    scalarCodedSourceCoeffs
    {
         selectionMode   all;
         
	       fields      (h);

        codeInclude
        #{

        #};

        codeCorrect
        #{
            Pout<< "**codeCorrect**" << endl;
        #};

        codeAddSup
        #{
	          scalar Tvol = 0;
            //const Time& time = mesh().time();
            const volScalarField& Tm = mesh_.lookupObject<volScalarField>("T"); // Look up temperature
            //Tvol = Tm.weightedAverage(mesh_.V()).value();                //averageValue of the volScalarField
            //const fvMesh& help = Tm.mesh().time();
            const vectorField& C = mesh_.C();                    //List of cellcentres
	          const scalarField& V = mesh_.V();
            //const scalarField& num = mesh_.C().size();
            scalarField& hSource = eqn.source();                //defining source
            forAll(C, i)
            {
                //hSource[i] = (Tvol - 310)*2400*V[i] ;
                hSource[i] = (Tm[2] - 310)*2400*V[i] ;
            }

            // Calling the mesh.C().size() method therefore yields the total size of the mesh.
            Pout << V << endl;
            Pout << "***codeAddSup***" << endl;
        #};

        codeSetValue
        #{
            Pout<< "**codeSetValue**" << endl;
        #};

        // Dummy entry. Make dependent on above to trigger recompilation
        code
        #{
            $codeInclude
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }

    sourceTimeCoeffs
    {
         $scalarCodedSourceCoeffs;
    }
}
As far as I can tell, mesh_.() only has access to the values of the mesh inside the region, not the combined mesh.

I have a couple of ideas on how to fix my problem, though I'm not very familiar with c++ so its difficult to really read all the source code and understand what methods I have at my disposal.
  • figure out how to extend mesh_.() to be able to pull temperature from a different region
  • it looks like coded source includes the sampling library, which should allow me to probe values, though again not sure if I can specify a different region to probe

Any input on how to solve my problem would be very appreciated, thanks.
malydilnar is offline   Reply With Quote

Old   August 31, 2020, 23:02
Default I am also stuck with similar problem
  #2
Senior Member
 
KGN
Join Date: Oct 2009
Location: Chennai, India
Posts: 121
Rep Power: 16
mecbe2002 is on a distinguished road
hi,


My problem is also similar to your..


I want to apply MFR at source point. To calculate MFR, pressure drop calculation has to be used, for this i need to get pressure at different locations and calculate MFR and then apply MFR at one of the location.


in fvOptions i can specify only one point where MFR has to be specified.



Did you able to found a way to do this?

Last edited by mecbe2002; September 1, 2020 at 01:45.
mecbe2002 is offline   Reply With Quote

Old   September 8, 2020, 14:27
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
From mesh_ you can access the time database, from there you have access to the various mesh regions.
olesen is online now   Reply With Quote

Old   September 8, 2020, 23:27
Default Let me explain my problem in detail.
  #4
Senior Member
 
KGN
Join Date: Oct 2009
Location: Chennai, India
Posts: 121
Rep Power: 16
mecbe2002 is on a distinguished road



Objective of my work is to replace small diameter pipe (dia <0.5 mm) with source and sink terms i.e. inlet of the pipe will be sink and outlet of the pipe is source.
I have to use pressure drop across the pipe to calculate the mass flow rate; for this i need to get pressure at inlet and exit of the pipe.
  • selection mode - points
  • i have specified inlet and exit of the pipe location
In the below code, inside the "forAll" loop i can access only pressure values of current point in the loop. But i need to get pressure value at some other point for MFR calculation. How to do this?


Code:
 codeAddSup
#{            
     const volScalarField& rhoJet = mesh_.lookupObject<volScalarField>("rho");
     const volVectorField& velJet = mesh_.lookupObject<volVectorField>("v1");
     scalarField& massSource1 = eqn.source();
     const labelList& cellIDs = cells();
            
      forAll(cellIDs, i)
      {
          label cellSource = cellIDs[i];
           
          massSource1[cellSource] += rhoJet[cellSink]*mag(velJet[cellSink])*6.28319*1e-6;               
      }                          
#};
mecbe2002 is offline   Reply With Quote

Old   August 9, 2021, 07:34
Default
  #5
New Member
 
walter white
Join Date: Jul 2021
Posts: 10
Rep Power: 4
lmw354 is on a distinguished road
Did you guys find a solution.
lmw354 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
Error when solving p_rgh bob94 OpenFOAM 0 March 17, 2020 08:12
Problem simulating the temperature rise in a composite material (chtMultiRegionFoam) Adam_K OpenFOAM Running, Solving & CFD 2 March 27, 2019 06:51
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 18:57
[Commercial meshers] Using starToFoam clo OpenFOAM Meshing & Mesh Conversion 33 September 26, 2012 04:04
[Gmsh] Import gmsh msh to Foam adorean OpenFOAM Meshing & Mesh Conversion 24 April 27, 2005 08:19


All times are GMT -4. The time now is 11:24.