32template<
class Triangulation,
class Type>
35 const Triangulation&
mesh,
36 const Field<Type>&
field
39 auto tNewField = tmp<Field<Type>>
::New(
field.size());
40 auto& newField = tNewField.ref();
47 typename Triangulation::Finite_vertices_iterator vit =
48 mesh.finite_vertices_begin();
49 vit !=
mesh.finite_vertices_end();
61 newField.resize(added);
67template<
class Triangulation>
68Foam::autoPtr<Foam::mapDistribute> Foam::smoothAlignmentSolver::buildReferredMap
70 const Triangulation&
mesh,
80 typename Triangulation::Finite_vertices_iterator vit =
81 mesh.finite_vertices_begin();
82 vit !=
mesh.finite_vertices_end();
90 globalIndexing.toGlobal(vit->procIndex(), vit->index())
95 indices.transfer(dynIndices);
107template<
class Triangulation>
108Foam::autoPtr<Foam::mapDistribute> Foam::smoothAlignmentSolver::buildMap
110 const Triangulation&
mesh,
114 pointPoints.setSize(
mesh.vertexCount());
120 typename Triangulation::Finite_vertices_iterator vit =
121 mesh.finite_vertices_begin();
122 vit !=
mesh.finite_vertices_end();
131 std::list<typename Triangulation::Vertex_handle> adjVerts;
132 mesh.finite_adjacent_vertices(vit, std::back_inserter(adjVerts));
138 typename std::list<typename Triangulation::Vertex_handle>::
140 adjVertI != adjVerts.
end();
144 typename Triangulation::Vertex_handle vh = *adjVertI;
150 globalIndexing.toGlobal(vh->procIndex(), vh->index())
155 pointPoints[vit->index()].transfer(indices);
168template<
class Triangulation>
169Foam::tmp<Foam::triadField> Foam::smoothAlignmentSolver::buildAlignmentField
171 const Triangulation&
mesh
182 typename Triangulation::Finite_vertices_iterator vit =
183 mesh.finite_vertices_begin();
184 vit !=
mesh.finite_vertices_end();
193 alignments[vit->index()] = vit->alignment();
200template<
class Triangulation>
201Foam::tmp<Foam::pointField> Foam::smoothAlignmentSolver::buildPointField
203 const Triangulation&
mesh
214 typename Triangulation::Finite_vertices_iterator vit =
215 mesh.finite_vertices_begin();
216 vit !=
mesh.finite_vertices_end();
232void Foam::smoothAlignmentSolver::applyBoundaryConditions
234 const triad& fixedAlignment,
240 forAll(fixedAlignment, dirI)
242 if (fixedAlignment.set(dirI))
250 forAll(fixedAlignment, dirI)
252 if (fixedAlignment.set(dirI))
254 t.align(fixedAlignment[dirI]);
258 else if (nFixed == 2)
260 forAll(fixedAlignment, dirI)
262 if (fixedAlignment.set(dirI))
264 t[dirI] = fixedAlignment[dirI];
274 else if (nFixed == 3)
276 forAll(fixedAlignment, dirI)
278 if (fixedAlignment.set(dirI))
280 t[dirI] = fixedAlignment[dirI];
305 const label maxSmoothingIterations
308 scalar minResidual = 0;
317 triadField alignments(buildAlignmentField(mesh_));
325 CellSizeDelaunay::Finite_vertices_iterator vit =
326 mesh_.finite_vertices_begin();
327 vit != mesh_.finite_vertices_end();
333 fixedAlignments[vit->index()] = vit->alignment();
340 for (label iter = 0; iter < maxSmoothingIterations; iter++)
342 Info<<
"Iteration " << iter;
344 meshDistributor().distribute(
points);
345 meshDistributor().distribute(fixedAlignments);
346 meshDistributor().distribute(alignments);
354 const labelList& pPoints = pointPoints[pI];
361 triad& newTriad = triadAv[pI];
363 forAll(pPoints, adjPointi)
365 const label adjPointIndex = pPoints[adjPointi];
369 triad tmpTriad = alignments[adjPointIndex];
373 if (tmpTriad.set(dir))
375 tmpTriad[dir] *= 1.0/(dist + SMALL);
379 newTriad += tmpTriad;
386 const triad& oldTriad = alignments[pI];
387 triad& newTriad = triadAv[pI];
390 newTriad.orthogonalize();
393 const triad& fixedAlignment = fixedAlignments[pI];
395 applyBoundaryConditions
401 newTriad = newTriad.sortxyz();
410 && !fixedAlignment.set(dir)
413 residual +=
diff(oldTriad, newTriad);
417 alignments[pI] = newTriad;
422 Info<<
", Residual = "
427 if (iter > 0 && residual <= minResidual)
433 meshDistributor().distribute(alignments);
437 CellSizeDelaunay::Finite_vertices_iterator vit =
438 mesh_.finite_vertices_begin();
439 vit != mesh_.finite_vertices_end();
445 vit->alignment() = alignments[vit->index()];
456 alignments.setSize(mesh_.vertexCount());
457 referredDistributor().distribute(alignments);
462 CellSizeDelaunay::Finite_vertices_iterator vit =
463 mesh_.finite_vertices_begin();
464 vit != mesh_.finite_vertices_end();
470 vit->alignment() = alignments[referredPoints[referredI++]];
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
iterator begin() noexcept
Return an iterator to begin traversing the UList.
iterator end() noexcept
Return an iterator to end traversing the UList.
void size(const label n)
Older name for setAddressableSize.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
void smoothAlignments(const label maxSmoothingIterations)
Smooth the alignments on the mesh.
~smoothAlignmentSolver()
Destructor.
A class for managing temporary objects.
Representation of a 3D Cartesian coordinate system as a Vector of row vectors.
void normalize()
Same as normalise.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
pointFromPoint topoint(const Point &P)
messageStream Info
Information stream (stdout output on master, null elsewhere).
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
vector point
Point is a vector.
Field< triad > triadField
Specialisation of Field<T> for triad.
vectorField pointField
pointField is a vectorField.
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.