PetscErrorCode MyDMComputeJacobian(DM dm,Vec x,Mat J,Mat Jp,MatStructure *str) { PetscErrorCode ierr; PetscFunctionBegin; ierr = FormMatrix(dm,Jp);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode MyComputeJacobian(SNES snes,Vec x,Mat *J,Mat *Jp,MatStructure *str,void* ctx) { PetscErrorCode ierr; DM dm; PetscFunctionBeginUser; ierr = SNESGetDM(snes,&dm);CHKERRQ(ierr); ierr = FormMatrix(dm,*Jp);CHKERRQ(ierr); *str = SAME_NONZERO_PATTERN; PetscFunctionReturn(0); }
PetscErrorCode MyDMComputeFunction(DM dm,Vec x,Vec F) { PetscErrorCode ierr; Mat J; PetscFunctionBegin; ierr = DMGetApplicationContext(dm,&J);CHKERRQ(ierr); if (!J) { ierr = DMCreateMatrix(dm,MATAIJ,&J);CHKERRQ(ierr); ierr = PetscObjectCompose((PetscObject)J,"DM",(PetscObject)PETSC_NULL);CHKERRQ(ierr); ierr = FormMatrix(dm,J);CHKERRQ(ierr); ierr = DMSetApplicationContext(dm,J);CHKERRQ(ierr); ierr = DMSetApplicationContextDestroy(dm,(PetscErrorCode (*)(void**))MatDestroy);CHKERRQ(ierr); } ierr = MatMult(J,x,F);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode MyComputeFunction(SNES snes,Vec x,Vec F,void *ctx) { PetscErrorCode ierr; Mat J; DM dm; PetscFunctionBeginUser; ierr = SNESGetDM(snes,&dm);CHKERRQ(ierr); ierr = DMGetApplicationContext(dm,&J);CHKERRQ(ierr); if (!J) { ierr = DMCreateMatrix(dm,MATAIJ,&J);CHKERRQ(ierr); ierr = MatSetDM(J, PETSC_NULL);CHKERRQ(ierr); ierr = FormMatrix(dm,J);CHKERRQ(ierr); ierr = DMSetApplicationContext(dm,J);CHKERRQ(ierr); ierr = DMSetApplicationContextDestroy(dm,(PetscErrorCode (*)(void**))MatDestroy);CHKERRQ(ierr); } ierr = MatMult(J,x,F);CHKERRQ(ierr); PetscFunctionReturn(0); }
void CDynDirDlg::UpdateReport() { bool bEn=true; for (Size g=0;g<pPT->pVs.size();g++) bEn&=(pGiven[g].IsNumber()); //m_move.EnableWindow(bEn); m_rep.DeleteAllItems(); int nColumnCount = m_rep.GetHeaderCtrl()->GetItemCount(); for (int i=0;i < nColumnCount;i++) m_rep.DeleteColumn(0); if (!FormMatrix(m_sv+1)) return; m_rep.InsertColumn(0,"»ндексы",LVCFMT_LEFT,60); m_rep.InsertColumn(1,"1",LVCFMT_LEFT,105); m_rep.InsertColumn(2,"2",LVCFMT_LEFT,105); m_rep.InsertColumn(3,"3",LVCFMT_LEFT,105); m_rep.InsertColumn(4,"4",LVCFMT_LEFT,105); LVITEM lvi; lvi.mask=LVIF_TEXT; CString st; for (Size y=0;y<4;y++) { st.Format("%i",y+1); int ai=m_rep.InsertItem(y,st); lvi.iItem=ai; for (Size x=0;x<4;x++) { lvi.iSubItem=x+1; st=(y<3)?GetLabelForMember(y*4+x,m_sv+1)+"=":""; st+=mt(y,x).GetAsStr().c_str(); lvi.pszText=(char*)(LPCSTR)st; m_rep.SetItem(&lvi); } } }