10 #ifndef MUELU_LINEDETECTIONFACTORY_DEF_HPP
11 #define MUELU_LINEDETECTIONFACTORY_DEF_HPP
24 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
28 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
31 #undef SET_VALID_ENTRY
36 return validParamList;
39 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
41 Input(currentLevel,
"A");
54 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
56 FactoryMonitor m(*
this,
"Line detection (Ray style)", currentLevel);
64 RCP<Matrix> A = Get<RCP<Matrix> >(currentLevel,
"A");
65 LO BlkSize = A->GetFixedBlockSize();
67 LO Ndofs = rowMap->getLocalNumElements();
68 LO Nnodes = Ndofs / BlkSize;
72 const std::string lineOrientation = pL.
get<std::string>(
"linedetection: orientation");
75 if (currentLevel.GetLevelID() == 0) {
76 if (lineOrientation ==
"vertical")
78 else if (lineOrientation ==
"horizontal")
80 else if (lineOrientation ==
"coordinates")
91 if (currentLevel.GetLevelID() == 0) {
94 GetOStream(
Runtime1) <<
"Number of layers for line detection: " << NumZDir <<
" (information from Level(0))" << std::endl;
97 NumZDir = pL.
get<
LO>(
"linedetection: num layers");
99 bool CoordsAvail = currentLevel.IsAvailable(
"Coordinates");
101 if (CoordsAvail ==
true) {
103 fineCoords = Get<RCP<CoordinateMultiVector> >(currentLevel,
"Coordinates");
105 x = fineCoords->getDataNonConst(0);
106 y = fineCoords->getDataNonConst(1);
107 z = fineCoords->getDataNonConst(2);
112 LO NumCoords = Ndofs / BlkSize;
126 sort_coordinates(NumCoords, OrigLoc, xptr, yptr, zptr, xtemp, ytemp, ztemp,
true);
131 LO NumNodesPerVertLine = 0;
134 while (index < NumCoords) {
138 while ((next != NumCoords) && (xtemp[next] == xfirst) &&
139 (ytemp[next] == yfirst))
141 if (NumBlocks == 0) {
142 NumNodesPerVertLine = next - index;
151 NumZDir = NumNodesPerVertLine;
152 GetOStream(
Runtime1) <<
"Number of layers for line detection: " << NumZDir <<
" (information reconstructed from provided node coordinates)" << std::endl;
157 GetOStream(
Runtime1) <<
"Number of layers for line detection: " << NumZDir <<
" (information provided by user through 'line detection: num layers')" << std::endl;
165 GetOStream(
Runtime1) <<
"Number of layers for line detection: " << NumZDir << std::endl;
173 bool CoordsAvail = currentLevel.IsAvailable(
"Coordinates");
175 if (CoordsAvail ==
false) {
176 if (currentLevel.GetLevelID() == 0)
179 throw Exceptions::RuntimeError(
"Coordinates not generated by previous invocation of LineDetectionFactory's BuildP() method.");
181 fineCoords = Get<RCP<CoordinateMultiVector> >(currentLevel,
"Coordinates");
183 x = fineCoords->getDataNonConst(0);
184 y = fineCoords->getDataNonConst(1);
185 z = fineCoords->getDataNonConst(2);
193 LO *LayerId, *VertLineId;
199 NumZDir = ML_compute_line_info(LayerId, VertLineId, Ndofs, BlkSize,
200 Zorientation_, NumZDir, xptr, yptr, zptr, *(rowMap->getComm()));
205 Set(currentLevel,
"CoarseNumZLayers", NumZDir);
206 Set(currentLevel,
"LineDetection_Layers", TLayerId);
207 Set(currentLevel,
"LineDetection_VertLineIds", TVertLineId);
215 Set(currentLevel,
"CoarseNumZLayers", NumZDir);
216 Set(currentLevel,
"LineDetection_Layers", TLayerId);
217 Set(currentLevel,
"LineDetection_VertLineIds", TVertLineId);
225 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 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 {
227 LO Nnodes, NVertLines, MyNode;
237 if ((xvals == NULL) || (yvals == NULL) || (zvals == NULL)) RetVal = -1;
239 if (NumNodesPerVertLine == -1) RetVal = -4;
240 if (((Ndof / DofsPerNode) % NumNodesPerVertLine) != 0) RetVal = -3;
242 if ((Ndof % DofsPerNode) != 0) RetVal = -2;
249 Nnodes = Ndof / DofsPerNode;
250 for (MyNode = 0; MyNode < Nnodes; MyNode++) VertLineId[MyNode] = -1;
251 for (MyNode = 0; MyNode < Nnodes; MyNode++) LayerId[MyNode] = -1;
254 for (MyNode = 0; MyNode < Nnodes; MyNode++) {
255 LayerId[MyNode] = MyNode % NumNodesPerVertLine;
256 VertLineId[MyNode] = (MyNode - LayerId[MyNode]) / NumNodesPerVertLine;
259 NVertLines = Nnodes / NumNodesPerVertLine;
260 for (MyNode = 0; MyNode < Nnodes; MyNode++) {
261 VertLineId[MyNode] = MyNode % NVertLines;
262 LayerId[MyNode] = (MyNode - VertLineId[MyNode]) / NVertLines;
266 NumCoords = Ndof / DofsPerNode;
282 sort_coordinates(NumCoords, OrigLoc, xvals, yvals, zvals, xtemp, ytemp, ztemp,
true);
287 while (index < NumCoords) {
288 xfirst = xtemp[index];
289 yfirst = ytemp[index];
291 while ((next != NumCoords) && (xtemp[next] == xfirst) &&
292 (ytemp[next] == yfirst))
294 if (NumBlocks == 0) {
295 NumNodesPerVertLine = next - index;
301 for (j = index; j < next; j++) {
302 VertLineId[OrigLoc[j]] = NumBlocks;
303 LayerId[OrigLoc[j]] = count++;
312 for (i = 0; i < Nnodes; i++) {
313 if (VertLineId[i] == -1) {
314 GetOStream(
Warnings1) <<
"Warning: did not assign " << i <<
" to a vertical line?????\n"
317 if (LayerId[i] == -1) {
318 GetOStream(
Warnings1) <<
"Warning: did not assign " << i <<
" to a Layer?????\n"
328 return NumNodesPerVertLine;
332 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
341 if (flipXY ==
false) {
342 for (
LO i = 0; i < numCoords; i++) xtemp[i] = xvals[i];
344 for (
LO i = 0; i < numCoords; i++) xtemp[i] = yvals[i];
346 for (
LO i = 0; i < numCoords; i++) OrigLoc[i] = i;
348 ML_az_dsort2(xtemp, numCoords, OrigLoc);
349 if (flipXY ==
false) {
350 for (
LO i = 0; i < numCoords; i++) ytemp[i] = yvals[OrigLoc[i]];
352 for (
LO i = 0; i < numCoords; i++) ytemp[i] = xvals[OrigLoc[i]];
357 while (index < numCoords) {
360 while ((next != numCoords) && (xtemp[next] == xfirst))
362 ML_az_dsort2(&(ytemp[index]), next - index, &(OrigLoc[index]));
363 for (
LO i = index; i < next; i++) ztemp[i] = zvals[OrigLoc[i]];
366 while (subindex != next) {
368 LO subnext = subindex + 1;
369 while ((subnext != next) && (ytemp[subnext] == yfirst)) subnext++;
370 ML_az_dsort2(&(ztemp[subindex]), subnext - subindex, &(OrigLoc[subindex]));
378 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
409 if (STS::real(dlist[j]) > STS::real(dlist[j - 1])) j = j + 1;
411 if (STS::real(dlist[j - 1]) > STS::real(dK)) {
412 dlist[i - 1] = dlist[j - 1];
413 list2[i - 1] = list2[j - 1];
449 if (STS::real(dlist[j]) > STS::real(dlist[j - 1])) j = j + 1;
450 if (STS::real(dlist[j - 1]) > STS::real(dK)) {
451 dlist[i - 1] = dlist[j - 1];
474 #endif // MUELU_LINEDETECTIONFACTORY_DEF_HPP
#define SET_VALID_ENTRY(name)
MueLu::DefaultLocalOrdinal LocalOrdinal
T & get(const std::string &name, T def_value)
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
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.