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>
52 
53 #include "MueLu_ConfigDefs.hpp"
55 #include "MueLu_GraphBase.hpp"
56 
57 #include <list>
58 
59 namespace MueLu {
60 
61  class Level;
62  //Utility classes used in convex hull algorithm
63 
64  class myTriangle
65  {
66  public:
67  myTriangle() : v1(0), v2(0), v3(0) {}
68  myTriangle(int v1in, int v2in, int v3in) : v1(v1in), v2(v2in), v3(v3in) {}
70  bool operator==(const myTriangle& l)
71  {
72  if(l.v1 == v1 && l.v2 == v2 && l.v3 == v3)
73  return true;
74  return false;
75  }
76  int v1;
77  int v2;
78  int v3;
79  };
80 
81  class myVec3
82  {
83  public:
84  myVec3() : x(0), y(0), z(0) {}
85  myVec3(double xin, double yin, double zin) : x(xin), y(yin), z(zin) {}
86  ~myVec3() {}
87  double x;
88  double y;
89  double z;
90  };
91 
92  class myVec2
93  {
94  public:
95  myVec2() : x(0), y(0) {}
96  myVec2(double xin, double yin) : x(xin), y(yin) {}
97  ~myVec2() {}
98  double x;
99  double y;
100  };
101 
111  template <class Scalar = double, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType>
112  class VisualizationHelpers {
113 #undef MUELU_VISUALIZATIONHELPERS_SHORT
114 #include "MueLu_UseShortNames.hpp"
115 
116  public:
118 
119 
122 
124  virtual ~VisualizationHelpers() { }
126 
128 
129  protected:
130 
131  void writeFileVTKOpening(std::ofstream & fout, std::vector<int> & uniqueFine, std::vector<int> & geomSizesFine) const;
132  void writeFileVTKNodes(std::ofstream & fout, std::vector<int> & uniqueFine, Teuchos::RCP<const Map> & nodeMap) const;
133  void writeFileVTKData(std::ofstream & fout, std::vector<int> & uniqueFine, LocalOrdinal myAggOffset, ArrayRCP<LocalOrdinal> & vertex2AggId, int myRank) const;
134  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;
135  void writeFileVTKCells(std::ofstream & fout, std::vector<int> & uniqueFine, std::vector<LocalOrdinal> & vertices, std::vector<LocalOrdinal> & geomSize) const;
136  void writeFileVTKClosing(std::ofstream & fout) const;
137  void writePVTU(std::ofstream& pvtu, std::string baseFname, int numProcs, bool bFineEdges = false, bool bCoarseEdges = false) const;
138  void buildColormap() const;
139 
140  std::string getFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList& pL) const;
141  std::string getBaseFileName(int numProcs, int level, const Teuchos::ParameterList& pL) const;
142  std::string getPVTUFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList& pL) const;
143 
144  // move these routines to a common base class for visualization factories?
145  static void doPointCloud(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes);
146  static void doJacks(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector<bool>& isRoot, const ArrayRCP<LO>& vertex2AggId);
147  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);
148  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);
149 
150 #ifdef HAVE_MUELU_CGAL
151  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);
152  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);
153 #endif
154 
155  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);
156 
157  static myVec3 crossProduct(myVec3 v1, myVec3 v2);
158  static double dotProduct(myVec2 v1, myVec2 v2);
159  static double dotProduct(myVec3 v1, myVec3 v2);
160  static bool isInFront(myVec3 point, myVec3 inPlane, myVec3 n);
161  static double mymagnitude(myVec2 vec);
162  static double mymagnitude(myVec3 vec);
163  static double distance(myVec2 p1, myVec2 p2);
164  static double distance(myVec3 p1, myVec3 p2);
165  static myVec2 vecSubtract(myVec2 v1, myVec2 v2);
166  static myVec3 vecSubtract(myVec3 v1, myVec3 v2);
167  static myVec2 getNorm(myVec2 v);
168  static myVec3 getNorm(myVec3 v1, myVec3 v2, myVec3 v3);
169  static double pointDistFromTri(myVec3 point, myVec3 v1, myVec3 v2, myVec3 v3);
170  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);
171  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);
172 
173  std::string replaceAll(std::string result, const std::string& replaceWhat, const std::string& replaceWithWhat) const;
174  std::vector<int> makeUnique(std::vector<int>& vertices) const;
175  }; // class VisualizationHelpers
176 } // namespace MueLu
177 
178 #define MUELU_VISUALIZATIONHELPERS_SHORT
179 
180 #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
LocalOrdinal LO
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 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)
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
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 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
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)