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

scalarCodedSource Not Implemented Error in OpenFOAM for Enthalpy Field

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By olesen
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 23, 2024, 07:52
Default scalarCodedSource Not Implemented Error in OpenFOAM for Enthalpy Field
  #1
New Member
 
mjavrincon's Avatar
 
Mario Javier Rincón
Join Date: Dec 2020
Location: Denmark
Posts: 9
Rep Power: 5
mjavrincon is on a distinguished road
Hi everyone,

I'm trying to set up a custom source term for the enthalpy field h in my OpenFOAM-v2212 simulation with buoyantSimpleFoam and using the scalarCodedSource functionality within fvOptions. To troubleshoot, I created an fvOptions file with no custom code, just the basic structure. However, I am consistently encountering the following error:

Code:
--> FOAM FATAL ERROR: (openfoam-2212 patch=230110)
Not implemented

    From virtual void Foam::fv::energySourceFvOptionscalarSource::addSup(const volScalarField&, Foam::fvMatrix<double>&, Foam::label)
    in file codedFvOptionTemplate.C at line 178.
Here's the dummy fvOptions file I'm using:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2212                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvOptions;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

codedSource
{
    type            scalarCodedSource;
    selectionMode   all;
    active          true;
    fields          ( h );
    name            exampleCodedSource;

    codeInclude
    #{
        // Empty block
    #};

    codeCorrect
    #{
        // Empty block
    #};

    codeConstrain
    #{
        // Empty block
    #};

    codeAddSup
    #{
        // Empty block
    #};
}

// ************************************************************************* //
Even with this minimal setup that doesn't include any operational code, I am still encountering the "not implemented" error. It seems like the addSup function might not be fully implemented for scalarCodedSource.

Has anyone experienced a similar issue or could provide guidance on how to correctly implement a custom source term for the enthalpy field in OpenFOAM? Any insights or examples would be greatly appreciated!

Thank you!
mjavrincon is offline   Reply With Quote

Old   May 23, 2024, 08:00
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by mjavrincon View Post
Hi everyone,

I'm trying to set up a custom source term for the enthalpy field h in my OpenFOAM-v2212 simulation with buoyantSimpleFoam and using the scalarCodedSource functionality within fvOptions. To troubleshoot, I created an fvOptions file with no custom code, just the basic structure. However, I am consistently encountering the following error:

There is indeed a bit of confusion there. As well as codeAddSup there is also a coddAddSupRho too. It looks like this is where your "not implemented" is coming from.
Unfortunately no way to template and define just a single code block for compressible/incompressible, thus the two different code chunks are needed.
ancolli and Goatow like this.
olesen is offline   Reply With Quote

Old   June 3, 2024, 17:35
Default
  #3
New Member
 
mjavrincon's Avatar
 
Mario Javier Rincón
Join Date: Dec 2020
Location: Denmark
Posts: 9
Rep Power: 5
mjavrincon is on a distinguished road
Thanks a lot That was actually what I needed.

It seems like you know quite a bit about coded source terms. Perhaps you can help me with another problem I have encountered: I am trying to retrieve the value of Cp in each cell and calculate its mean, but I cannot retrieve this data from the thermophysical properties. So far, this is what I have achieved (with errors):

