32 Eigen::MatrixXd Box, List<vector>& points2Move)
34 points2Move.resize(0);
36 pointField meshPoints(
mesh.points());
38 for (label j = 0; j < indices.size(); j++)
40 const polyPatch& patchFound =
mesh.boundaryMesh()[indices[j]];
41 labelList labelPatchFound(patchFound.meshPoints());
43 for (label
i = 0;
i < labelPatchFound.size();
i++)
45 auto px = meshPoints[labelPatchFound[
i]].component(0);
46 auto py = meshPoints[labelPatchFound[
i]].component(1);
47 auto pz = meshPoints[labelPatchFound[
i]].component(2);
49 if (px >= min(Box(0, 0), Box(1, 0)) && py >= min(Box(0, 1), Box(1, 1))
50 && pz >= min(Box(0, 2), Box(1, 2)) && px <= max(Box(0, 0), Box(1, 0))
51 && py <= max(Box(0, 1), Box(1, 1)) && pz <= max(Box(0, 2), Box(1, 2)) )
53 boxIndices.append(labelPatchFound[
i]);
54 points2Move.append(meshPoints[labelPatchFound[
i]]);
68 for (label
i = 0;
i < layers;
i++)
70 label size = out.size();
72 for (label j = 0; j < size; j++)
74 out.append(
mesh.cellCells()[out[j]]);
78 labelList uniqueIndex;
79 uniqueOrder(out, uniqueIndex);
83 out2.append(out[uniqueIndex[
i]]);
90 int index_col,
int layers)
97 for (label
i = 0;
i < layers;
i++)
99 label size = out.size();
101 for (label j = 0; j < size; j++)
103 out.append(
mesh.cellCells()[out[j]]);
107 labelList uniqueIndex;
108 uniqueOrder(out, uniqueIndex);
112 out2.append(out[uniqueIndex[
i]]);
119 List<vector>& points, labelList& indices)
121 pointField meshPoints(
mesh.points());
122 const polyPatch& patchFound =
mesh.boundaryMesh()[ind];
123 labelList labelPatchFound(patchFound.meshPoints());
124 points.resize(labelPatchFound.size());
126 for (label
i = 0;
i < labelPatchFound.size();
i++)
128 points[
i] = meshPoints[labelPatchFound[
i]];
131 indices = labelPatchFound;
135 double mux2,
double muy1,
double muy2)
137 vector minimum = min(x0);
138 vector maximum = max(x0);
139 double l = Foam::sqrt(pow(minimum[0] - maximum[0],
140 2) + pow(minimum[1] - maximum[1], 2));
143 List<vector> xdef(x0);
144 List<vector> displ(x0);
146 for (label
i = 0;
i < x0.size();
i++)
148 limin = Foam::sqrt(pow(x0[
i][0] - minimum[0], 2) + pow(x0[
i][1] - minimum[1],
150 limax = Foam::sqrt(pow(x0[
i][0] - maximum[0], 2) + pow(x0[
i][1] - maximum[1],
152 xdef[
i][0] = x0[
i][0] + mux1 * (1 - limin / l) + mux2 * (1 - limax / l);
153 xdef[
i][1] = x0[
i][1] + muy1 * (1 - limin / l) + muy2 * (1 - limax / l);
154 xdef[
i][2] = x0[
i][2];
162 double mux_low,
double mux_up,
double muy_low,
double muy_up,
double muz_low,
165 vector direction = x_up - x_low;
169 vector x_low_def(x_low[0] + mux_low, x_low[1] + muy_low, x_low[2] + muz_low);
170 vector x_up_def(x_up[0] + mux_up, x_up[1] + muy_up, x_up[2] + muz_up);
171 vector direction_def = x_up_def - x_low_def;
173 if (abs(direction[0]) > 1e-16)
175 t0 = (x0[0] - x_low[0]) / direction[0];
182 if (abs(direction[1]) > 1e-16)
184 t1 = (x0[1] - x_low[1]) / direction[1];
196 if (abs(direction[2]) > 1e-16)
198 t2 = (x0[2] - x_low[2]) / direction[2];
215 Info << abs((x_low + t0 * direction - x0)[0]) << endl;
216 Info << abs((x_low + t1 * direction - x0)[1]) << endl;
217 Info << abs((x_low + t2 * direction - x0)[2]) << endl;
218 M_Assert(abs(abs((x_low + t0 * direction - x0)[0]) + abs((
219 x_low + t0 * direction - x0)[1]) + abs((x_low + t0 * direction - x0)[2])) <
220 1e-6,
"The givent polabel is not on the segment");
221 vector def_polabel = x_low_def + t1 * direction_def;
222 Info << def_polabel << endl;
228 double alpha, labelList movingPointsIDs,
229 List<double> radii, word angleVariationMethod,
double v)
231 M_Assert(angleVariationMethod ==
"Linear"
232 || angleVariationMethod ==
"Sinusoidal" || angleVariationMethod ==
"Sigmoid",
233 "The variation function of the angle from the inner radius to the outer radius must be either Linear or Sinusoidal or Sigmoid");
234 Field<vector> pointRot(
mesh.points());
236 for (label
i = 0;
i < movingPointsIDs.size();
i++)
239 vector pointNow = pointRot[movingPointsIDs[
i]];
243 double theta = alpha / 180 * constant::mathematical::pi;
244 quaternion q(axis, theta);
245 pointRot[movingPointsIDs[
i]] = q.transform(pointNow);
247 else if (l > r1 && l <= r2)
249 if (angleVariationMethod ==
"Linear")
251 double theta = alpha / 180 * constant::mathematical::pi * (r2 - l) / (r2 - r1);
252 quaternion q(axis, theta);
253 pointRot[movingPointsIDs[
i]] = q.transform(pointNow);
255 else if (angleVariationMethod ==
"Sinusoidal")
257 double theta = alpha / 180 * constant::mathematical::pi * std::sin(
258 constant::mathematical::pi / 2 * (r2 - l) / (r2 - r1));
259 quaternion q(axis, theta);
260 pointRot[movingPointsIDs[
i]] = q.transform(pointNow);
262 else if (angleVariationMethod ==
"Sigmoid")
264 double theta = alpha / 180 * constant::mathematical::pi * (1 - 1 /
266 -
v * (l - (r1 + r2) / 2))));
267 quaternion q(axis, theta);
268 pointRot[movingPointsIDs[
i]] = q.transform(pointNow);
277 double AngleOfRotation)
279 Eigen::MatrixXd R(3, 3);
280 double theta = AngleOfRotation / 180 * constant::mathematical::pi;
281 scalar di = mag(AxisOfRotation);
282 scalar ux = AxisOfRotation[0] / di;
283 scalar uy = AxisOfRotation[1] / di;
284 scalar uz = AxisOfRotation[2] / di;
285 R(0, 0) = Foam::cos(theta) + ux * ux * (1 - Foam::cos(theta));
286 R(1, 0) = uy * ux * (1 - Foam::cos(theta)) + uz * Foam::sin(theta);
287 R(2, 0) = uz * ux * (1 - Foam::cos(theta)) - uy * Foam::sin(theta);
288 R(0, 1) = ux * uz * (1 - Foam::cos(theta)) - uz * Foam::sin(theta);
289 R(1, 1) = Foam::cos(theta) + uy * uy * (1 - Foam::cos(theta));
290 R(2, 1) = ux * uy * (1 - Foam::cos(theta)) + ux * Foam::sin(theta);
291 R(0, 2) = ux * uz * (1 - Foam::cos(theta)) + uy * Foam::sin(theta);
292 R(1, 2) = uy * uz * (1 - Foam::cos(theta)) - ux * Foam::sin(theta);
293 R(2, 2) = Foam::cos(theta) + uz * uz * (1 - Foam::cos(theta));
298 fvMesh&
mesh, label BC_ind)
300 Eigen::VectorXd cellFaceDistance;
301 const polyPatch& cPatch =
mesh.boundaryMesh()[BC_ind];
303 label faceId_start = cPatch.start() ;
305 const labelUList& faceCells = cPatch.faceCells();
306 cellFaceDistance.conservativeResize(cPatch.size());
310 label faceID = faceId_start + faceI;
312 label faceOwner = faceCells[faceI] ;
313 cellFaceDistance(faceI) = mag(
mesh.C()[faceOwner] -
mesh.Cf()[faceID]);
316 return (cellFaceDistance);
320 vector origin, vector axis, List<double>& radii)
322 pointField meshPoints(
mesh.points());
323 List<label> indices(meshPoints.size());
324 radii.resize(meshPoints.size());
327 for (label
i = 0;
i < meshPoints.size();
i++)
329 vector pointNow = meshPoints[
i];
330 vector r = pointNow - origin;
331 vector projComponent = (r & axis) / (pow(mag(axis), 2)) * axis;
332 vector d = r - projComponent;
333 double l = Foam::sqrt(pow(d[0],
334 2) + pow(d[1], 2) + pow(d[2], 2));
349template<
typename type_f>
351 GeometricField<type_f, fvPatchField, volMesh>& field, Eigen::MatrixXd Box)
355 "The box must be a 2*3 matrix shaped in this way: \nBox = \t|x0, y0, z0|\n\t|x1, yi, z1|\n");
356 List<label> indices(field.internalField().size());
359 for (label
i = 0;
i < field.internalField().size();
i++)
361 auto cx = field.mesh().C()[
i][0];
362 auto cy = field.mesh().C()[
i][1];
363 auto cz = field.mesh().C()[
i][2];
365 if (cx >= Box(0, 0) && cy >= Box(0, 1) && cz >= Box(0, 2) && cx <= Box(1, 0)
366 && cy <= Box(1, 1) && cz <= Box(1, 2) )
378 GeometricField<scalar, fvPatchField, volMesh>& field, Eigen::MatrixXd Box);
380 GeometricField<vector, fvPatchField, volMesh>& field, Eigen::MatrixXd Box);
382template<
typename type_f>
384 GeometricField<type_f, fvPatchField, volMesh>& field, Eigen::MatrixXd Box)
388 sub =
new fvMeshSubset(field.mesh());
391 sub->setCellSubset(indices);
393 sub->setLargeCellSubset(indices);
399 GeometricField<scalar, fvPatchField, volMesh>& field, Eigen::MatrixXd Box);
401 GeometricField<vector, fvPatchField, volMesh>& field, Eigen::MatrixXd Box);
404 volScalarField& NonOrtho)
406 scalarField sno = (polyMeshTools::faceOrthogonality(
mesh,
mesh.Sf(),
409 for (label
i = 0;
i < sno.size();
i++)
411 sno[
i] = Foam::acos(min(1, sno[
i])) * 180 / constant::mathematical::pi;
414 surfaceScalarField pippo =
mesh.magSf();
415 const fvPatchList& patches =
mesh.boundary();
417 for (label
i = 0;
i < pippo.internalField().size();
i++)
419 pippo.ref()[
i] = sno[
i];
422 for (label
i = 0;
i < patches.size();
i++)
424 if ( patches[
i].type() !=
"empty" )
426 label start = patches[
i].patch().start();
427 label n = patches[
i].patch().size();
429 for (label k = 0; k < n; k++)
431 pippo.boundaryFieldRef()[
i][k] = sno[start + k];
436 NonOrtho = fvc::average(pippo);
441 vector AxisOfRotation,
double AngleOfRotation)
443 double theta = AngleOfRotation / 180 * constant::mathematical::pi;
444 quaternion q(AxisOfRotation, theta);
445 List<vector> rotatedPoints(originalPoints);
447 for (label
i = 0;
i < rotatedPoints.size();
i++)
449 rotatedPoints[
i] = q.transform(rotatedPoints[
i]);
452 return rotatedPoints;
forAll(example_CG.gList, solutionI)
#define M_Assert(Expr, Msg)
Header file of the geometry namespace.
Namespace to implement some useful assign operation of OF fields.
Field< vector > rotateMesh(fvMesh &mesh, double r1, double r2, vector axis, double alpha, labelList movingPointsIDs, List< double > radii, word angleVariationMethod, double v)
A function that rotates the mesh rigidly, by a fixed specified angle for the points lying within a di...
List< label > getIndices(const fvMesh &mesh, int index, int layers)
Gets the indices of the cells around a certain cell.
vector displacePolabel(vector x0, vector x_low, vector x_up, double mux_low, double mux_up, double muy_low, double muy_up, double muz_low, double muz_up)
Displace a Polabel belonging to a given segment.
fvMeshSubset * getSubMeshFromBox(GeometricField< type_f, fvPatchField, volMesh > &field, Eigen::MatrixXd Box)
Gets a subMesh from a box of coordinates and a given field (used only for the mesh).
Eigen::MatrixXd rotationMatrix(vector AxisOfRotation, double AngleOfRotation)
Functions that return a Rotation Matrix given an axis of rotation and an angle in degrees.
List< vector > displacedSegment(List< vector > x0, double mux1, double mux2, double muy1, double muy2)
Get position of displaced segment of points given the displacements of the end points.
List< label > getIndicesFromDisc(const fvMesh &mesh, double radius, vector origin, vector axis, List< double > &radii)
Gets the indices of the points which are inside a disc of a specified radius before carrying out a ro...
volScalarField meshNonOrtho(fvMesh &mesh, volScalarField &NonOrtho)
Returns a scalarField that containes the non-orthogonality value of a given mesh.
void getPointsFromPatch(fvMesh &mesh, label ind, List< vector > &points, labelList &indices)
Get the polabel coordinates and indices from patch.
labelList getIndicesFromBox(const fvMesh &mesh, List< label > indices, Eigen::MatrixXd Box, List< vector > &points2Move)
Gives the indices conteined into a defined box.
Eigen::VectorXd boudaryFaceToCellDistance(fvMesh &mesh, label BC_ind)
Compute the distance between the boundary face center and the boundary cell center.
List< vector > rotatePoints(const List< vector > &originalPoints, vector AxisOfRotation, double AngleOfRotation)
Rotate a list of points in clockwise direction given an axis of rotation and an angle in degrees.