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]]);
89 int index_col,
int layers)
96 for (label
i = 0;
i < layers;
i++)
98 label size = out.size();
100 for (label j = 0; j < size; j++)
102 out.append(
mesh.cellCells()[out[j]]);
106 labelList uniqueIndex;
107 uniqueOrder(out, uniqueIndex);
111 out2.append(out[uniqueIndex[
i]]);
117 List<vector>& points, labelList& indices)
119 pointField meshPoints(
mesh.points());
120 const polyPatch& patchFound =
mesh.boundaryMesh()[ind];
121 labelList labelPatchFound(patchFound.meshPoints());
122 points.resize(labelPatchFound.size());
124 for (label
i = 0;
i < labelPatchFound.size();
i++)
126 points[
i] = meshPoints[labelPatchFound[
i]];
129 indices = labelPatchFound;
133 double mux2,
double muy1,
double muy2)
135 vector minimum = min(x0);
136 vector maximum = max(x0);
137 double l = Foam::sqrt(pow(minimum[0] - maximum[0],
138 2) + pow(minimum[1] - maximum[1], 2));
141 List<vector> xdef(x0);
142 List<vector> displ(x0);
144 for (label
i = 0;
i < x0.size();
i++)
146 limin = Foam::sqrt(pow(x0[
i][0] - minimum[0], 2) + pow(x0[
i][1] - minimum[1],
148 limax = Foam::sqrt(pow(x0[
i][0] - maximum[0], 2) + pow(x0[
i][1] - maximum[1],
150 xdef[
i][0] = x0[
i][0] + mux1 * (1 - limin / l) + mux2 * (1 - limax / l);
151 xdef[
i][1] = x0[
i][1] + muy1 * (1 - limin / l) + muy2 * (1 - limax / l);
152 xdef[
i][2] = x0[
i][2];
160 double mux_low,
double mux_up,
double muy_low,
double muy_up,
double muz_low,
163 vector direction = x_up - x_low;
167 vector x_low_def(x_low[0] + mux_low, x_low[1] + muy_low, x_low[2] + muz_low);
168 vector x_up_def(x_up[0] + mux_up, x_up[1] + muy_up, x_up[2] + muz_up);
169 vector direction_def = x_up_def - x_low_def;
171 if (abs(direction[0]) > 1e-16)
173 t0 = (x0[0] - x_low[0]) / direction[0];
180 if (abs(direction[1]) > 1e-16)
182 t1 = (x0[1] - x_low[1]) / direction[1];
194 if (abs(direction[2]) > 1e-16)
196 t2 = (x0[2] - x_low[2]) / direction[2];
213 Info << abs((x_low + t0 * direction - x0)[0]) << endl;
214 Info << abs((x_low + t1 * direction - x0)[1]) << endl;
215 Info << abs((x_low + t2 * direction - x0)[2]) << endl;
216 M_Assert(abs(abs((x_low + t0 * direction - x0)[0]) + abs((
217 x_low + t0 * direction - x0)[1]) + abs((x_low + t0 * direction - x0)[2])) <
218 1e-6,
"The givent polabel is not on the segment");
219 vector def_polabel = x_low_def + t1 * direction_def;
220 Info << def_polabel << endl;
226 double alpha, labelList movingPointsIDs,
227 List<double> radii, word angleVariationMethod,
double v)
229 M_Assert(angleVariationMethod ==
"Linear"
230 || angleVariationMethod ==
"Sinusoidal" || angleVariationMethod ==
"Sigmoid",
231 "The variation function of the angle from the inner radius to the outer radius must be either Linear or Sinusoidal or Sigmoid");
232 Field<vector> pointRot(
mesh.points());
234 for (label
i = 0;
i < movingPointsIDs.size();
i++)
237 vector pointNow = pointRot[movingPointsIDs[
i]];
241 double theta = alpha / 180 * constant::mathematical::pi;
242 quaternion q(axis, theta);
243 pointRot[movingPointsIDs[
i]] = q.transform(pointNow);
245 else if (l > r1 && l <= r2)
247 if (angleVariationMethod ==
"Linear")
249 double theta = alpha / 180 * constant::mathematical::pi * (r2 - l) / (r2 - r1);
250 quaternion q(axis, theta);
251 pointRot[movingPointsIDs[
i]] = q.transform(pointNow);
253 else if (angleVariationMethod ==
"Sinusoidal")
255 double theta = alpha / 180 * constant::mathematical::pi * std::sin(
256 constant::mathematical::pi / 2 * (r2 - l) / (r2 - r1));
257 quaternion q(axis, theta);
258 pointRot[movingPointsIDs[
i]] = q.transform(pointNow);
260 else if (angleVariationMethod ==
"Sigmoid")
262 double theta = alpha / 180 * constant::mathematical::pi * (1 - 1 /
264 -
v * (l - (r1 + r2) / 2))));
265 quaternion q(axis, theta);
266 pointRot[movingPointsIDs[
i]] = q.transform(pointNow);
275 double AngleOfRotation)
277 Eigen::MatrixXd R(3, 3);
278 double theta = AngleOfRotation / 180 * constant::mathematical::pi;
279 scalar di = mag(AxisOfRotation);
280 scalar ux = AxisOfRotation[0] / di;
281 scalar uy = AxisOfRotation[1] / di;
282 scalar uz = AxisOfRotation[2] / di;
283 R(0, 0) = Foam::cos(theta) + ux * ux * (1 - Foam::cos(theta));
284 R(1, 0) = uy * ux * (1 - Foam::cos(theta)) + uz * Foam::sin(theta);
285 R(2, 0) = uz * ux * (1 - Foam::cos(theta)) - uy * Foam::sin(theta);
286 R(0, 1) = ux * uz * (1 - Foam::cos(theta)) - uz * Foam::sin(theta);
287 R(1, 1) = Foam::cos(theta) + uy * uy * (1 - Foam::cos(theta));
288 R(2, 1) = ux * uy * (1 - Foam::cos(theta)) + ux * Foam::sin(theta);
289 R(0, 2) = ux * uz * (1 - Foam::cos(theta)) + uy * Foam::sin(theta);
290 R(1, 2) = uy * uz * (1 - Foam::cos(theta)) - ux * Foam::sin(theta);
291 R(2, 2) = Foam::cos(theta) + uz * uz * (1 - Foam::cos(theta));
296 fvMesh&
mesh, label BC_ind)
298 Eigen::VectorXd cellFaceDistance;
299 const polyPatch& cPatch =
mesh.boundaryMesh()[BC_ind];
301 label faceId_start = cPatch.start() ;
303 const labelUList& faceCells = cPatch.faceCells();
304 cellFaceDistance.conservativeResize(cPatch.size());
308 label faceID = faceId_start + faceI;
310 label faceOwner = faceCells[faceI] ;
311 cellFaceDistance(faceI) = mag(
mesh.C()[faceOwner] -
mesh.Cf()[faceID]);
313 return (cellFaceDistance);
317 vector origin, vector axis, List<double>& radii)
319 pointField meshPoints(
mesh.points());
320 List<label> indices(meshPoints.size());
321 radii.resize(meshPoints.size());
324 for (label
i = 0;
i < meshPoints.size();
i++)
326 vector pointNow = meshPoints[
i];
327 vector r = pointNow - origin;
328 vector projComponent = (r & axis) / (pow(mag(axis), 2)) * axis;
329 vector d = r - projComponent;
330 double l = Foam::sqrt(pow(d[0],
331 2) + pow(d[1], 2) + pow(d[2], 2));
346template<
typename type_f>
348 GeometricField<type_f, fvPatchField, volMesh>& field, Eigen::MatrixXd Box)
352 "The box must be a 2*3 matrix shaped in this way: \nBox = \t|x0, y0, z0|\n\t|x1, yi, z1|\n");
353 List<label> indices(field.internalField().size());
356 for (label
i = 0;
i < field.internalField().size();
i++)
358 auto cx = field.mesh().C()[
i][0];
359 auto cy = field.mesh().C()[
i][1];
360 auto cz = field.mesh().C()[
i][2];
362 if (cx >= Box(0, 0) && cy >= Box(0, 1) && cz >= Box(0, 2) && cx <= Box(1, 0)
363 && cy <= Box(1, 1) && cz <= Box(1, 2) )
375 GeometricField<scalar, fvPatchField, volMesh>& field, Eigen::MatrixXd Box);
377 GeometricField<vector, fvPatchField, volMesh>& field, Eigen::MatrixXd Box);
379template<
typename type_f>
381 GeometricField<type_f, fvPatchField, volMesh>& field, Eigen::MatrixXd Box)
385 sub =
new fvMeshSubset(field.mesh());
388 sub->setCellSubset(indices);
390 sub->setLargeCellSubset(indices);
396 GeometricField<scalar, fvPatchField, volMesh>& field, Eigen::MatrixXd Box);
398 GeometricField<vector, fvPatchField, volMesh>& field, Eigen::MatrixXd Box);
401 volScalarField& NonOrtho)
403 scalarField sno = (polyMeshTools::faceOrthogonality(
mesh,
mesh.Sf(),
406 for (label
i = 0;
i < sno.size();
i++)
408 sno[
i] = Foam::acos(min(1, sno[
i])) * 180 / constant::mathematical::pi;
411 surfaceScalarField pippo =
mesh.magSf();
412 const fvPatchList& patches =
mesh.boundary();
414 for (label
i = 0;
i < pippo.internalField().size();
i++)
416 pippo.ref()[
i] = sno[
i];
419 for (label
i = 0;
i < patches.size();
i++)
421 if ( patches[
i].type() !=
"empty" )
423 label start = patches[
i].patch().start();
424 label n = patches[
i].patch().size();
426 for (label k = 0; k < n; k++)
428 pippo.boundaryFieldRef()[
i][k] = sno[start + k];
433 NonOrtho = fvc::average(pippo);
438 vector AxisOfRotation,
double AngleOfRotation)
440 double theta = AngleOfRotation / 180 * constant::mathematical::pi;
441 quaternion q(AxisOfRotation, theta);
442 List<vector> rotatedPoints(originalPoints);
444 for (label
i = 0;
i < rotatedPoints.size();
i++)
446 rotatedPoints[
i] = q.transform(rotatedPoints[
i]);
449 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.