Skip to content
Snippets Groups Projects
Commit 1766e672 authored by Van Dung Nguyen's avatar Van Dung Nguyen
Browse files

add eigensolver options in NonLinearMechSolver

parent 17c76003
No related branches found
No related tags found
No related merge requests found
...@@ -39,19 +39,19 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho ...@@ -39,19 +39,19 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho
if(!_A) return false; if(!_A) return false;
Mat A = _A->getMatrix(); Mat A = _A->getMatrix();
Mat B = _B ? _B->getMatrix() : PETSC_NULL; Mat B = _B ? _B->getMatrix() : PETSC_NULL;
PetscInt N, M; PetscInt N, M;
_try(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY)); _try(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
_try(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY)); _try(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
_try(MatGetSize(A, &N, &M)); _try(MatGetSize(A, &N, &M));
PetscInt N2, M2; PetscInt N2, M2;
if (_B) { if (_B) {
_try(MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY)); _try(MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY));
_try(MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY)); _try(MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY));
_try(MatGetSize(B, &N2, &M2)); _try(MatGetSize(B, &N2, &M2));
} }
// generalized eigenvalue problem A x - \lambda B x = 0 // generalized eigenvalue problem A x - \lambda B x = 0
EPS eps; EPS eps;
_try(EPSCreate(PETSC_COMM_WORLD, &eps)); _try(EPSCreate(PETSC_COMM_WORLD, &eps));
...@@ -60,7 +60,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho ...@@ -60,7 +60,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho
_try(EPSSetProblemType(eps, _B ? EPS_GHEP : EPS_HEP)); _try(EPSSetProblemType(eps, _B ? EPS_GHEP : EPS_HEP));
else else
_try(EPSSetProblemType(eps, _B ? EPS_GNHEP : EPS_NHEP)); _try(EPSSetProblemType(eps, _B ? EPS_GNHEP : EPS_NHEP));
// set some default options // set some default options
_try(EPSSetDimensions(eps, numEigenValues, PETSC_DECIDE, PETSC_DECIDE)); _try(EPSSetDimensions(eps, numEigenValues, PETSC_DECIDE, PETSC_DECIDE));
_try(EPSSetTolerances(eps, tolVal, iterMax)); _try(EPSSetTolerances(eps, tolVal, iterMax));
...@@ -74,10 +74,10 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho ...@@ -74,10 +74,10 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho
_try(EPSSetType(eps, EPSPOWER)); _try(EPSSetType(eps, EPSPOWER));
else else
Msg::Fatal("eigenSolver: method '%s' not available", method.c_str()); Msg::Fatal("eigenSolver: method '%s' not available", method.c_str());
// override these options at runtime, petsc-style // override these options at runtime, petsc-style
_try(EPSSetFromOptions(eps)); _try(EPSSetFromOptions(eps));
// force options specified directly as arguments // force options specified directly as arguments
if (numEigenValues) if (numEigenValues)
_try(EPSSetDimensions(eps, numEigenValues, PETSC_DECIDE, PETSC_DECIDE)); _try(EPSSetDimensions(eps, numEigenValues, PETSC_DECIDE, PETSC_DECIDE));
...@@ -87,7 +87,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho ...@@ -87,7 +87,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho
_try(EPSSetWhichEigenpairs(eps, EPS_SMALLEST_REAL)); _try(EPSSetWhichEigenpairs(eps, EPS_SMALLEST_REAL));
else if (which=="largest") else if (which=="largest")
_try(EPSSetWhichEigenpairs(eps, EPS_LARGEST_MAGNITUDE)); _try(EPSSetWhichEigenpairs(eps, EPS_LARGEST_MAGNITUDE));
// print info // print info
#if (SLEPC_VERSION_RELEASE == 0 || (SLEPC_VERSION_MAJOR > 3 || (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR >= 4))) #if (SLEPC_VERSION_RELEASE == 0 || (SLEPC_VERSION_MAJOR > 3 || (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR >= 4)))
EPSType type; EPSType type;
...@@ -96,7 +96,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho ...@@ -96,7 +96,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho
#endif #endif
_try(EPSGetType(eps, &type)); _try(EPSGetType(eps, &type));
Msg::Debug("SLEPc solution method: %s", type); Msg::Debug("SLEPc solution method: %s", type);
PetscInt nev; PetscInt nev;
_try(EPSGetDimensions(eps, &nev, PETSC_NULL, PETSC_NULL)); _try(EPSGetDimensions(eps, &nev, PETSC_NULL, PETSC_NULL));
Msg::Debug("SLEPc number of requested eigenvalues: %d", nev); Msg::Debug("SLEPc number of requested eigenvalues: %d", nev);
...@@ -104,12 +104,12 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho ...@@ -104,12 +104,12 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho
PetscInt maxit; PetscInt maxit;
_try(EPSGetTolerances(eps, &tol, &maxit)); _try(EPSGetTolerances(eps, &tol, &maxit));
Msg::Debug("SLEPc stopping condition: tol=%g, maxit=%d", tol, maxit); Msg::Debug("SLEPc stopping condition: tol=%g, maxit=%d", tol, maxit);
// solve // solve
Msg::Info("SLEPc solving..."); Msg::Info("SLEPc solving...");
double t1 = Cpu(); double t1 = Cpu();
_try(EPSSolve(eps)); _try(EPSSolve(eps));
// check convergence // check convergence
int its; int its;
_try(EPSGetIterationNumber(eps, &its)); _try(EPSGetIterationNumber(eps, &its));
...@@ -127,12 +127,12 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho ...@@ -127,12 +127,12 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho
else if (reason==EPS_DIVERGED_NONSYMMETRIC) else if (reason==EPS_DIVERGED_NONSYMMETRIC)
Msg::Error("The operator is nonsymmetric"); Msg::Error("The operator is nonsymmetric");
#endif #endif
// get number of converged approximate eigenpairs // get number of converged approximate eigenpairs
PetscInt nconv; PetscInt nconv;
_try(EPSGetConverged(eps, &nconv)); _try(EPSGetConverged(eps, &nconv));
Msg::Debug("SLEPc number of converged eigenpairs: %d", nconv); Msg::Debug("SLEPc number of converged eigenpairs: %d", nconv);
// ignore additional eigenvalues if we get more than what we asked // ignore additional eigenvalues if we get more than what we asked
if (nconv>nev) nconv = nev; if (nconv>nev) nconv = nev;
...@@ -186,12 +186,13 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho ...@@ -186,12 +186,13 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho
Msg::Warning("SLEPc failed"); Msg::Warning("SLEPc failed");
return false; return false;
} }
} }
void eigenSolver::normalize_mode(double scale) { void eigenSolver::normalize_mode(std::vector<int> modeView, double scale) {
Msg::Info("Normalize all eigenvectors"); Msg::Info("Normalize all eigenvectors");
for (unsigned int i=0; i<_eigenVectors.size(); i++) { for (unsigned int imode=0; imode<modeView.size(); imode++) {
int i = modeView[imode];
double norm = 0.; double norm = 0.;
for (unsigned int j=0; j<_eigenVectors[i].size(); j++) { for (unsigned int j=0; j<_eigenVectors[i].size(); j++) {
std::complex<double> val = _eigenVectors[i][j]; std::complex<double> val = _eigenVectors[i][j];
......
...@@ -30,10 +30,10 @@ class eigenSolver { ...@@ -30,10 +30,10 @@ class eigenSolver {
bool hermitian=true); bool hermitian=true);
bool solve(int numEigenValues=0, std::string which="", std::string method="krylovschur", bool solve(int numEigenValues=0, std::string which="", std::string method="krylovschur",
double tolVal=1.e-7, int iterMax=20); double tolVal=1.e-7, int iterMax=20);
int getNumEigenValues() {return _eigenValues.size();} int getNumEigenValues() {return _eigenValues.size();}
int getNumberEigenvectors() {return _eigenVectors.size();} int getNumberEigenvectors() {return _eigenVectors.size();}
std::complex<double> getEigenValue(int num) { std::complex<double> getEigenValue(int num) {
return _eigenValues[num]; return _eigenValues[num];
} }
...@@ -43,9 +43,9 @@ class eigenSolver { ...@@ -43,9 +43,9 @@ class eigenSolver {
std::vector<std::complex<double> > &getEigenVector(int num) { std::vector<std::complex<double> > &getEigenVector(int num) {
return _eigenVectors[num]; return _eigenVectors[num];
} }
void normalize_mode(double scale=1.); void normalize_mode(std::vector<int> modeView, double scale=1.);
void clear() { void clear() {
_eigenValues.clear(); _eigenValues.clear();
_eigenVectors.clear(); _eigenVectors.clear();
...@@ -73,7 +73,7 @@ class eigenSolver { ...@@ -73,7 +73,7 @@ class eigenSolver {
std::complex<double> getEigenValue(int num) {return 0.;} std::complex<double> getEigenValue(int num) {return 0.;}
std::complex<double> getEigenVectorComp(int num, int com) {return 0.;} std::complex<double> getEigenVectorComp(int num, int com) {return 0.;}
std::vector<std::complex<double> > &getEigenVector(int num) {return _dummy;} std::vector<std::complex<double> > &getEigenVector(int num) {return _dummy;}
void normalize_mode(double scale=1.) {} void normalize_mode(std::vector<int> modeView, double scale=1.) {}
void clear() {} void clear() {}
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment