SubField.H 5.29 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9
    Copyright (C) 2018-2019 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    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.
18 19 20 21 22 23 24

    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
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

Class
    Foam::SubField

Description
    SubField is a Field obtained as a section of another Field.

    Thus it is itself unallocated so that no storage is allocated or
    deallocated during its use.  To achieve this behaviour, SubField is
    derived from a SubList rather than a List.

SourceFiles
    SubFieldI.H

\*---------------------------------------------------------------------------*/

#ifndef SubField_H
#define SubField_H

#include "SubList.H"
#include "Field.H"
47
#include "VectorSpace.H"
48 49 50 51 52 53

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

54
// Forward declarations
Mark Olesen's avatar
Mark Olesen committed
55 56 57
template<class Type> class Field;
template<class Type> class SubField;

58 59 60 61 62 63 64
/*---------------------------------------------------------------------------*\
                           Class SubField Declaration
\*---------------------------------------------------------------------------*/

template<class Type>
class SubField
:
65
    public refCount,
66 67 68 69 70 71 72 73 74 75 76
    public SubList<Type>
{

public:

    //- Component type
    typedef typename pTraits<Type>::cmptType cmptType;


    // Constructors

77 78 79 80
        //- Copy construct (shallow copy)
        inline SubField(const SubField<Type>& sfield);

        //- Copy construct from SubList
81
        inline SubField(const SubList<Type>& list);
82

83
        //- Construct from UList, the entire size
84
        inline explicit SubField(const UList<Type>& list);
85

86
        //- Construct from UList with a given sub-list size, start at 0
87 88 89 90 91 92
        inline SubField
        (
            const UList<Type>& list,
            const label subSize
        );

93
        //- Construct from UList with a given size and start index
94 95 96 97 98 99 100
        inline SubField
        (
            const UList<Type>& list,
            const label subSize,
            const label startIndex
        );

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        //- Construct from UList and a (start,size) range.
        //  The range is subsetted with the list size itself to ensure that the
        //  result always addresses a valid section of the list.
        inline SubField
        (
            const UList<Type>& list,
            const labelRange& range
        );

        //- Construct from UList and a (start,size) range, but bypassing
        //- run-time range checking.
        inline SubField
        (
            const labelRange& range,
            const UList<Type>& list
        );

118

119
    // Member Functions
120 121 122 123 124

        //- Return a null SubField
        static inline const SubField<Type>& null();

        //- Return a component field of the field
125
        inline tmp<Field<cmptType>> component(const direction) const;
126 127

        //- Return the field transpose (only defined for second rank tensors)
128
        tmp<Field<Type>> T() const;
129 130


131 132 133 134
    // Member Operators

        //- Allow cast to a const Field\<Type\>&
        inline operator const Foam::Field<Type>&() const;
135

136
        //- Copy assign via UList operator. Takes linear time.
137 138
        inline void operator=(const SubField<Type>&);

139
        //- Copy assign via UList operator. Takes linear time.
140 141
        inline void operator=(const Field<Type>&);

142 143 144 145 146 147
        //- Assign all entries to the given value
        inline void operator=(const Type& val);

        //- Assign all entries to zero
        inline void operator=(const zero);

148
        //- Copy assign via UList operator. Takes linear time.
149
        template<class Form, direction Ncmpts>
150
        inline void operator=(const VectorSpace<Form, Type, Ncmpts>& rhs);
151

152 153 154 155 156 157 158 159 160 161 162
        //- Add value to each entry
        inline void operator+=(const Type& val);

        //- Subtract value from each entry
        inline void operator-=(const Type& val);

        //- Multiply each entry by value
        inline void operator*=(const scalar& s);

        //- Divide each entry by value
        inline void operator/=(const scalar& s);
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "SubFieldI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //