void QVX_TensileTest::BeginTensileTest(QVX_Environment* pEnvIn, int NumStepIn, double ConvThreshIn, double MixRadiusIn, MatBlendModel ModelIn, double PolyExpIn) { //set up local copy of the environment and object... // if (MixRadius != 0) RenderMixedObject(pEnvIn->pObj, &LocObj, MixRadius); //if there's any mixing, we need to make it... //else LocObj = *(pEnvIn->pObj); //otherwise just simulate the original object. LocEnv = *pEnvIn; //set local environment params to those of the input LocEnv.pObj = &LocObj; //make sure local environment points to local object //set up blending if desired BlendingEnabled = false; if (MixRadiusIn != 0){ //if some blending... //check for 2 or fewer materials! if (LocObj.GetNumLeafMatInUse() > 2){ QMessageBox::warning(NULL, "Warning", "Currently blending only supported with 2 or fewer materials. Aborting."); return; } BlendingEnabled = true; MixRadius = MixRadiusIn; BlendModel = ModelIn; PolyExp = PolyExpIn; } NumStep = NumStepIn; ConvThresh = ConvThreshIn; CurTick = 0; TotalTick = NumStep; CancelFlag = false; std::string Message = ""; pEnvIn->EnableFloor(false); pEnvIn->EnableGravity(false); pEnvIn->EnableTemp(false); Import(&LocEnv, NULL, &Message); EnableSelfCollision(false); EnableEquilibriumMode(true); SetStopConditionType(SC_MIN_MAXMOVE); SetStopConditionValue(ConvThreshIn); // SetBondDampZ(1.0); // SetSlowDampZ(0.03); EnablePlasticity(false); EnableFailure(false); if (!DoBCChecks()) return; CurViewMode = RVM_VOXELS; CurViewCol = RVC_STRAIN_EN; CurViewVox = RVV_DEFORMED; //QString DispMesg; OutFilePath = QFileDialog::getSaveFileName(NULL, "Save Tensile Test Results", "", "TXT Files (*.txt)"); emit StartExternalGLUpdate(33); TestRunning = true; if (OutFilePath != "") TensileThread.Execute(false); // RunTensileTest(&DispMesg); if (ProgressMessage != "") QMessageBox::warning(NULL, "warning", QString::fromStdString(ProgressMessage)); }
/*! The environment should have been previously initialized and linked with a single voxel object. This function sets or resets the entire simulation with the new environment. @param[in] pEnvIn A pointer to initialized CVX_Environment to import into the simulator. @param[out] RetMessage A pointer to initialized string. Output information from the Import function is appended to this string. */ bool CVX_Sim::Import(CVX_Environment* pEnvIn, CMesh* pSurfMeshIn, std::string* RetMessage) { ClearAll(); //clears out all arrays and stuff if (pEnvIn != NULL) pEnv = pEnvIn; if (pEnv == NULL) {if (RetMessage) *RetMessage += "Invalid Environment pointer"; return false;} LocalVXC = *pEnv->pObj; //make a copy of the reference digital object! if (LocalVXC.GetNumVox() == 0) {if (RetMessage) *RetMessage += "No voxels in object"; return false;} int SIndexIt = 0; //keep track of how many voxel we've added (for storing reverse lookup array...) int NumBCs = pEnv->GetNumBCs(); CVX_FRegion* pCurBc; //initialize XtoSIndexMap & StoXIndexMap XtoSIndexMap.resize(LocalVXC.GetStArraySize(), -1); // = new int[LocalVXC.GetStArraySize()]; StoXIndexMap.resize(LocalVXC.GetNumVox(), -1); // = new int [m_NumVox]; std::vector<int> Sizes(NumBCs, 0); for (int i=0; i<NumBCs; i++) Sizes[i] = pEnv->GetNumTouching(i); // pEnv->GetNumVoxTouchingForced(&Sizes); //get the number of voxels in each region (to apply equal force to each voxel within this region!) // Vec3D BCpoint; Vec3D<> BCsize = pEnv->pObj->GetLatDimEnv()/2.0; Vec3D<> WSSize = pEnv->pObj->GetWorkSpace(); //Add all Voxels: bool HasPlasticMaterial = false; Vec3D<> ThisPos; Vec3D<> ThisScale = LocalVXC.GetLatDimEnv(); //Build voxel list for (int i=0; i<LocalVXC.GetStArraySize(); i++){ //for each voxel in the array XtoSIndexMap[i] = -1; //assume there is not a voxel here... if(LocalVXC.Structure[i] != 0 ){ //if there's material here int ThisMatIndex = LocalVXC.GetLeafMatIndex(i); int ThisMatModel = LocalVXC.Palette[ThisMatIndex].GetMatModel(); if (ThisMatModel == MDL_BILINEAR || ThisMatModel == MDL_DATA) HasPlasticMaterial = true; //enable plasticity in the sim LocalVXC.GetXYZ(&ThisPos, i, false);//Get XYZ location CVXS_Voxel CurVox(this, SIndexIt, i, ThisMatIndex, ThisPos, ThisScale); XtoSIndexMap[i] = SIndexIt; //so we can find this voxel based on it's original index StoXIndexMap[SIndexIt] = i; //so we can find the original index based on its simulator position for (int j = 0; j<NumBCs; j++){ //go through each primitive defined as a constraint! pCurBc = pEnv->GetBC(j); if (pCurBc->GetRegion()->IsTouching(&ThisPos, &BCsize, &WSSize)){ //if this point is within CurVox.FixDof(pCurBc->DofFixed); CurVox.AddExternalForce(pCurBc->Force/Sizes[j]); CurVox.AddExternalTorque(pCurBc->Torque/Sizes[j]); CurVox.SetExternalDisp(pCurBc->Displace); CurVox.SetExternalTDisp(pCurBc->AngDisplace); } } if(BlendingEnabled) CurVox.CalcMyBlendMix(); //needs to be done basically last. VoxArray.push_back(CurVox); SIndexIt++; } } //add input voxel so that NumVox() works! InputVoxSInd = (int)VoxArray.size(); CVXS_Voxel TmpVox(this, 0, 0, 0, Vec3D<>(0,0,0), Vec3D<>(0,0,0)); // TmpVox.LinkToVXSim(this); VoxArray.push_back(TmpVox); //SET UP ALL PERMANENT BONDS (in between materials and the input bond) Vec3D<> RelDist; //exhaustive (slower, but still OK) for (int i=0; i<NumVox(); i++){ //for each voxel in our newly-made array for (int j = i+1; j<NumVox(); j++){ if (!LocalVXC.IsAdjacent(StoXIndexMap[i], StoXIndexMap[j], false, &RelDist)) continue; if (!CreateBond(B_LINEAR, i, j, true) && RetMessage) *RetMessage += "At least one bond creation failed during import"; } } //Create input bond CreateBond(B_INPUT_LINEAR_NOROT, InputVoxSInd, InputVoxSInd, true, &InputBondInd, false); //create input bond, but initialize it to meaningless connection to self UpdateAllBondPointers(); //necessary since we probably reallocated the bond array when adding pbonds the first time //Set up our surface list... for (int i=0; i<NumVox(); i++){ //for each voxel in our newly-made array if (VoxArray[i].GetNumLocalBonds() != 6){ SurfVoxels.push_back(i); } //todo: only do for those on surfaces, I think. VoxArray[i].CalcNearby((int)(CollisionHorizon*1.5)); //populate the nearby array } #ifdef USE_OPEN_GL VoxMesh.ImportLinkSim(this); VoxMesh.DefMesh.DrawSmooth = false; //if the input mesh is not valid, use marching cubes to create one if (!pSurfMeshIn){ CMesh GeneratedSmoothMesh; CArray3Df OccupancyArray(pEnv->pObj->GetVXDim(), pEnv->pObj->GetVYDim(), pEnv->pObj->GetVZDim()); int NumPossibleVox = pEnv->pObj->GetStArraySize(); for (int g=0; g<NumPossibleVox; g++){ if (pEnv->pObj->Structure.GetData(g)>0) OccupancyArray[g] = 1.0; } CMarchCube::SingleMaterial(&GeneratedSmoothMesh, &OccupancyArray, 0.5, pEnv->pObj->GetLatticeDim()); SurfMesh.ImportSimWithMesh(this, &GeneratedSmoothMesh); } else SurfMesh.ImportSimWithMesh(this, pSurfMeshIn); #endif ResetSimulation(); OptimalDt = CalcMaxDt(); //to set up dialogs parameter ranges, we need this before the first iteration. EnablePlasticity(HasPlasticMaterial); //turn off plasticity if we don't need it... Initalized = true; // std::string tmpString; std::ostringstream os; os << "Completed Simulation Import: " << NumVox() << " Voxels, " << NumBond() << "Bonds.\n"; *RetMessage += os.str(); return true; }