void Q_Unlock(QMatrix *Q) /* unlock the matrix Q */ { if (Q != NULL) { Q->LockLevel--; if (Q->Instance == Tempor && Q->LockLevel <= 0) { Q_Destr(Q); free(Q); } } }
void LaspackMatrix<T>::clear () { if (this->initialized()) { Q_Destr(&_QMat); } _csr.clear(); _row_start.clear(); _closed = false; this->_is_initialized = false; }
void Solver::ProccessStart(void) { #include "perem.cpp" #include "viraj.cpp" #ifdef __TASK1__ QMatrix A; Vector B, D; Q_Constr(&A, (char*)"A", 3 * total, False, Rowws, Normal, True); V_Constr(&B, (char*)"B", 3 * total, Normal, True); V_Constr(&D, (char*)"D", 3 * total, Normal, True); SetRTCAccuracy(1e-8); #endif #ifdef __TASK2__ double *A = new double [3 * 9 * total * 3]; int sizeA = 0; double *B = new double [3 * total]; double *D = new double [3 * total]; #endif #ifdef __TASK1__ mm = 1; #endif #ifdef __TASK2__ mm = 0; #endif for(int i = 0; i < total; i++) { #ifdef __TASK1__ V_SetCmp(&D, 3 * i + mm, G[i]); V_SetCmp(&D, 3 * i + 1 + mm, V1[i]); V_SetCmp(&D, 3 * i + 2 + mm, V2[i]); #endif #ifdef __TASK2__ D[3 * i + mm] = G[i]; D[3 * i + 1 + mm] = V1[i]; D[3 * i + 2 + mm] = V2[i]; #endif } for (nn = 1; nn <= N;nn++) { tt = nn * tau; #include "mum.cpp" //#ifdef __TASK1__ mm = 1; //#endif #ifdef __TASK2__ // mm = 0; sizeA = 0; #endif for (m = 0; m < Dim; m++) { int n_, m_; int i00, i0m1, i0p1, i0pp1, i0mm1; i00 = m; Getmn(i00, &m_, &n_); GetN(&i0m1, m_, n_ - 1); GetN(&i0p1, m_, n_ + 1); GetN(&i0pp1, m_,n_ + 2); GetN(&i0mm1, m_,n_ - 2); M0L[m] = i0m1; M0R[m] = i0p1; xx = m_ * h1; yy = n_ * h2; switch (st[m]){ #include "case0.cpp" #include "case1.cpp" #include "case2.cpp" #include "case3.cpp" #include "case4.cpp" #include "case5.cpp" #include "case6.cpp" #include "case7.cpp" #include "case8.cpp" #include "case9.cpp" } } //CGSIter(&A, &D, &B, 2000, NULL, 1.2); #ifdef __TASK1__ SetRTCAccuracy(1e-8); BiCGSTABIter(&A, &D, &B, 2000, NULL, 1.2); #endif #ifdef __TASK2__ t2Solve(A, D, B, 3 * total, 2000); #endif #ifdef __TASK1__ mm = 1; #endif #ifdef __TASK2__ mm = 0; #endif for (m = 0; m < Dim; m++) { #ifdef __TASK1__ G[m] = V_GetCmp(&D, 3 * m + mm); V1[m] = V_GetCmp(&D, 3 * m + 1 + mm); V2[m] = V_GetCmp(&D, 3 * m + 2 + mm); #endif #ifdef __TASK2__ G[m] = D[3 * m + mm]; V1[m] = D[3 * m + 1 + mm]; V2[m] = D[3 * m + 2 + mm]; #endif } #ifdef __TASK3__ std::stringstream str; str << "_plot" << nn; FILE *f = fopen(str.str().c_str(), "w"); for (m = 0; m < Dim; m++) { int n_, m_; Getmn(m, &m_, &n_); fprintf(f, "%lf %lf %lf %lf\n", m_ * h1, - n_ * h2, V1[m] / 10, - V2[m]); } fclose(f); str.str(""); str << "_dense" << nn; FILE *fd = fopen(str.str().c_str(), "w"); for (m = 0; m < Dim; m++) { int n_, m_; Getmn(m, &m_, &n_); fprintf(fd, "%lf %lf %d\n", m_ * h1, - n_ * h2, exp(G[m]) > 1); } fclose(fd); #endif } #ifdef __TASK1__ Q_Destr(&A); V_Destr(&B); V_Destr(&D); #endif #ifdef __TASK2__ delete [] A; delete [] B; delete [] D; #endif }
void Q_Destr(QMatrix *Q) /* destructor of the type QMatrix */ { size_t Dim, RoC; if (Q->Name != NULL) free(Q->Name); Dim = Q->Dim; if (Q->OwnData) { if (Q->Len != NULL && Q->El != NULL) { for (RoC = 1; RoC <= Dim; RoC++) { if (Q->Len[RoC] > 0) { if (Q->El[RoC] != NULL) free(Q->El[RoC]); } } } if (Q->Len != NULL) { free(Q->Len); Q->Len = NULL; } if (Q->El != NULL) { free(Q->El); Q->El = NULL; } if (Q->ElSorted != NULL) { free(Q->ElSorted); Q->ElSorted = NULL; } if (Q->DiagElAlloc != NULL) { free(Q->DiagElAlloc); Q->DiagElAlloc = NULL; } if (Q->DiagEl != NULL) { free(Q->DiagEl); Q->DiagEl = NULL; } if (Q->ZeroInDiag != NULL) { free(Q->ZeroInDiag); Q->ZeroInDiag = NULL; } if (Q->InvDiagEl != NULL) { free(Q->InvDiagEl); Q->InvDiagEl = NULL; } if (Q->ILUExists != NULL && Q->ILU != NULL) { if (*Q->ILUExists) Q_Destr(Q->ILU); } if (Q->ILUExists != NULL) { free(Q->ILUExists); Q->ILUExists = NULL; } if (Q->ILU != NULL) { free(Q->ILU); Q->ILU = NULL; } } if (Q->RightKerCmp != NULL) { free(Q->RightKerCmp); Q->RightKerCmp = NULL; } if (Q->LeftKerCmp != NULL) { free(Q->LeftKerCmp); Q->LeftKerCmp = NULL; } if (Q->EigenvalInfo != NULL) { free(Q->EigenvalInfo); Q->EigenvalInfo = NULL; } }
Vector *Test4_QV(QMatrix *Q, Vector *V) /* VRes = Q * V ... implementation using local variables and pointers, descended counting of matrix elements */ { Vector *VRes; char *VResName; size_t Dim, Row, Clm, Len, ElCount; size_t *QLen; ElType **QEl, *PtrEl; Real Sum, Cmp; Real *VCmp, *VResCmp; if (LASResult() == LASOK) { if (Q->Dim == V->Dim) { Dim = Q->Dim; VRes = (Vector *)malloc(sizeof(Vector)); VResName = (char *)malloc((strlen(Q_GetName(Q)) + strlen(V_GetName(V)) + 10) * sizeof(char)); if (VRes != NULL && VResName != NULL) { sprintf(VResName, "(%s) * (%s)", Q_GetName(Q), V_GetName(V)); V_Constr(VRes, VResName, Dim, Tempor, True); if (LASResult() == LASOK) { /* initialisation of vector VRes */ if (Q->Symmetry || Q->ElOrder == Clmws) V_SetAllCmp(VRes, 0.0); /* analysis of multipliers of matrix Q and vector V is not implemented yet */ /* multiplication of matrix elements by vector components */ VCmp = V->Cmp; VResCmp = VRes->Cmp; QLen = Q->Len; QEl = Q->El; if (!Q->Symmetry) { if (Q->ElOrder == Rowws) { for (Row = Dim; Row > 0; Row--) { Len = QLen[Row]; PtrEl = QEl[Row] + Len - 1; Sum = 0.0; for (ElCount = Len; ElCount > 0; ElCount--) { Sum += (*PtrEl).Val * VCmp[(*PtrEl).Pos]; PtrEl--; } VResCmp[Row] = Sum; } } if (Q->ElOrder == Clmws) { for (Clm = Dim; Clm > 0; Clm--) { Len = QLen[Clm]; PtrEl = QEl[Clm] + Len - 1; Cmp = VCmp[Clm]; for (ElCount = Len; ElCount > 0; ElCount--) { VResCmp[(*PtrEl).Pos] += (*PtrEl).Val * Cmp; PtrEl--;; } } } } else { /* multiplication by symmetric matrix is not implemented yet */ V_SetAllCmp(VRes, 0.0); } } } else { LASError(LASMemAllocErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL); if (VRes != NULL) free(VRes); if (VResName != NULL) free(VResName); } } else { LASError(LASDimErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL); VRes = NULL; } } else { VRes = NULL; } if (Q != NULL) { if (Q->Instance == Tempor) { Q_Destr(Q); free(Q); } } if (V != NULL) { if (V->Instance == Tempor) { V_Destr(V); free(V); } } return(VRes); }
Vector *Test1_QV(QMatrix *Q, Vector *V) /* VRes = Q * V ... very simple implementation */ { Vector *VRes; char *VResName; size_t Dim, Row, Clm, ElCount; ElType **QEl; if (LASResult() == LASOK) { if (Q->Dim == V->Dim) { Dim = Q->Dim; QEl = Q->El; VRes = (Vector *)malloc(sizeof(Vector)); VResName = (char *)malloc((strlen(Q_GetName(Q)) + strlen(V_GetName(V)) + 10) * sizeof(char)); if (VRes != NULL && VResName != NULL) { sprintf(VResName, "(%s) * (%s)", Q_GetName(Q), V_GetName(V)); V_Constr(VRes, VResName, Dim, Tempor, True); if (LASResult() == LASOK) { /* initialisation of vector VRes */ V_SetAllCmp(VRes, 0.0); /* analysis of multipliers of matrix Q and vector V is not implemented yet */ /* multiplication of matrix elements by vector components */ if (!Q->Symmetry) { if (Q->ElOrder == Rowws) { for (Row = 1; Row <= Dim; Row++) { for (ElCount = 0; ElCount < Q->Len[Row]; ElCount++) { Clm = QEl[Row][ElCount].Pos; VRes->Cmp[Row] += QEl[Row][ElCount].Val * V->Cmp[Clm]; } } } if (Q->ElOrder == Clmws) { for (Clm = 1; Clm <= Dim; Clm++) { for (ElCount = 0; ElCount < Q->Len[Clm]; ElCount++) { Row = QEl[Clm][ElCount].Pos; VRes->Cmp[Row] += QEl[Clm][ElCount].Val * V->Cmp[Clm]; } } } } else { /* multiplication by symmetric matrix is not implemented yet */ V_SetAllCmp(VRes, 0.0); } } } else { LASError(LASMemAllocErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL); if (VRes != NULL) free(VRes); if (VResName != NULL) free(VResName); } } else { LASError(LASDimErr, "Mul_QV", Q_GetName(Q), V_GetName(V), NULL); VRes = NULL; } } else { VRes = NULL; } if (Q != NULL) { if (Q->Instance == Tempor) { Q_Destr(Q); free(Q); } } if (V != NULL) { if (V->Instance == Tempor) { V_Destr(V); free(V); } } return(VRes); }