MueLu  Version of the Day
MueLu_VisualizationHelpers_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 
47 #ifndef MUELU_VISUALIZATIONHELPERS_DECL_HPP_
48 #define MUELU_VISUALIZATIONHELPERS_DECL_HPP_
49 
50 #include <Xpetra_Matrix_fwd.hpp>
51 #include <Xpetra_CrsMatrixWrap_fwd.hpp>
52 
53 #include "MueLu_ConfigDefs.hpp"
55 #include "MueLu_GraphBase.hpp"
56 
57 namespace MueLu {
58 
59  class Level;
60  //Utility classes used in convex hull algorithm
61 
62  class myTriangle
63  {
64  public:
65  myTriangle() : v1(0), v2(0), v3(0) {}
66  myTriangle(int v1in, int v2in, int v3in) : v1(v1in), v2(v2in), v3(v3in) {}
68  bool operator==(const myTriangle& l)
69  {
70  if(l.v1 == v1 && l.v2 == v2 && l.v3 == v3)
71  return true;
72  return false;
73  }
74  int v1;
75  int v2;
76  int v3;
77  };
78 
79  class myVec3
80  {
81  public:
82  myVec3() : x(0), y(0), z(0) {}
83  myVec3(double xin, double yin, double zin) : x(xin), y(yin), z(zin) {}
84  ~myVec3() {}
85  double x;
86  double y;
87  double z;
88  };
89 
90  class myVec2
91  {
92  public:
93  myVec2() : x(0), y(0) {}
94  myVec2(double xin, double yin) : x(xin), y(yin) {}
95  ~myVec2() {}
96  double x;
97  double y;
98  };
99 
109  template <class Scalar = double, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType>
110  class VisualizationHelpers {
111 #undef MUELU_VISUALIZATIONHELPERS_SHORT
112 #include "MueLu_UseShortNames.hpp"
113 
114  public:
116 
117 
120 
122  virtual ~VisualizationHelpers() { }
124 
126 
127  protected:
128 
129  void writeFileVTKOpening(std::ofstream & fout, std::vector<int> & uniqueFine, std::vector<int> & geomSizesFine) const;
130  void writeFileVTKNodes(std::ofstream & fout, std::vector<int> & uniqueFine, Teuchos::RCP<const Map> & nodeMap) const;
131  void writeFileVTKData(std::ofstream & fout, std::vector<int> & uniqueFine, LocalOrdinal myAggOffset, ArrayRCP<LocalOrdinal> & vertex2AggId, int myRank) const;
132  void writeFileVTKCoordinates(std::ofstream & fout, std::vector<int> & uniqueFine, Teuchos::ArrayRCP<const double> & fx, Teuchos::ArrayRCP<const double> & fy, Teuchos::ArrayRCP<const double> & fz, int dim) const;
133  void writeFileVTKCells(std::ofstream & fout, std::vector<int> & uniqueFine, std::vector<LocalOrdinal> & vertices, std::vector<LocalOrdinal> & geomSize) const;
134  void writeFileVTKClosing(std::ofstream & fout) const;
135  void writePVTU(std::ofstream& pvtu, std::string baseFname, int numProcs, bool bFineEdges = false, bool bCoarseEdges = false) const;
136  void buildColormap() const;
137 
138  std::string getFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList& pL) const;
139  std::string getBaseFileName(int numProcs, int level, const Teuchos::ParameterList& pL) const;
140  std::string getPVTUFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList& pL) const;
141 
142  // move these routines to a common base class for visualization factories?
143  static void doPointCloud(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes);
144  static void doJacks(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector<bool>& isRoot, const ArrayRCP<LO>& vertex2AggId);
145  static void doConvexHulls2D(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector<bool>& isRoot, const ArrayRCP<LO>& vertex2AggId, const Teuchos::ArrayRCP<const double>& xCoords, const Teuchos::ArrayRCP<const double>& yCoords, const Teuchos::ArrayRCP<const double>& zCoords);
146  static void doConvexHulls3D(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector<bool>& isRoot, const ArrayRCP<LO>& vertex2AggId, const Teuchos::ArrayRCP<const double>& xCoords, const Teuchos::ArrayRCP<const double>& yCoords, const Teuchos::ArrayRCP<const double>& zCoords);
147 
148 #ifdef HAVE_MUELU_CGAL
149  static void doCGALConvexHulls2D(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector<bool>& isRoot, const ArrayRCP<LO>& vertex2AggId, const Teuchos::ArrayRCP<const double>& xCoords, const Teuchos::ArrayRCP<const double>& yCoords, const Teuchos::ArrayRCP<const double>& zCoords);
150  static void doCGALConvexHulls3D(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector<bool>& isRoot, const ArrayRCP<LO>& vertex2AggId, const Teuchos::ArrayRCP<const double>& xCoords, const Teuchos::ArrayRCP<const double>& yCoords, const Teuchos::ArrayRCP<const double>& zCoords);
151 #endif
152 
153  static void doGraphEdges(std::vector<int>& vertices, std::vector<int>& geomSizes, Teuchos::RCP<GraphBase>& G, Teuchos::ArrayRCP<const double> & fx, Teuchos::ArrayRCP<const double> & fy, Teuchos::ArrayRCP<const double> & fz);
154 
155  static myVec3 crossProduct(myVec3 v1, myVec3 v2);
156  static double dotProduct(myVec2 v1, myVec2 v2);
157  static double dotProduct(myVec3 v1, myVec3 v2);
158  static bool isInFront(myVec3 point, myVec3 inPlane, myVec3 n);
159  static double mymagnitude(myVec2 vec);
160  static double mymagnitude(myVec3 vec);
161  static double distance(myVec2 p1, myVec2 p2);
162  static double distance(myVec3 p1, myVec3 p2);
163  static myVec2 vecSubtract(myVec2 v1, myVec2 v2);
164  static myVec3 vecSubtract(myVec3 v1, myVec3 v2);
165  static myVec2 getNorm(myVec2 v);
166  static myVec3 getNorm(myVec3 v1, myVec3 v2, myVec3 v3);
167  static double pointDistFromTri(myVec3 point, myVec3 v1, myVec3 v2, myVec3 v3);
168  static std::vector<myTriangle> processTriangle(std::list<myTriangle>& tris, myTriangle tri, std::list<int>& pointsInFront, myVec3& barycenter, const Teuchos::ArrayRCP<const double>& xCoords, const Teuchos::ArrayRCP<const double>& yCoords, const Teuchos::ArrayRCP<const double>& zCoords);
169  static std::vector<int> giftWrap(std::vector<myVec2>& points, std::vector<int>& nodes, const Teuchos::ArrayRCP<const double> & xCoords, const Teuchos::ArrayRCP<const double> & yCoords);
170 
171  std::string replaceAll(std::string result, const std::string& replaceWhat, const std::string& replaceWithWhat) const;
172  std::vector<int> makeUnique(std::vector<int>& vertices) const;
173  }; // class VisualizationHelpers
174 } // namespace MueLu
175 
176 #define MUELU_VISUALIZATIONHELPERS_SHORT
177 
178 #endif /* MUELU_VISUALIZATIONHELPERS_DECL_HPP_ */
void writePVTU(std::ofstream &pvtu, std::string baseFname, int numProcs, bool bFineEdges=false, bool bCoarseEdges=false) const
static void doPointCloud(std::vector< int > &vertices, std::vector< int > &geomSizes, LO numLocalAggs, LO numFineNodes)
void writeFileVTKOpening(std::ofstream &fout, std::vector< int > &uniqueFine, std::vector< int > &geomSizesFine) const
myVec2(double xin, double yin)
RCP< ParameterList > GetValidParameterList() const
myTriangle(int v1in, int v2in, int v3in)
std::string getPVTUFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList &pL) const
Namespace for MueLu classes and methods.
void writeFileVTKNodes(std::ofstream &fout, std::vector< int > &uniqueFine, Teuchos::RCP< const Map > &nodeMap) const
void writeFileVTKCoordinates(std::ofstream &fout, std::vector< int > &uniqueFine, Teuchos::ArrayRCP< const double > &fx, Teuchos::ArrayRCP< const double > &fy, Teuchos::ArrayRCP< const double > &fz, int dim) const
static double pointDistFromTri(myVec3 point, myVec3 v1, myVec3 v2, myVec3 v3)
static double dotProduct(myVec2 v1, myVec2 v2)
Base class providing routines to visualize aggregates and coarsening information. ...
std::vector< int > makeUnique(std::vector< int > &vertices) const
replaces node indices in vertices with compressed unique indices, and returns list of unique points ...
static void doGraphEdges(std::vector< int > &vertices, std::vector< int > &geomSizes, Teuchos::RCP< GraphBase > &G, Teuchos::ArrayRCP< const double > &fx, Teuchos::ArrayRCP< const double > &fy, Teuchos::ArrayRCP< const double > &fz)
std::string replaceAll(std::string result, const std::string &replaceWhat, const std::string &replaceWithWhat) const
static std::vector< int > giftWrap(std::vector< myVec2 > &points, std::vector< int > &nodes, const Teuchos::ArrayRCP< const double > &xCoords, const Teuchos::ArrayRCP< const double > &yCoords)
static void doJacks(std::vector< int > &vertices, std::vector< int > &geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector< bool > &isRoot, const ArrayRCP< LO > &vertex2AggId)
void writeFileVTKCells(std::ofstream &fout, std::vector< int > &uniqueFine, std::vector< LocalOrdinal > &vertices, std::vector< LocalOrdinal > &geomSize) const
static void doConvexHulls2D(std::vector< int > &vertices, std::vector< int > &geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector< bool > &isRoot, const ArrayRCP< LO > &vertex2AggId, const Teuchos::ArrayRCP< const double > &xCoords, const Teuchos::ArrayRCP< const double > &yCoords, const Teuchos::ArrayRCP< const double > &zCoords)
void writeFileVTKData(std::ofstream &fout, std::vector< int > &uniqueFine, LocalOrdinal myAggOffset, ArrayRCP< LocalOrdinal > &vertex2AggId, int myRank) const
bool operator==(const myTriangle &l)
static myVec3 crossProduct(myVec3 v1, myVec3 v2)
static myVec2 vecSubtract(myVec2 v1, myVec2 v2)
static void doCGALConvexHulls2D(std::vector< int > &vertices, std::vector< int > &geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector< bool > &isRoot, const ArrayRCP< LO > &vertex2AggId, const Teuchos::ArrayRCP< const double > &xCoords, const Teuchos::ArrayRCP< const double > &yCoords, const Teuchos::ArrayRCP< const double > &zCoords)
static void doCGALConvexHulls3D(std::vector< int > &vertices, std::vector< int > &geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector< bool > &isRoot, const ArrayRCP< LO > &vertex2AggId, const Teuchos::ArrayRCP< const double > &xCoords, const Teuchos::ArrayRCP< const double > &yCoords, const Teuchos::ArrayRCP< const double > &zCoords)
std::string getFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList &pL) const
void writeFileVTKClosing(std::ofstream &fout) const
static std::vector< myTriangle > processTriangle(std::list< myTriangle > &tris, myTriangle tri, std::list< int > &pointsInFront, myVec3 &barycenter, const Teuchos::ArrayRCP< const double > &xCoords, const Teuchos::ArrayRCP< const double > &yCoords, const Teuchos::ArrayRCP< const double > &zCoords)
static void doConvexHulls3D(std::vector< int > &vertices, std::vector< int > &geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector< bool > &isRoot, const ArrayRCP< LO > &vertex2AggId, const Teuchos::ArrayRCP< const double > &xCoords, const Teuchos::ArrayRCP< const double > &yCoords, const Teuchos::ArrayRCP< const double > &zCoords)
static double distance(myVec2 p1, myVec2 p2)
static bool isInFront(myVec3 point, myVec3 inPlane, myVec3 n)
myVec3(double xin, double yin, double zin)
std::string getBaseFileName(int numProcs, int level, const Teuchos::ParameterList &pL) const