38#include <boost/core/ignore_unused.hpp>
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()->GetSpaceComm()->IsSerial(),
82 "Parallel execution is "
83 "not supported yet in "
87 ASSERTL0(
m_f->m_graph,
"A session file file must be provided before the "
91 if (
m_f->m_exp[0]->GetNumElmts() == 0)
97 if (
m_config[
"file"].as<string>().compare(
"NotSet") == 0)
100 "Reading Phi function from session file, the provided scale "
101 "value will not be used");
108 "Need to specify a scale coefficient, scale=value");
128 in.read(buf,
sizeof(buf));
129 memcpy(&tmp, buf,
sizeof(buf));
131 in.read(buf,
sizeof(buf));
132 memcpy(&tmp, buf,
sizeof(buf));
134 in.read(buf,
sizeof(buf));
135 memcpy(&tmp, buf,
sizeof(buf));
153 ifstream fileStl(filename.c_str(), ios::binary);
154 ASSERTL0(fileStl,
"An error occurred while trying to open the STL file.")
162 fileStl.read(headerBuf,
sizeof(headerBuf));
163 fileStl.read(numTriBuf,
sizeof(numTriBuf));
164 memcpy(&out.
numTri, numTriBuf,
sizeof(numTriBuf));
181 centre[0] = (tmpTri.
v0[0] + tmpTri.
v1[0] + tmpTri.
v2[0]) / 3.0;
182 centre[1] = (tmpTri.
v0[1] + tmpTri.
v1[1] + tmpTri.
v2[1]) / 3.0;
183 centre[2] = (tmpTri.
v0[2] + tmpTri.
v1[2] + tmpTri.
v2[2]) / 3.0;
189 fileStl.read(dumpBuf,
sizeof(dumpBuf));
208 return -0.5 * (std::tanh(dist / coeff) - 1.0);
218 ASSERTL0(
m_f->m_session->DefinesFunction(
"ShapeFunction"),
219 "If file=file.stl is not supplied as an argument, a "
220 "'ShapeFunction' block must be provided in the session "
225 m_f->m_session->GetFunction(
"ShapeFunction",
"Phi");
228 int nPts =
m_f->m_exp[0]->GetNpoints();
229 int nVars =
m_f->m_variables.size();
231 m_f->m_session->LoadParameter(
"Strip_Z", nStrips, 1);
234 m_f->m_variables.push_back(
"phi");
236 for (
int s = 0; s < nStrips; ++s)
239 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
240 auto it =
m_f->m_exp.begin() + s * (nVars + 1) + nVars;
241 m_f->m_exp.insert(it, Exp);
244 for (
int s = 0; s < nStrips; ++s)
248 for (
int i = 0; i < 3; ++i)
252 m_f->m_exp[s * nVars]->GetCoords(coords[0], coords[1], coords[2]);
255 int fid = s * (nVars + 1) + nVars;
257 phiFunction->Evaluate(coords[0], coords[1], coords[2],
258 m_f->m_exp[fid]->UpdatePhys());
259 m_f->m_exp[fid]->FwdTrans(
m_f->m_exp[fid]->GetPhys(),
260 m_f->m_exp[fid]->UpdateCoeffs());
273 int nPts =
m_f->m_exp[0]->GetNpoints();
274 int nVars =
m_f->m_variables.size();
278 for (
int i = 0; i < 3; ++i)
282 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
285 m_f->m_variables.push_back(
"phi");
289 m_f->m_session->LoadParameter(
"Strip_Z", nStrips, 1);
293 bounds[0] = coords[0][0];
294 bounds[1] = coords[0][0];
295 bounds[2] = coords[1][0];
296 bounds[3] = coords[1][0];
297 bounds[4] = coords[2][0];
298 bounds[5] = coords[2][0];
299 for (
int i = 1; i < nPts; ++i)
301 bounds[0] = (bounds[0] < coords[0][i]) ? bounds[0] : coords[0][i];
302 bounds[1] = (bounds[1] > coords[0][i]) ? bounds[1] : coords[0][i];
303 bounds[2] = (bounds[2] < coords[1][i]) ? bounds[2] : coords[1][i];
304 bounds[3] = (bounds[3] > coords[1][i]) ? bounds[3] : coords[1][i];
305 bounds[4] = (bounds[4] < coords[2][i]) ? bounds[4] : coords[2][i];
306 bounds[5] = (bounds[5] > coords[2][i]) ? bounds[5] : coords[2][i];
309 for (
int i = 0; i < 6; ++i)
311 bounds[i] -= pow(-1, i) * 1e-10;
316 for (
int i = 0; i < file.
numTri; ++i)
318 centroids[i] = file.
triangles[i].centroid;
324 for (
int s = 0; s < nStrips; ++s)
327 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
328 auto it =
m_f->m_exp.begin() + s * (nVars + 1) + nVars;
329 m_f->m_exp.insert(it, Exp);
333 for (
int s = 0; s < nStrips; ++s)
335 int fid = s * (nVars + 1) + nVars;
340 for (
int i = 0; i < nPts; ++i)
344 tmpCoords[2] = coords[2][i];
345 tmpCoords[1] = coords[1][i];
346 tmpCoords[0] = coords[0][i];
357 m_f->m_exp[fid]->FwdTrans(phys,
m_f->m_exp[fid]->UpdateCoeffs());
383 double &distance,
double &u,
double &v)
394 double inv_det = 1.0 / det;
397 distance = numeric_limits<double>::max();
398 u = numeric_limits<double>::max();
399 v = numeric_limits<double>::max();
414 if ((u < 0.0 || u > 1.0) || (v < 0.0 || u + v > 1.0))
441 dist = numeric_limits<double>::max();
448 vector<int> treeTriangles;
450 for (
int point : tmpTriangles)
452 treeTriangles.push_back(point);
457 for (
int neighNode : neighbours)
460 for (
int point : tmpTriangles)
462 treeTriangles.push_back(point);
472 double tParam = dist;
474 for (
int i = 0; i < treeTriangles.size(); ++i)
478 double currentTparam;
483 int currentDistSign = (currentTparam >= 0) - (currentTparam < 0);
493 currentDist = fabs(currentTparam);
518 if (dist - currentDist > 1e-5 * currentDist ||
519 (
IsEqual(dist, currentDist, 1e-5) &&
521 fabs(currentTparam) > fabs(tParam)))
524 tParam = currentTparam;
525 distSign = currentDistSign;
545 return (fabs(x - y) <= relTol * y);
573 out[0] = v0[1] * v1[2] - v0[2] * v1[1];
574 out[1] = v0[2] * v1[0] - v0[0] * v1[2];
575 out[2] = v0[0] * v1[1] - v0[1] * v1[0];
601 for (
size_t i = 0; i < n; ++i)
612 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.
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.
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 .
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'....
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)
svtvvtp (scalar times vector plus scalar times vector):
T Dot(int n, const T *w, const T *x)
dot (vector times vector): z = w*x
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