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
43{
44namespace FieldUtils
45{
46
47/**
48 * Converter for STL files.
49 */
51{
52public:
53 /// Creates an instance of this class
55 {
57 }
58 /// ModuleKey for class.
60
62 virtual ~ProcessPhiFromFile();
63
64protected:
65 virtual void v_Process(po::variables_map &vm) override;
66
67 virtual std::string v_GetModuleName() override
68 {
69 return "ProcessPhiFromFile";
70 }
71
72 virtual std::string v_GetModuleDescription() override
73 {
74 return "Processing input STL file to calculate Phi";
75 }
76
78 {
79 return eModifyExp;
80 }
81
82protected:
83 /// Object representing a 3D triangle
84 struct triangle
85 {
91
92 triangle() : normal(3, 0.0), v0(3, 0.0), v1(3, 0.0), v2(3, 0.0)
93 {
94 }
95 };
96 /// STL file object
97 struct STLobject
98 {
99 // Number of triangles
101 // Triangles definition
103 };
104 /// Octree object
106
107 // Reads one vector from a binary STL file
108 Array<OneD, NekDouble> ReadVector(std::ifstream &in);
109 // Reads an STL file and returns an 'STLobject' struct
110 STLobject ReadSTL(std::string filename);
111 // Smoothing function
112 NekDouble PhiFunction(double dist, double coeff);
113 // Calculates Phi from 'ShapeFunction' in the session file
114 void GetPhifromSession();
115 // Calculates Phi from an external STL binary file
116 void GetPhifromSTL(const STLobject &file);
117 // Checks if a ray hits a specific 3D triangle
118 bool CheckHit(const triangle &tri, const Array<OneD, NekDouble> &Origin,
119 const Array<OneD, NekDouble> &Dvec, double &distance,
120 double &u, double &v);
121 // Shortest distance from a point to a 3D geometry
122 void FindShortestDist(const STLobject &file,
123 const Array<OneD, NekDouble> &x, double &dist);
124 // Utility to find if two doubles are equal
125 bool IsEqual(double x, double y, double relTol);
126 // Utility to find if a double is negative with a certain tolerance
127 bool IsNegative(double x, double tol);
128 // Utility to calculate the cross-product of two 3D vectors
130 const Array<OneD, NekDouble> &v1);
131 // Utility to measure shortest distance to a segment
133 const Array<OneD, NekDouble> &e1,
134 const Array<OneD, NekDouble> &e2);
135
136private:
137};
138} // namespace FieldUtils
139} // namespace Nektar
140
141#endif // FIELDUTILS_PROCESSPHIFROMFILE
Abstract base class for processing modules.
Definition: Module.h:292
static ModuleKey m_className
ModuleKey for class.
virtual std::string v_GetModuleDescription() override
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'....
virtual std::string v_GetModuleName() override
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'.
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.
virtual ModulePriority v_GetModulePriority() override
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 .
virtual void v_Process(po::variables_map &vm) 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:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
std::shared_ptr< Module > ModuleSharedPtr
Definition: Module.h:321
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::uint32_t NekUInt32
double NekDouble