void MyFrame::OnLoadNonLinearModes(wxCommandEvent& event) { wxFileDialog *dlg = new wxFileDialog(this, _T("Load nonlinear modes"), uiState.currentWorkingDirectory, _T(""), _T("Modal Matrix Files(*.U)|*.U|All files(*.*)|*.*"), wxFD_OPEN /*| wxHIDE_READONLY*/, wxDefaultPosition); if ( dlg->ShowModal() == wxID_OK ) { wxString nonLinearModesFilename( dlg->GetPath()); SaveCurrentWorkingDirectory(nonLinearModesFilename); if( !nonLinearModesFilename.empty() ) { int newrNonLin; double * newNonLinearModes = NULL; int n1; SetCursor(*wxHOURGLASS_CURSOR); const char * filename = nonLinearModesFilename.mb_str(); int code = ReadMatrixFromDisk((char*)filename, &n1, &newrNonLin, &newNonLinearModes); SetCursor(*wxSTANDARD_CURSOR); if (code != 0) { this->errMsg( _T("Loading error"), _T("Unable to load nonlinear modes from ") + nonLinearModesFilename ); dlg->Destroy(); return; } if (n1 != 3 * precomputationState.simulationMesh->getNumVertices()) { this->errMsg( _T("Loading error"), _T("The number of vertices in ") + nonLinearModesFilename + _T(" does not match the simulation mesh.")); free(newNonLinearModes); dlg->Destroy(); return; } // success delete(precomputationState.nonLinearModalMatrix); precomputationState.rNonLin = newrNonLin; precomputationState.nonLinearModalMatrix = new ModalMatrix(precomputationState.simulationMesh->getNumVertices(), precomputationState.rNonLin, newNonLinearModes); free(newNonLinearModes); precomputationState.nonLinearModesAvailable = true; modeSelectionControl->SetValue(1); SelectView(UIState::VIEW_NONLINEAR_MODES); SetAutoRenderingMagnitude(precomputationState.nonLinearModalMatrix); UpdateMenus(); myGLCanvas->UpdateNonLinearModesRenderData(); Refresh(); } } dlg->Destroy(); }
void MyFrame::OnComputeLinearModes(wxCommandEvent& event) { char numLinearModesStringC[256]; int numSuggestedModes = uiState.numComputedLinearModes; if (uiState.firstModalComputation) { // increase the number of suggested modes based on the number of constrained vertices if (precomputationState.fixedVertices.size() == 2) { numSuggestedModes += 1; } else if (precomputationState.fixedVertices.size() == 1) { numSuggestedModes += 3; } else if (precomputationState.fixedVertices.size() == 0) { numSuggestedModes += 6; } } sprintf(numLinearModesStringC, "%d", numSuggestedModes); wxDialog * dlg = new wxDialog(this, -1, _T("Select number of modes"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("dialogBox") ); wxBoxSizer * dlgSizer = new wxBoxSizer(wxVERTICAL); wxStaticText * numModesText = new wxStaticText(dlg, -1, _T("Number of modes: "), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER, _T( "staticText")); wxTextCtrl * numModesControl = new wxTextCtrl(dlg, -1, wxString(numLinearModesStringC, wxConvUTF8), wxDefaultPosition, wxSize(100,-1)); wxBoxSizer * numModesSizer = new wxBoxSizer(wxHORIZONTAL); numModesSizer->Add(numModesText, 0, wxCENTER); numModesSizer->Add(numModesControl, 0, wxCENTER); dlgSizer->Add(numModesSizer, 0, wxALL | wxCENTER, 8); dlgSizer->Add(dlg->CreateButtonSizer(wxOK | wxCANCEL), 0, wxLEFT | wxRIGHT | wxBOTTOM | wxCENTER, 8); dlg->SetSizer(dlgSizer); dlgSizer->SetSizeHints(dlg); if (dlg->ShowModal() != wxID_OK) { delete(dlg); return; } wxString valueString = numModesControl->GetValue(); delete(dlg); long value; bool goodInput = valueString.ToLong(&value); if (goodInput) { if ((value <= 0) || (value > 16384)) goodInput = false; } if (goodInput) { int oldNumModes = uiState.numComputedLinearModes; uiState.numComputedLinearModes = value; double * newFrequencies = NULL; double * newLinearModes = NULL; int newr; SetCursor(*wxHOURGLASS_CURSOR); LinearModesWorker( uiState.numComputedLinearModes, &newr, &newFrequencies, &newLinearModes ); SetCursor(*wxSTANDARD_CURSOR); if (newr != uiState.numComputedLinearModes) { uiState.numComputedLinearModes = oldNumModes; this->errMsg( _T("Linear mode computation failed"), _T("Linear mode computation failed.") ); free(newFrequencies); free(newLinearModes); return; } else { precomputationState.linearModesAvailable = true; uiState.firstModalComputation = false; UpdateMenus(); delete(precomputationState.linearModalMatrix); precomputationState.rLin = uiState.numComputedLinearModes; precomputationState.linearModalMatrix = new ModalMatrix( precomputationState.simulationMesh->getNumVertices(), precomputationState.rLin, newLinearModes); free(newLinearModes); free(precomputationState.frequencies); precomputationState.frequencies = newFrequencies; precomputationState.frequenciesAvailable = true; precomputationState.linearModesAvailable = true; uiState.eraseRangeHi = precomputationState.rLin; // set the rigid modes based on the number of constrained vertices if (precomputationState.fixedVertices.size() >= 3) { precomputationState.numRigidModes = 0; } else if (precomputationState.fixedVertices.size() == 2) { precomputationState.numRigidModes = 1; } else if (precomputationState.fixedVertices.size() == 1) { precomputationState.numRigidModes = 3; } else { precomputationState.numRigidModes = 6; } uiState.numComputedNonLinearModes = 2 * (precomputationState.rLin - precomputationState.numRigidModes); modeSelectionControl->SetValue(1); SelectView(UIState::VIEW_LINEAR_MODES); SetAutoRenderingMagnitude(precomputationState.linearModalMatrix); UpdateMenus(); myGLCanvas->UpdateLinearModesRenderData(); Refresh(); } } else { this->errMsg( _T("Invalid number of linear modes"), _T("Invalid number of linear modes: ") + valueString ); } }
void MyFrame::OnComputeNonLinearModes(wxCommandEvent& event) { if (! ( (precomputationState.linearModesAvailable && precomputationState.frequenciesAvailable && precomputationState.modalDerivativesAvailable) || (precomputationState.sketchDataAvailable) ) ) { this->errMsg( _T("Cannot compute the simulation basis"), _T("You must compute/provide at least one of the following:\n" " (1) linear modes, frequencies, and modal derivatives, OR\n" " (2) external simulation data.\n" ) ); return; } char numNonLinearModesStringC[256]; sprintf(numNonLinearModesStringC, "%d", uiState.numComputedNonLinearModes); wxDialog * dlg = new wxDialog(this, -1, _T("Compute nonlinear modes (via SVD)"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("dialogBox") ); wxBoxSizer * dlgSizer = new wxBoxSizer(wxVERTICAL); // create dialog box to choose source of data wxString radioBoxChoices[2] = { _T("Linear modes and modal derivatives"), _T("External simulation data") }; wxRadioBox * dataOriginRadioBox = new wxRadioBox(dlg, -1, _T("Source of data for nonlinear modes:"), wxDefaultPosition, wxDefaultSize, 2, radioBoxChoices, 2, wxRA_SPECIFY_ROWS); dataOriginRadioBox->Enable(0, precomputationState.modalDerivativesAvailable); dataOriginRadioBox->Enable(1, precomputationState.sketchDataAvailable); if (precomputationState.modalDerivativesAvailable) dataOriginRadioBox->SetSelection(0); else dataOriginRadioBox->SetSelection(1); dlgSizer->Add(dataOriginRadioBox, wxLEFT | wxRIGHT | wxBOTTOM | wxCENTER, 8); wxStaticText * numModesText = new wxStaticText(dlg, -1, _T("Number of nonlinear modes: "), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER, _T( "staticText")); wxTextCtrl * numModesControl = new wxTextCtrl(dlg, -1, wxString(numNonLinearModesStringC, wxConvUTF8), wxDefaultPosition, wxSize(100,-1)); wxBoxSizer * numModesSizer = new wxBoxSizer(wxHORIZONTAL); numModesSizer->Add(numModesText, 0, wxCENTER); numModesSizer->Add(numModesControl, 0, wxCENTER); dlgSizer->Add(numModesSizer, 0, wxALL | wxCENTER, 8); dlgSizer->Add(dlg->CreateButtonSizer(wxOK | wxCANCEL), 0, wxLEFT | wxRIGHT | wxBOTTOM | wxCENTER, 8); dlg->SetSizer(dlgSizer); dlgSizer->SetSizeHints(dlg); if (dlg->ShowModal() != wxID_OK) { delete(dlg); return; } wxString valueString = numModesControl->GetValue(); int dataOrigin = dataOriginRadioBox->GetSelection(); delete(dlg); long value; bool goodInput = valueString.ToLong(&value); if (goodInput) { if ((value <= 0) || (value > 16384)) goodInput = false; } if (goodInput) { uiState.numComputedNonLinearModes = value; double * newNonLinearModes = NULL; SetCursor(*wxHOURGLASS_CURSOR); int code; NonLinearModesWorker(&code, dataOrigin, uiState.numComputedNonLinearModes, &newNonLinearModes ); SetCursor(*wxSTANDARD_CURSOR); if (code != 0) { char s[96]; if (code < 0) sprintf(s, "Nonlinear mode computation failed. Memory allocation error."); else sprintf(s, "Nonlinear mode computation failed. dgesvd exit code: %d\n", code); this->errMsg( _T("Nonlinear mode computation failed"), wxString(s, wxConvUTF8)); free(newNonLinearModes); return; } else { precomputationState.nonLinearModesAvailable = true; UpdateMenus(); delete(precomputationState.nonLinearModalMatrix); precomputationState.rNonLin = uiState.numComputedNonLinearModes; precomputationState.nonLinearModalMatrix = new ModalMatrix( precomputationState.simulationMesh->getNumVertices(), precomputationState.rNonLin, newNonLinearModes); free(newNonLinearModes); modeSelectionControl->SetValue(1); SelectView(UIState::VIEW_NONLINEAR_MODES); SetAutoRenderingMagnitude(precomputationState.nonLinearModalMatrix); UpdateMenus(); myGLCanvas->UpdateNonLinearModesRenderData(); Refresh(); } } else { this->errMsg( _T("Invalid number of nonlinear modes"), _T("Invalid number of nonlinear modes: ") + valueString ); } }
void MyFrame::OnLoadLinearModes(wxCommandEvent& event) { wxFileDialog *dlg = new wxFileDialog(this, _T("Load linear modes"), uiState.currentWorkingDirectory, _T(""), _T("Modal Matrix Files(*.Ulin)|*.Ulin|Modal Matrix Files(*.U)|*.U|All files(*.*)|*.*"), wxFD_OPEN /*| wxHIDE_READONLY*/, wxDefaultPosition); if ( dlg->ShowModal() == wxID_OK ) { wxString linearModesFilename( dlg->GetPath()); SaveCurrentWorkingDirectory(linearModesFilename); if( !linearModesFilename.empty() ) { int newr; double * newLinearModes = NULL; int n1; SetCursor(*wxHOURGLASS_CURSOR); const char * filename = linearModesFilename.mb_str(); int code = ReadMatrixFromDisk((char*)filename, &n1, &newr, &newLinearModes); SetCursor(*wxSTANDARD_CURSOR); if (code != 0) { this->errMsg( _T("Loading error"), _T("Unable to load linear modes from ") + linearModesFilename ); dlg->Destroy(); return; } if (n1 != 3 * precomputationState.simulationMesh->getNumVertices()) { this->errMsg( _T("Loading error"), _T("The number of vertices in ") + linearModesFilename + _T(" does not match the simulation mesh.")); free(newLinearModes); dlg->Destroy(); return; } if (precomputationState.frequenciesAvailable) { // check that the number of modes is consistent with the existing number of frequencies if (newr != precomputationState.rLin) { wxMessageDialog * confirmationDialog = new wxMessageDialog (this, _T("Warning: number of existing frequencies does not match the number of modes. Delete existing frequencies?"), _T("Mismatch in the number of frequencies"), wxYES_NO | wxICON_EXCLAMATION); if (confirmationDialog->ShowModal() != wxID_YES) { free(newLinearModes); delete(confirmationDialog); dlg->Destroy(); return; } else { delete(confirmationDialog); free(precomputationState.frequencies); precomputationState.frequenciesAvailable = false; } } } // success delete(precomputationState.linearModalMatrix); precomputationState.rLin = newr; precomputationState.linearModalMatrix = new ModalMatrix( precomputationState.simulationMesh->getNumVertices(), precomputationState.rLin, newLinearModes); free(newLinearModes); precomputationState.linearModesAvailable = true; uiState.numComputedNonLinearModes = 2 * (precomputationState.rLin - precomputationState.numRigidModes); uiState.eraseRangeHi = precomputationState.rLin; modeSelectionControl->SetValue(1); SelectView(UIState::VIEW_LINEAR_MODES); SetAutoRenderingMagnitude(precomputationState.linearModalMatrix); UpdateMenus(); myGLCanvas->UpdateLinearModesRenderData(); Refresh(); } } dlg->Destroy(); }