View Issue Details

IDProjectCategoryView StatusLast Update
0001843OpenFOAMBugpublic2015-09-02 15:36
ReporterDanielJ Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSUbuntuOS Version14.10
Summary0001843: Chemkin Reader element balance fails because of round-off error
DescriptionFor complex reactions Chemkin Reader shows an element imbalance for a balanced reaction (I added value of the imbalance to show that it is a round-off error):

"
--> FOAM FATAL ERROR:
Elemental imbalance of 1.110223e-15 in C in reaction
"VOLATILES = 9.1H2^1 + 7.2CH4^1 + 13.6CO^1 + 1.2CO2^1";

 on line 22

    From function chemkinReader::addReaction
    in file chemistryReaders/chemkinReader/chemkinReader.C at line 758.
"

To correct this error the imbalance should probably be checked against sqrt(SMALL).

In my opinion a even better solution would be an additional, optional, input for Chemkin reader: 'imbalanceTolerance' to allow for definition of custom reactions with some imbalances.
TagsNo tags attached.

Activities

henry

2015-09-02 11:59

manager   ~0005312

> To correct this error the imbalance should probably be checked against sqrt(SMALL).

Have you tested this?

> In my opinion a even better solution would be an additional, optional, input for Chemkin reader: 'imbalanceTolerance' to allow for definition of custom reactions with some imbalances.

Can you provide a patch?

DanielJ

2015-09-02 12:34

reporter   ~0005314

The simple option works, but this is a solution for my particular case.

I will prepare a patch with the proposal.

DanielJ

2015-09-02 13:12

reporter  

chemkinReader-imbalance-tolerance.patch (3,369 bytes)   
From abb9c57ffbcbefaab6e2564a84d1a2f569c283f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Jasi=C5=84ski?= <daniel.jasinski@gmail.com>
Date: Wed, 2 Sep 2015 13:58:42 +0200
Subject: [PATCH] chemkinReader imbalance tolerance

---
 .../chemistryReaders/chemkinReader/chemkinReader.C     | 18 ++++++++++++++----
 .../chemistryReaders/chemkinReader/chemkinReader.H     |  4 ++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C
index 701ce73..907a612 100755
--- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C
+++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C
@@ -52,6 +52,8 @@ namespace Foam
 
 /* * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * */
 