Code:
enthalpySource
{
    type            scalarCodedSource;
    selectionMode   all;
    active          true;
    fields          ( h );  // Applying the source term to the temperature field
    name            enthalpySource;

    codeInclude
    #{
        #include "fvCFD.H"
        #include "$FOAM_SRC/thermophysicalModels/basic/basicThermo/basicThermo.H"
    #};

    codeCorrect
    #{
        // Ensure this block is present but empty
    #};

    codeConstrain
    #{
        // Ensure this block is present but empty
    #};

    codeAddSupRho
    #{
        const scalar temperatureTarget = 323.15;  // Target temperature provided by the user in Kelvin

        // Get the temperature and enthalpy fields
        const volScalarField& T = mesh().lookupObject<volScalarField>("T");
        const volScalarField& h = mesh().lookupObject<volScalarField>("h");

        const scalarField& V = mesh_.V();

        scalarField& heSource = eqn.source();

        // Calculate the volumetric mean value of temperature
        scalar meanT = 0.0;
        scalar Vtotal = 0.0;

        forAll(T, celli)
        {
            meanT += T[celli] * V[celli];
            Vtotal += V[celli];
        }
        meanT /= Vtotal;

        // Get the specific heat capacity (Cp) for each cell
        const volScalarField& Cp = basicThermo.Cp();  // ERROR ENCOUNTERED

        // Calculate the mean Cp across all cells
        scalar Cp_mean = 0.0;
        scalar Vtotal = 0.0;
        forAll(Cp, celli)
        {
            Cp_mean += Cp[celli] * V[celli];
            Vtotal += V[celli];
        }
        Cp_mean /= Vtotal;       

        const scalar delta_h = Cp_mean * (temperatureTarget - meanT);  // Change in enthalpy
        // Apply the enthalpy source term        
        forAll(h, celli)
        {
            // cell volume specific source
            heSource[celli] += delta_h * V[celli];
        }
    #};

}
I am using buoyantSimpleFoam and I get an error each time I try and get the Cp values. I have tried pretty much everything... Any clues?
mjavrincon is offline   Reply With Quote

Old   June 5, 2024, 08:47
Default
  #4
New Member
 
Join Date: Jun 2024
Posts: 1
Rep Power: 0
zapp.branigan is on a distinguished road
The cell-index is not correct I think.


see problems creating a sink term with scalarCodedSource
zapp.branigan is offline   Reply With Quote

Old   June 7, 2024, 07:46
Default
  #5
New Member
 
mjavrincon's Avatar
 
Mario Javier Rincón
Join Date: Dec 2020
Location: Denmark
Posts: 9
Rep Power: 5
mjavrincon is on a distinguished road
Thank you! You are right, the cellIDs were wrong. Now is corrected as shown below, however, I am still unable to obtain the Cp values at each cell. Any ideas?

Code:
enthalpySource
{
    type            scalarCodedSource;
    selectionMode   all;
    active          false;
    fields          ( h );  // Applying the source term to the enthalpy field
    name            enthalpySource;

    codeInclude
    #{
        #include "fvCFD.H"
        #include "$FOAM_SRC/thermophysicalModels/basic/basicThermo/basicThermo.H"
    #};

    codeCorrect
    #{
        // Ensure this block is present but empty
    #};

    codeConstrain
    #{
        // Ensure this block is present but empty
    #};

    codeAddSupRho
    #{
        const scalar temperatureTarget = 323.15;  // Target temperature provided by the user in Kelvin

        // Get the temperature, enthalpy, and static pressure fields
        const volScalarField& T = mesh().lookupObject<volScalarField>("T");
        const volScalarField& h = mesh().lookupObject<volScalarField>("h");

        // Get the mesh volume and cell IDs
        const scalarField& V = mesh_.V();
        const labelList& cellIDs = cells();

        scalarField& heSource = eqn.source();

        // Calculate the volumetric mean value of temperature
        scalar meanT = 0.0;
        scalar Vtotal = 0.0;

        forAll(T, i)
        {
            label celli = cellIDs[i];

            meanT += T[celli] * V[celli];
            Vtotal += V[celli];
        }
        meanT /= Vtotal;

        // Get the specific heat capacity (Cp) for each cell
        const volScalarField& Cp = basicThermo.Cp();  // ERROR ENCOUNTERED

    #};

}
mjavrincon is offline   Reply With Quote

Old   June 10, 2024, 05:25
Default
  #6
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 802
Blog Entries: 1
Rep Power: 18
dlahaye is on a distinguished road
Not sure.

Cp(), however, is merely a virtual member function of the basisThermo class, see e.g. (depending on the version you are using) L436 of https://www.openfoam.com/documentati...8H_source.html

This implies that the implementation of the Cp() member function is postponed to a child class of the basisThermo parent class.

