mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
- relocated ListAppendEqOp and ListUniqueEqOp to ListOps::appendEqOp
and ListOps::UniqueEqOp, respectively for better code isolation and
documentation of purpose.
- relocated setValues to ListOps::setValue() with many more
alternative selectors possible
- relocated createWithValues to ListOps::createWithValue
for better code isolation. The default initialization value is itself
now a default parameter, which allow for less typing.
Negative indices in the locations to set are now silently ignored,
which makes it possible to use an oldToNew mapping that includes
negative indices.
- additional ListOps::createWithValue taking a single position to set,
available both in copy assign and move assign versions.
Since a negative index is ignored, it is possible to combine with
the output of List::find() etc.
STYLE: changes for PackedList
- code simplication in the PackedList iterators, including dropping
the unused operator() on iterators, which is not available in plain
list versions either.
- improved sizing for PackedBoolList creation from a labelUList.
ENH: additional List constructors, for handling single element list.
- can assist in reducing constructor ambiguity, but can also helps
memory optimization when creating a single element list.
For example,
labelListList labels(one(), identity(mesh.nFaces()));
321 lines
8.3 KiB
C
321 lines
8.3 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
|
\\/ M anipulation |
|
|
-------------------------------------------------------------------------------
|
|
License
|
|
This file is part of OpenFOAM.
|
|
|
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
#include "parLagrangianRedistributor.H"
|
|
#include "Time.H"
|
|
#include "IOobjectList.H"
|
|
#include "mapDistributePolyMesh.H"
|
|
#include "cloud.H"
|
|
#include "CompactIOField.H"
|
|
#include "passivePositionParticleCloud.H"
|
|
|
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
|
|
template<class Container>
|
|
Foam::wordList Foam::parLagrangianRedistributor::filterObjects
|
|
(
|
|
const IOobjectList& objects,
|
|
const wordHashSet& selectedFields
|
|
)
|
|
{
|
|
const word fieldClassName(Container::typeName);
|
|
|
|
// Parallel synchronise
|
|
wordList fieldNames(objects.names(fieldClassName));
|
|
Pstream::combineGather(fieldNames, ListOps::uniqueEqOp<word>());
|
|
Pstream::combineScatter(fieldNames);
|
|
|
|
if (!selectedFields.empty())
|
|
{
|
|
DynamicList<word> selectedNames(fieldNames.size());
|
|
forAll(fieldNames, i)
|
|
{
|
|
if (selectedFields.found(fieldNames[i]))
|
|
{
|
|
selectedNames.append(fieldNames[i]);
|
|
}
|
|
}
|
|
fieldNames.transfer(selectedNames);
|
|
}
|
|
return fieldNames;
|
|
}
|
|
|
|
|
|
template<class Type>
|
|
void Foam::parLagrangianRedistributor::redistributeLagrangianFields
|
|
(
|
|
const mapDistributeBase& map,
|
|
const word& cloudName,
|
|
const IOobjectList& objects,
|
|
const wordHashSet& selectedFields
|
|
) const
|
|
{
|
|
const wordList objectNames
|
|
(
|
|
filterObjects<IOField<Type>>
|
|
(
|
|
objects,
|
|
selectedFields
|
|
)
|
|
);
|
|
|
|
if (objectNames.size())
|
|
{
|
|
const word fieldClassName(IOField<Type>::typeName);
|
|
|
|
Info<< " Redistributing lagrangian "
|
|
<< fieldClassName << "s\n" << endl;
|
|
|
|
forAll(objectNames, i)
|
|
{
|
|
Info<< " " << objectNames[i] << endl;
|
|
|
|
// Read if present
|
|
IOField<Type> field
|
|
(
|
|
IOobject
|
|
(
|
|
objectNames[i],
|
|
srcMesh_.time().timeName(),
|
|
cloud::prefix/cloudName,
|
|
srcMesh_,
|
|
IOobject::READ_IF_PRESENT,
|
|
IOobject::NO_WRITE,
|
|
false
|
|
),
|
|
label(0)
|
|
);
|
|
|
|
map.distribute(field);
|
|
|
|
|
|
if (field.size())
|
|
{
|
|
IOField<Type>
|
|
(
|
|
IOobject
|
|
(
|
|
objectNames[i],
|
|
tgtMesh_.time().timeName(),
|
|
cloud::prefix/cloudName,
|
|
tgtMesh_,
|
|
IOobject::NO_READ,
|
|
IOobject::NO_WRITE,
|
|
false
|
|
),
|
|
xferMove<Field<Type>>(field)
|
|
).write();
|
|
}
|
|
}
|
|
|
|
Info<< endl;
|
|
}
|
|
}
|
|
|
|
|
|
template<class Type>
|
|
void Foam::parLagrangianRedistributor::redistributeLagrangianFieldFields
|
|
(
|
|
const mapDistributeBase& map,
|
|
const word& cloudName,
|
|
const IOobjectList& objects,
|
|
const wordHashSet& selectedFields
|
|
) const
|
|
{
|
|
wordList objectNames
|
|
(
|
|
filterObjects<CompactIOField<Field<Type>, Type>>
|
|
(
|
|
objects,
|
|
selectedFields
|
|
)
|
|
);
|
|
|
|
// Append IOField names
|
|
{
|
|
const wordList ioFieldNames
|
|
(
|
|
filterObjects<IOField<Field<Type>>>
|
|
(
|
|
objects,
|
|
selectedFields
|
|
)
|
|
);
|
|
objectNames.append(ioFieldNames);
|
|
}
|
|
|
|
|
|
if (objectNames.size())
|
|
{
|
|
const word fieldClassName(CompactIOField<Field<Type>, Type>::typeName);
|
|
|
|
Info<< " Redistributing lagrangian "
|
|
<< fieldClassName << "s\n" << endl;
|
|
|
|
forAll(objectNames, i)
|
|
{
|
|
Info<< " " << objectNames[i] << endl;
|
|
|
|
// Read if present
|
|
CompactIOField<Field<Type>, Type> field
|
|
(
|
|
IOobject
|
|
(
|
|
objectNames[i],
|
|
srcMesh_.time().timeName(),
|
|
cloud::prefix/cloudName,
|
|
srcMesh_,
|
|
IOobject::READ_IF_PRESENT,
|
|
IOobject::NO_WRITE,
|
|
false
|
|
),
|
|
label(0)
|
|
);
|
|
|
|
// Distribute
|
|
map.distribute(field);
|
|
|
|
// Write
|
|
if (field.size())
|
|
{
|
|
CompactIOField<Field<Type>, Type>
|
|
(
|
|
IOobject
|
|
(
|
|
objectNames[i],
|
|
tgtMesh_.time().timeName(),
|
|
cloud::prefix/cloudName,
|
|
tgtMesh_,
|
|
IOobject::NO_READ,
|
|
IOobject::NO_WRITE,
|
|
false
|
|
),
|
|
xferMove<Field<Field<Type>>>(field)
|
|
).write();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
template<class Container>
|
|
void Foam::parLagrangianRedistributor::readLagrangianFields
|
|
(
|
|
const passivePositionParticleCloud& cloud,
|
|
const IOobjectList& objects,
|
|
const wordHashSet& selectedFields
|
|
)
|
|
{
|
|
const wordList objectNames
|
|
(
|
|
filterObjects<Container>
|
|
(
|
|
objects,
|
|
selectedFields
|
|
)
|
|
);
|
|
|
|
if (objectNames.size())
|
|
{
|
|
const word fieldClassName(Container::typeName);
|
|
|
|
Info<< " Reading lagrangian "
|
|
<< fieldClassName << "s\n" << endl;
|
|
|
|
forAll(objectNames, i)
|
|
{
|
|
Info<< " " << objectNames[i] << endl;
|
|
|
|
// Read if present
|
|
Container* fieldPtr = new Container
|
|
(
|
|
IOobject
|
|
(
|
|
objectNames[i],
|
|
cloud.time().timeName(),
|
|
cloud,
|
|
IOobject::READ_IF_PRESENT,
|
|
IOobject::NO_WRITE
|
|
),
|
|
label(0)
|
|
);
|
|
|
|
fieldPtr->store();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
template<class Container>
|
|
void Foam::parLagrangianRedistributor::redistributeStoredLagrangianFields
|
|
(
|
|
const mapDistributeBase& map,
|
|
passivePositionParticleCloud& cloud
|
|
) const
|
|
{
|
|
HashTable<Container*> fields
|
|
(
|
|
cloud.lookupClass<Container>()
|
|
);
|
|
|
|
if (fields.size())
|
|
{
|
|
const word fieldClassName(Container::typeName);
|
|
|
|
Info<< " Redistributing lagrangian "
|
|
<< fieldClassName << "s\n" << endl;
|
|
|
|
forAllIter(typename HashTable<Container*>, fields, iter)
|
|
{
|
|
Container& field = *iter();
|
|
|
|
Info<< " " << field.name() << endl;
|
|
|
|
map.distribute(field);
|
|
|
|
if (field.size())
|
|
{
|
|
Container
|
|
(
|
|
IOobject
|
|
(
|
|
field.name(),
|
|
tgtMesh_.time().timeName(),
|
|
cloud::prefix/cloud.name(),
|
|
tgtMesh_,
|
|
IOobject::NO_READ,
|
|
IOobject::NO_WRITE,
|
|
false
|
|
),
|
|
xferMove<Field<typename Container::value_type>>(field)
|
|
).write();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// ************************************************************************* //
|