46 #ifndef MUELU_LINEDETECTIONFACTORY_DEF_HPP
47 #define MUELU_LINEDETECTIONFACTORY_DEF_HPP
60 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
67 #undef SET_VALID_ENTRY
72 return validParamList;
75 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 Input(currentLevel,
"A");
90 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
92 FactoryMonitor m(*
this,
"Line detection (Ray style)", currentLevel);
100 RCP<Matrix> A = Get<RCP<Matrix> >(currentLevel,
"A");
101 LO BlkSize = A->GetFixedBlockSize();
103 LO Ndofs = rowMap->getLocalNumElements();
104 LO Nnodes = Ndofs / BlkSize;
108 const std::string lineOrientation = pL.
get<std::string>(
"linedetection: orientation");
111 if (currentLevel.GetLevelID() == 0) {
112 if (lineOrientation ==
"vertical")
114 else if (lineOrientation ==
"horizontal")
116 else if (lineOrientation ==
"coordinates")
127 if (currentLevel.GetLevelID() == 0) {
130 GetOStream(
Runtime1) <<
"Number of layers for line detection: " << NumZDir <<
" (information from Level(0))" << std::endl;
133 NumZDir = pL.
get<
LO>(
"linedetection: num layers");
135 bool CoordsAvail = currentLevel.IsAvailable(
"Coordinates");
137 if (CoordsAvail ==
true) {
139 fineCoords = Get<RCP<CoordinateMultiVector> >(currentLevel,
"Coordinates");
141 x = fineCoords->getDataNonConst(0);
142 y = fineCoords->getDataNonConst(1);
143 z = fineCoords->getDataNonConst(2);
148 LO NumCoords = Ndofs / BlkSize;
162 sort_coordinates(NumCoords, OrigLoc, xptr, yptr, zptr, xtemp, ytemp, ztemp,
true);
167 LO NumNodesPerVertLine = 0;
170 while (index < NumCoords) {
174 while ((next != NumCoords) && (xtemp[next] == xfirst) &&
175 (ytemp[next] == yfirst))
177 if (NumBlocks == 0) {
178 NumNodesPerVertLine = next - index;
187 NumZDir = NumNodesPerVertLine;
188 GetOStream(
Runtime1) <<
"Number of layers for line detection: " << NumZDir <<
" (information reconstructed from provided node coordinates)" << std::endl;
193 GetOStream(
Runtime1) <<
"Number of layers for line detection: " << NumZDir <<
" (information provided by user through 'line detection: num layers')" << std::endl;
201 GetOStream(
Runtime1) <<
"Number of layers for line detection: " << NumZDir << std::endl;
209 bool CoordsAvail = currentLevel.IsAvailable(
"Coordinates");
211 if (CoordsAvail ==
false) {
212 if (currentLevel.GetLevelID() == 0)
215 throw Exceptions::RuntimeError(
"Coordinates not generated by previous invocation of LineDetectionFactory's BuildP() method.");
217 fineCoords = Get<RCP<CoordinateMultiVector> >(currentLevel,
"Coordinates");
219 x = fineCoords->getDataNonConst(0);
220 y = fineCoords->getDataNonConst(1);
221 z = fineCoords->getDataNonConst(2);
229 LO *LayerId, *VertLineId;
235 NumZDir = ML_compute_line_info(LayerId, VertLineId, Ndofs, BlkSize,
236 Zorientation_, NumZDir, xptr, yptr, zptr, *(rowMap->getComm()));
241 Set(currentLevel,
"CoarseNumZLayers", NumZDir);
242 Set(currentLevel,
"LineDetection_Layers", TLayerId);
243 Set(currentLevel,
"LineDetection_VertLineIds", TVertLineId);
251 Set(currentLevel,
"CoarseNumZLayers", NumZDir);
252 Set(currentLevel,
"LineDetection_Layers", TLayerId);
253 Set(currentLevel,
"LineDetection_VertLineIds", TVertLineId);
261 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
262 LocalOrdinal LineDetectionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ML_compute_line_info(
LocalOrdinal LayerId[],
LocalOrdinal VertLineId[],
LocalOrdinal Ndof,
LocalOrdinal DofsPerNode,
LocalOrdinal MeshNumbering,
LocalOrdinal NumNodesPerVertLine,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* xvals,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* yvals,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* zvals,
const Teuchos::Comm<int>& )
const {
263 LO Nnodes, NVertLines, MyNode;
273 if ((xvals == NULL) || (yvals == NULL) || (zvals == NULL)) RetVal = -1;
275 if (NumNodesPerVertLine == -1) RetVal = -4;
276 if (((Ndof / DofsPerNode) % NumNodesPerVertLine) != 0) RetVal = -3;
278 if ((Ndof % DofsPerNode) != 0) RetVal = -2;
285 Nnodes = Ndof / DofsPerNode;
286 for (MyNode = 0; MyNode < Nnodes; MyNode++) VertLineId[MyNode] = -1;
287 for (MyNode = 0; MyNode < Nnodes; MyNode++) LayerId[MyNode] = -1;
290 for (MyNode = 0; MyNode < Nnodes; MyNode++) {
291 LayerId[MyNode] = MyNode % NumNodesPerVertLine;
292 VertLineId[MyNode] = (MyNode - LayerId[MyNode]) / NumNodesPerVertLine;
295 NVertLines = Nnodes / NumNodesPerVertLine;
296 for (MyNode = 0; MyNode < Nnodes; MyNode++) {
297 VertLineId[MyNode] = MyNode % NVertLines;
298 LayerId[MyNode] = (MyNode - VertLineId[MyNode]) / NVertLines;
302 NumCoords = Ndof / DofsPerNode;
318 sort_coordinates(NumCoords, OrigLoc, xvals, yvals, zvals, xtemp, ytemp, ztemp,
true);
323 while (index < NumCoords) {
324 xfirst = xtemp[index];
325 yfirst = ytemp[index];
327 while ((next != NumCoords) && (xtemp[next] == xfirst) &&
328 (ytemp[next] == yfirst))
330 if (NumBlocks == 0) {
331 NumNodesPerVertLine = next - index;
337 for (j = index; j < next; j++) {
338 VertLineId[OrigLoc[j]] = NumBlocks;
339 LayerId[OrigLoc[j]] = count++;
348 for (i = 0; i < Nnodes; i++) {
349 if (VertLineId[i] == -1) {
350 GetOStream(
Warnings1) <<
"Warning: did not assign " << i <<
" to a vertical line?????\n"
353 if (LayerId[i] == -1) {
354 GetOStream(
Warnings1) <<
"Warning: did not assign " << i <<
" to a Layer?????\n"
364 return NumNodesPerVertLine;
368 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
377 if (flipXY ==
false) {
378 for (
LO i = 0; i < numCoords; i++) xtemp[i] = xvals[i];
380 for (
LO i = 0; i < numCoords; i++) xtemp[i] = yvals[i];
382 for (
LO i = 0; i < numCoords; i++) OrigLoc[i] = i;
384 ML_az_dsort2(xtemp, numCoords, OrigLoc);
385 if (flipXY ==
false) {
386 for (
LO i = 0; i < numCoords; i++) ytemp[i] = yvals[OrigLoc[i]];
388 for (
LO i = 0; i < numCoords; i++) ytemp[i] = xvals[OrigLoc[i]];
393 while (index < numCoords) {
396 while ((next != numCoords) && (xtemp[next] == xfirst))
398 ML_az_dsort2(&(ytemp[index]), next - index, &(OrigLoc[index]));
399 for (
LO i = index; i < next; i++) ztemp[i] = zvals[OrigLoc[i]];
402 while (subindex != next) {
404 LO subnext = subindex + 1;
405 while ((subnext != next) && (ytemp[subnext] == yfirst)) subnext++;
406 ML_az_dsort2(&(ztemp[subindex]), subnext - subindex, &(OrigLoc[subindex]));
414 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
445 if (STS::real(dlist[j]) > STS::real(dlist[j - 1])) j = j + 1;
447 if (STS::real(dlist[j - 1]) > STS::real(dK)) {
448 dlist[i - 1] = dlist[j - 1];
449 list2[i - 1] = list2[j - 1];
485 if (STS::real(dlist[j]) > STS::real(dlist[j - 1])) j = j + 1;
486 if (STS::real(dlist[j - 1]) > STS::real(dK)) {
487 dlist[i - 1] = dlist[j - 1];
510 #endif // MUELU_LINEDETECTIONFACTORY_DEF_HPP
#define SET_VALID_ENTRY(name)
MueLu::DefaultLocalOrdinal LocalOrdinal
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Timer to be used in factories. Similar to Monitor but with additional timers.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
User data are always kept. This flag is set automatically when Level::Set("data", data) is used...
typename Teuchos::ScalarTraits< SC >::coordinateType coordinate_type
static const NoFactory * get()
void Build(Level ¤tLevel) const
Build method.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void ML_az_dsort2(coordinate_type dlist[], LO N, LO list2[]) const
Class that holds all level-specific information.
void sort_coordinates(LO numCoords, LO *OrigLoc, coordinate_type *xvals, coordinate_type *yvals, coordinate_type *zvals, coordinate_type *xtemp, coordinate_type *ytemp, coordinate_type *ztemp, bool flipXY=false) const
void RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
LO ML_compute_line_info(LO LayerId[], LO VertLineId[], LO Ndof, LO DofsPerNode, LO MeshNumbering, LO NumNodesPerVertLine, coordinate_type *xvals, coordinate_type *yvals, coordinate_type *zvals, const Teuchos::Comm< int > &comm) const
Exception throws to report errors in the internal logical of the program.
Description of what is happening (more verbose)
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
void DeclareInput(Level ¤tLevel) const
Input.