48 "Computes the Phi function from a file, used in IB methods.")};
57 ConfigOption(
false,
"NotSet",
"Scale coefficient for Phi.");
59 ConfigOption(
false,
"NotSet",
"File with the IB definition.");
75 ASSERTL0(
m_f->m_session->GetComm()->GetSpaceComm()->IsSerial(),
76 "Parallel execution is "
77 "not supported yet in "
81 ASSERTL0(
m_f->m_graph,
"A session file file must be provided before the "
85 if (
m_f->m_exp[0]->GetNumElmts() == 0)
91 if (
m_config[
"file"].as<string>().compare(
"NotSet") == 0)
94 "Reading Phi function from session file, the provided scale "
95 "value will not be used");
102 "Need to specify a scale coefficient, scale=value");
122 in.read(buf,
sizeof(buf));
123 memcpy(&tmp, buf,
sizeof(buf));
125 in.read(buf,
sizeof(buf));
126 memcpy(&tmp, buf,
sizeof(buf));
128 in.read(buf,
sizeof(buf));
129 memcpy(&tmp, buf,
sizeof(buf));
147 ifstream fileStl(filename.c_str(), ios::binary);
148 ASSERTL0(fileStl,
"An error occurred while trying to open the STL file.")
156 fileStl.read(headerBuf,
sizeof(headerBuf));
157 fileStl.read(numTriBuf,
sizeof(numTriBuf));
158 memcpy(&out.
numTri, numTriBuf,
sizeof(numTriBuf));
175 centre[0] = (tmpTri.
v0[0] + tmpTri.
v1[0] + tmpTri.
v2[0]) / 3.0;
176 centre[1] = (tmpTri.
v0[1] + tmpTri.
v1[1] + tmpTri.
v2[1]) / 3.0;
177 centre[2] = (tmpTri.
v0[2] + tmpTri.
v1[2] + tmpTri.
v2[2]) / 3.0;
183 fileStl.read(dumpBuf,
sizeof(dumpBuf));
202 return -0.5 * (std::tanh(dist / coeff) - 1.0);
212 ASSERTL0(
m_f->m_session->DefinesFunction(
"ShapeFunction"),
213 "If file=file.stl is not supplied as an argument, a "
214 "'ShapeFunction' block must be provided in the session "
219 m_f->m_session->GetFunction(
"ShapeFunction",
"Phi");
222 int nPts =
m_f->m_exp[0]->GetNpoints();
223 int nVars =
m_f->m_variables.size();
225 m_f->m_session->LoadParameter(
"Strip_Z", nStrips, 1);
228 m_f->m_variables.push_back(
"phi");
230 for (
int s = 0; s < nStrips; ++s)
233 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
234 auto it =
m_f->m_exp.begin() + s * (nVars + 1) + nVars;
235 m_f->m_exp.insert(it, Exp);
238 for (
int s = 0; s < nStrips; ++s)
242 for (
int i = 0; i < 3; ++i)
246 m_f->m_exp[s * nVars]->GetCoords(coords[0], coords[1], coords[2]);
249 int fid = s * (nVars + 1) + nVars;
251 phiFunction->Evaluate(coords[0], coords[1], coords[2],
252 m_f->m_exp[fid]->UpdatePhys());
253 m_f->m_exp[fid]->FwdTrans(
m_f->m_exp[fid]->GetPhys(),
254 m_f->m_exp[fid]->UpdateCoeffs());
267 int nPts =
m_f->m_exp[0]->GetNpoints();
268 int nVars =
m_f->m_variables.size();
272 for (
int i = 0; i < 3; ++i)
276 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
279 m_f->m_variables.push_back(
"phi");
283 m_f->m_session->LoadParameter(
"Strip_Z", nStrips, 1);
287 bounds[0] = coords[0][0];
288 bounds[1] = coords[0][0];
289 bounds[2] = coords[1][0];
290 bounds[3] = coords[1][0];
291 bounds[4] = coords[2][0];
292 bounds[5] = coords[2][0];
293 for (
int i = 1; i < nPts; ++i)
295 bounds[0] = (bounds[0] < coords[0][i]) ? bounds[0] : coords[0][i];
296 bounds[1] = (bounds[1] > coords[0][i]) ? bounds[1] : coords[0][i];
297 bounds[2] = (bounds[2] < coords[1][i]) ? bounds[2] : coords[1][i];
298 bounds[3] = (bounds[3] > coords[1][i]) ? bounds[3] : coords[1][i];
299 bounds[4] = (bounds[4] < coords[2][i]) ? bounds[4] : coords[2][i];
300 bounds[5] = (bounds[5] > coords[2][i]) ? bounds[5] : coords[2][i];
303 for (
int i = 0; i < 6; ++i)
305 bounds[i] -= pow(-1, i) * 1e-10;
310 for (
int i = 0; i < file.
numTri; ++i)
312 centroids[i] = file.
triangles[i].centroid;
318 for (
int s = 0; s < nStrips; ++s)
321 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
322 auto it =
m_f->m_exp.begin() + s * (nVars + 1) + nVars;
323 m_f->m_exp.insert(it, Exp);
327 for (
int s = 0; s < nStrips; ++s)
329 int fid = s * (nVars + 1) + nVars;
334 for (
int i = 0; i < nPts; ++i)
338 tmpCoords[2] = coords[2][i];
339 tmpCoords[1] = coords[1][i];
340 tmpCoords[0] = coords[0][i];
351 m_f->m_exp[fid]->FwdTrans(phys,
m_f->m_exp[fid]->UpdateCoeffs());
377 double &distance,
double &u,
double &v)
388 double inv_det = 1.0 / det;
391 distance = numeric_limits<double>::max();
392 u = numeric_limits<double>::max();
393 v = numeric_limits<double>::max();
408 if ((u < 0.0 || u > 1.0) || (v < 0.0 || u + v > 1.0))
435 dist = numeric_limits<double>::max();
442 vector<int> treeTriangles;
444 for (
int point : tmpTriangles)
446 treeTriangles.push_back(point);
451 for (
int neighNode : neighbours)
454 for (
int point : tmpTriangles)
456 treeTriangles.push_back(point);
466 double tParam = dist;
468 for (
int i = 0; i < treeTriangles.size(); ++i)
472 double currentTparam;
477 int currentDistSign = (currentTparam >= 0) - (currentTparam < 0);
487 currentDist = fabs(currentTparam);
512 if (dist - currentDist > 1e-5 * currentDist ||
513 (
IsEqual(dist, currentDist, 1e-5) &&
515 fabs(currentTparam) > fabs(tParam)))
518 tParam = currentTparam;
519 distSign = currentDistSign;
539 return (fabs(x - y) <= relTol * y);
567 out[0] = v0[1] * v1[2] - v0[2] * v1[1];
568 out[1] = v0[2] * v1[0] - v0[0] * v1[2];
569 out[2] = v0[0] * v1[1] - v0[1] * v1[0];
595 for (
size_t i = 0; i < n; ++i)
606 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.
~ProcessPhiFromFile() override
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'.
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'.
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
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.
void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta, const T *y, int incy, T *z, int incz)
Svtsvtp (scalar times vector plus scalar times vector):
T Dot(int n, const T *w, const T *x)
dot product
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