void CArrayInt2D::SetRows(int iNumRows) { if (miWidth == 0) { miHeight = iNumRows; } else { if (iNumRows > miHeight) { if (miHeight > 0) { InsertRows(miHeight, iNumRows-miHeight); } else { InsertRows(0, iNumRows); } } else if (iNumRows < miHeight) { RemoveRows(iNumRows, miHeight-iNumRows); } } }
void THXVarTable::NewConstant() { const JIndex rowIndex = itsVarList->NewFunction() - THXVarList::kUserFnOffset; InsertRows(rowIndex, 1); BeginEditing(JPoint(1,rowIndex)); }
bool CListView::_createItemSkill() { std::vector <SKILLEDITOR::SListItemShowData> showDataVec = SKILLEDITOR::sSkillMgr.getShowData(); BSLib::s32 rowSize = showDataVec.size(); InsertRows(0, rowSize); for (BSLib::s32 i = 0; i < rowSize; ++i) { wxString column1Str = wxString(wxConvUTF8.cMB2WC(showDataVec[i].showName.c_str()), *wxConvCurrent); SetCellValue(i, 0, column1Str); if (m_skillItemWindow[showDataVec[i].indexName]) { SetAttr(i, 1, m_skillItemWindow[showDataVec[i].indexName]->m_cellAttr); //SetCellRenderer(i, 1, m_skillItemWindow[showDataVec[i].indexName]->m_cellRenderer); } //BSLib::s64 index = this->InsertItem(i, column1Str, -1); //wxRect rect; //GetSubItemRect(index, 0, rect); //BSLib::s32 width = GetColumnWidth(1); //CListViewItem lvItem; //lvItem.init(m_skillItemWindow, showDataVec[i].indexName, column1Str, rect.GetRightTop(), rect); ////SetItem() //this->InsertItem(i, lvItem); } return true; }
int wxPropertyList::AddPropertyToGrid(wxPropertyItem *pItem, int order) { int row = 0; if(order == 1) InsertRows(0,1); else { AppendRows(1); row = GetNumberRows() - 1; } // initialise the type of renderer if(pItem->GetItemType() == wxPropertyList::CHECKBOX) { SetCellRenderer(row, 1, new wxGridCellBoolRenderer); SetCellEditor(row, 1, new wxGridCellBoolEditor); } #ifdef __LINUX__ // fix to make sure scrollbars are drawn properly wxGrid::AdjustScrollbars(); #endif // the property display is read only UpdatePropertyItem(pItem, row); return row; }
//--------------------------------------------------------- bool CVIEW_Table_Control::Ins_Record(void) { if( !FIXED_ROWS && m_pTable->Get_ObjectType() == DATAOBJECT_TYPE_Table ) { int iRecord = GetGridCursorRow(); if( iRecord >= 0 && iRecord < GetNumberRows() ) { InsertRows(iRecord); m_pRecords = (CSG_Table_Record **)SG_Realloc(m_pRecords, GetNumberRows() * sizeof(CSG_Table_Record *)); for(int i=GetNumberRows()-1; i>iRecord; i--) { m_pRecords[i] = m_pRecords[i - 1]; } _Set_Record(iRecord, m_pTable->Ins_Record(iRecord)); return( true ); } } return( false ); }
void DataTable::Receive ( JBroadcaster* sender, const Message& message ) { // Here we check to see what messages we have received. // We first check if the sender is our data array if (sender == itsData) { // Our data array sent us a message // Was data inserted? if (message.Is(JOrderedSetT::kElementsInserted)) { // cast the message to an ElementsInserted object const JOrderedSetT::ElementsInserted* info = dynamic_cast<const JOrderedSetT::ElementsInserted*>(&message); assert(info != NULL); // For each element inserted, we insert a row InsertRows(info->GetFirstIndex(), info->GetCount(), kDefRowHeight); } // Was data removed? else if (message.Is(JOrderedSetT::kElementsRemoved)) { // cast the message to an ElementsRemoved object const JOrderedSetT::ElementsRemoved* info = dynamic_cast<const JOrderedSetT::ElementsRemoved*>(&message); assert(info != NULL); // Remove the corresponding table rows. RemoveNextRows(info->GetFirstIndex(), info->GetCount()); } // Was an element changed? else if (message.Is(JOrderedSetT::kElementChanged)) { // cast the message to an ElementsRemoved object const JOrderedSetT::ElementChanged* info = dynamic_cast<const JOrderedSetT::ElementChanged*>(&message); assert(info != NULL); // The element changed, so redraw it. // (This would not be necessary if we were using a // class derived from JTableData.) TableRefreshCell(info->GetFirstIndex(), 1); } } // pass the message to our base class else { JXTable::Receive(sender, message); } }
int CArrayInt2D::AddRow(void) { int iOldHeight; iOldHeight = miHeight; InsertRows(miHeight-1, 1); return iOldHeight; }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ InsertElementIntoTable /*e*/ // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Inserts the passed element into the table. This should be called when the element has been made visible and needs putting // in the table. The element should already be in the hierarchy. void CHierarchicalTable::InsertElementIntoTable( CHierarchicalElement *inElement, CHierarchicalGroup::TVisibilityOperation inOp) { TableIndexT subRowsToAdd; bool addHeaderRow=!inElement->IsInTable(); CHierarchicalGroup *group=dynamic_cast<CHierarchicalGroup*>(inElement); switch (inOp) { case CHierarchicalGroup::kShowHeaderAndSubGroup: subRowsToAdd=group->CountVisibleSubElements(); break; case CHierarchicalGroup::kShowSubGroupOnly: subRowsToAdd=group->CountVisibleSubElements(); addHeaderRow=false; break; case CHierarchicalGroup::kShowHeaderElementOnly: subRowsToAdd=0; break; default: Throw_(paramErr); break; } // Work out where in the table it should go and insert it STableCell cellPos; CalcInsertPosition(inElement,cellPos); if (inElement->IsInTable()) cellPos.row++; // Insert a row(s) and set the cell(s) InsertRows(subRowsToAdd+addHeaderRow,cellPos.row-1,0L,0L,true); if (addHeaderRow) { PutInTable(inElement,cellPos); cellPos.row++; } // group == 0L if the element is not a group leader if (group) { CVisibleElementsIndexer indexer(group->GetSubList()); CHierarchicalElement *element; while ((element=indexer.GetNextData()) && subRowsToAdd--) { PutInTable(element,cellPos); cellPos.row++; } } }
QuestObjectiveModel::QuestObjectiveModel(CYIString name, YI_INT32 numberStates) : CYIAbstractDataModel(numberStates, 1) { this->name = name; if (numberStates <=1)//No good. An objective must at least have 2 states, incomplete and resolved. { InsertRows(0, 2); } currentState = 0; }
void QuestModel::AddRowsToMatchIndex(YI_INT32 index) { YI_INT32 n_row = GetRowCount(); YI_INT32 missingRows = (index + 1) - n_row; if (missingRows > 0) { InsertRows(n_row, missingRows); } }
void JXTreeListWidget::Receive ( JBroadcaster* sender, const Message& message ) { if (sender == itsTreeList && message.Is(JTreeList::kNodeInserted)) { const JTreeList::NodeInserted* info = dynamic_cast(const JTreeList::NodeInserted*, &message); assert( info != NULL ); InsertRows(info->GetIndex(), 1); NeedsAdjustToTree(); } else if (sender == itsTreeList && message.Is(JTreeList::kNodeRemoved))
void JXFSBindingTable::AddPattern() { if (EndEditing()) { const JFSBinding* b = itsBindingList->GetDefaultCommand(); JFSBinding::CommandType type; JBoolean singleFile; const JString& cmd = b->GetCommand(&type, &singleFile); const JIndex rowIndex = itsBindingList->AddBinding("", cmd, type, singleFile); InsertRows(rowIndex, 1); BeginEditing(JPoint(kPatternColumn, rowIndex)); Broadcast(DataChanged()); } }
void JXFSBindingTable::DuplicatePattern() { JPoint cell; if ((GetTableSelection()).GetFirstSelectedCell(&cell) && EndEditing()) { const JFSBinding* b = itsBindingList->GetBinding(cell.y); JFSBinding::CommandType type; JBoolean singleFile; const JString& cmd = b->GetCommand(&type, &singleFile); const JIndex rowIndex = itsBindingList->AddBinding("", cmd, type, singleFile); InsertRows(rowIndex, 1); BeginEditing(JPoint(kPatternColumn, rowIndex)); Broadcast(DataChanged()); } }
void GMAccountList::Receive ( JBroadcaster* sender, const Message& message ) { if (sender == itsAccountInfo && message.Is(JOrderedSetT::kElementsInserted)) { const JOrderedSetT::ElementsInserted* info = dynamic_cast(const JOrderedSetT::ElementsInserted*, &message); assert( info != NULL ); const JIndex firstIndex = info->GetFirstIndex(); const JSize count = info->GetCount(); InsertRows(firstIndex, count); } else if (sender == itsAccountInfo &&
void CArrayInt2D::InsertRow(int iRow) { InsertRows(iRow, 1); }
void CGridRFURunBase::_Build() // called from _SetupKit(); { nwxLabelGridBatch x(this); ClearAll(); // nwxGrid.h nwxLabelGrid::ClearAll(); wxFont fontChannel = GetDefaultCellFont(); wxFont fontLabel = fontChannel; fontChannel.SetWeight(wxFONTWEIGHT_BOLD); fontLabel.SetStyle(wxFONTSTYLE_ITALIC); SetDefaultLabelFont(fontLabel); SetDefaultLabelTextColour(wxColour(192, 192, 192)); const CChannelColors *pChannelColors = NULL; int nCurrentRowCount = GetNumberRows(); int i; int j; if(nCurrentRowCount < m_nROW_COUNT) { InsertRows(m_nROW_CHANNEL_START, m_nROW_COUNT - nCurrentRowCount); _UpdateReadOnly(); } else if(nCurrentRowCount > m_nROW_COUNT) { DeleteRows(m_nROW_CHANNEL_START,nCurrentRowCount - m_nROW_COUNT); } SetDefaultCellValidator( new nwxGridCellUIntRangeValidator( mainApp::RFU_MIN_ENTER,mainApp::RFU_MAX_ENTER,true)); EnableDragColSize(false); EnableDragRowSize(false); SetDefaultCellAlignment(wxALIGN_RIGHT,wxALIGN_CENTRE); for(i = 0; i < m_nROW_COUNT; i++) { for(j = 0; j < COL_COUNT; j++) { SetCellValue(i,j,"00000000"); // used for size if(_DisabledCell(i,j)) { SetCellBackgroundColour(i,j,GetGridLineColour()); } } } SetDefaultEditor(new wxGridCellFloatEditor(1,0)); SetRowLabelValue(m_nROW_SAMPLE,"Sample"); SetRowLabelValue(m_nROW_LADDER,"Ladder"); SetRowLabelValue(m_nROW_ILS," ILS "); SetColLabelValue(COL_ANALYSIS,"Analysis"); SetColLabelValue(COL_DETECTION,"Detection"); SetColLabelValue(COL_INTERLOCUS,"Interlocus"); SetRowLabelAlignment(wxALIGN_LEFT, wxALIGN_CENTRE); SetMargins(0,0); ChannelNumberIterator itrChannelCol; int nRow; const wxChar *psDye = NULL; wxString sLabel; for(itrChannelCol = m_vnChannelNumbers.begin(), nRow = m_nROW_CHANNEL_START; itrChannelCol != m_vnChannelNumbers.end(); ++itrChannelCol, ++nRow) { if(m_pKitColors != NULL) { pChannelColors = m_pKitColors->GetColorChannel(*itrChannelCol); psDye = (pChannelColors == NULL) ? NULL : (const wxChar *) pChannelColors->GetDyeName(); } CGridLocusColumns::FORMAT_CHANNEL_DYE(&sLabel,*itrChannelCol,psDye); SetRowLabelValue(nRow,sLabel); if(pChannelColors != NULL) { _SetupChannelRow(nRow,pChannelColors->GetColorAnalyzed(),fontChannel); } else { _SetupDefaultChannelRow(nRow); } } nwxGrid::UpdateLabelSizes(this); AutoSize(); _DisableUnused(); }
int CentralDifferencesSparse::DoTimestep() { PerformanceCounter counterForceAssemblyTime; forceModel->GetInternalForce(q, internalForces); for (int i=0; i<r; i++) internalForces[i] *= internalForceScalingFactor; counterForceAssemblyTime.StopCounter(); forceAssemblyTime = counterForceAssemblyTime.GetElapsedTime(); if (tangentialDampingMode > 0) if (timestepIndex % tangentialDampingMode == 0) DecomposeSystemMatrix(); // this routines also updates the damping and system matrices // update equation is (see WRIGGERS P.: Computational Contact Mechanics. John Wiley & Sons, Ltd., 2002., page 275) : // // (M + dt / 2 * C) * q(t+1) = (dt)^2 * (fext(t) - fint(q(t))) + dt / 2 * C * q(t-1) + M * (2q(t) - q(t-1)) // // (M + dt / 2 * C) * (q(t+1) - q(t)) = (dt)^2 * (fext(t) - fint(q(t))) + dt / 2 * C * (q(t-1) - q(t)) + M * (q(t) - q(t-1)) // fext are the external forces // fint is the vector of internal forces // compute rhs = (dt)^2 * (fext - fint(q(t))) + dt / 2 * C * (q(t-1) - q(t)) + M * (q(t) - q(t-1)) // first, compute rhs = M * (q - q_1) for (int i=0; i<r; i++) buffer[i] = q[i] - q_1[i]; massMatrix->MultiplyVector(buffer, rhs); // rhs += dt / 2 * dampingMatrix * (q_{n-1} - q_n) for (int i=0; i<r; i++) qdelta[i] = q_1[i] - q[i]; rayleighDampingMatrix->MultiplyVector(qdelta, buffer); for (int i=0; i<r; i++) rhs[i] += 0.5 * timestep * buffer[i]; // rhs += dt * dt * (fext - fint(q(t))) double timestep2 = timestep * timestep; for (int i=0; i<r; i++) rhs[i] += timestep2 * (externalForces[i] - internalForces[i]); // now rhs contains the correct value RemoveRows(r, rhsConstrained, rhs, numConstrainedDOFs, constrainedDOFs); PerformanceCounter counterSystemSolveTime; memset(buffer, 0, sizeof(double) * r); #ifdef SPOOLES int info = spoolesSolver->SolveLinearSystem(buffer, rhsConstrained); char solverString[16] = "SPOOLES"; #endif #ifdef PARDISO int info = pardisoSolver->SolveLinearSystem(buffer, rhsConstrained); char solverString[16] = "PARDISO"; #endif #ifdef PCG int info = jacobiPreconditionedCGSolver->SolveLinearSystemWithJacobiPreconditioner(buffer, rhsConstrained, 1e-6, 10000); if (info > 0) info = 0; char solverString[16] = "PCG"; #endif InsertRows(r, buffer, qdelta, numConstrainedDOFs, constrainedDOFs); counterSystemSolveTime.StopCounter(); systemSolveTime = counterSystemSolveTime.GetElapsedTime(); if (info != 0) { printf("Error: %s sparse solver returned non-zero exit status %d.\n", solverString, (int)info); return 1; } // the new value of q is now in buffer // update velocity, and previous and current positions for (int i=0; i<r; i++) { q_1[i] = q[i]; qvel[i] = qdelta[i] / timestep; qaccel[i] = (qvel[i] - qvel_1[i]) / timestep; qvel_1[i] = qvel[i]; qaccel_1[i] = qaccel[i]; q[i] += qdelta[i]; } timestepIndex++; return 0; }
void JXTreeListWidget::Receive ( JBroadcaster* sender, const Message& message ) { if (sender == itsTreeList && message.Is(JTreeList::kNodeInserted)) { const JTreeList::NodeInserted* info = dynamic_cast<const JTreeList::NodeInserted*>(&message); assert( info != NULL ); InsertRows(info->GetIndex(), 1); NeedsAdjustToTree(); } else if (sender == itsTreeList && message.Is(JTreeList::kNodeRemoved)) { const JTreeList::NodeRemoved* info = dynamic_cast<const JTreeList::NodeRemoved*>(&message); assert( info != NULL ); RemoveRow(info->GetIndex()); NeedsAdjustToTree(); } else if (sender == itsTreeList && message.Is(JTreeList::kNodeChanged)) { const JTreeList::NodeChanged* info = dynamic_cast<const JTreeList::NodeChanged*>(&message); assert( info != NULL ); TableRefreshRow(info->GetIndex()); NeedsAdjustToTree(); } else if (sender == itsTreeList && (message.Is(JTreeList::kNodeOpened) || message.Is(JTreeList::kNodeClosed))) { const JTreeList::NodeMessage* info = dynamic_cast<const JTreeList::NodeMessage*>(&message); assert( info != NULL ); TableRefreshRow(info->GetIndex()); } else if (sender == itsTreeList->GetTree() && message.Is(JTree::kPrepareForNodeMove)) { HandlePrepareForNodeMove(); } else if (sender == itsTreeList->GetTree() && message.Is(JTree::kNodeMoveFinished)) { HandleNodeMoveFinished(); } else { if (sender == this && message.Is(kColsInserted)) { const ColsInserted* info = dynamic_cast<const ColsInserted*>(&message); assert( info != NULL ); info->AdjustIndex(&itsToggleOpenColIndex); info->AdjustIndex(&itsNodeColIndex); info->AdjustIndex(&itsElasticColIndex); NeedsAdjustToTree(); } else if (sender == this && message.Is(kColsRemoved)) { const ColsRemoved* info = dynamic_cast<const ColsRemoved*>(&message); assert( info != NULL ); JBoolean ok = info->AdjustIndex(&itsToggleOpenColIndex); assert( ok ); ok = info->AdjustIndex(&itsNodeColIndex); assert( ok ); info->AdjustIndex(&itsElasticColIndex); // ok to let it go to zero NeedsAdjustToTree(); } else if (sender == this && message.Is(kColMoved)) { const ColMoved* info = dynamic_cast<const ColMoved*>(&message); assert( info != NULL ); info->AdjustIndex(&itsToggleOpenColIndex); info->AdjustIndex(&itsNodeColIndex); info->AdjustIndex(&itsElasticColIndex); itsMinColWidths->MoveElementToIndex(info->GetOrigIndex(), info->GetNewIndex()); } JXStyleTable::Receive(sender, message); } }
void CBCommandTable::HandleDNDDrop ( const JPoint& pt, const JArray<Atom>& typeList, const Atom action, const Time time, const JXWidget* source ) { JXSelectionManager* selMgr = GetSelectionManager(); JXDNDManager* dndMgr = GetDNDManager(); const Atom selName = dndMgr->GetDNDSelectionName(); if (source == this && action == dndMgr->GetDNDActionMoveXAtom()) { JPoint cell; if ((GetTableSelection()).GetSingleSelectedCell(&cell) && itsDNDRowIndex != JIndex(cell.y) && itsDNDRowIndex != JIndex(cell.y)+1) { JIndex newIndex = itsDNDRowIndex; if (newIndex > JIndex(cell.y)) { newIndex--; } newIndex = JMin(newIndex, GetRowCount()); itsCmdList->MoveElementToIndex(cell.y, newIndex); MoveRow(cell.y, newIndex); SelectSingleCell(JPoint(1, newIndex)); } } else if (source == this) { JPoint cell; if ((GetTableSelection()).GetSingleSelectedCell(&cell)) { itsCmdList->InsertElementAtIndex( itsDNDRowIndex, (itsCmdList->GetElement(cell.y)).Copy()); InsertRows(itsDNDRowIndex, 1); SelectSingleCell(JPoint(1, itsDNDRowIndex)); } } else { Atom returnType; unsigned char* data; JSize dataLength; JXSelectionManager::DeleteMethod delMethod; if (selMgr->GetData(selName, time, itsCommandXAtom, &returnType, &data, &dataLength, &delMethod)) { if (returnType == itsCommandXAtom) { const std::string s((char*) data, dataLength); std::istringstream input(s); CBCommandManager::CmdInfo cmdInfo = CBCommandManager::ReadCmdInfo(input, CBCommandManager::GetCurrentCmdInfoFileVersion()); if (!input.fail()) { const JIndex newIndex = JMax(JIndex(1), itsDNDRowIndex); itsCmdList->InsertElementAtIndex(newIndex, cmdInfo); InsertRows(newIndex, 1); SelectSingleCell(JPoint(1, newIndex)); if (action == dndMgr->GetDNDActionMoveXAtom()) { selMgr->SendDeleteRequest(selName, time); } } } selMgr->DeleteData(&data, delMethod); } } HandleDNDLeave(); }
void SelectionTable::Receive ( JBroadcaster* sender, const Message& message ) { // Here we check to see what messages we have received. // We first check if the sender is our data array if (sender == itsData) { // Our data array sent us a message // Was data inserted? if (message.Is(JOrderedSetT::kElementsInserted)) { // cast the message to an ElementsInserted object const JOrderedSetT::ElementsInserted* info = dynamic_cast<const JOrderedSetT::ElementsInserted*>(&message); assert(info != NULL); // For each element inserted, we insert a row InsertRows(info->GetFirstIndex(), info->GetCount(), kDefRowHeight); } // Was data removed? else if (message.Is(JOrderedSetT::kElementsRemoved)) { // cast the message to an ElementsRemoved object const JOrderedSetT::ElementsRemoved* info = dynamic_cast<const JOrderedSetT::ElementsRemoved*>(&message); assert(info != NULL); // Remove corresponding table rows. for (JSize i = info->GetLastIndex(); i >= info->GetFirstIndex() ; i--) { RemoveNextRows(info->GetFirstIndex(), info->GetCount()); } } // Was an element changed? else if (message.Is(JOrderedSetT::kElementChanged)) { // cast the message to an ElementsRemoved object const JOrderedSetT::ElementChanged* info = dynamic_cast<const JOrderedSetT::ElementChanged*>(&message); assert(info != NULL); // The element changed, so redraw it. // (This would not be necessary if we were using a // class derived from JTableData.) TableRefreshRow(info->GetFirstIndex()); } } // Did the Table menu send a message? else if (sender == itsTableMenu) { // Does the menu need an update? if (message.Is(JXMenu::kNeedsUpdate)) { UpdateTableMenu(); } // Has a menu item been selected? else if (message.Is(JXMenu::kItemSelected)) { // cast the message to an ItemSelecte object. // This will tell us which item was selected. const JXMenu::ItemSelected* info = dynamic_cast<const JXMenu::ItemSelected*>(&message); assert(info != NULL); // Pass the selected menu item to our menu handler function. HandleTableMenu(info->GetIndex()); } } // pass the message to our base class else { JXTable::Receive(sender, message); } }
int ImplicitNewmarkSparse::DoTimestep() { int numIter = 0; double error0 = 0; // error after the first step double errorQuotient; // store current amplitudes and set initial guesses for qaccel, qvel for(int i=0; i<r; i++) { q_1[i] = q[i]; qvel_1[i] = qvel[i]; qaccel_1[i] = qaccel[i]; qaccel[i] = alpha1 * (q[i] - q_1[i]) - alpha2 * qvel_1[i] - alpha3 * qaccel_1[i]; qvel[i] = alpha4 * (q[i] - q_1[i]) + alpha5 * qvel_1[i] + alpha6 * qaccel_1[i]; } do { int i; /* printf("q:\n"); for(int i=0; i<r; i++) printf("%G ", q[i]); printf("\n"); printf("Internal forces:\n"); for(int i=0; i<r; i++) printf("%G ", internalForces[i]); printf("\n"); */ PerformanceCounter counterForceAssemblyTime; forceModel->GetForceAndMatrix(q, internalForces, tangentStiffnessMatrix); counterForceAssemblyTime.StopCounter(); forceAssemblyTime = counterForceAssemblyTime.GetElapsedTime(); //tangentStiffnessMatrix->Print(); //tangentStiffnessMatrix->Save("K"); // scale internal forces for(i=0; i<r; i++) internalForces[i] *= internalForceScalingFactor; *tangentStiffnessMatrix *= internalForceScalingFactor; memset(qresidual, 0, sizeof(double) * r); if (useStaticSolver) { // no operation } else { // build effective stiffness: add mass matrix and damping matrix to tangentStiffnessMatrix tangentStiffnessMatrix->ScalarMultiply(dampingStiffnessCoef, rayleighDampingMatrix); rayleighDampingMatrix->AddSubMatrix(dampingMassCoef, *massMatrix); rayleighDampingMatrix->ScalarMultiplyAdd(alpha4, tangentStiffnessMatrix); //*tangentStiffnessMatrix += alpha4 * *rayleighDampingMatrix; tangentStiffnessMatrix->AddSubMatrix(alpha4, *dampingMatrix, 1); tangentStiffnessMatrix->AddSubMatrix(alpha1, *massMatrix); // compute force residual, store it into aux variable qresidual // qresidual = M * qaccel + C * qvel - externalForces + internalForces massMatrix->MultiplyVector(qaccel, qresidual); rayleighDampingMatrix->MultiplyVectorAdd(qvel, qresidual); dampingMatrix->MultiplyVectorAdd(qvel, qresidual); } // add externalForces, internalForces for(i=0; i<r; i++) { qresidual[i] += internalForces[i] - externalForces[i]; qresidual[i] *= -1; qdelta[i] = qresidual[i]; } /* printf("internal forces:\n"); for(int i=0; i<r; i++) printf("%G ", internalForces[i]); printf("\n"); printf("external forces:\n"); for(int i=0; i<r; i++) printf("%G ", externalForces[i]); printf("\n"); printf("residual:\n"); for(int i=0; i<r; i++) printf("%G ", -qresidual[i]); printf("\n"); */ double error = 0; for(i=0; i<r; i++) error += qresidual[i] * qresidual[i]; // on the first iteration, compute initial error if (numIter == 0) { error0 = error; errorQuotient = 1.0; } else { // error divided by the initial error, before performing this iteration errorQuotient = error / error0; } if (errorQuotient < epsilon * epsilon) { break; } //tangentStiffnessMatrix->Save("Keff"); RemoveRows(r, bufferConstrained, qdelta, numConstrainedDOFs, constrainedDOFs); systemMatrix->AssignSuperMatrix(tangentStiffnessMatrix); // solve: systemMatrix * buffer = bufferConstrained PerformanceCounter counterSystemSolveTime; memset(buffer, 0, sizeof(double) * r); #ifdef SPOOLES SPOOLESSolver solver(systemMatrix); int info = solver.SolveLinearSystem(buffer, bufferConstrained); char solverString[16] = "SPOOLES"; #endif #ifdef PARDISO int info = pardisoSolver->ComputeCholeskyDecomposition(systemMatrix); if (info == 0) info = pardisoSolver->SolveLinearSystem(buffer, bufferConstrained); char solverString[16] = "PARDISO"; #endif #ifdef PCG int info = jacobiPreconditionedCGSolver->SolveLinearSystemWithJacobiPreconditioner(buffer, bufferConstrained, 1e-6, 10000); if (info > 0) info = 0; char solverString[16] = "PCG"; #endif if (info != 0) { printf("Error: %s sparse solver returned non-zero exit status %d.\n", solverString, (int)info); return 1; } counterSystemSolveTime.StopCounter(); systemSolveTime = counterSystemSolveTime.GetElapsedTime(); InsertRows(r, buffer, qdelta, numConstrainedDOFs, constrainedDOFs); /* printf("qdelta:\n"); for(int i=0; i<r; i++) printf("%G ", qdelta[i]); printf("\n"); exit(1); */ // update state for(i=0; i<r; i++) { q[i] += qdelta[i]; qaccel[i] = alpha1 * (q[i] - q_1[i]) - alpha2 * qvel_1[i] - alpha3 * qaccel_1[i]; qvel[i] = alpha4 * (q[i] - q_1[i]) + alpha5 * qvel_1[i] + alpha6 * qaccel_1[i]; } for(int i=0; i<numConstrainedDOFs; i++) q[constrainedDOFs[i]] = qvel[constrainedDOFs[i]] = qaccel[constrainedDOFs[i]] = 0.0; numIter++; } while (numIter < maxIterations); /* printf("qvel:\n"); for(int i=0; i<r; i++) printf("%G ", qvel[i]); printf("\n"); printf("qaccel:\n"); for(int i=0; i<r; i++) printf("%G ", qaccel[i]); printf("\n"); */ //printf("Num iterations performed: %d\n",numIter); //if ((numIter >= maxIterations) && (maxIterations > 1)) //{ //printf("Warning: method did not converge in max number of iterations.\n"); //} return 0; }
// sets the state based on given q, qvel // automatically computes acceleration assuming zero external force int ImplicitNewmarkSparse::SetState(double * q_, double * qvel_) { memcpy(q, q_, sizeof(double)*r); if (qvel_ != NULL) memcpy(qvel, qvel_, sizeof(double)*r); else memset(qvel, 0, sizeof(double)*r); for(int i=0; i<numConstrainedDOFs; i++) q[constrainedDOFs[i]] = qvel[constrainedDOFs[i]] = 0.0; // M * qaccel + C * qvel + R(q) = P_0 // R(q) = P_0 = 0 // i.e. M * qaccel = - C * qvel - R(q) forceModel->GetForceAndMatrix(q, internalForces, tangentStiffnessMatrix); *rayleighDampingMatrix = dampingStiffnessCoef * (*tangentStiffnessMatrix); rayleighDampingMatrix->AddSubMatrix(dampingMassCoef, *massMatrix); // buffer = C * qvel rayleighDampingMatrix->MultiplyVector(qvel, buffer); dampingMatrix->MultiplyVectorAdd(qvel, buffer); for(int i=0; i<r; i++) buffer[i] = -buffer[i] - internalForces[i]; // solve M * qaccel = buffer RemoveRows(r, bufferConstrained, buffer, numConstrainedDOFs, constrainedDOFs); // use tangentStiffnessMatrix as the buffer place tangentStiffnessMatrix->ResetToZero(); tangentStiffnessMatrix->AddSubMatrix(1.0, *massMatrix); tangentStiffnessMatrix->AddSubMatrix(1.0, *dampingMatrix, 1); systemMatrix->AssignSuperMatrix(tangentStiffnessMatrix); // must go via a matrix with tangentStiffnessMatrix's topology, because the AssignSuperMatrix indices were computed with respect to such topology memset(buffer, 0, sizeof(double) * r); #ifdef SPOOLES SPOOLESSolver solver(systemMatrix); int info = solver.SolveLinearSystem(buffer, bufferConstrained); char solverString[16] = "SPOOLES"; #endif //massMatrix->Save("M"); //systemMatrix->Save("A"); #ifdef PARDISO pardisoSolver->ComputeCholeskyDecomposition(systemMatrix); int info = pardisoSolver->SolveLinearSystem(buffer, bufferConstrained); char solverString[16] = "PARDISO"; #endif #ifdef PCG int info = jacobiPreconditionedCGSolver->SolveLinearSystemWithJacobiPreconditioner(buffer, bufferConstrained, 1e-6, 10000); if (info > 0) info = 0; char solverString[16] = "PCG"; #endif if (info != 0) { printf("Error: %s sparse solver returned non-zero exit status %d.\n", solverString, (int)info); return 1; } InsertRows(r, buffer, qaccel, numConstrainedDOFs, constrainedDOFs); return 0; }
void DboInstaller::Install() { CreateTables(); InsertRows(); }
int VolumeConservingIntegrator::DoTimestep() { int numIter = 0; //Error after the first step double error0 = 0; double errorQuotient; // store current amplitudes and set initial guesses for qaccel, qvel for (int i = 0; i < r; i++) { qaccel_1[i] = qaccel[i] = 0; q_1[i] = q[i]; qvel_1[i] = qvel[i]; } do { int i; /* printf("q:\n"); for(int i=0; i<r; i++) printf("%G ", q[i]); printf("\n"); printf("Internal forces:\n"); for(int i=0; i<r; i++) printf("%G ", internalForces[i]); printf("\n"); */ PerformanceCounter counterForceAssemblyTime; forceModel->GetForceAndMatrix(q, internalForces, tangentStiffnessMatrix); counterForceAssemblyTime.StopCounter(); forceAssemblyTime = counterForceAssemblyTime.GetElapsedTime(); //tangentStiffnessMatrix->Print(); //tangentStiffnessMatrix->Save("K"); //Scale internal forces for (i = 0; i < r; i++) internalForces[i] *= internalForceScalingFactor; *tangentStiffnessMatrix *= internalForceScalingFactor; memset(qresidual, 0, sizeof(double) * r); if (useStaticSolver) { // fint + K * qdelta = fext // add externalForces, internalForces for (i = 0; i < r; i++) { qresidual[i] = externalForces[i] - internalForces[i]; qdelta[i] = qresidual[i]; } } else { tangentStiffnessMatrix->ScalarMultiply(dampingStiffnessCoef, rayleighDampingMatrix); rayleighDampingMatrix->AddSubMatrix(dampingMassCoef, *massMatrix); // build effective stiffness: // Keff = M + h D + h^2 * K // compute force residual, store it into aux variable qresidual // qresidual = h * (-D qdot - fint + fext - h * K * qdot)) //add mass matrix and damping matrix to tangentStiffnessMatrix *tangentStiffnessMatrix *= timestep; *tangentStiffnessMatrix += *rayleighDampingMatrix; tangentStiffnessMatrix->AddSubMatrix(1.0, *dampingMatrix, 1); // at this point, tangentStiffnessMatrix = h * K + D tangentStiffnessMatrix->MultiplyVector(qvel, qresidual); *tangentStiffnessMatrix *= timestep; tangentStiffnessMatrix->AddSubMatrix(1.0, *massMatrix); // add externalForces, internalForces for (i = 0; i < r; i++) { qresidual[i] += internalForces[i] - externalForces[i]; qresidual[i] *= -timestep; qdelta[i] = qresidual[i]; } } /* printf("internal forces:\n"); for(int i=0; i<r; i++) printf("%G ", internalForces[i]); printf("\n"); printf("external forces:\n"); for(int i=0; i<r; i++) printf("%G ", externalForces[i]); printf("\n"); printf("residual:\n"); for(int i=0; i<r; i++) printf("%G ", -qresidual[i]); printf("\n"); */ double error = 0; for (i = 0; i < r; i++) error += qresidual[i] * qresidual[i]; // on the first iteration, compute initial error if (numIter == 0) { error0 = error; errorQuotient = 1.0; } else { // rel error wrt to initial error before performing this iteration errorQuotient = error / error0; } if (errorQuotient < epsilon * epsilon) break; //tangentStiffnessMatrix->Save("Keff"); RemoveRows(r, bufferConstrained, qdelta, numConstrainedDOFs, constrainedDOFs); systemMatrix->AssignSuperMatrix(tangentStiffnessMatrix); // solve: systemMatrix * qdelta = qresidual PerformanceCounter counterSystemSolveTime; memset(buffer, 0, sizeof(double) * r); #ifdef SPOOLES int info; if (numSolverThreads > 1) { SPOOLESSolverMT * solver = new SPOOLESSolverMT(systemMatrix, numSolverThreads); info = solver->SolveLinearSystem(buffer, bufferConstrained); delete(solver); } else { SPOOLESSolver * solver = new SPOOLESSolver(systemMatrix); info = solver->SolveLinearSystem(buffer, bufferConstrained); delete(solver); } char solverString[16] = "SPOOLES"; #endif #ifdef PARDISO int info = pardisoSolver->ComputeCholeskyDecomposition(systemMatrix); if (info == 0) info = pardisoSolver->SolveLinearSystem(buffer, bufferConstrained); char solverString[16] = "PARDISO"; #endif //Profile finds this function as a hotspot #ifdef PCG int info = jacobiPreconditionedCGSolver->SolveLinearSystemWithJacobiPreconditioner( buffer, bufferConstrained, 1e-6, 10000); if (info > 0) info = 0; char solverString[16] = "PCG"; #endif if (info != 0) { printf( "Error: %s sparse solver returned non-zero exit status %d.\n", solverString, (int) info); exit(-1); return 1; } counterSystemSolveTime.StopCounter(); systemSolveTime = counterSystemSolveTime.GetElapsedTime(); InsertRows(r, buffer, qdelta, numConstrainedDOFs, constrainedDOFs); /* printf("qdelta:\n"); for(int i=0; i<r; i++) printf("%G ", qdelta[i]); printf("\n"); exit(1); */ // update state if (useStaticSolver) { for (i = 0; i < r; i++) { q[i] += qdelta[i]; qvel[i] = (q[i] - q_1[i]) / timestep; } } else { for (i = 0; i < r; i++) { qvel[i] += qdelta[i]; q[i] += timestep * qvel[i]; } } for (int i = 0; i < numConstrainedDOFs; i++) q[constrainedDOFs[i]] = qvel[constrainedDOFs[i]] = qaccel[constrainedDOFs[i]] = 0.0; numIter++; } while (numIter < maxIterations); /* printf("q:\n"); for(int i=0; i<r; i++) printf("%G ", q[i]); printf("\n"); printf("qvel:\n"); for(int i=0; i<r; i++) printf("%G ", qvel[i]); printf("\n"); */ //printf("Num iterations performed: %d\n",numIter); //if ((numIter >= maxIterations) && (maxIterations > 1)) //{ //printf("Warning: method did not converge in max number of iterations.\n"); //} return 0; }
void * MyFrame::LinearModesWorker( int numDesiredModes, int * r, double ** frequencies_, double ** modes_ ) { *r = -1; // create mass matrix SparseMatrix * massMatrix; GenerateMassMatrix::computeMassMatrix(precomputationState.simulationMesh, &massMatrix, true); // create stiffness matrix StVKElementABCD * precomputedIntegrals = StVKElementABCDLoader::load(precomputationState.simulationMesh); StVKInternalForces * internalForces = new StVKInternalForces(precomputationState.simulationMesh, precomputedIntegrals); SparseMatrix * stiffnessMatrix; StVKStiffnessMatrix * stiffnessMatrixClass = new StVKStiffnessMatrix(internalForces); stiffnessMatrixClass->GetStiffnessMatrixTopology(&stiffnessMatrix); double * zero = (double*) calloc(3 * precomputationState.simulationMesh->getNumVertices(), sizeof(double)); stiffnessMatrixClass->ComputeStiffnessMatrix(zero, stiffnessMatrix); free(zero); delete(precomputedIntegrals); delete(stiffnessMatrixClass); delete(internalForces); // constrain the degrees of freedom int numConstrainedVertices = (int) (precomputationState.fixedVertices.size()); int * constrainedDOFs = (int*) malloc (sizeof(int) * 3 * numConstrainedVertices); set<int> :: iterator iter; int i = 0; for(iter = precomputationState.fixedVertices.begin(); iter != precomputationState.fixedVertices.end(); iter++) { constrainedDOFs[3*i+0] = 3 * (*iter) + 1; constrainedDOFs[3*i+1] = 3 * (*iter) + 2; constrainedDOFs[3*i+2] = 3 * (*iter) + 3; i++; } int oneIndexed = 1; massMatrix->RemoveRowsColumns( 3 * numConstrainedVertices, constrainedDOFs, oneIndexed); stiffnessMatrix->RemoveRowsColumns( 3 * numConstrainedVertices, constrainedDOFs, oneIndexed); // call ARPACK double * frequenciesTemp = (double*) malloc (sizeof(double) * numDesiredModes); int numRetainedDOFs = stiffnessMatrix->Getn(); double * modesTemp = (double*) malloc (sizeof(double) * numDesiredModes * numRetainedDOFs); printf("Computing linear modes using ARPACK: ...\n"); PerformanceCounter ARPACKCounter; double sigma = -1.0; int numLinearSolverThreads = wxThread::GetCPUCount(); if (numLinearSolverThreads > 3) numLinearSolverThreads = 3; // diminished returns in solver beyond 3 threads //massMatrix->Save("MFactory"); //stiffnessMatrix->Save("KFactory"); ARPACKSolver generalizedEigenvalueProblem; int nconv = generalizedEigenvalueProblem.SolveGenEigShInv (stiffnessMatrix, massMatrix, numDesiredModes, frequenciesTemp, modesTemp, sigma, numLinearSolverThreads); ARPACKCounter.StopCounter(); double ARPACKTime = ARPACKCounter.GetElapsedTime(); printf("ARPACK time: %G s.\n", ARPACKTime); fflush(NULL); if (nconv < numDesiredModes) { free(modesTemp); free(frequenciesTemp); *r = -3; free(constrainedDOFs); delete(massMatrix); delete(stiffnessMatrix); return NULL; } int n3 = 3 * precomputationState.simulationMesh->getNumVertices(); *frequencies_ = (double*) calloc (numDesiredModes, sizeof(double)); *modes_ = (double*) calloc (numDesiredModes * n3, sizeof(double)); for(int i=0; i<numDesiredModes; i++) { // insert zero rows into the computed modes int oneIndexed = 1; InsertRows(n3, &modesTemp[numRetainedDOFs*i], &((*modes_)[n3*i]), 3 * numConstrainedVertices, constrainedDOFs, oneIndexed); } for(int i=0; i<numDesiredModes; i++) { if (frequenciesTemp[i] <= 0) (*frequencies_)[i] = 0.0; else (*frequencies_)[i] = sqrt((frequenciesTemp)[i]) / (2 * M_PI); } free(modesTemp); free(frequenciesTemp); free(constrainedDOFs); delete(massMatrix); delete(stiffnessMatrix); *r = numDesiredModes; return NULL; }