Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:14

0001 // Created on: 1991-05-13
0002 // Created by: Laurent PAINNOT
0003 // Copyright (c) 1991-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _math_Gauss_HeaderFile
0018 #define _math_Gauss_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <math_Matrix.hxx>
0025 #include <math_IntegerVector.hxx>
0026 #include <math_Vector.hxx>
0027 #include <Standard_OStream.hxx>
0028 #include <Message_ProgressRange.hxx>
0029 
0030 
0031 //! This class implements the Gauss LU decomposition (Crout algorithm)
0032 //! with partial pivoting (rows interchange) of a square matrix and
0033 //! the different possible derived calculation :
0034 //! - solution of a set of linear equations.
0035 //! - inverse of a matrix.
0036 //! - determinant of a matrix.
0037 class math_Gauss 
0038 {
0039 public:
0040 
0041   DEFINE_STANDARD_ALLOC
0042 
0043   //! Given an input n X n matrix A this constructor performs its LU
0044   //! decomposition with partial pivoting (interchange of rows).
0045   //! This LU decomposition is stored internally and may be used to
0046   //! do subsequent calculation.
0047   //! If the largest pivot found is less than MinPivot the matrix A is
0048   //! considered as singular.
0049   //! Exception NotSquare is raised if A is not a square matrix.
0050   Standard_EXPORT math_Gauss(const math_Matrix& A, 
0051                              const Standard_Real MinPivot = 1.0e-20, 
0052                              const Message_ProgressRange& theProgress = Message_ProgressRange());
0053   
0054   //! Returns true if the computations are successful, otherwise returns false
0055   Standard_Boolean IsDone() const { return Done; }
0056 
0057   //! Given the input Vector B this routine returns the solution X of the set
0058   //! of linear equations A . X = B.
0059   //! Exception NotDone is raised if the decomposition of A was not done
0060   //! successfully.
0061   //! Exception DimensionError is raised if the range of B is not
0062   //! equal to the number of rows of A.
0063   Standard_EXPORT void Solve (const math_Vector& B, math_Vector& X) const;
0064 
0065   //! Given the input Vector B this routine solves the set of linear
0066   //! equations A . X = B. B is replaced by the vector solution X.
0067   //! Exception NotDone is raised if the decomposition of A was not done
0068   //! successfully.
0069   //! Exception DimensionError is raised if the range of B is not
0070   //! equal to the number of rows of A.
0071   Standard_EXPORT void Solve (math_Vector& B) const;
0072 
0073   //! This routine returns the value of the determinant of the previously LU
0074   //! decomposed matrix A.
0075   //! Exception NotDone may be raised if the decomposition of A was not done
0076   //! successfully, zero is returned if the matrix A was considered as singular.
0077   Standard_EXPORT Standard_Real Determinant() const;
0078 
0079   //! This routine outputs Inv the inverse of the previously LU decomposed
0080   //! matrix A.
0081   //! Exception DimensionError is raised if the ranges of B are not
0082   //! equal to the ranges of A.
0083   Standard_EXPORT void Invert (math_Matrix& Inv) const;
0084   
0085   //! Prints on the stream o information on the current state
0086   //! of the object.
0087   //! Is used to redefine the operator <<.
0088   Standard_EXPORT void Dump (Standard_OStream& o) const;
0089 
0090 protected:
0091 
0092   math_Matrix LU;
0093   math_IntegerVector Index;
0094   Standard_Real D;
0095   Standard_Boolean Done;
0096 
0097 };
0098 
0099 inline Standard_OStream& operator<<(Standard_OStream& o, const math_Gauss& mG)
0100 {
0101   mG.Dump(o);
0102   return o;
0103 }
0104 
0105 #endif // _math_Gauss_HeaderFile