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(); }
Matrix<real>::Matrix(const char * filename) { if (ReadMatrixFromDisk(filename, &m, &n, &data) != 0) { printf("Error loading matrix from %s.\n", filename); throw 1; } freeDataInDestructor = true; }
void MyFrame::OnLoadSketchData(wxCommandEvent& event) { wxFileDialog *dlg = new wxFileDialog(this, _T("Load external simulation data"), uiState.currentWorkingDirectory, _T(""), _T("External Data Files(*.UData)|*.UData|All files(*.*)|*.*"), wxFD_OPEN /*| wxHIDE_READONLY*/, wxDefaultPosition); if ( dlg->ShowModal() == wxID_OK ) { wxString sketchDataFilename( dlg->GetPath()); SaveCurrentWorkingDirectory(sketchDataFilename); if( !sketchDataFilename.empty() ) { int newSketchDatasamples; double * newSketchData = NULL; int n1; SetCursor(*wxHOURGLASS_CURSOR); const char * filename = sketchDataFilename.mb_str(); printf("Loading external simulation data from %s.\n", filename); int code = ReadMatrixFromDisk((char*)filename, &n1, &newSketchDatasamples, &newSketchData); SetCursor(*wxSTANDARD_CURSOR); if (code != 0) { this->errMsg( _T("Loading error"), _T("Unable to load external simulation data from ") + sketchDataFilename ); dlg->Destroy(); return; } if (n1 != 3 * precomputationState.simulationMesh->getNumVertices()) { this->errMsg( _T("Loading error"), _T("The number of vertices in ") + sketchDataFilename + _T(" does not match the simulation mesh.")); free(newSketchData); dlg->Destroy(); return; } // success delete(precomputationState.sketchDataMatrix); precomputationState.sketchDataMatrix = new ModalMatrix(precomputationState.simulationMesh->getNumVertices(), newSketchDatasamples, newSketchData); free(newSketchData); precomputationState.sketchDataAvailable = true; UpdateMenus(); Refresh(); } } dlg->Destroy(); }
void StVKReducedInternalForces::TestPolynomial(double * q, StVKInternalForces * stVKInternalForces, const char * filenameU) { double * fqPoly = (double*) malloc (sizeof(double) * r); double * fqDirect = (double*) malloc (sizeof(double) * r); Evaluate(q, fqPoly); double * U1; int n1,r1; if (ReadMatrixFromDisk(filenameU, &n1, &r1, &U1) != 0) { printf("Error loading file %s\n",filenameU); exit(1); } n1 /= 3; printf("\nNumber of vertices is: %d\n",n1); printf("Number of nonlinear modes is: %d\n",r1); double * u = (double*) malloc (sizeof(double) * 3 * n1); double * forces = (double*) malloc (sizeof(double) * 3 * n1); // u = U*q SynthesizeVector(3*n1, r1, U1, q, u); stVKInternalForces->ComputeForces(u,forces); /* printf("g***\n"); for(int j=0; j<3*n1; j++) printf("%G\n",forces[j]); printf("g***\n"); */ ProjectVector(3*n1,r1,U1,fqDirect,forces); int i; printf("ViaCubPoly ViaProjection:\n"); for(i=0; i<r1; i++) { printf("%G %G\n",fqPoly[i],fqDirect[i]); } free(u); free(forces); free(U1); free(fqDirect); free(fqPoly); }
void MyFrame::OnLoadFrequencies(wxCommandEvent& event) { wxFileDialog *dlg = new wxFileDialog(this, _T("Load frequencies"), uiState.currentWorkingDirectory, _T(""), _T("Frequency Files(*.freq)|*.freq|All files(*.*)|*.*"), wxFD_OPEN /*| wxHIDE_READONLY*/, wxDefaultPosition); if ( dlg->ShowModal() == wxID_OK ) { wxString frequencyFilename( dlg->GetPath() ); SaveCurrentWorkingDirectory(frequencyFilename); if( !frequencyFilename.empty() ) { int newr; double * newFrequencies = NULL; int m1; SetCursor(*wxHOURGLASS_CURSOR); const char * filename = frequencyFilename.mb_str(); int code = ReadMatrixFromDisk((char*)filename, &newr, &m1, &newFrequencies); SetCursor(*wxSTANDARD_CURSOR); if (code != 0) { this->errMsg( _T("Loading error"), _T("Unable to load frequencies from ") + frequencyFilename ); dlg->Destroy(); return; } if (precomputationState.linearModesAvailable && (newr != precomputationState.rLin)) { char s[4096]; const char * filename = frequencyFilename.mb_str(); sprintf(s, "The number of frequencies (%d) " "in %s does not match the currently available number of linear modes (%d).", newr, (char*)filename, precomputationState.rLin); this->errMsg( _T("Loading error"), wxString(s, wxConvUTF8)); free(newFrequencies); dlg->Destroy(); return; } // success free(precomputationState.frequencies); precomputationState.rLin = newr; precomputationState.frequencies = newFrequencies; precomputationState.frequenciesAvailable = true; UpdateMenus(); UpdateModalToolbar(); Refresh(); } } dlg->Destroy(); }
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(); }