Unverified Commit 06d633e3 authored by Luc Berger-Vergiat's avatar Luc Berger-Vergiat
Browse files

MueLu: fix type issues in LineDetetion factory, see issue #5112

Mainly removing the Scalar type in favor of the coordinate_type type.
parent 0f5ec727
...@@ -71,6 +71,9 @@ namespace MueLu { ...@@ -71,6 +71,9 @@ namespace MueLu {
public: public:
using coordinate_type = typename Teuchos::ScalarTraits<SC>::coordinateType;
using CoordinateMultiVector = typename Xpetra::MultiVector<coordinate_type, LO, GO, NO>;
//! @name Constructors/Destructors. //! @name Constructors/Destructors.
//@{ //@{
...@@ -103,15 +106,22 @@ namespace MueLu { ...@@ -103,15 +106,22 @@ namespace MueLu {
//@} //@}
private: private:
void sort_coordinates(LO numCoords, LO* OrigLoc, Scalar* xvals, Scalar* yvals, Scalar* zvals, Scalar* xtemp, Scalar* ytemp, Scalar* ztemp, bool flipXY = false) const; 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;
LO ML_compute_line_info(LO LayerId[], LO VertLineId[], LO ML_compute_line_info(LO LayerId[], LO VertLineId[],
LO Ndof, LO DofsPerNode, LO Ndof, LO DofsPerNode,
LO MeshNumbering, LO NumNodesPerVertLine, LO MeshNumbering, LO NumNodesPerVertLine,
SC *xvals, SC *yvals, SC *zvals, coordinate_type *xvals, coordinate_type *yvals, coordinate_type *zvals,
const Teuchos::Comm<int>& comm ) const ; const Teuchos::Comm<int>& comm ) const ;
void ML_az_dsort2(SC dlist[], LO N, LO list2[]) const; void ML_az_dsort2(coordinate_type dlist[], LO N, LO list2[]) const;
//! internally stores line detection mode //! internally stores line detection mode
//! can be either vertical, horizontal or coordinates //! can be either vertical, horizontal or coordinates
......
...@@ -93,9 +93,9 @@ namespace MueLu { ...@@ -93,9 +93,9 @@ namespace MueLu {
FactoryMonitor m(*this, "Line detection (Ray style)", currentLevel); FactoryMonitor m(*this, "Line detection (Ray style)", currentLevel);
LO NumZDir = 0; LO NumZDir = 0;
RCP<MultiVector> fineCoords; RCP<CoordinateMultiVector> fineCoords;
ArrayRCP<Scalar> x, y, z; ArrayRCP<coordinate_type> x, y, z;
Scalar *xptr = NULL, *yptr = NULL, *zptr = NULL; coordinate_type *xptr = NULL, *yptr = NULL, *zptr = NULL;
// obtain general variables // obtain general variables
RCP<Matrix> A = Get< RCP<Matrix> > (currentLevel, "A"); RCP<Matrix> A = Get< RCP<Matrix> > (currentLevel, "A");
...@@ -137,7 +137,7 @@ namespace MueLu { ...@@ -137,7 +137,7 @@ namespace MueLu {
if (CoordsAvail == true) { if (CoordsAvail == true) {
// try to reconstruct the number of layers from coordinates // try to reconstruct the number of layers from coordinates
fineCoords = Get< RCP<MultiVector> > (currentLevel, "Coordinates"); fineCoords = Get< RCP<CoordinateMultiVector> > (currentLevel, "Coordinates");
TEUCHOS_TEST_FOR_EXCEPTION(fineCoords->getNumVectors() != 3, Exceptions::RuntimeError, "Three coordinates arrays must be supplied if line detection orientation not given."); TEUCHOS_TEST_FOR_EXCEPTION(fineCoords->getNumVectors() != 3, Exceptions::RuntimeError, "Three coordinates arrays must be supplied if line detection orientation not given.");
x = fineCoords->getDataNonConst(0); x = fineCoords->getDataNonConst(0);
y = fineCoords->getDataNonConst(1); y = fineCoords->getDataNonConst(1);
...@@ -150,9 +150,9 @@ namespace MueLu { ...@@ -150,9 +150,9 @@ namespace MueLu {
/* sort coordinates so that we can order things according to lines */ /* sort coordinates so that we can order things according to lines */
Teuchos::ArrayRCP<LO> TOrigLoc= Teuchos::arcp<LO>(NumCoords); LO* OrigLoc= TOrigLoc.getRawPtr(); Teuchos::ArrayRCP<LO> TOrigLoc= Teuchos::arcp<LO>(NumCoords); LO* OrigLoc= TOrigLoc.getRawPtr();
Teuchos::ArrayRCP<SC> Txtemp = Teuchos::arcp<SC>(NumCoords); SC* xtemp = Txtemp.getRawPtr(); Teuchos::ArrayRCP<coordinate_type> Txtemp = Teuchos::arcp<coordinate_type>(NumCoords); coordinate_type* xtemp = Txtemp.getRawPtr();
Teuchos::ArrayRCP<SC> Tytemp = Teuchos::arcp<SC>(NumCoords); SC* ytemp = Tytemp.getRawPtr(); Teuchos::ArrayRCP<coordinate_type> Tytemp = Teuchos::arcp<coordinate_type>(NumCoords); coordinate_type* ytemp = Tytemp.getRawPtr();
Teuchos::ArrayRCP<SC> Tztemp = Teuchos::arcp<SC>(NumCoords); SC* ztemp = Tztemp.getRawPtr(); Teuchos::ArrayRCP<coordinate_type> Tztemp = Teuchos::arcp<coordinate_type>(NumCoords); coordinate_type* ztemp = Tztemp.getRawPtr();
// sort coordinates in {x,y,z}vals (returned in {x,y,z}temp) so that we can order things according to lines // sort coordinates in {x,y,z}vals (returned in {x,y,z}temp) so that we can order things according to lines
// switch x and y coordinates for semi-coarsening... // switch x and y coordinates for semi-coarsening...
...@@ -165,7 +165,7 @@ namespace MueLu { ...@@ -165,7 +165,7 @@ namespace MueLu {
LO index = 0; LO index = 0;
while ( index < NumCoords ) { while ( index < NumCoords ) {
SC xfirst = xtemp[index]; SC yfirst = ytemp[index]; coordinate_type xfirst = xtemp[index]; coordinate_type yfirst = ytemp[index];
LO next = index+1; LO next = index+1;
while ( (next != NumCoords) && (xtemp[next] == xfirst) && while ( (next != NumCoords) && (xtemp[next] == xfirst) &&
(ytemp[next] == yfirst)) (ytemp[next] == yfirst))
...@@ -210,7 +210,7 @@ namespace MueLu { ...@@ -210,7 +210,7 @@ namespace MueLu {
else else
throw Exceptions::RuntimeError("Coordinates not generated by previous invocation of LineDetectionFactory's BuildP() method."); throw Exceptions::RuntimeError("Coordinates not generated by previous invocation of LineDetectionFactory's BuildP() method.");
} }
fineCoords = Get< RCP<MultiVector> > (currentLevel, "Coordinates"); fineCoords = Get< RCP<CoordinateMultiVector> > (currentLevel, "Coordinates");
TEUCHOS_TEST_FOR_EXCEPTION(fineCoords->getNumVectors() != 3, Exceptions::RuntimeError, "Three coordinates arrays must be supplied if line detection orientation not given."); TEUCHOS_TEST_FOR_EXCEPTION(fineCoords->getNumVectors() != 3, Exceptions::RuntimeError, "Three coordinates arrays must be supplied if line detection orientation not given.");
x = fineCoords->getDataNonConst(0); x = fineCoords->getDataNonConst(0);
y = fineCoords->getDataNonConst(1); y = fineCoords->getDataNonConst(1);
...@@ -253,12 +253,12 @@ namespace MueLu { ...@@ -253,12 +253,12 @@ namespace MueLu {
} }
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node> template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
LocalOrdinal LineDetectionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ML_compute_line_info(LocalOrdinal LayerId[], LocalOrdinal VertLineId[], LocalOrdinal Ndof, LocalOrdinal DofsPerNode, LocalOrdinal MeshNumbering, LocalOrdinal NumNodesPerVertLine, Scalar *xvals, Scalar *yvals, Scalar *zvals, const Teuchos::Comm<int>& /* comm */) const { 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>& /* comm */) const {
LO Nnodes, NVertLines, MyNode; LO Nnodes, NVertLines, MyNode;
LO NumCoords, next; //, subindex, subnext; LO NumCoords, next; //, subindex, subnext;
SC xfirst, yfirst; coordinate_type xfirst, yfirst;
SC *xtemp, *ytemp, *ztemp; coordinate_type *xtemp, *ytemp, *ztemp;
LO *OrigLoc; LO *OrigLoc;
LO i,j,count; LO i,j,count;
LO RetVal; LO RetVal;
...@@ -301,9 +301,9 @@ namespace MueLu { ...@@ -301,9 +301,9 @@ namespace MueLu {
// reserve temporary memory // reserve temporary memory
Teuchos::ArrayRCP<LO> TOrigLoc= Teuchos::arcp<LO>(NumCoords); OrigLoc= TOrigLoc.getRawPtr(); Teuchos::ArrayRCP<LO> TOrigLoc= Teuchos::arcp<LO>(NumCoords); OrigLoc= TOrigLoc.getRawPtr();
Teuchos::ArrayRCP<SC> Txtemp = Teuchos::arcp<SC>(NumCoords); xtemp = Txtemp.getRawPtr(); Teuchos::ArrayRCP<coordinate_type> Txtemp = Teuchos::arcp<coordinate_type>(NumCoords); xtemp = Txtemp.getRawPtr();
Teuchos::ArrayRCP<SC> Tytemp = Teuchos::arcp<SC>(NumCoords); ytemp = Tytemp.getRawPtr(); Teuchos::ArrayRCP<coordinate_type> Tytemp = Teuchos::arcp<coordinate_type>(NumCoords); ytemp = Tytemp.getRawPtr();
Teuchos::ArrayRCP<SC> Tztemp = Teuchos::arcp<SC>(NumCoords); ztemp = Tztemp.getRawPtr(); Teuchos::ArrayRCP<coordinate_type> Tztemp = Teuchos::arcp<coordinate_type>(NumCoords); ztemp = Tztemp.getRawPtr();
// build vertical line info for semi-coarsening // build vertical line info for semi-coarsening
...@@ -357,7 +357,14 @@ namespace MueLu { ...@@ -357,7 +357,14 @@ namespace MueLu {
/* Private member function to sort coordinates in arrays. This is an expert routine. Do not use or change.*/ /* Private member function to sort coordinates in arrays. This is an expert routine. Do not use or change.*/
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node> template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
void LineDetectionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::sort_coordinates(LO numCoords, LO* OrigLoc, Scalar* xvals, Scalar* yvals, Scalar* zvals, Scalar* xtemp, Scalar* ytemp, Scalar* ztemp, bool flipXY) const { void LineDetectionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::sort_coordinates(LO numCoords, LO* OrigLoc,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* xvals,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* yvals,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* zvals,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* xtemp,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* ytemp,
typename Teuchos::ScalarTraits<Scalar>::coordinateType* ztemp,
bool flipXY) const {
if( flipXY == false ) { // for line-smoothing if( flipXY == false ) { // for line-smoothing
for (LO i = 0; i < numCoords; i++) xtemp[i]= xvals[i]; for (LO i = 0; i < numCoords; i++) xtemp[i]= xvals[i];
...@@ -376,7 +383,7 @@ namespace MueLu { ...@@ -376,7 +383,7 @@ namespace MueLu {
LO index = 0; LO index = 0;
while ( index < numCoords ) { while ( index < numCoords ) {
SC xfirst = xtemp[index]; coordinate_type xfirst = xtemp[index];
LO next = index+1; LO next = index+1;
while ( (next != numCoords) && (xtemp[next] == xfirst)) while ( (next != numCoords) && (xtemp[next] == xfirst))
next++; next++;
...@@ -385,7 +392,7 @@ namespace MueLu { ...@@ -385,7 +392,7 @@ namespace MueLu {
/* One final sort so that the ztemps are in order */ /* One final sort so that the ztemps are in order */
LO subindex = index; LO subindex = index;
while (subindex != next) { while (subindex != next) {
SC yfirst = ytemp[subindex]; coordinate_type yfirst = ytemp[subindex];
LO subnext = subindex+1; LO subnext = subindex+1;
while ( (subnext != next) && (ytemp[subnext] == yfirst)) subnext++; while ( (subnext != next) && (ytemp[subnext] == yfirst)) subnext++;
ML_az_dsort2(&(ztemp[subindex]),subnext-subindex,&(OrigLoc[subindex])); ML_az_dsort2(&(ztemp[subindex]),subnext-subindex,&(OrigLoc[subindex]));
...@@ -398,10 +405,10 @@ namespace MueLu { ...@@ -398,10 +405,10 @@ namespace MueLu {
/* Sort coordinates and additional array accordingly (if provided). This is an expert routine borrowed from ML. Do not change.*/ /* Sort coordinates and additional array accordingly (if provided). This is an expert routine borrowed from ML. Do not change.*/
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node> template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
void LineDetectionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ML_az_dsort2(Scalar dlist[], LocalOrdinal N, LocalOrdinal list2[]) const { void LineDetectionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ML_az_dsort2(typename Teuchos::ScalarTraits<Scalar>::coordinateType dlist[], LocalOrdinal N, LocalOrdinal list2[]) const {
LO l, r, j, i, flag; LO l, r, j, i, flag;
LO RR2; LO RR2;
SC dRR, dK; coordinate_type dRR, dK;
// note: we use that routine for sorting coordinates only. No complex coordinates are assumed... // note: we use that routine for sorting coordinates only. No complex coordinates are assumed...
typedef Teuchos::ScalarTraits<SC> STS; typedef Teuchos::ScalarTraits<SC> STS;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment