/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 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 .
\*---------------------------------------------------------------------------*/
#include "SlicedGeometricField.H"
#include "processorFvPatch.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::tmp>
Foam::SlicedGeometricField::
slicedBoundaryField
(
const Mesh& mesh,
const Field& completeField,
const bool preserveCouples,
const bool preserveProcessorOnly
)
{
tmp> tbf
(
new FieldField(mesh.boundary().size())
);
FieldField& bf = tbf.ref();
forAll(mesh.boundary(), patchi)
{
if
(
preserveCouples
&& mesh.boundary()[patchi].coupled()
&& (
!preserveProcessorOnly
|| isA(mesh.boundary()[patchi])
)
)
{
// For coupled patched construct the correct patch field type
bf.set
(
patchi,
PatchField::New
(
mesh.boundary()[patchi].type(),
mesh.boundary()[patchi],
*this
)
);
// Initialize the values on the coupled patch to those of the slice
// of the given field.
// Note: these will usually be over-ridden by the boundary field
// evaluation e.g. in the case of processor and cyclic patches.
bf[patchi] = SlicedPatchField
(
mesh.boundary()[patchi],
DimensionedField::null(),
completeField
);
}
else
{
bf.set
(
patchi,
new SlicedPatchField
(
mesh.boundary()[patchi],
DimensionedField::null(),
completeField
)
);
}
}
return tbf;
}
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::tmp>
Foam::SlicedGeometricField::
slicedBoundaryField
(
const Mesh& mesh,
const FieldField& bField,
const bool preserveCouples
)
{
tmp> tbf
(
new FieldField(mesh.boundary().size())
);
FieldField& bf = tbf.ref();
forAll(mesh.boundary(), patchi)
{
if (preserveCouples && mesh.boundary()[patchi].coupled())
{
// For coupled patched construct the correct patch field type
bf.set
(
patchi,
PatchField::New
(
mesh.boundary()[patchi].type(),
mesh.boundary()[patchi],
*this
)
);
// Assign field
bf[patchi] == bField[patchi];
}
else
{
// Create unallocated copy of patch field
bf.set
(
patchi,
new SlicedPatchField
(
mesh.boundary()[patchi],
DimensionedField::null()
)
);
bf[patchi].UList::shallowCopy(bField[patchi]);
}
}
return tbf;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::SlicedGeometricField::
Internal::Internal
(
const IOobject& io,
const Mesh& mesh,
const dimensionSet& ds,
const Field& iField
)
:
DimensionedField
(
io,
mesh,
ds,
Field()
)
{
// Set the internalField to the slice of the complete field
UList::shallowCopy
(
typename Field::subField(iField, GeoMesh::size(mesh))
);
}
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::SlicedGeometricField::
SlicedGeometricField
(
const IOobject& io,
const Mesh& mesh,
const dimensionSet& ds,
const Field& completeField,
const bool preserveCouples
)
:
GeometricField
(
io,
mesh,
ds,
Field(),
slicedBoundaryField(mesh, completeField, preserveCouples)
)
{
// Set the internalField to the slice of the complete field
UList::shallowCopy
(
typename Field::subField(completeField, GeoMesh::size(mesh))
);
correctBoundaryConditions();
}
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::SlicedGeometricField::
SlicedGeometricField
(
const IOobject& io,
const Mesh& mesh,
const dimensionSet& ds,
const Field& completeIField,
const Field& completeBField,
const bool preserveCouples,
const bool preserveProcessorOnly
)
:
GeometricField
(
io,
mesh,
ds,
Field(),
slicedBoundaryField
(
mesh,
completeBField,
preserveCouples,
preserveProcessorOnly
)
)
{
// Set the internalField to the slice of the complete field
UList::shallowCopy
(
typename Field::subField(completeIField, GeoMesh::size(mesh))
);
correctBoundaryConditions();
}
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::SlicedGeometricField::
SlicedGeometricField
(
const IOobject& io,
const GeometricField& gf,
const bool preserveCouples
)
:
GeometricField
(
io,
gf.mesh(),
gf.dimensions(),
Field(),
slicedBoundaryField(gf.mesh(), gf.boundaryField(), preserveCouples)
)
{
// Set the internalField to the supplied internal field
UList::shallowCopy(gf.primitiveField());
correctBoundaryConditions();
}
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::SlicedGeometricField::
SlicedGeometricField
(
const SlicedGeometricField& gf
)
:
GeometricField
(
gf,
gf.mesh(),
gf.dimensions(),
Field(),
slicedBoundaryField(gf.mesh(), gf.boundaryField(), true)
)
{
// Set the internalField to the supplied internal field
UList::shallowCopy(gf.primitiveField());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::SlicedGeometricField::
~SlicedGeometricField()
{
// Set the internalField storage pointer to NULL before its destruction
// to protect the field it a slice of.
UList::shallowCopy(UList(NULL, 0));
}
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
Foam::SlicedGeometricField::
Internal::~Internal()
{
// Set the internalField storage pointer to NULL before its destruction
// to protect the field it a slice of.
UList::shallowCopy(UList(NULL, 0));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class Type,
template class PatchField,
template class SlicedPatchField,
class GeoMesh
>
void Foam::SlicedGeometricField::
correctBoundaryConditions()
{
GeometricField::correctBoundaryConditions();
}
// ************************************************************************* //