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_(),
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_(),
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_(),
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_(),
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<input_t> xyz_;
242 ArrayRCP<input_t> weights_;
244 template <
typename AdapterWithCoords>
245 void sharedConstructor(
const AdapterWithCoords *ia,
246 const RCP<const Environment> &env,
247 const RCP<
const Comm<int> > &comm,
256 template <
typename Adapter>
257 template <
typename AdapterWithCoords>
258 void CoordinateModel<Adapter>::sharedConstructor(
259 const AdapterWithCoords *ia,
260 const RCP<const Environment> &env,
261 const RCP<
const Comm<int> > &comm,
264 size_t nLocalIds = ia->getLocalNumIDs();
269 tmp[0] = ia->getDimension();
270 tmp[1] = ia->getNumWeightsPerID();
271 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, tmp, gtmp);
272 coordinateDim_ = gtmp[0];
273 userNumWeights_ = gtmp[1];
275 env_->localBugAssertion(__FILE__, __LINE__,
"coordinate dimension",
278 input_t *coordArray =
new input_t [coordinateDim_];
279 input_t *weightArray = NULL;
281 weightArray =
new input_t [userNumWeights_];
283 env_->localMemoryAssertion(__FILE__, __LINE__, userNumWeights_+coordinateDim_,
284 coordArray && (!userNumWeights_|| weightArray));
288 const gno_t *gids=NULL;
289 ia->getIDsView(gids);
290 gids_ = arcp(gids, 0, nLocalIds,
false);
292 for (
int dim=0; dim < coordinateDim_; dim++){
294 const scalar_t *coords=NULL;
296 ia->getCoordinatesView(coords, stride, dim);
300 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
301 coordArray[dim] = input_t(cArray, stride);
304 for (
int idx=0; idx < userNumWeights_; idx++){
308 ia->getWeightsView(
weights, stride, idx);
312 ArrayRCP<const scalar_t> wArray(
weights, 0, nLocalIds*stride,
false);
313 weightArray[idx] = input_t(wArray, stride);
317 xyz_ = arcp(coordArray, 0, coordinateDim_);
320 weights_ = arcp(weightArray, 0, userNumWeights_);
322 Teuchos::reduceAll<int, size_t>(*comm, Teuchos::REDUCE_SUM, 1,
323 &nLocalIds, &numGlobalCoordinates_);
325 env_->memory(
"After construction of coordinate model");
int getCoordinateDim() const
Returns the dimension of the coordinates.
size_t getLocalNumCoordinates() const
Returns the number of coordinates on this process.
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.
size_t getGlobalNumObjects() const
Return the global number of objects.
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.
The StridedData class manages lists of weights or coordinates.
Defines the MatrixAdapter interface.
The base class for all model classes.
size_t getLocalNumObjects() const
Return the local number of objects.
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 getNumWeightsPerCoordinate() const
Returns the number (0 or greater) of weights per coordinate.
CoordinateModel(const RCP< const IdentifierAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
global_size_t getGlobalNumCoordinates() const
Returns the global number coordinates.
This file defines the StridedData class.