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

problems creating a sink term with scalarCodedSource

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By alexeym
  • 1 Post By alexeym

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 6, 2018, 22:32
Default problems creating a sink term with scalarCodedSource
  #1
New Member
 
Stephen Waite
Join Date: May 2013
Location: Auckland, New Zealand
Posts: 29
Rep Power: 13
Stephen Waite is on a distinguished road
Hi guys,


I am tyring to create a sink term that will remove some amount of a passive scalar depending on the amount of said scalar within the cell.


So I thought I would start of with the scalarCodedSource function within fvOptions. I have an example from online of this working (attached as buoyantPimpleFoam).


So I added a simple passive transport equation to a Piso solver for a volScalarField psi. This works fine for a scalarSemiImplicitSource, but when I change this to a scalarCodedSource (both options are in passiveScalarPisoFOAM attachment, along with the make files for the solver, works for OF 4.1 and 5), I start getting the following error.



Code:
Courant Number mean: 0 max: 0
smoothSolver:  Solving for Ux, Initial residual = 0, Final residual = 0, No Iterations 0
smoothSolver:  Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
GAMG:  Solving for p, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 0, global = 0, cumulative = 0
GAMG:  Solving for p, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 0, global = 0, cumulative = 0
Using dynamicCode for fvOption:: sourceTime at line 51 in "/hpc_ntot/swai013/PostDoc/SimulationWork/passiveScalarPisoFOAM/Example/square/constant/fvOptions.psiSource.scalarCodedSourceCoeffs"
Creating new library in "dynamicCode/sourceTime/platforms/linux64GccDPInt32Opt/lib/libsourceTime_f2075c0c6387b361c5451a93d1f438c9885adef6.so"
Invoking "wmake -s libso /hpc_ntot/swai013/PostDoc/SimulationWork/passiveScalarPisoFOAM/Example/square/dynamicCode/sourceTime"
wmake libso /hpc_ntot/swai013/PostDoc/SimulationWork/passiveScalarPisoFOAM/Example/square/dynamicCode/sourceTime
    ln: ./lnInclude
    wmkdep: codedFvOptionTemplate.C
    Ctoo: codedFvOptionTemplate.C
/hpc_ntot/swai013/PostDoc/SimulationWork/passiveScalarPisoFOAM/Example/square/constant/fvOptions.psiSource.scalarCodedSourceCoeffs: In member function ‘virtual void Foam::fv::sourceTimeFvOptionscalarSource::addSup(Foam::fvMatrix<double>&, Foam::label)’:
/hpc_ntot/swai013/PostDoc/SimulationWork/passiveScalarPisoFOAM/Example/square/constant/fvOptions.psiSource.scalarCodedSourceCoeffs:73:18: error: passing ‘const scalarField {aka const Foam::Field<double>}’ as ‘this’ argument of ‘void Foam::Field<Type>::operator-=(const Type&) [with Type = double]’ discards qualifiers [-fpermissive]
/hpc_ntot/swai013/PostDoc/SimulationWork/passiveScalarPisoFOAM/Example/square/constant/fvOptions.psiSource.scalarCodedSourceCoeffs: In member function ‘virtual void Foam::fv::sourceTimeFvOptionscalarSource::addSup(const volScalarField&, Foam::fvMatrix<double>&, Foam::label)’:
/hpc_ntot/swai013/PostDoc/SimulationWork/passiveScalarPisoFOAM/Example/square/constant/fvOptions.psiSource.scalarCodedSourceCoeffs:73:18: error: passing ‘const scalarField {aka const Foam::Field<double>}’ as ‘this’ argument of ‘void Foam::Field<Type>::operator-=(const Type&) [with Type = double]’ discards qualifiers [-fpermissive]
make: *** [Make/linux64GccDPInt32Opt/codedFvOptionTemplate.o] Error 1


--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/sourceTime/platforms/linux64GccDPInt32Opt/lib/libsourceTime_f2075c0c6387b361c5451a93d1f438c9885adef6.so"


file: /hpc_ntot/swai013/PostDoc/SimulationWork/passiveScalarPisoFOAM/Example/square/constant/fvOptions.psiSource.scalarCodedSourceCoeffs from line 51 to line 82.

    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.

FOAM exiting
So the problem seems to be that it doesn’t like to take the volScalarField psi, which is strange because again scalarSemiImplicitSource is happy to use it.

