51 #ifndef _ZOLTAN2_COORDINATEMODEL_HPP_ 52 #define _ZOLTAN2_COORDINATEMODEL_HPP_ 70 template <
typename Adapter>
75 #ifndef DOXYGEN_SHOULD_SKIP_THIS 76 typedef typename Adapter::scalar_t scalar_t;
77 typedef typename Adapter::gno_t gno_t;
78 typedef typename Adapter::lno_t lno_t;
79 typedef typename Adapter::user_t user_t;
80 typedef typename Adapter::userCoord_t userCoord_t;
90 const RCP<const Environment> &env,
91 const RCP<
const Comm<int> > &comm,
93 numGlobalCoordinates_(), env_(env), comm_(comm),
94 coordinateDim_(), gids_(), gidsConst_(),
95 xyz_(), userNumWeights_(0), weights_()
98 sharedConstructor<adapterWithCoords_t>(&(*ia), env, comm, flags);
103 const RCP<const Environment> &env,
104 const RCP<
const Comm<int> > &comm,
106 numGlobalCoordinates_(), env_(env), comm_(comm),
107 coordinateDim_(), gids_(), gidsConst_(),
108 xyz_(), userNumWeights_(0), weights_()
110 if (!(ia->coordinatesAvailable()))
111 throw std::logic_error(
"No coordinate info provided to MatrixAdapter.");
114 adapterWithCoords_t *va = ia->getCoordinateInput();
115 sharedConstructor<adapterWithCoords_t>(va, env, comm, flags);
121 const RCP<const Environment> &env,
122 const RCP<
const Comm<int> > &comm,
124 numGlobalCoordinates_(), env_(env), comm_(comm),
125 coordinateDim_(), gids_(), gidsConst_(),
126 xyz_(), userNumWeights_(0), weights_()
128 if (!(ia->coordinatesAvailable()))
129 throw std::logic_error(
"No coordinate info provided to GraphAdapter.");
132 adapterWithCoords_t *va = ia->getCoordinateInput();
133 sharedConstructor<adapterWithCoords_t>(va, env, comm, flags);
139 const RCP<const Environment> &env,
140 const RCP<
const Comm<int> > &comm,
142 numGlobalCoordinates_(), env_(env), comm_(comm),
143 coordinateDim_(), gids_(), gidsConst_(),
144 xyz_(), userNumWeights_(0), weights_()
147 sharedConstructor<adapterWithCoords_t>(&(*ia), env, comm, flags);
152 const RCP<const Environment> &env,
153 const RCP<
const Comm<int> > &comm,
156 throw std::logic_error(
157 "A coordinate model can not be build from an IdentifierAdapter");
203 ArrayView<input_t> &xyz,
204 ArrayView<input_t> &wgts)
const 206 xyz = xyz_.view(0, coordinateDim_);
207 wgts = weights_.view(0, userNumWeights_);
210 Ids = ArrayView<const gno_t>();
213 Ids = Teuchos::arrayView<const gno_t>(
214 reinterpret_cast<const gno_t *
>(gids_.getRawPtr()), nCoord);
235 size_t numGlobalCoordinates_;
236 const RCP<const Environment> env_;
237 const RCP<const Comm<int> > comm_;
239 ArrayRCP<const gno_t> gids_;
240 ArrayRCP<const gno_t> gidsConst_;
241 ArrayRCP<input_t> xyz_;
243 ArrayRCP<input_t> weights_;
245 template <
typename AdapterWithCoords>
246 void sharedConstructor(
const AdapterWithCoords *ia,
247 const RCP<const Environment> &env,
248 const RCP<
const Comm<int> > &comm,
257 template <
typename Adapter>
258 template <
typename AdapterWithCoords>
260 const AdapterWithCoords *ia,
261 const RCP<const Environment> &env,
262 const RCP<
const Comm<int> > &comm,
265 size_t nLocalIds = ia->getLocalNumIDs();
270 tmp[0] = ia->getDimension();
271 tmp[1] = ia->getNumWeightsPerID();
272 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, tmp, gtmp);
273 coordinateDim_ = gtmp[0];
274 userNumWeights_ = gtmp[1];
276 env_->localBugAssertion(__FILE__, __LINE__,
"coordinate dimension",
279 input_t *coordArray =
new input_t [coordinateDim_];
280 input_t *weightArray = NULL;
282 weightArray =
new input_t [userNumWeights_];
284 env_->localMemoryAssertion(__FILE__, __LINE__, userNumWeights_+coordinateDim_,
285 coordArray && (!userNumWeights_|| weightArray));
289 const gno_t *gids=NULL;
290 ia->getIDsView(gids);
291 gids_ = arcp(gids, 0, nLocalIds,
false);
293 for (
int dim=0; dim < coordinateDim_; dim++){
295 const scalar_t *coords=NULL;
297 ia->getCoordinatesView(coords, stride, dim);
301 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
302 coordArray[dim] = input_t(cArray, stride);
305 for (
int idx=0; idx < userNumWeights_; idx++){
307 const scalar_t *weights;
309 ia->getWeightsView(weights, stride, idx);
313 ArrayRCP<const scalar_t> wArray(weights, 0, nLocalIds*stride,
false);
314 weightArray[idx] = input_t(wArray, stride);
318 xyz_ = arcp(coordArray, 0, coordinateDim_);
321 weights_ = arcp(weightArray, 0, userNumWeights_);
323 Teuchos::reduceAll<int, size_t>(*comm, Teuchos::REDUCE_SUM, 1,
324 &nLocalIds, &numGlobalCoordinates_);
326 env_->memory(
"After construction of coordinate model");
global_size_t getGlobalNumCoordinates() const
Returns the global number coordinates.
IdentifierAdapter defines the interface for identifiers.
CoordinateModel(const RCP< const MatrixAdapter< user_t, userCoord_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
CoordinateModel(const RCP< const MeshAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
MatrixAdapter defines the adapter interface for matrices.
Defines the Model interface.
GraphAdapter defines the interface for graph-based user data.
Defines the MeshAdapter interface.
MeshAdapter defines the interface for mesh input.
more involved, like validate a graph
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
Defines the IdentifierAdapter interface.
Defines the VectorAdapter interface.
This class provides geometric coordinates with optional weights to the Zoltan2 algorithm.
size_t getCoordinates(ArrayView< const gno_t > &Ids, ArrayView< input_t > &xyz, ArrayView< input_t > &wgts) const
Returns the coordinate ids, values and optional weights.
CoordinateModel(const RCP< const GraphAdapter< user_t, userCoord_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
VectorAdapter defines the interface for vector input.
size_t getLocalNumObjects() const
Return the local number of objects.
The StridedData class manages lists of weights or coordinates.
size_t getGlobalNumObjects() const
Return the global number of objects.
size_t getLocalNumCoordinates() const
Returns the number of coordinates on this process.
int getNumWeightsPerCoordinate() const
Returns the number (0 or greater) of weights per coordinate.
Defines the MatrixAdapter interface.
The base class for all model classes.
CoordinateModel(const RCP< const VectorAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
Defines the GraphAdapter interface.
int getCoordinateDim() const
Returns the dimension of the coordinates.
CoordinateModel(const RCP< const IdentifierAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
This file defines the StridedData class.