mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: dsmcFields fails with scoped field names
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
/*--------------------------------*- C++ -*----------------------------------*\
|
/*--------------------------------*- C++ -*----------------------------------*\
|
||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Version: v2106
|
\\ / O peration | Version: v2112
|
||||||
\\ / A nd | Website: www.openfoam.com
|
\\ / A nd | Website: www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@ -18,6 +18,7 @@ Description
|
|||||||
type dsmcFields;
|
type dsmcFields;
|
||||||
libs ("liblagrangianFunctionObjects.so");
|
libs ("liblagrangianFunctionObjects.so");
|
||||||
|
|
||||||
|
// Names for reference purposes only
|
||||||
fields ( rhoNMean rhoMMean momentumMean linearKEMean internalEMean
|
fields ( rhoNMean rhoMMean momentumMean linearKEMean internalEMean
|
||||||
iDofMean fDMean );
|
iDofMean fDMean );
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2016 OpenCFD Ltd.
|
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -31,6 +31,7 @@ License
|
|||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
#include "dsmcCloud.H"
|
#include "dsmcCloud.H"
|
||||||
#include "constants.H"
|
#include "constants.H"
|
||||||
|
#include "stringListOps.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
using namespace Foam::constant;
|
using namespace Foam::constant;
|
||||||
@ -53,6 +54,37 @@ namespace functionObjects
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
static const word& filteredName
|
||||||
|
(
|
||||||
|
const word& baseName,
|
||||||
|
const wordList& names,
|
||||||
|
const string& scopePrefix
|
||||||
|
)
|
||||||
|
{
|
||||||
|
label idx = names.find(baseName);
|
||||||
|
|
||||||
|
if (idx < 0 && !scopePrefix.empty())
|
||||||
|
{
|
||||||
|
// Take the first matching item
|
||||||
|
idx = firstMatchingString(regExp(scopePrefix + baseName), names);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idx < 0)
|
||||||
|
{
|
||||||
|
return word::null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return names[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::functionObjects::dsmcFields::dsmcFields
|
Foam::functionObjects::dsmcFields::dsmcFields
|
||||||
@ -68,12 +100,6 @@ Foam::functionObjects::dsmcFields::dsmcFields
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::functionObjects::dsmcFields::~dsmcFields()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::dsmcFields::read(const dictionary& dict)
|
bool Foam::functionObjects::dsmcFields::read(const dictionary& dict)
|
||||||
@ -91,40 +117,92 @@ bool Foam::functionObjects::dsmcFields::execute()
|
|||||||
|
|
||||||
bool Foam::functionObjects::dsmcFields::write()
|
bool Foam::functionObjects::dsmcFields::write()
|
||||||
{
|
{
|
||||||
word rhoNMeanName = "rhoNMean";
|
// This is fairly horrible with too many hard-coded names...
|
||||||
word rhoMMeanName = "rhoMMean";
|
|
||||||
word momentumMeanName = "momentumMean";
|
|
||||||
word linearKEMeanName = "linearKEMean";
|
|
||||||
word internalEMeanName = "internalEMean";
|
|
||||||
word iDofMeanName = "iDofMean";
|
|
||||||
word fDMeanName = "fDMean";
|
|
||||||
|
|
||||||
const volScalarField& rhoNMean =
|
// Pre-filter names to obtain 'Mean' vol fields
|
||||||
obr_.lookupObject<volScalarField>(rhoNMeanName);
|
const wordList allMeanNames
|
||||||
|
(
|
||||||
|
obr_.sortedNames
|
||||||
|
(
|
||||||
|
regExp("vol.*Field"), // Any vol field type
|
||||||
|
regExp(".+Mean") // Mean field names
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const volScalarField& rhoMMean =
|
// The separator is often ':', but could be something else.
|
||||||
obr_.lookupObject<volScalarField>(rhoMMeanName);
|
// Replace as first char in [..], so that the regex remains valid,
|
||||||
|
// even if the separator happens to be '-'.
|
||||||
|
|
||||||
const volVectorField& momentumMean =
|
string scopePrefix = ".+[_:]";
|
||||||
obr_.lookupObject<volVectorField>(momentumMeanName);
|
scopePrefix[3] = IOobject::scopeSeparator;
|
||||||
|
|
||||||
const volScalarField& linearKEMean =
|
|
||||||
obr_.lookupObject<volScalarField>(linearKEMeanName);
|
|
||||||
|
|
||||||
const volScalarField& internalEMean =
|
// Find scoped/unscoped field name and do lookup.
|
||||||
obr_.lookupObject<volScalarField>(internalEMeanName);
|
// Short-circuit with message if not found (name or field)
|
||||||
|
|
||||||
const volScalarField& iDofMean =
|
// Note: currently just find a match without and with a scoping prefix
|
||||||
obr_.lookupObject<volScalarField>(iDofMeanName);
|
// but could refine to pick the longest name etc, or after finding
|
||||||
|
// the first matching field, use the same prefix for all subsequent fields
|
||||||
|
|
||||||
const volVectorField& fDMean =
|
#undef doLocalCode
|
||||||
obr_.lookupObject<volVectorField>(fDMeanName);
|
#define doLocalCode(Name, FieldType, Member) \
|
||||||
|
\
|
||||||
|
const FieldType* Member##Ptr = nullptr; \
|
||||||
|
{ \
|
||||||
|
const word& fldName = \
|
||||||
|
filteredName(Name, allMeanNames, scopePrefix); \
|
||||||
|
\
|
||||||
|
if (!fldName.empty()) \
|
||||||
|
{ \
|
||||||
|
Member##Ptr = obr_.cfindObject<FieldType>(fldName); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
if (returnReduce(!Member##Ptr, orOp<bool>())) \
|
||||||
|
{ \
|
||||||
|
Log << type() << ' ' << name() << " : no " << Name \
|
||||||
|
<< " field found - not calculating\n"; \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
/* Define the const reference */ \
|
||||||
|
const FieldType& Member = *Member##Ptr;
|
||||||
|
|
||||||
if (min(mag(rhoNMean)).value() > VSMALL)
|
|
||||||
|
// rhoNMean: always required
|
||||||
|
doLocalCode("rhoNMean", volScalarField, rhoNMean);
|
||||||
|
|
||||||
|
// Also check for division by zero
|
||||||
|
{
|
||||||
|
const scalar minval = min(mag(rhoNMean)).value();
|
||||||
|
|
||||||
|
if (minval <= VSMALL)
|
||||||
|
{
|
||||||
|
Log << type() << ' ' << name()
|
||||||
|
<< " : Small value (" << minval << ") in rhoNMean field"
|
||||||
|
<< " - not calculating to avoid division by zero" << nl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// The other fields
|
||||||
|
|
||||||
|
doLocalCode("rhoMMean", volScalarField, rhoMMean);
|
||||||
|
doLocalCode("momentumMean", volVectorField, momentumMean);
|
||||||
|
doLocalCode("linearKEMean", volScalarField, linearKEMean);
|
||||||
|
doLocalCode("internalEMean", volScalarField, internalEMean);
|
||||||
|
doLocalCode("iDofMean", volScalarField, iDofMean);
|
||||||
|
doLocalCode("fDMean", volVectorField, fDMean);
|
||||||
|
#undef doLocalCode
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Everything seem to be okay - can execute
|
||||||
|
//
|
||||||
{
|
{
|
||||||
Log << "Calculating dsmcFields." << endl;
|
Log << "Calculating dsmcFields." << endl;
|
||||||
|
|
||||||
Log << " Calculating UMean field." << endl;
|
Log << " Calculating UMean field." << nl;
|
||||||
volVectorField UMean
|
volVectorField UMean
|
||||||
(
|
(
|
||||||
IOobject
|
IOobject
|
||||||
@ -207,26 +285,30 @@ bool Foam::functionObjects::dsmcFields::write()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Report
|
||||||
|
|
||||||
Log << " mag(UMean) max/min : "
|
Log << " mag(UMean) max/min : "
|
||||||
<< max(mag(UMean)).value() << " "
|
<< max(mag(UMean)).value() << token::SPACE
|
||||||
<< min(mag(UMean)).value() << nl
|
<< min(mag(UMean)).value() << nl
|
||||||
|
|
||||||
<< " translationalT max/min : "
|
<< " translationalT max/min : "
|
||||||
<< max(translationalT).value() << " "
|
<< max(translationalT).value() << token::SPACE
|
||||||
<< min(translationalT).value() << nl
|
<< min(translationalT).value() << nl
|
||||||
|
|
||||||
<< " internalT max/min : "
|
<< " internalT max/min : "
|
||||||
<< max(internalT).value() << " "
|
<< max(internalT).value() << token::SPACE
|
||||||
<< min(internalT).value() << nl
|
<< min(internalT).value() << nl
|
||||||
|
|
||||||
<< " overallT max/min : "
|
<< " overallT max/min : "
|
||||||
<< max(overallT).value() << " "
|
<< max(overallT).value() << token::SPACE
|
||||||
<< min(overallT).value() << nl
|
<< min(overallT).value() << nl
|
||||||
|
|
||||||
<< " p max/min : "
|
<< " p max/min : "
|
||||||
<< max(p).value() << " "
|
<< max(p).value() << token::SPACE
|
||||||
<< min(p).value() << endl;
|
<< min(p).value() << endl;
|
||||||
|
|
||||||
|
|
||||||
|
// Write
|
||||||
UMean.write();
|
UMean.write();
|
||||||
|
|
||||||
translationalT.write();
|
translationalT.write();
|
||||||
@ -236,21 +318,11 @@ bool Foam::functionObjects::dsmcFields::write()
|
|||||||
overallT.write();
|
overallT.write();
|
||||||
|
|
||||||
p.write();
|
p.write();
|
||||||
|
}
|
||||||
|
|
||||||
Log << "dsmcFields written." << nl << endl;
|
Log << "dsmcFields written." << nl << endl;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Log << "Small value (" << min(mag(rhoNMean))
|
|
||||||
<< ") found in rhoNMean field. "
|
|
||||||
<< "Not calculating dsmcFields to avoid division by zero."
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2020 OpenCFD Ltd.
|
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -66,7 +66,6 @@ SourceFiles
|
|||||||
#define functionObjects_dsmcFields_H
|
#define functionObjects_dsmcFields_H
|
||||||
|
|
||||||
#include "fvMeshFunctionObject.H"
|
#include "fvMeshFunctionObject.H"
|
||||||
#include "Switch.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -84,8 +83,6 @@ class dsmcFields
|
|||||||
public fvMeshFunctionObject
|
public fvMeshFunctionObject
|
||||||
{
|
{
|
||||||
|
|
||||||
//- Switch to send output to Info as well as to file
|
|
||||||
Switch log_;
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- No copy construct
|
//- No copy construct
|
||||||
@ -113,7 +110,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~dsmcFields();
|
virtual ~dsmcFields() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
Reference in New Issue
Block a user