Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / multiSolver / timeCluster / timeClusterList.C
blob43e022ecf253cd9b707bebd6a780a6277dd936cc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "timeClusterList.H"
27 #include "objectRegistry.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 const char* const Foam::timeClusterList::typeName = "timeClusterList";
33 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
35 Foam::timeClusterList::timeClusterList()
37     List<timeCluster>()
41 Foam::timeClusterList::timeClusterList(const Foam::label size)
43     List<timeCluster>(size)
47 Foam::timeClusterList::timeClusterList(const timeCluster& tcIn)
49     List<timeCluster>(1, tcIn)
53 Foam::timeClusterList::timeClusterList(const Foam::label size, const Foam::timeCluster& tcIn)
55     List<timeCluster>(size, tcIn)
59 Foam::timeClusterList::timeClusterList(const labelList& subIndices, const timeClusterList& tclIn)
61     List<timeCluster>(subIndices.size())
63     forAll(subIndices, i)
64     {
65         this->operator[](i) = tclIn[subIndices[i]];
66     }
70 Foam::timeClusterList::timeClusterList(Foam::Istream& is)
72     List<timeCluster>(is)
76 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
78 void Foam::timeClusterList::globalSort()
80     Foam::sort(*this, timeCluster::less());
83 void Foam::timeClusterList::append(const timeClusterList& tclIn)
85     label wasSize = this->size();
86     this->setSize(tclIn.size() + this->size());
87     
88     for (label i = 0; i < tclIn.size(); i++)
89     {
90         this->operator[](i + wasSize) = tclIn[i];
91     }
95 void Foam::timeClusterList::append(const timeCluster& tcIn)
97     label wasSize = this->size();
98     this->setSize(this->size() + 1);
99     
100     this->operator[](wasSize) = tcIn;
104 bool Foam::timeClusterList::purgeEmpties()
106     if (!this->size()) return false;
107     
108     label empties(0);
109     for (label i = 0; i < this->size(); i++)
110     {
111         if (!this->operator[](i).times().size())
112         {
113             empties++;
114             continue;
115         }
116         if (empties)
117         {
118             this->operator[](i - empties) = this->operator[](i);
119         }
120     }
121     if (empties)
122     {
123         this->setSize(this->size() - empties);
124     }
125     if (!this->size()) return false;
126     return true;
129 Foam::timeClusterList Foam::timeClusterList::selectiveSubList
131     const labelList& indices
132 ) const
134     timeClusterList tcl(indices.size());
135     
136     forAll(indices, i)
137     {
138         if (indices[i] > this->size())
139         {
140             FatalErrorIn("timeClusterList::selectiveSubList")
141                 << "Out of range index passed to this function.  Indices "
142                 << "passed are: \n" << indices << "\nFailure at index " << i
143                 << ", with value " << indices[i] << ".\n This timeClusterList "
144                 << "has size " << this->size() << "."
145                 << abort(FatalError);
146         }
148         tcl[i] = this->operator[](indices[i]);
149     }
150     return tcl;
153 // ************************************************************************* //