mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: basic i-j-k Field container (#1216)
- this is a simple container for fields with i-j-k addressing.
It does not support field operations directly, but is primarily
intended to be used when assembling field information with i-j-k
logic. After assembly, the field can be transferred to a regular
field for normal operations. Eg,
IjkField<scalar> assemble({15, 16, 200});
// .. fill in i-j-k fields
Field<scalar> final(std::move(assemble));
assemble.clear(); // be pedantic
...
This commit is contained in:
committed by
Andrew Heather
parent
e9323ecbbb
commit
4d499d3c20
3
applications/test/IjkField/Make/files
Normal file
3
applications/test/IjkField/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-IjkField.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-IjkField
|
||||
4
applications/test/IjkField/Make/options
Normal file
4
applications/test/IjkField/Make/options
Normal file
@ -0,0 +1,4 @@
|
||||
EXE_INC = -DFULLDEBUG
|
||||
|
||||
/* EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude */
|
||||
/* EXE_LIBS = -lfiniteVolume */
|
||||
138
applications/test/IjkField/Test-IjkField.C
Normal file
138
applications/test/IjkField/Test-IjkField.C
Normal file
@ -0,0 +1,138 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ 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/>.
|
||||
|
||||
Description
|
||||
Functionality of IjkField
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "point.H"
|
||||
#include "IjkField.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T>
|
||||
Ostream& print(const IjkField<T>& fld)
|
||||
{
|
||||
Info<< static_cast<const Field<T>&>(fld).size()
|
||||
<< " " << fld.sizes() << ' ' << flatOutput(fld);
|
||||
|
||||
return Info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Create with inconsistent sizes
|
||||
IjkField<label> field0({1, 2, 3}, identity(10));
|
||||
|
||||
IjkField<scalar> field1({3, 4, 5});
|
||||
IjkField<scalar> field2({2, 3, 3});
|
||||
|
||||
forAll(field1, i)
|
||||
{
|
||||
field1[i] = -i;
|
||||
}
|
||||
forAll(field2, i)
|
||||
{
|
||||
field2[i] = i;
|
||||
}
|
||||
|
||||
Info<< "ijk field "; print(field1) << nl;
|
||||
Info<< "ijk field "; print(field2) << nl;
|
||||
|
||||
field1.resize(field2.sizes());
|
||||
|
||||
Info<< "resized "; print(field1) << nl;
|
||||
|
||||
field1 *= 2;
|
||||
|
||||
Info<< "Multiply: "; print(field1) << nl;
|
||||
|
||||
field1.resize({1, 2, 3});
|
||||
|
||||
Info<< "Resize - shrink: "; print(field1) << nl;
|
||||
|
||||
field1.resize({2, 3, 2});
|
||||
|
||||
Info<< "Resize - grow: "; print(field1) << nl;
|
||||
|
||||
field1.resize({3, 2, 2});
|
||||
|
||||
Info<< "Resize - repartition: "; print(field1) << nl;
|
||||
|
||||
field1 = field2;
|
||||
|
||||
Info<< "Copied: "; print(field1) << nl;
|
||||
|
||||
field1 = 3.14159;
|
||||
|
||||
Info<< "Assigned: "; print(field1) << nl;
|
||||
|
||||
field1 += 3.14159;
|
||||
|
||||
Info<< "+= operator: "; print(field1) << nl;
|
||||
|
||||
field1 /= 1.2;
|
||||
|
||||
Info<< "/= operator: "; print(field1) << nl;
|
||||
|
||||
// Field operations are still limited, but we can bypass things too
|
||||
|
||||
{
|
||||
Field<scalar>& tmpField = field1;
|
||||
tmpField = sqr(tmpField);
|
||||
|
||||
Info<< "squared (workaround): "; print(field1) << nl;
|
||||
}
|
||||
|
||||
|
||||
Info<< nl
|
||||
<< "Before transfer: addr:" << long(field1.data())
|
||||
<< " size:" << field1.size() << nl;
|
||||
|
||||
Field<scalar> sfield1(std::move(field1));
|
||||
field1.clear();
|
||||
|
||||
Info<< "After transfer to regular field" << nl
|
||||
<< " source:" << long(field1.data()) << nl
|
||||
<< " target:" << long(sfield1.data()) << nl
|
||||
<< "Values"
|
||||
<< " source:";
|
||||
print(field1) << nl;
|
||||
|
||||
Info<< " target:" << flatOutput(sfield1) << nl;
|
||||
|
||||
|
||||
Info << "\nEnd\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user