SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / gromacs / analysisdata / abstractdata.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2010,2011,2012,2013,2014 by the GROMACS development team.
5  * Copyright (c) 2015,2018,2019,2020, by the GROMACS development team, led by
6  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7  * and including many others, as listed in the AUTHORS file in the
8  * top-level source directory and at http://www.gromacs.org.
9  *
10  * GROMACS is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * as published by the Free Software Foundation; either version 2.1
13  * of the License, or (at your option) any later version.
14  *
15  * GROMACS is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with GROMACS; if not, see
22  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24  *
25  * If you want to redistribute modifications to GROMACS, please
26  * consider that scientific software is very special. Version
27  * control is crucial - bugs must be traceable. We will be happy to
28  * consider code for inclusion in the official distribution, but
29  * derived work must not be called official GROMACS. Details are found
30  * in the README & COPYING files - if they are missing, get the
31  * official version at http://www.gromacs.org.
32  *
33  * To help us fund GROMACS development, we humbly ask that you cite
34  * the research papers on the package. Check out http://www.gromacs.org.
35  */
36 /*! \internal \file
37  * \brief
38  * Implements gmx::AbstractAnalysisData.
39  *
40  * \author Teemu Murtola <teemu.murtola@gmail.com>
41  * \ingroup module_analysisdata
42  */
43 #include "gmxpre.h"
44
45 #include "abstractdata.h"
46
47 #include <utility>
48 #include <vector>
49
50 #include "gromacs/analysisdata/dataframe.h"
51 #include "gromacs/analysisdata/datamodule.h"
52 #include "gromacs/analysisdata/datamodulemanager.h"
53 #include "gromacs/utility/exceptions.h"
54 #include "gromacs/utility/gmxassert.h"
55
56 #include "dataproxy.h"
57
58 namespace gmx
59 {
60
61 /********************************************************************
62  * AbstractAnalysisData::Impl
63  */
64
65 /*! \internal \brief
66  * Private implementation class for AbstractAnalysisData.
67  *
68  * \ingroup module_analysisdata
69  */
70 class AbstractAnalysisData::Impl
71 {
72 public:
73     Impl();
74
75     //! Column counts for each data set in the data.
76     std::vector<int> columnCounts_;
77     //! Whether the data is multipoint.
78     bool bMultipoint_;
79     //! Manager for the added modules.
80     AnalysisDataModuleManager modules_;
81 };
82
83 AbstractAnalysisData::Impl::Impl() : bMultipoint_(false)
84 {
85     columnCounts_.push_back(0);
86 }
87
88
89 /********************************************************************
90  * AbstractAnalysisData
91  */
92 /*! \cond libapi */
93 AbstractAnalysisData::AbstractAnalysisData() : impl_(new Impl()) {}
94 //! \endcond
95
96 AbstractAnalysisData::~AbstractAnalysisData() {}
97
98 bool AbstractAnalysisData::isMultipoint() const
99 {
100     return impl_->bMultipoint_;
101 }
102
103 int AbstractAnalysisData::dataSetCount() const
104 {
105     return impl_->columnCounts_.size();
106 }
107
108 int AbstractAnalysisData::columnCount(int dataSet) const
109 {
110     GMX_ASSERT(dataSet >= 0 && dataSet < dataSetCount(), "Out of range data set index");
111     return impl_->columnCounts_[dataSet];
112 }
113
114 int AbstractAnalysisData::columnCount() const
115 {
116     GMX_ASSERT(dataSetCount() == 1, "Convenience method not available for multiple data sets");
117     return columnCount(0);
118 }
119
120
121 AnalysisDataFrameRef AbstractAnalysisData::tryGetDataFrame(int index) const
122 {
123     if (index < 0 || index >= frameCount())
124     {
125         return AnalysisDataFrameRef();
126     }
127     return tryGetDataFrameInternal(index);
128 }
129
130
131 AnalysisDataFrameRef AbstractAnalysisData::getDataFrame(int index) const
132 {
133     AnalysisDataFrameRef frame = tryGetDataFrame(index);
134     if (!frame.isValid())
135     {
136         GMX_THROW(APIError("Invalid frame accessed"));
137     }
138     return frame;
139 }
140
141
142 bool AbstractAnalysisData::requestStorage(int nframes)
143 {
144     GMX_RELEASE_ASSERT(nframes >= -1, "Invalid number of frames requested");
145     if (nframes == 0)
146     {
147         return true;
148     }
149     return requestStorageInternal(nframes);
150 }
151
152
153 void AbstractAnalysisData::addModule(const AnalysisDataModulePointer& module)
154 {
155     impl_->modules_.addModule(this, module);
156 }
157
158
159 void AbstractAnalysisData::addColumnModule(int col, int span, const AnalysisDataModulePointer& module)
160 {
161     GMX_RELEASE_ASSERT(col >= 0 && span >= 1, "Invalid columns specified for a column module");
162     std::shared_ptr<AnalysisDataProxy> proxy(new AnalysisDataProxy(col, span, this));
163     proxy->addModule(module);
164     addModule(proxy);
165 }
166
167
168 void AbstractAnalysisData::applyModule(IAnalysisDataModule* module)
169 {
170     impl_->modules_.applyModule(this, module);
171 }
172
173 /*! \cond libapi */
174 void AbstractAnalysisData::setDataSetCount(int dataSetCount)
175 {
176     GMX_RELEASE_ASSERT(dataSetCount > 0, "Invalid data column count");
177     impl_->modules_.dataPropertyAboutToChange(AnalysisDataModuleManager::eMultipleDataSets,
178                                               dataSetCount > 1);
179     impl_->columnCounts_.resize(dataSetCount);
180 }
181
182 void AbstractAnalysisData::setColumnCount(int dataSet, int columnCount)
183 {
184     GMX_RELEASE_ASSERT(dataSet >= 0 && dataSet < dataSetCount(), "Out of range data set index");
185     GMX_RELEASE_ASSERT(columnCount > 0, "Invalid data column count");
186
187     bool bMultipleColumns = columnCount > 1;
188     for (int i = 0; i < dataSetCount() && !bMultipleColumns; ++i)
189     {
190         if (i != dataSet && this->columnCount(i) > 1)
191         {
192             bMultipleColumns = true;
193         }
194     }
195     impl_->modules_.dataPropertyAboutToChange(AnalysisDataModuleManager::eMultipleColumns, bMultipleColumns);
196     impl_->columnCounts_[dataSet] = columnCount;
197 }
198
199 void AbstractAnalysisData::setMultipoint(bool bMultipoint)
200 {
201     impl_->modules_.dataPropertyAboutToChange(AnalysisDataModuleManager::eMultipoint, bMultipoint);
202     impl_->bMultipoint_ = bMultipoint;
203 }
204
205 AnalysisDataModuleManager& AbstractAnalysisData::moduleManager()
206 {
207     return impl_->modules_;
208 }
209
210 const AnalysisDataModuleManager& AbstractAnalysisData::moduleManager() const
211 {
212     return impl_->modules_;
213 }
214 //! \endcond
215
216 } // namespace gmx