MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_VisualizationHelpers_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_VISUALIZATIONHELPERS_DECL_HPP_
11 #define MUELU_VISUALIZATIONHELPERS_DECL_HPP_
12 
13 #include "MueLu_ConfigDefs.hpp"
15 #include "MueLu_LWGraph.hpp"
16 
17 #include <list>
18 
19 namespace MueLu {
20 
21 class Level;
22 // Utility classes used in convex hull algorithm
23 
24 class myTriangle {
25  public:
27  : v1(0)
28  , v2(0)
29  , v3(0) {}
30  myTriangle(int v1in, int v2in, int v3in)
31  : v1(v1in)
32  , v2(v2in)
33  , v3(v3in) {}
35  bool operator==(const myTriangle& l) {
36  if (l.v1 == v1 && l.v2 == v2 && l.v3 == v3)
37  return true;
38  return false;
39  }
40  int v1;
41  int v2;
42  int v3;
43 };
44 
45 class myVec3 {
46  public:
48  : x(0)
49  , y(0)
50  , z(0) {}
51  myVec3(double xin, double yin, double zin)
52  : x(xin)
53  , y(yin)
54  , z(zin) {}
55  ~myVec3() {}
56  double x;
57  double y;
58  double z;
59 };
60 
61 class myVec2 {
62  public:
64  : x(0)
65  , y(0) {}
66  myVec2(double xin, double yin)
67  : x(xin)
68  , y(yin) {}
69  ~myVec2() {}
70  double x;
71  double y;
72 };
73 
83 template <class Scalar = DefaultScalar,
86  class Node = DefaultNode>
88 #undef MUELU_VISUALIZATIONHELPERS_SHORT
89 #include "MueLu_UseShortNames.hpp"
90 
91  public:
93 
94 
97 
99  virtual ~VisualizationHelpers() {}
101 
103 
104  protected:
105  void writeFileVTKOpening(std::ofstream& fout, std::vector<int>& uniqueFine, std::vector<int>& geomSizesFine) const;
106  void writeFileVTKNodes(std::ofstream& fout, std::vector<int>& uniqueFine, Teuchos::RCP<const Map>& nodeMap) const;
107  void writeFileVTKData(std::ofstream& fout, std::vector<int>& uniqueFine, LocalOrdinal myAggOffset, ArrayRCP<LocalOrdinal>& vertex2AggId, int myRank) const;
108  void writeFileVTKCoordinates(std::ofstream& fout, std::vector<int>& uniqueFine, Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& fx, Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& fy, Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& fz, int dim) const;
109  void writeFileVTKCells(std::ofstream& fout, std::vector<int>& uniqueFine, std::vector<LocalOrdinal>& vertices, std::vector<LocalOrdinal>& geomSize) const;
110  void writeFileVTKClosing(std::ofstream& fout) const;
111  void writePVTU(std::ofstream& pvtu, std::string baseFname, int numProcs, bool bFineEdges = false, bool bCoarseEdges = false) const;
112  void buildColormap() const;
113 
114  std::string getFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList& pL) const;
115  std::string getBaseFileName(int numProcs, int level, const Teuchos::ParameterList& pL) const;
116  std::string getPVTUFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList& pL) const;
117 
118  // move these routines to a common base class for visualization factories?
119  static void doPointCloud(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes);
120  static void doJacks(std::vector<int>& vertices, std::vector<int>& geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector<bool>& isRoot, const ArrayRCP<LO>& vertex2AggId);
121  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 typename Teuchos::ScalarTraits<Scalar>::coordinateType>& xCoords, const Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& yCoords);
122  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 typename Teuchos::ScalarTraits<Scalar>::coordinateType>& xCoords, const Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& yCoords, const Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& zCoords);
123 
124  static void doGraphEdges(std::vector<int>& vertices, std::vector<int>& geomSizes, Teuchos::RCP<LWGraph>& G, Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& fx, Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& fy, Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& fz);
125 
126  static int ccw(const myVec2& a, const myVec2& b, const myVec2& c);
127  static myVec3 crossProduct(myVec3 v1, myVec3 v2);
128  static double dotProduct(myVec2 v1, myVec2 v2);
129  static double dotProduct(myVec3 v1, myVec3 v2);
130  static bool isInFront(myVec3 point, myVec3 inPlane, myVec3 n);
131  static double mymagnitude(myVec2 vec);
132  static double mymagnitude(myVec3 vec);
133  static double distance(myVec2 p1, myVec2 p2);
134  static double distance(myVec3 p1, myVec3 p2);
135  static myVec2 vecSubtract(myVec2 v1, myVec2 v2);
136  static myVec3 vecSubtract(myVec3 v1, myVec3 v2);
137  static myVec2 getNorm(myVec2 v);
138  static myVec3 getNorm(myVec3 v1, myVec3 v2, myVec3 v3);
139  static double pointDistFromTri(myVec3 point, myVec3 v1, myVec3 v2, myVec3 v3);
140  static std::vector<myTriangle> processTriangle(std::list<myTriangle>& tris, myTriangle tri, std::list<int>& pointsInFront, myVec3& barycenter, const Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& xCoords, const Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& yCoords, const Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& zCoords);
141  static std::vector<int> giftWrap(std::vector<myVec2>& points, std::vector<int>& nodes, const Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& xCoords, const Teuchos::ArrayRCP<const typename Teuchos::ScalarTraits<Scalar>::coordinateType>& yCoords);
142 
143  std::string replaceAll(std::string result, const std::string& replaceWhat, const std::string& replaceWithWhat) const;
144  std::vector<int> makeUnique(std::vector<int>& vertices) const;
145 }; // class VisualizationHelpers
146 } // namespace MueLu
147 
148 #define MUELU_VISUALIZATIONHELPERS_SHORT
149 
150 #endif /* MUELU_VISUALIZATIONHELPERS_DECL_HPP_ */
static void doPointCloud(std::vector< int > &vertices, std::vector< int > &geomSizes, LO numLocalAggs, LO numFineNodes)
MueLu::DefaultLocalOrdinal LocalOrdinal
myVec2(double xin, double yin)
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
std::string getPVTUFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList &pL) const
void writeFileVTKOpening(std::ofstream &fout, std::vector< int > &uniqueFine, std::vector< int > &geomSizesFine) const
void writeFileVTKCoordinates(std::ofstream &fout, std::vector< int > &uniqueFine, Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &fx, Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &fy, Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &fz, int dim) const
std::string replaceAll(std::string result, const std::string &replaceWhat, const std::string &replaceWithWhat) 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 typename Teuchos::ScalarTraits< Scalar >::coordinateType > &xCoords, const Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &yCoords)
myTriangle(int v1in, int v2in, int v3in)
void writeFileVTKData(std::ofstream &fout, std::vector< int > &uniqueFine, LocalOrdinal myAggOffset, ArrayRCP< LocalOrdinal > &vertex2AggId, int myRank) const
std::vector< int > makeUnique(std::vector< int > &vertices) const
replaces node indices in vertices with compressed unique indices, and returns list of unique points ...
std::string getFileName(int numProcs, int myRank, int level, const Teuchos::ParameterList &pL) const
LocalOrdinal LO
void writeFileVTKNodes(std::ofstream &fout, std::vector< int > &uniqueFine, Teuchos::RCP< const Map > &nodeMap) const
MueLu::DefaultNode Node
RCP< ParameterList > GetValidParameterList() const
static int ccw(const myVec2 &a, const myVec2 &b, const myVec2 &c)
static double pointDistFromTri(myVec3 point, myVec3 v1, myVec3 v2, myVec3 v3)
static double dotProduct(myVec2 v1, myVec2 v2)
void writePVTU(std::ofstream &pvtu, std::string baseFname, int numProcs, bool bFineEdges=false, bool bCoarseEdges=false) const
Base class providing routines to visualize aggregates and coarsening information. ...
std::string getBaseFileName(int numProcs, int level, const Teuchos::ParameterList &pL) const
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 typename Teuchos::ScalarTraits< Scalar >::coordinateType > &xCoords, const Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &yCoords, const Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &zCoords)
MueLu::DefaultScalar Scalar
Tpetra::Details::DefaultTypes::scalar_type DefaultScalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
static void doJacks(std::vector< int > &vertices, std::vector< int > &geomSizes, LO numLocalAggs, LO numFineNodes, const std::vector< bool > &isRoot, const ArrayRCP< LO > &vertex2AggId)
bool operator==(const myTriangle &l)
static myVec3 crossProduct(myVec3 v1, myVec3 v2)
static myVec2 vecSubtract(myVec2 v1, myVec2 v2)
static double distance(myVec2 p1, myVec2 p2)
void writeFileVTKCells(std::ofstream &fout, std::vector< int > &uniqueFine, std::vector< LocalOrdinal > &vertices, std::vector< LocalOrdinal > &geomSize) const
static bool isInFront(myVec3 point, myVec3 inPlane, myVec3 n)
myVec3(double xin, double yin, double zin)
static std::vector< myTriangle > processTriangle(std::list< myTriangle > &tris, myTriangle tri, std::list< int > &pointsInFront, myVec3 &barycenter, const Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &xCoords, const Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &yCoords, const Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &zCoords)
static void doGraphEdges(std::vector< int > &vertices, std::vector< int > &geomSizes, Teuchos::RCP< LWGraph > &G, Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &fx, Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &fy, Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &fz)
static std::vector< int > giftWrap(std::vector< myVec2 > &points, std::vector< int > &nodes, const Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &xCoords, const Teuchos::ArrayRCP< const typename Teuchos::ScalarTraits< Scalar >::coordinateType > &yCoords)
void writeFileVTKClosing(std::ofstream &fout) const