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 {
public:
using coordinate_type = typename Teuchos::ScalarTraits<SC>::coordinateType;
using CoordinateMultiVector = typename Xpetra::MultiVector<coordinate_type, LO, GO, NO>;
//! @name Constructors/Destructors.
//@{
......@@ -103,15 +106,22 @@ namespace MueLu {
//@}
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 Ndof, LO DofsPerNode,
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 ;
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
//! can be either vertical, horizontal or coordinates
......
......@@ -93,9 +93,9 @@ namespace MueLu {
FactoryMonitor m(*this, "Line detection (Ray style)", currentLevel);
LO NumZDir = 0;
RCP<MultiVector> fineCoords;
ArrayRCP<Scalar> x, y, z;
Scalar *xptr = NULL, *yptr = NULL, *zptr = NULL;
RCP<CoordinateMultiVector> fineCoords;
ArrayRCP<coordinate_type> x, y, z;
coordinate_type *xptr = NULL, *yptr = NULL, *zptr = NULL;
// obtain general variables
RCP<Matrix> A = Get< RCP<Matrix> > (currentLevel, "A");
......@@ -137,7 +137,7 @@ namespace MueLu {
if (CoordsAvail == true) {
// 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.");
x = fineCoords->getDataNonConst(0);
y = fineCoords->getDataNonConst(1);
......@@ -150,9 +150,9 @@ namespace MueLu {
/* 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<SC> Txtemp = Teuchos::arcp<SC>(NumCoords); SC* xtemp = Txtemp.getRawPtr();
Teuchos::ArrayRCP<SC> Tytemp = Teuchos::arcp<SC>(NumCoords); SC* ytemp = Tytemp.getRawPtr();
Teuchos::ArrayRCP<SC> Tztemp = Teuchos::arcp<SC>(NumCoords); SC* ztemp = Tztemp.getRawPtr();
Teuchos::ArrayRCP<coordinate_type> Txtemp = Teuchos::arcp<coordinate_type>(NumCoords); coordinate_type* xtemp = Txtemp.getRawPtr();
Teuchos::ArrayRCP<coordinate_type> Tytemp = Teuchos::arcp<coordinate_type>(NumCoords); coordinate_type* ytemp = Tytemp.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
// switch x and y coordinates for semi-coarsening...
......@@ -165,7 +165,7 @@ namespace MueLu {
LO index = 0;
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;
while ( (next != NumCoords) && (xtemp[next] == xfirst) &&
(ytemp[next] == yfirst))
......@@ -210,7 +210,7 @@ namespace MueLu {
else
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.");
x = fineCoords->getDataNonConst(0);
y = fineCoords->getDataNonConst(1);
......@@ -253,12 +253,12 @@ namespace MueLu {
}
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 NumCoords, next; //, subindex, subnext;
SC xfirst, yfirst;
SC *xtemp, *ytemp, *ztemp;
coordinate_type xfirst, yfirst;
coordinate_type *xtemp, *ytemp, *ztemp;
LO *OrigLoc;
LO i,j,count;
LO RetVal;
......@@ -301,9 +301,9 @@ namespace MueLu {
// reserve temporary memory
Teuchos::ArrayRCP<LO> TOrigLoc= Teuchos::arcp<LO>(NumCoords); OrigLoc= TOrigLoc.getRawPtr();
Teuchos::ArrayRCP<SC> Txtemp = Teuchos::arcp<SC>(NumCoords); xtemp = Txtemp.getRawPtr();
Teuchos::ArrayRCP<SC> Tytemp = Teuchos::arcp<SC>(NumCoords); ytemp = Tytemp.getRawPtr();
Teuchos::ArrayRCP<SC> Tztemp = Teuchos::arcp<SC>(NumCoords); ztemp = Tztemp.getRawPtr();
Teuchos::ArrayRCP<coordinate_type> Txtemp = Teuchos::arcp<coordinate_type>(NumCoords); xtemp = Txtemp.getRawPtr();
Teuchos::ArrayRCP<coordinate_type> Tytemp = Teuchos::arcp<coordinate_type>(NumCoords); ytemp = Tytemp.getRawPtr();
Teuchos::ArrayRCP<coordinate_type> Tztemp = Teuchos::arcp<coordinate_type>(NumCoords); ztemp = Tztemp.getRawPtr();
// build vertical line info for semi-coarsening
......@@ -357,7 +357,14 @@ namespace MueLu {
/* 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>
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
for (LO i = 0; i < numCoords; i++) xtemp[i]= xvals[i];
......@@ -376,7 +383,7 @@ namespace MueLu {
LO index = 0;
while ( index < numCoords ) {
SC xfirst = xtemp[index];
coordinate_type xfirst = xtemp[index];
LO next = index+1;
while ( (next != numCoords) && (xtemp[next] == xfirst))
next++;
......@@ -385,7 +392,7 @@ namespace MueLu {
/* One final sort so that the ztemps are in order */
LO subindex = index;
while (subindex != next) {
SC yfirst = ytemp[subindex];
coordinate_type yfirst = ytemp[subindex];
LO subnext = subindex+1;
while ( (subnext != next) && (ytemp[subnext] == yfirst)) subnext++;
ML_az_dsort2(&(ztemp[subindex]),subnext-subindex,&(OrigLoc[subindex]));
......@@ -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.*/
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 RR2;
SC dRR, dK;
coordinate_type dRR, dK;
// note: we use that routine for sorting coordinates only. No complex coordinates are assumed...
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