13 #if !defined(KRATOS_PLANE_APPROXIMATION_UTILITY )
14 #define KRATOS_PLANE_APPROXIMATION_UTILITY
57 template <
unsigned int TDim>
100 ComputeBasePoint(rPointsCoords,rPlaneBasePointCoords);
101 ComputePlaneNormal(rPointsCoords, rPlaneBasePointCoords, rPlaneNormal);
142 static void ComputeBasePoint(
146 const unsigned int n_points = rPointsCoords.size();
147 KRATOS_ERROR_IF(n_points == 0) <<
"No base point can be computed. Points container is empty." << std::endl;
150 for (
unsigned int j = 0;
j < n_points; ++
j){
151 rBasePointCoords += rPointsCoords[
j];
153 rBasePointCoords /= n_points;
162 static void SetMatrixA(
163 const std::vector< array_1d< double,3 > > &rPointsCoords,
164 const array_1d<double,3> &rPlaneBasePointCoords,
165 BoundedMatrix<double,TDim,TDim> &rA)
168 const unsigned int n_points = rPointsCoords.size();
170 for (
unsigned int i = 0;
i < TDim; ++
i){
171 const double base_i = rPlaneBasePointCoords(
i);
172 for (
unsigned int j = 0;
j < TDim; ++
j){
173 const double base_j = rPlaneBasePointCoords(
j);
174 for (
unsigned int m = 0;
m < n_points; ++
m){
175 const double pt_m_i = rPointsCoords[
m](
i);
176 const double pt_m_j = rPointsCoords[
m](
j);
177 rA(
i,
j) += (base_i - pt_m_i)*(base_j - pt_m_j);
189 static void ComputePlaneNormal(
190 const std::vector< array_1d<double,3> > &rPointsCoords,
191 const array_1d<double,3> &rPlaneBasePointCoords,
192 array_1d<double,3> &rPlaneNormal)
195 BoundedMatrix<double, TDim, TDim> a_mat, eigenval_mat, eigenvector_mat;
196 SetMatrixA(rPointsCoords, rPlaneBasePointCoords, a_mat);
198 KRATOS_ERROR_IF(!converged) <<
"Plane normal can't be computed. Eigenvalue problem did not converge." << std::endl;
202 unsigned int min_eigval_id = 0;
203 for (
unsigned int i = 0;
i < TDim; ++
i){
204 if (eigenval_mat(
i,
i) < min_eigval){
206 min_eigval = eigenval_mat(
i,
i);
212 for (
unsigned int i = 0;
i < TDim; ++
i){
213 rPlaneNormal(
i) = eigenvector_mat(
i, min_eigval_id);
static bool GaussSeidelEigenSystem(const TMatrixType1 &rA, TMatrixType2 &rEigenVectorsMatrix, TMatrixType2 &rEigenValuesMatrix, const double Tolerance=1.0e-18, const SizeType MaxIterations=20)
Calculates the eigenvectors and eigenvalues of given symmetric matrix.
Definition: math_utils.h:1587
Utility to compute an approximation plane for a set of points.
Definition: plane_approximation_utility.h:59
virtual ~PlaneApproximationUtility()
Destructor.
Definition: plane_approximation_utility.h:82
PlaneApproximationUtility()
Default constructor.
Definition: plane_approximation_utility.h:79
KRATOS_CLASS_POINTER_DEFINITION(PlaneApproximationUtility)
Pointer definition of PlaneApproximationUtility.
static void ComputePlaneApproximation(const std::vector< array_1d< double, 3 > > &rPointsCoords, array_1d< double, 3 > &rPlaneBasePointCoords, array_1d< double, 3 > &rPlaneNormal)
Provided a list of point coordinates, computes the best plane approximation in a least squares sense.
Definition: plane_approximation_utility.h:95
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
static double max(double a, double b)
Definition: GeometryFunctions.h:79
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
integer i
Definition: TensorModule.f:17