45 void Foam::projectEdge::findNearest
49 pointConstraint& constraint
54 const scalar distSqr =
magSqr(points_[end_]-points_[start_]);
57 List<pointConstraint> boundaryConstraint(1);
68 near = boundaryNear[0];
69 constraint = boundaryConstraint[0];
74 constraint = pointConstraint();
81 Foam::projectEdge::projectEdge
94 surfaces_.setSize(names.
size());
97 surfaces_[i] = geometry_.findSurfaceID(names[i]);
99 if (surfaces_[i] == -1)
102 <<
"Cannot find surface " << names[i] <<
" in geometry" 114 const point start(points_[start_] + lambda*(points_[end_]-points_[start_]));
118 if (lambda >= small && lambda < 1.0-small)
121 findNearest(start, near, constraint);
132 static label eIter = 0;
141 Info<<
"Writing lines from straight-line start points" 142 <<
" to projected points to " << debugStr().name() <<
endl;
149 const point& startPt = points_[start_];
150 const point& endPt = points_[end_];
151 const vector d = endPt-startPt;
156 points[i] = startPt+lambdas[i]*d;
161 const label maxIter = 10;
163 const scalar relTol = 0.1;
164 const scalar absTol = 1
e-4;
166 scalar initialResidual = 0.0;
168 for (
label iter = 0; iter < maxIter; iter++)
185 if (lambdas[0] < small)
189 if (lambdas.
last() > 1.0-small)
191 points.
last() = endPt;
194 if (debugStr.
valid())
206 projLambdas[0] = 0.0;
207 for (
label i = 1; i < points.
size(); i++)
209 projLambdas[i] = projLambdas[i-1] +
mag(points[i]-points[i-1]);
211 projLambdas /= projLambdas.last();
220 for (
label i = 1; i < points.
size() - 1; i++)
222 interpolator.
valueWeights(lambdas[i], indices, weights);
227 predicted += weights[indexi]*points[indices[indexi]];
229 residual[i] = predicted-points[i];
232 scalar scalarResidual =
sum(
mag(residual));
236 Pout<<
"Iter:" << iter <<
" initialResidual:" << initialResidual
237 <<
" residual:" << scalarResidual <<
endl;
240 if (scalarResidual < absTol*0.5*lambdas.
size())
246 initialResidual = scalarResidual;
248 else if (scalarResidual/initialResidual < relTol)
254 if (debugStr.
valid())
258 const point predicted(points[i] + residual[i]);
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
A list of keyword definitions, which are a keyword followed by any number of values (e...
static void findNearest(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &, const scalarField &nearestDistSqr, labelList &surfaces, List< pointIndexHit > &)
Find nearest. Return -1 (and a miss()) or surface and nearest.
virtual point position(const scalar) const
Return the point positions corresponding to the curve parameters.
T & ref() const
Return non-const reference or generate a fatal error.
Unit conversion functions.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Macros for easy insertion into run-time selection tables.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
vectorField pointField
pointField is a vectorField.
virtual bool valueWeights(const scalar t, labelList &indices, scalarField &weights) const
Calculate weights and indices to calculate t from samples.
line< point, const point & > linePointRef
Line using referred points.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Container for searchableSurfaces.
Accumulates point constraints through successive applications of the applyConstraint function...
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
OFstream which keeps track of vertices.
defineTypeNameAndDebug(combustionModel, 0)
word name(const complex &)
Return a string representation of a complex.
Define a curved edge that is parameterized for 0<lambda<1 between the start and end point...
vector point
Point is a vector.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
prefixOSstream Pout(cout, "Pout")
dimensionedScalar lambda(laminarTransport.lookup("lambda"))
dimensioned< scalar > mag(const dimensioned< Type > &)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
const doubleScalar e
Elementary charge.
A class for managing temporary objects.
T & last()
Return the last element of the list.
static const Vector< scalar > zero