heThermo is an example of such a child class. See e.g. L372 of https://www.openfoam.com/documentati...8C_source.html

This implies that in your code block you might (emphasis on "might") be required to

1/ extract your thermo object from the object registry (not sure whether thermo object is stored in object registry - should check)

2/ cast your thermo object to a type that has a Cp() member function explicitly defined (most likely the thermo type used in your simulation);

I appreciate learning how it goes.
dlahaye is offline   Reply With Quote

Old   June 10, 2024, 08:21
Default
  #7
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by mjavrincon View Post
Thanks a lot That was actually what I needed.

It seems like you know quite a bit about coded source terms.

Thanks. I really enjoyed that comment (unironically)!
ancolli likes this.
olesen is offline   Reply With Quote

Old   June 27, 2024, 04:58
Default Same issue
  #8
New Member
 
Arunkl
Join Date: Jun 2024
Posts: 7
Rep Power: 2
arunkl is on a distinguished road
I am new to these user defined terms in Openfoam so I am trying to implement the degassing boundary condition using Fvoptions and getting the error of not implemented
can you please help me debug the code
degassing bc.txt


/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 3.0.0 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

degassingMassSource
{
type scalarCodedSource;
active yes;
selectionMode all;

name degassingMassSource;
patches (outlet);
rhoName thermo:rho.air;
alphaName alpha.air;

scalarCodedSourceCoeffs
{
selectionMode all;

fields (thermo:rho.air);

codeInclude
#{
#include "fvm.H"
#};

codeCorrect
#{

#};

codeAddSup
#{
// Get the names of the patches on which to apply the degassing forces
DynamicList<word, 1, 0> patches;
coeffs().lookup("patches") >> patches;

// Get the required fields
const word rhoName = coeffs().lookup("rhoName");
const volScalarField& rhoAir = mesh().lookupObject<volScalarField>(rhoName);
const word alphaName = coeffs().lookup("alphaName");
const volScalarField& alphaAir = mesh().lookupObject<volScalarField>(alphaName);

// Get the timestep
const scalar deltaT = mesh().time().deltaT().value();

// Create degassing mass source coefficient and initialize to zero
volScalarField degassingMassSourceCoeff
(
IOobject
(
"degassingMassSourceCoeff",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh(),
dimensionedScalar("degassingMassSourceCoeff", dimless/dimTime, 0.0)
);

// Compute the degassing mass source coefficient for each cell adjacent to the selected patches
forAll(patches, iPatch)
{
// Get the boundary patch
const fvPatch& patch = mesh().boundary()[patches[iPatch]];

// Loop through each boundary face and compute degassing force coefficient in adjacent cell
forAll(patch, iFace)
{
label iCell = patch.faceCells()[iFace];
degassingMassSourceCoeff[iCell] = -alphaAir[iCell]/deltaT;
}
}

// Add the degassing force term
eqn += fvm::Sp(degassingMassSourceCoeff, rhoAir);
#};

codeSetValue
#{

#};

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

degassingForce
{
type vectorCodedSource;
active yes;
selectionMode all;

name degassingForce;
patches (outlet);
rhoName thermo:rho.air;
alphaName alpha.air;
UName U.air;

vectorCodedSourceCoeffs
{
selectionMode all;

fields (U.air);

codeInclude
#{
#include "fvm.H"
#};

codeCorrect
#{

#};

codeAddSup
#{
// Get the names of the patches on which to apply the degassing forces
DynamicList<word, 1, 0> patches;
coeffs().lookup("patches") >> patches;

// Get the required fields
const word rhoName = coeffs().lookup("rhoName");
const volScalarField& rhoAir = mesh().lookupObject<volScalarField>(rhoName);
const word alphaName = coeffs().lookup("alphaName");
const volScalarField& alphaAir = mesh().lookupObject<volScalarField>(alphaName);
const word UName = coeffs().lookup("UName");
const volVectorField& UAir = mesh().lookupObject<volVectorField>(UName);

// Get the timestep
const scalar deltaT = mesh().time().deltaT().value();

// Create degassing force coefficient and initialize to zero
volScalarField degassingForceCoeff
(
IOobject
(
"degassingForceCoeff",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh(),
dimensionedScalar("degassingForceCoeff", dimDensity/dimTime, 0.0)
);

// Compute the degassing force coefficient for each cell adjacent to the selected patches
forAll(patches, iPatch)
{
// Get the boundary patch
const fvPatch& patch = mesh().boundary()[patches[iPatch]];

// Loop through each boundary face and compute degassing force coefficient in adjacent cell
forAll(patch, iFace)
{
label iCell = patch.faceCells()[iFace];
degassingForceCoeff[iCell] = -rhoAir[iCell]*alphaAir[iCell]/deltaT;
}
}

// Add the degassing force term
eqn += fvm::Sp(degassingForceCoeff, UAir);
#};

codeSetValue
#{

#};

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


// ************************************************** *********************** //




i am also getting varies errors like type conversion and number of variables

thankyou in advance please help me
arunkl is offline   Reply With Quote

Old   June 27, 2024, 05:02
Wink Error message:
  #9
New Member
 
Arunkl
Join Date: Jun 2024
Posts: 7
Rep Power: 2
arunkl is on a distinguished road
PIMPLE: iteration 1
MULES: Solving for alpha.air
MULES: Solving for alpha.air
alpha.air volume fraction = 0.40003 Min(alpha1) = 0.4 Max(alpha1) = 0.5
Using dynamicCode for fvOption::degassingMassSource at line 31 in "/home/arunkl/openFoamFiles/bubbleColumn/constant/fvOptions/degassingMassSource/scalarCodedSourceCoeffs"
Selecting finite volume options type degassingMassSource
Source: degassingMassSource
- selecting all cells
- selected 1875 cell(s) with volume 0.015


--> FOAM FATAL ERROR: (openfoam-2312)
Not implemented

From virtual void Foam::fv::degassingMassSourceFvOptionscalarSource: :addSup(const volScalarField&, Foam::fvMatrix<double>&, Foam::label)
in file /home/arunkl/openFoamFiles/bubbleColumn/constant/fvOptions/degassingMassSource/scalarCodedSourceCoeffs at line 109.

FOAM aborting

[stack trace]
=============
#1 Foam::error::simpleExit(int, bool) in /usr/lib/openfoam/openfoam2312/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so
#2 ? in /usr/lib/openfoam/openfoam2312/platforms/linux64GccDPInt32Opt/lib/libreactingMultiphaseSystem.so
#3 ? in /usr/lib/openfoam/openfoam2312/platforms/linux64GccDPInt32Opt/lib/libreactingMultiphaseSystem.so
#4 Foam:haseSystem::correct() in /usr/lib/openfoam/openfoam2312/platforms/linux64GccDPInt32Opt/lib/libreactingMultiphaseSystem.so
#5 ? in /usr/lib/openfoam/openfoam2312/platforms/linux64GccDPInt32Opt/lib/libreactingTwoPhaseSystem.so
#6 ? in /usr/lib/openfoam/openfoam2312/platforms/linux64GccDPInt32Opt/bin/reactingTwoPhaseEulerFoam
#7 ? in /lib/x86_64-linux-gnu/libc.so.6
#8 __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
#9 ? in /usr/lib/openfoam/openfoam2312/platforms/linux64GccDPInt32Opt/bin/reactingTwoPhaseEulerFoam
=============
Aborted
arunkl is offline   Reply With Quote

Reply

Tags
buoyantsimplefoam, enthalpy, openfoam, scalarcodedsource, source terms


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
Phase Field modeling in OpenFOAM adona058 OpenFOAM Running, Solving & CFD 35 November 16, 2021 01:16
[swak4Foam] swakExpression not writing to log alexfells OpenFOAM Community Contributions 3 March 16, 2020 19:19
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 06:36
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 07:20
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51


All times are GMT -4. The time now is 10:27.