+const Foam::scalar Foam::chemkinReader::defImbalanceTol_ = sqrt(SMALL);
+
 const char* Foam::chemkinReader::reactionTypeNames[4] =
 {
     "irreversible",
@@ -753,10 +755,11 @@ void Foam::chemkinReader::addReaction
 
     forAll(nAtoms, i)
     {
-        if (mag(nAtoms[i]) > SMALL)
+        if (mag(nAtoms[i]) > imbalanceTol_)
         {
             FatalErrorIn("chemkinReader::addReaction")
-                << "Elemental imbalance in " << elementNames_[i]
+                << "Elemental imbalance of " << mag(nAtoms[i])
+                << " in " << elementNames_[i]
                 << " in reaction" << nl
                 << reactions_.last() << nl
                 << " on line " << lineNo_-1
@@ -839,7 +842,8 @@ Foam::chemkinReader::chemkinReader
     specieNames_(10),
     speciesTable_(species),
     reactions_(speciesTable_, speciesThermo_),
-    newFormat_(newFormat)
+    newFormat_(newFormat),
+    imbalanceTol_(defImbalanceTol_)
 {
     read(CHEMKINFileName, thermoFileName);
 }
@@ -855,13 +859,19 @@ Foam::chemkinReader::chemkinReader
     specieNames_(10),
     speciesTable_(species),
     reactions_(speciesTable_, speciesThermo_),
-    newFormat_(thermoDict.lookupOrDefault("newFormat", false))
+    newFormat_(thermoDict.lookupOrDefault("newFormat", false)),
+    imbalanceTol_(defImbalanceTol_)
 {
     if (newFormat_)
     {
         Info<< "Reading CHEMKIN thermo data in new file format" << endl;
     }
 
+    if (thermoDict.found("imbalanceTolerance"))
+    {
+        imbalanceTol_ = readScalar(thermoDict.lookup("imbalanceTolerance"));
+    }
+
     fileName chemkinFile(fileName(thermoDict.lookup("CHEMKINFile")).expand());
 
     fileName thermoFile = fileName::null;
diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H
index ad1c50a..9f509ee 100755
--- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H
+++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H
@@ -211,6 +211,10 @@ private:
         //- Flag to indicate that file is in new format
         Switch newFormat_;
 
+        //- Tolerance for element imbalance in a reaction
+        static const scalar defImbalanceTol_;
+        scalar imbalanceTol_;
+
 
     // Private Member Functions
 
-- 
1.9.1

DanielJ

2015-09-02 13:12

reporter  

solid-temperature-report.patch (1,696 bytes)   
From 8e71a0853f63885f5a209f7833c05522f93f3ec0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Jasi=C5=84ski?= <daniel.jasinski@gmail.com>
Date: Wed, 2 Sep 2015 14:07:35 +0200
Subject: [PATCH] solid temperature report

---
 .../chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H     | 3 ++-
 .../solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H         | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H
index d455bb0..d0f13dd 100755
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H
@@ -24,4 +24,5 @@
 
 thermo.correct();
 
-Info<< "Min/max T:" << min(thermo.T()) << ' ' << max(thermo.T()) << endl;
+Info<< "Min/max T:" << min(thermo.T()).value() << ' '
+    << max(thermo.T()).value() << endl;
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H
index 27f1737..49fd39e 100755
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H
@@ -30,7 +30,8 @@ if (finalIter)
 
 thermo.correct();
 
-Info<< "Min/max T:" << min(thermo.T()) << ' ' << max(thermo.T()) << endl;
+Info<< "Min/max T:" << min(thermo.T()).value() << ' '
+    << max(thermo.T()).value() << endl;
 
 if (finalIter)
 {
-- 
1.9.1

solid-temperature-report.patch (1,696 bytes)   

DanielJ

2015-09-02 13:14

reporter   ~0005315

I uploaded the patch, it was tested and works fine.

Additionally I uploaded small patch with corrected solid temperature report in CHT solvers.

henry

2015-09-02 13:17

manager   ~0005316

Thanks for the patches. Could you also provide the complete files as I need to merge the changes into 2.4.x and dev and the patches are unlikely to apply correctly.

DanielJ

2015-09-02 13:26

reporter  

chemkinReader.zip (7,357 bytes)

DanielJ

2015-09-02 13:28

reporter  

chtMultiRegionFoam.zip (1,515 bytes)

DanielJ

2015-09-02 13:29

reporter   ~0005317

Here you are :)

henry

2015-09-02 15:36

manager   ~0005318

Resolved in OpenFOAM-2.4.x: commit 51457432eeff0028f5c97ef1fc87b87760bdb1b4
Resolved in OpenFOAM-dev: commit f00623d40a5eef1cee97314f297647774c504a8e

Issue History

Date Modified Username Field Change
2015-09-02 11:57 DanielJ New Issue
2015-09-02 11:59 henry Note Added: 0005312
2015-09-02 12:34 DanielJ Note Added: 0005314
2015-09-02 13:12 DanielJ File Added: chemkinReader-imbalance-tolerance.patch
2015-09-02 13:12 DanielJ File Added: solid-temperature-report.patch
2015-09-02 13:14 DanielJ Note Added: 0005315
2015-09-02 13:17 henry Note Added: 0005316
2015-09-02 13:26 DanielJ File Added: chemkinReader.zip
2015-09-02 13:28 DanielJ File Added: chtMultiRegionFoam.zip
2015-09-02 13:29 DanielJ Note Added: 0005317
2015-09-02 15:36 henry Note Added: 0005318
2015-09-02 15:36 henry Status new => resolved
2015-09-02 15:36 henry Resolution open => fixed
2015-09-02 15:36 henry Assigned To => henry