mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: explicitSource: work on matrix, not matrix.source() level
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -42,84 +42,23 @@ namespace Foam
|
||||
);
|
||||
}
|
||||
|
||||
const Foam::wordList Foam::explicitSource::volumeModeTypeNames_
|
||||
(
|
||||
IStringStream("(absolute specific)")()
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::explicitSource::setSelectedCellsFromPoints()
|
||||
template<> const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::explicitSource::volumeModeType,
|
||||
2
|
||||
>::names[] =
|
||||
{
|
||||
labelHashSet selectedCells;
|
||||
"absolute",
|
||||
"specific"
|
||||
};
|
||||
|
||||
forAll(points_, i)
|
||||
{
|
||||
label cellI = this->mesh().findCell(points_[i]);
|
||||
if (cellI >= 0)
|
||||
{
|
||||
selectedCells.insert(cellI);
|
||||
}
|
||||
|
||||
label globalCellI = returnReduce(cellI, maxOp<label>());
|
||||
|
||||
if (globalCellI < 0)
|
||||
{
|
||||
WarningIn("explicitSource::setSelectedCellsFromPoints()")
|
||||
<< "Unable to find owner cell for point " << points_[i]
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
this->cells() = selectedCells.toc();
|
||||
}
|
||||
const Foam::NamedEnum<Foam::explicitSource::volumeModeType, 2>
|
||||
Foam::explicitSource::volumeModeTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::explicitSource::volumeModeType
|
||||
Foam::explicitSource::wordToVolumeModeType
|
||||
(
|
||||
const word& vmtName
|
||||
) const
|
||||
{
|
||||
forAll(volumeModeTypeNames_, i)
|
||||
{
|
||||
if (vmtName == volumeModeTypeNames_[i])
|
||||
{
|
||||
return volumeModeType(i);
|
||||
}
|
||||
}
|
||||
|
||||
FatalErrorIn
|
||||
(
|
||||
"explicitSource<Type>::volumeModeType"
|
||||
"explicitSource<Type>::wordToVolumeModeType(const word&)"
|
||||
) << "Unknown volumeMode type " << vmtName
|
||||
<< ". Valid volumeMode types are:" << nl << volumeModeTypeNames_
|
||||
<< exit(FatalError);
|
||||
|
||||
return volumeModeType(0);
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::explicitSource::volumeModeTypeToWord
|
||||
(
|
||||
const volumeModeType& vmtType
|
||||
) const
|
||||
{
|
||||
if (vmtType > volumeModeTypeNames_.size())
|
||||
{
|
||||
return "UNKNOWN";
|
||||
}
|
||||
else
|
||||
{
|
||||
return volumeModeTypeNames_[vmtType];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::explicitSource::setFieldData(const dictionary& dict)
|
||||
{
|
||||
scalarFields_.clear();
|
||||
@ -170,83 +109,22 @@ Foam::explicitSource::explicitSource
|
||||
)
|
||||
:
|
||||
basicSource(name, dict, mesh),
|
||||
scalarFields_(0, *this),
|
||||
vectorFields_(0, *this),
|
||||
dict_(dict.subDict(typeName + "Coeffs")),
|
||||
volumeMode_(wordToVolumeModeType(dict_.lookup("volumeMode"))),
|
||||
points_(),
|
||||
volSource_(this->cells().size(), 1.0)
|
||||
volumeMode_(volumeModeTypeNames_.read(dict_.lookup("volumeMode")))
|
||||
{
|
||||
setFieldData(dict_.subDict("fieldData"));
|
||||
|
||||
// Set points if selectionMode is smPoints
|
||||
if (this->selectionMode() == smPoints)
|
||||
{
|
||||
dict_.lookup("points") >> points_;
|
||||
setSelectedCellsFromPoints();
|
||||
volSource_.setSize(points_.size(), 1.0);
|
||||
}
|
||||
|
||||
const labelList& cellList = this->cells();
|
||||
scalar V = 0.0;
|
||||
if (volumeMode_ == vmAbsolute)
|
||||
{
|
||||
forAll(cellList, cellI)
|
||||
{
|
||||
volSource_[cellI] = mesh.V()[cellList[cellI]];
|
||||
V += volSource_[cellI];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
forAll(cellList, cellI)
|
||||
{
|
||||
V += mesh.V()[cellList[cellI]];
|
||||
}
|
||||
}
|
||||
|
||||
reduce(V, sumOp<scalar>());
|
||||
|
||||
Info<< "- selected " << returnReduce(cellList.size(), sumOp<label>())
|
||||
<< " cell(s) with Volume: " << V << " in time activated sources "
|
||||
<< endl;
|
||||
}
|
||||
|
||||
|
||||
void Foam::explicitSource::addSu(fvMatrix<scalar>& Eqn)
|
||||
{
|
||||
Field<scalar>& source = Eqn.source();
|
||||
scalar data = scalarFields_[Eqn.psi().name()];
|
||||
addSources<scalar>(source, data);
|
||||
addSource(Eqn, scalarFields_[Eqn.psi().name()]);
|
||||
}
|
||||
|
||||
|
||||
void Foam::explicitSource::addSu(fvMatrix<vector>& Eqn)
|
||||
{
|
||||
Field<vector>& source = Eqn.source();
|
||||
vector data = vectorFields_[Eqn.psi().name()];
|
||||
addSources<vector>(source, data);
|
||||
}
|
||||
|
||||
|
||||
void Foam::explicitSource::addSu(DimensionedField<scalar, volMesh>& field)
|
||||
{
|
||||
scalar data = scalarFields_[field.name()];
|
||||
addSources<scalar>(field, data);
|
||||
}
|
||||
|
||||
|
||||
void Foam::explicitSource::addSu(DimensionedField<vector, volMesh>& field)
|
||||
{
|
||||
vector data = vectorFields_[field.name()];
|
||||
addSources<vector>(field, data);
|
||||
}
|
||||
|
||||
|
||||
void Foam::explicitSource::addExplicitSources()
|
||||
{
|
||||
scalarFields_.applySources();
|
||||
vectorFields_.applySources();
|
||||
addSource(Eqn, vectorFields_[Eqn.psi().name()]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -70,60 +70,15 @@ class explicitSource
|
||||
:
|
||||
public basicSource
|
||||
{
|
||||
// Private classes
|
||||
|
||||
template<class Type>
|
||||
class fieldList
|
||||
:
|
||||
public HashTable<Type>
|
||||
{
|
||||
|
||||
explicitSource& OwnerPtr_;
|
||||
|
||||
public:
|
||||
|
||||
//- null Constructor
|
||||
fieldList()
|
||||
:
|
||||
HashTable<Type>(0),
|
||||
OwnerPtr_(*reinterpret_cast<explicitSource*>(0))
|
||||
{}
|
||||
|
||||
|
||||
//- Constructor
|
||||
fieldList(label size, explicitSource& ownerPtr)
|
||||
:
|
||||
HashTable<Type>(size),
|
||||
OwnerPtr_(ownerPtr)
|
||||
{}
|
||||
|
||||
|
||||
void applySources()
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh>
|
||||
geometricField;
|
||||
|
||||
forAll(this->toc(), i)
|
||||
{
|
||||
geometricField& field = const_cast<geometricField&>
|
||||
(
|
||||
OwnerPtr_.mesh().template lookupObject<geometricField>
|
||||
(this->toc()[i])
|
||||
);
|
||||
|
||||
Type data = this->operator[](field.name());
|
||||
OwnerPtr_.addSources<Type>(field.internalField(), data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// Private cdata
|
||||
// Private data
|
||||
|
||||
//- List of field types
|
||||
fieldList<scalar> scalarFields_;
|
||||
fieldList<vector> vectorFields_;
|
||||
HashTable<scalar> scalarFields_;
|
||||
HashTable<vector> vectorFields_;
|
||||
|
||||
//- Add source to matrix
|
||||
template<class Type>
|
||||
void addSource(fvMatrix<Type>&, const Type&) const;
|
||||
|
||||
//- Add field names and values to field table for types.
|
||||
template<class Type>
|
||||
@ -132,22 +87,12 @@ private:
|
||||
HashTable<Type>& fields,
|
||||
const wordList& fieldTypes,
|
||||
const wordList& fieldNames,
|
||||
const dictionary& dict_
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Add data to field source
|
||||
template<class Type>
|
||||
void addSources
|
||||
(
|
||||
Field<Type>& fieldSource,
|
||||
Type& data
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// Public data
|
||||
|
||||
//- Enumeration for volume types
|
||||
@ -158,7 +103,7 @@ public:
|
||||
};
|
||||
|
||||
//- Word list of volume mode type names
|
||||
static const wordList volumeModeTypeNames_;
|
||||
static const NamedEnum<volumeModeType, 2> volumeModeTypeNames_;
|
||||
|
||||
|
||||
protected:
|
||||
@ -171,27 +116,12 @@ protected:
|
||||
//- Volume mode
|
||||
volumeModeType volumeMode_;
|
||||
|
||||
//- List of points for "points" selectionMode
|
||||
List<point> points_;
|
||||
|
||||
//- Volume of the explicit source
|
||||
scalarList volSource_;
|
||||
|
||||
|
||||
// Protected functions
|
||||
|
||||
//- Helper function to convert from a word to a volumeModeType
|
||||
volumeModeType wordToVolumeModeType(const word& vtName) const;
|
||||
|
||||
//- Helper function to convert from a volumeModeType to a word
|
||||
word volumeModeTypeToWord(const volumeModeType& vtType) const;
|
||||
|
||||
//- Set the local field data
|
||||
void setFieldData(const dictionary& dict);
|
||||
|
||||
//- Set selected cells when smPoint is used
|
||||
void setSelectedCellsFromPoints();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -246,15 +176,6 @@ public:
|
||||
//-Source term to fvMatrix<scalar>
|
||||
virtual void addSu(fvMatrix<scalar>& UEqn);
|
||||
|
||||
//- Add all explicit source
|
||||
virtual void addExplicitSources();
|
||||
|
||||
//- Add source to scalar field
|
||||
virtual void addSu(DimensionedField<vector, volMesh>& field);
|
||||
|
||||
//- Add source to vector field
|
||||
virtual void addSu(DimensionedField<scalar, volMesh>& field);
|
||||
|
||||
|
||||
// I-O
|
||||
|
||||
|
||||
@ -46,4 +46,6 @@ Foam::explicitSource::points() const
|
||||
{
|
||||
return points_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -32,7 +32,7 @@ void Foam::explicitSource::writeData(Ostream& os) const
|
||||
os << indent << name_ << nl
|
||||
<< indent << token::BEGIN_BLOCK << incrIndent << nl;
|
||||
|
||||
os.writeKeyword("volumeMode") << volumeModeTypeToWord(volumeMode_)
|
||||
os.writeKeyword("volumeMode") << volumeModeTypeNames_[volumeMode_]
|
||||
<< token::END_STATEMENT << nl;
|
||||
|
||||
if (scalarFields_.size() > 0)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -23,17 +23,42 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
void Foam::explicitSource::addSources
|
||||
template <class Type>
|
||||
void Foam::explicitSource::addSource
|
||||
(
|
||||
Field<Type>& fieldSource,
|
||||
Type& data
|
||||
fvMatrix<Type>& Eqn,
|
||||
const Type& sourceData
|
||||
) const
|
||||
{
|
||||
forAll(this->cells(), i)
|
||||
Type data = sourceData;
|
||||
if (volumeMode_ == vmAbsolute)
|
||||
{
|
||||
fieldSource[this->cells()[i]] = data/volSource_[i];
|
||||
// Convert to specific quantity
|
||||
data /= V_;
|
||||
}
|
||||
|
||||
DimensionedField<Type, volMesh> rhs
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"rhs",
|
||||
Eqn.psi().mesh().time().timeName(),
|
||||
Eqn.psi().mesh(),
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
),
|
||||
Eqn.psi().mesh(),
|
||||
dimensioned<Type>
|
||||
(
|
||||
"zero",
|
||||
Eqn.dimensions()/dimVolume,
|
||||
pTraits<Type>::zero
|
||||
)
|
||||
);
|
||||
UIndirectList<Type>(rhs, this->cells()) = data;
|
||||
|
||||
Eqn -= rhs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user