36 #include <boost/core/ignore_unused.hpp>
48 ModuleKey ProcessPhiFromFile::m_className = {
51 ProcessPhiFromFile::create,
52 "Computes the Phi function from a file, used in IB methods.")
62 "Scale coefficient for Phi.");
64 "File with the IB definition.");
80 boost::ignore_unused(vm);
83 ASSERTL0(
m_f->m_session->GetComm()->IsSerial(),
"Parallel execution is "
84 "not supported yet in "
88 ASSERTL0(
m_f->m_graph,
"A session file file must be provided before the "
92 if (
m_f->m_exp[0]->GetNumElmts() == 0)
98 if (
m_config[
"file"].as<string>().compare(
"NotSet") == 0)
101 "Reading Phi function from session file, the provided scale "
102 "value will not be used");
109 "Need to specify a scale coefficient, scale=value");
129 in.read(buf,
sizeof(buf));
130 memcpy(&tmp, buf,
sizeof(buf)); out[0] = tmp;
131 in.read(buf,
sizeof(buf));
132 memcpy(&tmp, buf,
sizeof(buf)); out[1] = tmp;
133 in.read(buf,
sizeof(buf));
134 memcpy(&tmp, buf,
sizeof(buf)); out[2] = tmp;
151 ifstream fileStl(filename.c_str(), ios::binary);
152 ASSERTL0(fileStl,
"An error occurred while trying to open the STL file.")
160 fileStl.read(headerBuf,
sizeof(headerBuf));
161 fileStl.read(numTriBuf,
sizeof(numTriBuf));
162 memcpy(&out.
numTri, numTriBuf,
sizeof(numTriBuf));
179 centre[0] = (tmpTri.
v0[0]+tmpTri.
v1[0]+tmpTri.
v2[0]) / 3.0;
180 centre[1] = (tmpTri.
v0[1]+tmpTri.
v1[1]+tmpTri.
v2[1]) / 3.0;
181 centre[2] = (tmpTri.
v0[2]+tmpTri.
v1[2]+tmpTri.
v2[2]) / 3.0;
187 fileStl.read(dumpBuf,
sizeof(dumpBuf));
206 return -0.5*(std::tanh(dist/coeff)-1.0);
216 ASSERTL0(
m_f->m_session->DefinesFunction(
"ShapeFunction"),
217 "If file=file.stl is not supplied as an argument, a "
218 "'ShapeFunction' block must be provided in the session "
223 m_f->m_session->GetFunction(
"ShapeFunction",
"Phi");
226 int nPts =
m_f->m_exp[0]->GetNpoints();
227 int nVars =
m_f->m_variables.size();
229 m_f->m_session->LoadParameter(
"Strip_Z", nStrips, 1);
232 m_f->m_variables.push_back(
"phi");
234 for (
int s = 0; s < nStrips; ++s)
238 for (
int i = 0; i < 3; ++i)
242 m_f->m_exp[s*nVars]->GetCoords(coords[0], coords[1], coords[2]);
246 Exp =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
247 phiFunction->Evaluate(coords[0], coords[1], coords[2],
249 Exp->FwdTrans(Exp->GetPhys(), Exp->UpdateCoeffs());
251 auto it =
m_f->m_exp.begin() + s * (nVars + 1) + nVars;
252 m_f->m_exp.insert(it, Exp);
265 int nPts =
m_f->m_exp[0]->GetNpoints();
266 int nVars =
m_f->m_variables.size();
270 for (
int i = 0; i < 3; ++i)
274 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
277 m_f->m_variables.push_back(
"phi");
281 m_f->m_session->LoadParameter(
"Strip_Z", nStrips, 1);
285 bounds[0] = coords[0][0];
286 bounds[1] = coords[0][0];
287 bounds[2] = coords[1][0];
288 bounds[3] = coords[1][0];
289 bounds[4] = coords[2][0];
290 bounds[5] = coords[2][0];
291 for (
int i = 1; i < nPts; ++i)
293 bounds[0] = (bounds[0] < coords[0][i]) ? bounds[0] : coords[0][i];
294 bounds[1] = (bounds[1] > coords[0][i]) ? bounds[1] : coords[0][i];
295 bounds[2] = (bounds[2] < coords[1][i]) ? bounds[2] : coords[1][i];
296 bounds[3] = (bounds[3] > coords[1][i]) ? bounds[3] : coords[1][i];
297 bounds[4] = (bounds[4] < coords[2][i]) ? bounds[4] : coords[2][i];
298 bounds[5] = (bounds[5] > coords[2][i]) ? bounds[5] : coords[2][i];
301 for (
int i = 0; i < 6; ++i)
303 bounds[i] -= pow(-1,i) * 1e-10;
308 for (
int i = 0; i < file.
numTri; ++i)
310 centroids[i] = file.
triangles[i].centroid;
317 for (
int s = 0; s < nStrips; ++s)
321 phi =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
324 for (
int i = 0; i < nPts; ++i)
328 tmpCoords[2] = coords[2][i];
329 tmpCoords[1] = coords[1][i];
330 tmpCoords[0] = coords[0][i];
342 phi->FwdTrans(phi->GetPhys(), phi->UpdateCoeffs());
343 auto it =
m_f->m_exp.begin() + s * (nVars + 1) + nVars;
344 m_f->m_exp.insert(it, phi);
370 double &distance,
double &u,
double &v)
381 double inv_det = 1.0 / det;
384 distance = numeric_limits<double>::max();
385 u = numeric_limits<double>::max();
386 v = numeric_limits<double>::max();
401 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);
562 out[0] = v0[1]*v1[2] - v0[2]*v1[1];
563 out[1] = v0[2]*v1[0] - v0[0]*v1[2];
564 out[2] = v0[0]*v1[1] - v0[1]*v1[0];
591 for (
size_t i = 0; i < n; ++i)
602 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