38 #include <boost/core/ignore_unused.hpp>
48 ModuleKey ProcessPhiFromFile::m_className = {
51 "Computes the Phi function from a file, used in IB methods.")};
60 ConfigOption(
false,
"NotSet",
"Scale coefficient for Phi.");
62 ConfigOption(
false,
"NotSet",
"File with the IB definition.");
78 boost::ignore_unused(vm);
81 ASSERTL0(
m_f->m_session->GetComm()->IsSerial(),
"Parallel execution is "
82 "not supported yet in "
86 ASSERTL0(
m_f->m_graph,
"A session file file must be provided before the "
90 if (
m_f->m_exp[0]->GetNumElmts() == 0)
96 if (
m_config[
"file"].as<string>().compare(
"NotSet") == 0)
99 "Reading Phi function from session file, the provided scale "
100 "value will not be used");
107 "Need to specify a scale coefficient, scale=value");
127 in.read(buf,
sizeof(buf));
128 memcpy(&tmp, buf,
sizeof(buf));
130 in.read(buf,
sizeof(buf));
131 memcpy(&tmp, buf,
sizeof(buf));
133 in.read(buf,
sizeof(buf));
134 memcpy(&tmp, buf,
sizeof(buf));
152 ifstream fileStl(filename.c_str(), ios::binary);
153 ASSERTL0(fileStl,
"An error occurred while trying to open the STL file.")
161 fileStl.read(headerBuf,
sizeof(headerBuf));
162 fileStl.read(numTriBuf,
sizeof(numTriBuf));
163 memcpy(&out.
numTri, numTriBuf,
sizeof(numTriBuf));
180 centre[0] = (tmpTri.
v0[0] + tmpTri.
v1[0] + tmpTri.
v2[0]) / 3.0;
181 centre[1] = (tmpTri.
v0[1] + tmpTri.
v1[1] + tmpTri.
v2[1]) / 3.0;
182 centre[2] = (tmpTri.
v0[2] + tmpTri.
v1[2] + tmpTri.
v2[2]) / 3.0;
188 fileStl.read(dumpBuf,
sizeof(dumpBuf));
207 return -0.5 * (std::tanh(dist / coeff) - 1.0);
217 ASSERTL0(
m_f->m_session->DefinesFunction(
"ShapeFunction"),
218 "If file=file.stl is not supplied as an argument, a "
219 "'ShapeFunction' block must be provided in the session "
224 m_f->m_session->GetFunction(
"ShapeFunction",
"Phi");
227 int nPts =
m_f->m_exp[0]->GetNpoints();
228 int nVars =
m_f->m_variables.size();
230 m_f->m_session->LoadParameter(
"Strip_Z", nStrips, 1);
233 m_f->m_variables.push_back(
"phi");
235 for (
int s = 0; s < nStrips; ++s)
239 for (
int i = 0; i < 3; ++i)
243 m_f->m_exp[s * nVars]->GetCoords(coords[0], coords[1], coords[2]);
247 Exp =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
248 phiFunction->Evaluate(coords[0], coords[1], coords[2],
250 Exp->FwdTrans(Exp->GetPhys(), Exp->UpdateCoeffs());
252 auto it =
m_f->m_exp.begin() + s * (nVars + 1) + nVars;
253 m_f->m_exp.insert(it, Exp);
266 int nPts =
m_f->m_exp[0]->GetNpoints();
267 int nVars =
m_f->m_variables.size();
271 for (
int i = 0; i < 3; ++i)
275 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
278 m_f->m_variables.push_back(
"phi");
282 m_f->m_session->LoadParameter(
"Strip_Z", nStrips, 1);
286 bounds[0] = coords[0][0];
287 bounds[1] = coords[0][0];
288 bounds[2] = coords[1][0];
289 bounds[3] = coords[1][0];
290 bounds[4] = coords[2][0];
291 bounds[5] = coords[2][0];
292 for (
int i = 1; i < nPts; ++i)
294 bounds[0] = (bounds[0] < coords[0][i]) ? bounds[0] : coords[0][i];
295 bounds[1] = (bounds[1] > coords[0][i]) ? bounds[1] : coords[0][i];
296 bounds[2] = (bounds[2] < coords[1][i]) ? bounds[2] : coords[1][i];
297 bounds[3] = (bounds[3] > coords[1][i]) ? bounds[3] : coords[1][i];
298 bounds[4] = (bounds[4] < coords[2][i]) ? bounds[4] : coords[2][i];
299 bounds[5] = (bounds[5] > coords[2][i]) ? bounds[5] : coords[2][i];
302 for (
int i = 0; i < 6; ++i)
304 bounds[i] -= pow(-1, i) * 1e-10;
309 for (
int i = 0; i < file.
numTri; ++i)
311 centroids[i] = file.
triangles[i].centroid;
318 for (
int s = 0; s < nStrips; ++s)
322 phi =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
325 for (
int i = 0; i < nPts; ++i)
329 tmpCoords[2] = coords[2][i];
330 tmpCoords[1] = coords[1][i];
331 tmpCoords[0] = coords[0][i];
338 phi->UpdatePhys()[i] =
343 phi->FwdTrans(phi->GetPhys(), phi->UpdateCoeffs());
344 auto it =
m_f->m_exp.begin() + s * (nVars + 1) + nVars;
345 m_f->m_exp.insert(it, phi);
371 double &distance,
double &u,
double &v)
382 double inv_det = 1.0 / det;
385 distance = numeric_limits<double>::max();
386 u = numeric_limits<double>::max();
387 v = numeric_limits<double>::max();
402 if ((u < 0.0 || u > 1.0) || (v < 0.0 || u + v > 1.0))
429 dist = numeric_limits<double>::max();
436 vector<int> treeTriangles;
438 for (
int point : tmpTriangles)
440 treeTriangles.push_back(point);
445 for (
int neighNode : neighbours)
448 for (
int point : tmpTriangles)
450 treeTriangles.push_back(point);
460 double tParam = dist;
462 for (
int i = 0; i < treeTriangles.size(); ++i)
466 double currentTparam;
471 int currentDistSign = (currentTparam >= 0) - (currentTparam < 0);
481 currentDist = fabs(currentTparam);
506 if (dist - currentDist > 1e-5 * currentDist ||
507 (
IsEqual(dist, currentDist, 1e-5) &&
509 fabs(currentTparam) > fabs(tParam)))
512 tParam = currentTparam;
513 distSign = currentDistSign;
533 return (fabs(x - y) <= relTol * y);
561 out[0] = v0[1] * v1[2] - v0[2] * v1[1];
562 out[1] = v0[2] * v1[0] - v0[0] * v1[2];
563 out[2] = v0[0] * v1[1] - v0[1] * v1[0];
589 for (
size_t i = 0; i < n; ++i)
600 else if (proj > norm)
#define ASSERTL0(condition, msg)
#define WARNINGL0(condition, msg)
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
int QueryDepth(int nodeID)
std::vector< int > QueryNeighbours(int nodeID)
Returns the IDs of the octants that surround the queried node. First, it finds the neighbouring nodes...
std::vector< int > QueryPoints(int nodeID)
Returns the indices of the points of the mesh contained in the tree.
int QueryNode(const Array< OneD, NekDouble > &coords, int depth=std::numeric_limits< int >::max())
Given the coordinates 'coords' of a point, returns the leaf octant that contains it....
Abstract base class for processing modules.
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'.
Octree m_tree
Octree object.
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'.
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.
virtual ~ProcessPhiFromFile()
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'....
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()
std::shared_ptr< Equation > EquationSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
The above copyright notice and this permission notice shall be included.
void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta, const T *y, int incy, T *z, int incz)
vvtvvtp (scalar times vector plus scalar times vector):
T Dot(int n, const T *w, const T *x)
vvtvp (vector times vector times vector): z = w*x*y
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
scalarT< T > sqrt(scalarT< T > in)
Represents a command-line configuration option.
Array< OneD, triangle > triangles
Object representing a 3D triangle.
Array< OneD, NekDouble > normal
Array< OneD, NekDouble > v1
Array< OneD, NekDouble > centroid
Array< OneD, NekDouble > v0
Array< OneD, NekDouble > v2