Skip to content

Commit 868290f

Browse files
committed
upload v4.3.0
1 parent 9a5cfeb commit 868290f

10 files changed

+420
-12
lines changed

doc/Manual_Of_FEMTIC.pdf

1000 KB
Binary file not shown.

doc/Manual_Of_FEMTIC_v4.1.pdf

-1.03 MB
Binary file not shown.

src/AnalysisControl.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,8 @@ void AnalysisControl::inputControlData(){
10041004
m_maxIterationIRWLSForLpOptimization = ibuf;
10051005
inFile >> dbuf;
10061006
m_thresholdIRWLSForLpOptimization = dbuf;
1007+
}else if (line.substr(0,19).compare("SENSE_MAT_DIRECTORY") == 0) {
1008+
inFile >> m_directoryOfOutOfCoreFilesForSensitivityMatrix;
10071009
}else if( line.substr(0,3).compare("END") == 0 ){
10081010
break;
10091011
}else{
@@ -1099,10 +1101,10 @@ void AnalysisControl::inputControlData(){
10991101
#ifdef _DEBUG_WRITE
11001102
std::cout << "strEnv " << strEnv.str() << std::endl;// For debug
11011103
#endif
1102-
if( putenv( strEnv.str().c_str() ) != 0 ){
1103-
OutputFiles::m_logFile << "Error : Environment variable MKL_PARDISO_OOC_MAX_CORE_SIZE was not set correctly ! " << std::endl;
1104-
exit(1);
1105-
}
1104+
//if( putenv( strEnv.str().c_str() ) != 0 ){
1105+
// OutputFiles::m_logFile << "Error : Environment variable MKL_PARDISO_OOC_MAX_CORE_SIZE was not set correctly ! " << std::endl;
1106+
// exit(1);
1107+
//}
11061108
#endif
11071109

11081110
OutputFiles::m_logFile << "# Maximum value of the memory used by out-of-core mode of forward solver : " << m_maxMemoryPARDISO << " [MB]" << std::endl;
@@ -1444,6 +1446,10 @@ void AnalysisControl::inputControlData(){
14441446
OutputFiles::m_logFile << "# Maximum number of retrials : " << m_numCutbackMax << "." << std::endl;
14451447
}
14461448

1449+
if (!getDirectoryOfOutOfCoreFilesForSensitivityMatrix().empty()) {
1450+
OutputFiles::m_logFile << "# Directory of out-of-core files for the sensitivitry matrix: " << getDirectoryOfOutOfCoreFilesForSensitivityMatrix() << std::endl;
1451+
}
1452+
14471453
OutputFiles::m_logFile << "#==============================================================================" << std::endl;
14481454
}
14491455

@@ -1750,6 +1756,11 @@ double AnalysisControl::getThresholdIRWLSForLpOptimization() const{
17501756
return m_thresholdIRWLSForLpOptimization;
17511757
}
17521758

1759+
// Get directory of out-of-core files for the sensitivitry matrix
1760+
std::string AnalysisControl::getDirectoryOfOutOfCoreFilesForSensitivityMatrix() const {
1761+
return m_directoryOfOutOfCoreFilesForSensitivityMatrix;
1762+
}
1763+
17531764
#ifdef _ANISOTOROPY
17541765
// Get type of anisotropy
17551766
int AnalysisControl::getTypeOfAnisotropy() const{

src/AnalysisControl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class AnalysisControl{
273273
// Get threshold value for deciding convergence about IRWLS for Lp optimization
274274
double getThresholdIRWLSForLpOptimization() const;
275275

276+
// Get directory of out-of-core files for the sensitivitry matrix
277+
std::string getDirectoryOfOutOfCoreFilesForSensitivityMatrix() const;
278+
276279
#ifdef _ANISOTOROPY
277280
// Get type of anisotropy
278281
int getTypeOfAnisotropy() const;
@@ -559,6 +562,9 @@ class AnalysisControl{
559562
// Threshold value for deciding convergence about IRWLS for Lp optimization
560563
double m_thresholdIRWLSForLpOptimization;
561564

565+
// Directory of out-of-core files for the sensitivitry matrix
566+
std::string m_directoryOfOutOfCoreFilesForSensitivityMatrix;
567+
562568
#ifdef _ANISOTOROPY
563569
// Type of anisotropy
564570
int m_typeOfAnisotropy;

src/CommonParameters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static char programName[]="femtic";
162162
// [MajorVersion#].[MinorVersion#].[Revision#]
163163
// x.x.xa -> alpha version
164164
// x.x.xb -> beta version
165-
static char versionID[]="4.2.5";
165+
static char versionID[] = "4.3.0";
166166

167167
}
168168

src/DoubleSparseSquareMatrix.cpp

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
#include "DoubleSparseSquareMatrix.h"
2828
#include "OutputFiles.h"
2929
#include <assert.h>
30+
#include <math.h>
31+
32+
#ifdef _DEBUG_WRITE_FOR_BOTTOM_RESISTIVITY
33+
#ifdef _LINUX
34+
#include <sys/time.h>
35+
#include <sys/resource.h>
36+
#endif
37+
#endif
3038

3139
//Default Constructer
3240
DoubleSparseSquareMatrix::DoubleSparseSquareMatrix():
@@ -135,6 +143,147 @@ void DoubleSparseSquareMatrix::solvePhaseMatrixSolver( const int nrhs, double* r
135143
m_pardisoSolver.solve( m_rowIndex, m_columns, m_values, nrhs, rhs, solution );
136144
}
137145

146+
//Solve phase of matrix solver by the conjugate gradient method with the point Jacobi preconditioner
147+
//@note Matrix should be symmetric
148+
void DoubleSparseSquareMatrix::solvePhaseMatrixSolverByPCGPointJacobi(const int nrhs, double* rhs, double* solution) const{
149+
assert(m_hasConvertedToCRSFormat);
150+
151+
const int maxIterationNumber = m_numRows;
152+
const double eps = 1.0e-20;
153+
double* invDiagonals = new double[m_numRows];
154+
double* workP = new double[m_numRows];
155+
double* workR = new double[m_numRows];// Residuals
156+
double* workQ = new double[m_numRows];
157+
double* workX = new double[m_numRows];// Solution vector
158+
double* workZ = new double[m_numRows];
159+
160+
for (int irow = 0; irow < m_numRows; ++irow)
161+
{
162+
for (int j = m_rowIndex[irow]; j < m_rowIndex[irow + 1]; ++j)
163+
{
164+
if (irow == m_columns[j])
165+
{
166+
invDiagonals[irow] = 1.0 / m_values[j];
167+
}
168+
}
169+
}
170+
for (int irhs = 0; irhs < nrhs; ++irhs)
171+
{
172+
// Initial solution is a zero vector
173+
for (int irow = 0; irow < m_numRows; ++irow)
174+
{
175+
workX[irow] = 0.0;
176+
}
177+
// [r0] = [b] - [A][x0]
178+
double normOfRhsVector(0.0);
179+
for (int irow = 0; irow < m_numRows; ++irow)
180+
{
181+
const long long int index = static_cast<long long int>(irow) + static_cast<long long int>(irhs) * static_cast<long long int>(m_numRows);
182+
normOfRhsVector += rhs[index] * rhs[index];
183+
workR[irow] = rhs[index];
184+
}
185+
int iter = 0;
186+
double rhoPre(0.0);
187+
for (; iter < maxIterationNumber; ++iter)
188+
{
189+
// [z] = [M]^-1[r]
190+
for (int irow = 0; irow < m_numRows; ++irow)
191+
{
192+
workZ[irow] = invDiagonals[irow] * workR[irow];
193+
}
194+
// rho = [r]T[z]
195+
double rho(0.0);
196+
for (int irow = 0; irow < m_numRows; ++irow)
197+
{
198+
rho += workR[irow] * workZ[irow];
199+
}
200+
if (iter == 0)
201+
{
202+
// [p0] - [z0]
203+
for (int irow = 0; irow < m_numRows; ++irow)
204+
{
205+
workP[irow] = workZ[irow];
206+
}
207+
}
208+
else
209+
{
210+
// [p] = [z] + beta*[p]
211+
const double beta = rho / rhoPre;
212+
for (int irow = 0; irow < m_numRows; ++irow)
213+
{
214+
workP[irow] = workZ[irow] + beta * workP[irow];
215+
}
216+
}
217+
// [q] = [A][p]
218+
for (int irow = 0; irow < m_numRows; ++irow)
219+
{
220+
workQ[irow] = 0.0;
221+
for (int j = m_rowIndex[irow]; j < m_rowIndex[irow + 1]; ++j)
222+
{
223+
workQ[irow] += m_values[j] * workP[m_columns[j]];
224+
}
225+
}
226+
// alpha = rho / [p]T[q]
227+
double pq(0.0);
228+
for (int irow = 0; irow < m_numRows; ++irow)
229+
{
230+
pq += workP[irow] * workQ[irow];
231+
}
232+
const double alpha = rho / pq;
233+
// [x] = [x] + alpha * [p]
234+
// [r] = [r] - alpha * [q]
235+
for (int irow = 0; irow < m_numRows; ++irow)
236+
{
237+
workX[irow] += alpha * workP[irow];
238+
workR[irow] -= alpha * workQ[irow];
239+
}
240+
// Check convergence
241+
double normOfResidualVector(0.0);
242+
for (int irow = 0; irow < m_numRows; ++irow)
243+
{
244+
normOfResidualVector += workR[irow] * workR[irow];
245+
}
246+
if( sqrt(normOfResidualVector/ normOfRhsVector) < eps )
247+
{
248+
break;
249+
}
250+
rhoPre = rho;
251+
}
252+
if (iter >= maxIterationNumber) {
253+
OutputFiles::m_logFile << "Error : PCG solver is not converged !!" << std::endl;
254+
exit(1);
255+
}
256+
else {
257+
OutputFiles::m_logFile << "# PCG solver is converged after " << iter << " iterations." << std::endl;
258+
}
259+
for (int irow = 0; irow < m_numRows; ++irow)
260+
{
261+
const long long int index = static_cast<long long int>(irow) + static_cast<long long int>(irhs) * static_cast<long long int>(m_numRows);
262+
solution[index] = workX[irow];
263+
}
264+
}
265+
266+
#ifdef _DEBUG_WRITE_FOR_BOTTOM_RESISTIVITY
267+
#ifdef _LINUX
268+
{
269+
struct rusage r;
270+
if (getrusage(RUSAGE_SELF, &r) != 0) {
271+
/*Failure*/
272+
}
273+
OutputFiles::m_logFile << "maxrss= " << r.ru_maxrss << std::endl;
274+
}
275+
#endif
276+
#endif
277+
278+
delete[] invDiagonals;
279+
delete[] workP;
280+
delete[] workR;
281+
delete[] workQ;
282+
delete[] workX;
283+
delete[] workZ;
284+
285+
}
286+
138287
//Release memory of matrix solver
139288
void DoubleSparseSquareMatrix::releaseMemoryMatrixSolver(){
140289
if( m_pardisoSolver.getSolutionStage() > PARDISOSolver::MEMORY_RELEASED ){

src/DoubleSparseSquareMatrix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class DoubleSparseSquareMatrix : public DoubleSparseMatrix{
6868
//Solve phase of matrix solver
6969
void solvePhaseMatrixSolver( const int nrhs, double* rhs, double* solution );
7070

71+
//Solve phase of matrix solver by the conjugate gradient method with the point Jacobi preconditioner
72+
//@note Matrix should be symmetric
73+
void solvePhaseMatrixSolverByPCGPointJacobi(const int nrhs, double* rhs, double* solution) const;
74+
7175
//Release memory of matrix solver
7276
void releaseMemoryMatrixSolver();
7377

src/Inversion.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ void Inversion::calculateSensitivityMatrix( const int freqIDAmongThisPE, const d
185185
// Write sensitivity matrix to out-of-core file ---
186186
//-------------------------------------------------
187187
std::ostringstream fileName;
188+
if ( !ptrAnalysisControl->getDirectoryOfOutOfCoreFilesForSensitivityMatrix().empty() ){
189+
#ifdef _LINUX
190+
fileName << ptrAnalysisControl->getDirectoryOfOutOfCoreFilesForSensitivityMatrix() + "\/";
191+
#else
192+
fileName << ptrAnalysisControl->getDirectoryOfOutOfCoreFilesForSensitivityMatrix() + "\\";
193+
#endif
194+
}
188195
fileName << "sensMatFreq" << freqIDGlobal;
189196
//std::ofstream outputFile(fileName.str().c_str(), std::ios::out|std::ios::binary|std::ios::trunc);
190197
//if( outputFile.fail() ){
@@ -713,10 +720,18 @@ void Inversion::multiplyModelTransformingJacobian( const int numData, const int
713720
void Inversion::deleteOutOfCoreFileAll(){
714721

715722
const ObservedData* const ptrObservedData = ObservedData::getInstance();
723+
const AnalysisControl* const ptrAnalysisControl = AnalysisControl::getInstance();
716724
const int nFreq = ptrObservedData->getNumOfFrequenciesCalculatedByThisPE();
717725
for( int iFreq = 0; iFreq < nFreq; ++iFreq ){
718726
const int freqID = ptrObservedData->getIDsOfFrequenciesCalculatedByThisPE(iFreq);
719727
std::ostringstream fileName;
728+
if (!ptrAnalysisControl->getDirectoryOfOutOfCoreFilesForSensitivityMatrix().empty()) {
729+
#ifdef _LINUX
730+
fileName << ptrAnalysisControl->getDirectoryOfOutOfCoreFilesForSensitivityMatrix() + "\/";
731+
#else
732+
fileName << ptrAnalysisControl->getDirectoryOfOutOfCoreFilesForSensitivityMatrix() + "\\";
733+
#endif
734+
}
720735
fileName << "sensMatFreq" << freqID;
721736
FILE* fp = fopen( fileName.str().c_str(), "rb" );
722737
if( fp != NULL ){// File exists

0 commit comments

Comments
 (0)