Nektar++
ProcessPhiFromFile.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessPhiFromFile.h
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: geometry file converter.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef FIELDUTILS_PROCESSPHIFROMFILE
36 #define FIELDUTILS_PROCESSPHIFROMFILE
37 
38 #include "../Module.h"
39 #include "../Octree.h"
40 #include <random>
41 
42 namespace Nektar
43 {
44 namespace FieldUtils
45 {
46 
47 /**
48  * Converter for STL files.
49  */
51 {
52 public:
53  /// Creates an instance of this class
55  {
57  }
58  /// ModuleKey for class.
60 
62  virtual ~ProcessPhiFromFile();
63  virtual void Process(po::variables_map &vm);
64 
65  virtual std::string GetModuleName()
66  {
67  return "ProcessPhiFromFile";
68  }
69 
70  virtual std::string GetModuleDescription()
71  {
72  return "Processing input STL file to calculate Phi";
73  }
74 
76  {
77  return eModifyExp;
78  }
79 
80 protected:
81  /// Object representing a 3D triangle
82  struct triangle
83  {
89 
90  triangle() : normal(3, 0.0), v0(3, 0.0), v1(3, 0.0), v2(3, 0.0) {}
91  };
92  /// STL file object
93  struct STLobject
94  {
95  // Number of triangles
97  // Triangles definition
99  };
100  /// Octree object
102 
103  // Reads one vector from a binary STL file
104  Array<OneD, NekDouble> ReadVector(std::ifstream &in);
105  // Reads an STL file and returns an 'STLobject' struct
106  STLobject ReadSTL(std::string filename);
107  // Smoothing function
108  NekDouble PhiFunction(double dist, double coeff);
109  // Calculates Phi from 'ShapeFunction' in the session file
110  void GetPhifromSession();
111  // Calculates Phi from an external STL binary file
112  void GetPhifromSTL(const STLobject &file);
113  // Checks if a ray hits a specific 3D triangle
114  bool CheckHit(const triangle &tri,
115  const Array<OneD, NekDouble> &Origin,
116  const Array<OneD, NekDouble> &Dvec,
117  double &distance, double &u, double &v);
118  // Shortest distance from a point to a 3D geometry
119  void FindShortestDist(const STLobject &file,
120  const Array<OneD, NekDouble> &x,
121  double &dist);
122  // Utility to find if two doubles are equal
123  bool IsEqual(double x, double y, double relTol);
124  // Utility to find if a double is negative with a certain tolerance
125  bool IsNegative(double x, double tol);
126  // Utility to calculate the cross-product of two 3D vectors
128  const Array<OneD, NekDouble> &v1);
129  // Utility to measure shortest distance to a segment
131  const Array<OneD, NekDouble> &e1,
132  const Array<OneD, NekDouble> &e2);
133 
134 private:
135 };
136 }
137 }
138 
139 #endif // FIELDUTILS_PROCESSPHIFROMFILE
Abstract base class for processing modules.
Definition: Module.h:265
static ModuleKey m_className
ModuleKey for class.
virtual void Process(po::variables_map &vm)
bool CheckHit(const triangle &tri, const Array< OneD, NekDouble > &Origin, const Array< OneD, NekDouble > &Dvec, double &distance, double &u, double &v)
Checks if a ray traced from 'Origin' with direction 'Dvec' hits the triangle defined by 'tri'....
void GetPhifromSession()
Assigns to 'phi' the values indicated by 'ShapeFunction'.
Array< OneD, NekDouble > Vector2edge(const Array< OneD, NekDouble > &x, const Array< OneD, NekDouble > &e1, const Array< OneD, NekDouble > &e2)
Determines the shortest distance from a point 'x' to the segment defined by the points 'e1' and 'e2'....
Array< OneD, NekDouble > Cross(const Array< OneD, NekDouble > &v0, const Array< OneD, NekDouble > &v1)
Returns the cross product of vectors 'v0' y 'v1'.
virtual ModulePriority GetModulePriority()
ProcessPhiFromFile(FieldSharedPtr f)
Set up ProcessPhiFromFile object.
STLobject ReadSTL(std::string filename)
Read an STL binary file and returns a struct of type 'STLobject' containing the parsed data.
void GetPhifromSTL(const STLobject &file)
Assigns to 'phi' the corresponding values of Phi.
static ModuleSharedPtr create(FieldSharedPtr f)
Creates an instance of this class.
void FindShortestDist(const STLobject &file, const Array< OneD, NekDouble > &x, double &dist)
Calculates the shortest distance from a point to the closed body contained in the STL file.
NekDouble PhiFunction(double dist, double coeff)
Smoothing function for the SPM method given a distance value and a scaling coefficient.
bool IsNegative(double x, double tol)
Returns true if .
bool IsEqual(double x, double y, double relTol)
Returns true if within the relative tolerance 'relTol' (relative to 'y')
Array< OneD, NekDouble > ReadVector(std::ifstream &in)
Read one 3D vector from a STL file, starting from the next line of the input 'ifstream'....
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
std::shared_ptr< Module > ModuleSharedPtr
Definition: Module.h:294
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
std::uint32_t NekUInt32
double NekDouble