Going back to the working case, the field used (h) is maybe a scalarField, not a volScalarField (I found it pretty tough going understanding the solver and where it actually creates h, but it looks like it is created in heThermo.C), and so that's the only difference I can think of.


Hopefully this is just a simple fix because of my poor coding skills, if anyone knows how to fix this, or knows of a better way to add in a sink term, that would be great!


Cheers
Stephen
Attached Files
File Type: zip buoyantPimpleFoam.zip (127.4 KB, 27 views)
File Type: zip passiveScalarPisoFOAM.zip (12.4 KB, 27 views)
Stephen Waite is offline   Reply With Quote

Old   June 7, 2018, 03:40
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

const specifier is, in general, for values you do not want to change. So this

Code:
const scalarField& psiS = eqn.source();
psiS -= sqr(time.value());
is not very reasonable. In fact, compiler error message tells you about your logic flaw:

Code:
error: passing ‘const scalarField {aka const Foam::Field<double>}’ as ‘this’ argument of ‘void Foam::Field<Type>::operator-=(const Type&)
Just remove const before scalarField.
Stephen Waite likes this.
alexeym is offline   Reply With Quote

Old   June 7, 2018, 05:35
Default
  #3
New Member
 
Stephen Waite
Join Date: May 2013
Location: Auckland, New Zealand
Posts: 29
Rep Power: 13
Stephen Waite is on a distinguished road
Fantastic that fixed that issue, although I don't understand why it could be a const field for the example case, but not for mine (although I'm happy to accept that it is).


I dont know if you are familiar with this fvOptions...option but it looks like eqn.source() is grabbing the rhs vector for the whole domain, not just the selectionMode. Which is fine, but when I try and just apply source values to the cellZone


Code:
codeAddSup
        #{
            //const Time& time = mesh().time();
            //const scalarField& V = mesh_.V();
            label cellZoneID = mesh_.cellZones().findZoneID("scalarBlob");
            const labelList& cells = mesh_.cellZones()[cellZoneID];
            scalarField& psiS = eqn.source();
            forAll(cells, cellI)            
            {
              psiS[cellI] -= 0.0001;   
            }  
        #};

It sort of does something, it applies to cells at the bottom of the domain, not in the cellZone


Any thoughts?

Thanks for your help
Stephen Waite is offline   Reply With Quote

Old   June 7, 2018, 06:16
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

In example case const scalarField is volume of the mesh:

Code:
const scalarField& V = mesh_.V();
equation source is non-constant reference:

Code:
scalarField& heSource = eqn.source();
Your second problem has almost nothing to do with fvOptions. In this cycle:

Code:
forAll(cells, cellI)            
{
  psiS[cellI] -= 0.0001;   
}
cellI is just counter, which goes from 0 to a size of cells list (so, it seems, numbering of cells in your mesh starts from bottom). You need real cell IDs, if you would like to add source in cell zone, to get them use cells list:

Code:
forAll(cells, i)
{
  const label cellIdx = cells[i];
  psiS[cellIdx] -= 0.0001;
}
Stephen Waite likes this.
alexeym is offline   Reply With Quote

Old   June 7, 2018, 06:26
Default
  #5
New Member
 
Stephen Waite
Join Date: May 2013
Location: Auckland, New Zealand
Posts: 29
Rep Power: 13
Stephen Waite is on a distinguished road
Haha dam I realised the cellI mistake when I was on the bus and was hoping to get home and change the post before you saw it!!

And you are absolutely right about the scalarField I cant even copy and paste properly I cant believe I didnt notice that. I have spent the better part of the day trying to figure that out.

Thanks again for your help your a life saver!

Cheers
Stephen
Stephen Waite is offline   Reply With Quote

Reply

Tags
passivescalar, scalarcodedsource

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
ATTENTION! Reliability problems in CFX 5.7 Joseph CFX 14 April 20, 2010 15:45
heat transfer problems of a heat sink tina FLUENT 2 August 13, 2008 06:11
Really big problems when creating own materials da Jop FLUENT 0 June 28, 2007 11:15
Problems with SUPG body force term FEM question Main CFD Forum 0 January 21, 2006 17:51
source term problems!!! Christian FLUENT 0 June 10, 2003 10:33


All times are GMT -4. The time now is 22:43.