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
42namespace Nektar::FieldUtils
43{
44
45/**
46 * Converter for STL files.
47 */
49{
50public:
51 /// Creates an instance of this class
53 {
55 }
56 /// ModuleKey for class.
58
60 ~ProcessPhiFromFile() override;
61
62protected:
63 void v_Process(po::variables_map &vm) override;
64
65 std::string v_GetModuleName() override
66 {
67 return "ProcessPhiFromFile";
68 }
69
70 std::string v_GetModuleDescription() override
71 {
72 return "Processing input STL file to calculate Phi";
73 }
74
76 {
77 return eModifyExp;
78 }
79
80protected:
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 }
93 };
94 /// STL file object
95 struct STLobject
96 {
97 // Number of triangles
99 // Triangles definition
101 };
102 /// Octree object
104
105 // Reads one vector from a binary STL file
106 Array<OneD, NekDouble> ReadVector(std::ifstream &in);
107 // Reads an STL file and returns an 'STLobject' struct
108 STLobject ReadSTL(std::string filename);
109 // Smoothing function
110 NekDouble PhiFunction(double dist, double coeff);
111 // Calculates Phi from 'ShapeFunction' in the session file
112 void GetPhifromSession();
113 // Calculates Phi from an external STL binary file
114 void GetPhifromSTL(const STLobject &file);
115 // Checks if a ray hits a specific 3D triangle
116 bool CheckHit(const triangle &tri, const Array<OneD, NekDouble> &Origin,
117 const Array<OneD, NekDouble> &Dvec, double &distance,
118 double &u, double &v);
119 // Shortest distance from a point to a 3D geometry
120 void FindShortestDist(const STLobject &file,
121 const Array<OneD, NekDouble> &x, 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
134private:
135};
136} // namespace Nektar::FieldUtils
137
138#endif // FIELDUTILS_PROCESSPHIFROMFILE
Abstract base class for processing modules.
Definition: Module.h:301
static ModuleKey m_className
ModuleKey for class.
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'.
std::string v_GetModuleDescription() override
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 .
void v_Process(po::variables_map &vm) override
ModulePriority v_GetModulePriority() override
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:1026
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
std::shared_ptr< Module > ModuleSharedPtr
Definition: Module.h:329
std::uint32_t NekUInt32
double NekDouble