View Issue Details

IDProjectCategoryView StatusLast Update
0003953OpenFOAMPatchpublic2023-01-26 08:58
Reportertniemi Assigned Towill  
PrioritynormalSeverityminorReproducibilitysometimes
Status resolvedResolutionfixed 
Product Versiondev 
Fixed in Versiondev 
Summary0003953: Fixes for lagrangian parcel liquid models
DescriptionI have attached a patch, which fixes a couple of issues:

1. The generic "liquid" liquid does not currently work if used with steady tracking. The problem is that clouds are repeatedly cloned and restored when doing steady tracking and the clone-function in liquid.H calls the default constructor, which in turn calls default constructors of autoPtr. These destroy the contents of the original autoPtrs, which then can't be restored.

The patch adds a copy-constructor to liquid, which calls "clone"-functions.

Also, when searching the lagrangian codebase for examples of other clone-functions/copy-constructors, I noticed that the scaledForce-model has and incorrect copy constructor, which uses nullPtr. The patch includes a fix for that.

2. The second issue is that the list of carrierIds is not re-sized in phaseProperties reorder-function. This creates out-of-bounds bugs in several places when looping over all liquids and trying to use corresponding carrierId. The bug can be fixed by also re-sizing the carrierIds.

Steps To ReproduceTo reproduce all issues, I have added modified verticalChannelSteady, where H2O has been replaced with a custom liquid specification, air is added as a second liquid and drag is replaced by scaled drag. By default one gets

--> FOAM FATAL ERROR:
object of type N4Foam9Function1IdEE is not allocated

after the first cloud update due to the liquid cloning bug. The other two bugs cause a crash during the second update.

The "liquid" air specification is just a dummy to trigger the bug without having to add species to the test case. In real cases the bug happens if one has multiple clouds with different liquids and not all clouds have all liquids specified under their singleMixtureFractionCoeffs such that the resizing is needed.
TagsNo tags attached.

Activities

tniemi

2023-01-25 08:58

reporter  

patch.diff (3,019 bytes)   
diff --git a/src/lagrangian/parcel/phaseProperties/phaseProperties/phaseProperties.C b/src/lagrangian/parcel/phaseProperties/phaseProperties/phaseProperties.C
index 146595dbf4..b2fd9da731 100644
--- a/src/lagrangian/parcel/phaseProperties/phaseProperties/phaseProperties.C
+++ b/src/lagrangian/parcel/phaseProperties/phaseProperties/phaseProperties.C
@@ -71,6 +71,7 @@ void Foam::phaseProperties::reorder(const wordList& specieNames)
     {
         Y_.setSize(names_.size());
         Y_ = 0;
+        carrierIds_.setSize(names_.size(), -1);
     }
 
     // Set the mass-fraction for each specie in the list to the corresponding
diff --git a/src/lagrangian/parcel/submodels/Momentum/ParticleForces/Scaled/ScaledForce.C b/src/lagrangian/parcel/submodels/Momentum/ParticleForces/Scaled/ScaledForce.C
index abf329fb75..3090c7c142 100644
--- a/src/lagrangian/parcel/submodels/Momentum/ParticleForces/Scaled/ScaledForce.C
+++ b/src/lagrangian/parcel/submodels/Momentum/ParticleForces/Scaled/ScaledForce.C
@@ -72,7 +72,7 @@ Foam::ScaledForce<CloudType>::ScaledForce
 )
 :
     ParticleForce<CloudType>(df),
-    model_(nullptr),
+    model_(df.model_().clone().ptr()),
     factor_(1)
 {}
 
diff --git a/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquid/liquid.C b/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquid/liquid.C
index c1f6efd12d..b23c16e396 100644
--- a/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquid/liquid.C
+++ b/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquid/liquid.C
@@ -83,6 +83,27 @@ Foam::liquid::liquid(const dictionary& dict)
 {}
 
 
+Foam::liquid::liquid(const liquid& lm)
+:
+    liquidProperties(lm),
+    rho_(lm.rho_().clone().ptr()),
+    pv_(lm.pv_().clone().ptr()),
+    hl_(lm.hl_().clone().ptr()),
+    Cp_(lm.Cp_().clone().ptr()),
+    h_(lm.h_().clone().ptr()),
+    Cpg_(lm.Cpg_().clone().ptr()),
+    B_(lm.B_().clone().ptr()),
+    mu_(lm.mu_().clone().ptr()),
+    mug_(lm.mug_().clone().ptr()),
+    kappa_(lm.kappa_().clone().ptr()),
+    kappag_(lm.kappag_().clone().ptr()),
+    sigma_(lm.sigma_().clone().ptr()),
+    D_(lm.D_().clone().ptr()),
+    Hf_(lm.Hf_)
+{}
+
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void Foam::liquid::write(Ostream& os) const
diff --git a/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquid/liquid.H b/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquid/liquid.H
index eb089a480f..cfdc4887bc 100644
--- a/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquid/liquid.H
+++ b/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquid/liquid.H
@@ -94,6 +94,9 @@ public:
         //- Construct from dictionary
         liquid(const dictionary& dict);
 
+        //- Copy constructor
+        liquid(const liquid& lm);
+
         //- Construct and return clone
         virtual autoPtr<liquidProperties> clone() const
         {
patch.diff (3,019 bytes)   

will

2023-01-26 08:58

manager   ~0012939

Yes, this stuff comes up occasionally. Not everything has been tested with cloud clone/restore, and not everything has had copy construction implemented thoroughly. Thanks for the patch. Applied here:

https://github.com/OpenFOAM/OpenFOAM-dev/commit/64ce9b2e2563e4be0e38a7f1795d479cb61910f9

Issue History

Date Modified Username Field Change
2023-01-25 08:58 tniemi New Issue
2023-01-25 08:58 tniemi File Added: patch.diff
2023-01-25 08:58 tniemi File Added: verticalChannelSteady.tar.gz
2023-01-26 08:58 will Assigned To => will
2023-01-26 08:58 will Status new => resolved
2023-01-26 08:58 will Resolution open => fixed
2023-01-26 08:58 will Fixed in Version => dev
2023-01-26 08:58 will Note Added: 0012939