Skip to content
Snippets Groups Projects
parallelFea.js 41.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • Amira Abdel-Rahman's avatar
    Amira Abdel-Rahman committed
        var _2xSqMxExS = (2.0*Math.sqrt(node.mass*E*node.nomSize));
        var zetaCollision=0.01;
        return zetaCollision*_2xSqMxExS;
    } //!< Returns the global material damping coefficient (translation)
    function collisionDampingRotateC(node)  {
    	var zetaCollision=1.0;
        var _momentInertia = (node.mass*node.nomSize*node.nomSize / 6.0); //simple 1D approx
        var _2xSqIxExSxSxS = (2.0*Math.sqrt(_momentInertia*E*node.nomSize*node.nomSize*node.nomSize));
        return zetaCollision*_2xSqIxExSxSxS;
    } //!< Returns the global material damping coefficient (rotation)
    
    
    function moment(node) {
    	//moments from internal bonds
    	var totalMoment=new THREE.Vector3(0,0,0);
    	// for (int i=0; i<6; i++){ 
    	// 	if (links[i]) totalMoment += links[i]->moment(isNegative((linkDirection)i)); //total force in LCS
    	// }
    	totalMoment.add(node.intMoment);
    	totalMoment = RotateVec3D(node.orient,totalMoment);
    	
    	totalMoment.add(new THREE.Vector3(node.moment.x,node.moment.y,node.moment.z));
    
    	//other moments
    	// if (externalExists()) totalMoment += external()->moment(); //external moments
    	// totalMoment -= angularVelocity()*mat->globalDampingRotateC(); //global damping
    	node.intMoment=new THREE.Vector3(0,0,0);
    	return totalMoment;
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////
    
    //void haltMotion(){linMom = angMom = Vec3D<>(0,0,0);} //!< Halts all momentum of this block. Unless fixed the voxel will continue to move in subsequent timesteps.
    
    function recommendedTimeStep()  {
    	// //find the largest natural frequency (Math.sqrt(k/m)) that anything in the simulation will experience, then multiply by 2*pi and invert to get the optimally largest timestep that should retain stability
    	// float MaxFreq2 = 0.0f; //maximum frequency in the simulation in rad/sec
    
    	// for (std::vector<CVX_Link*>::const_iterator it=linksList.begin(); it != linksList.end(); it++){ //for each link
    	// 	CVX_Link* pL = (*it);
    	// 	//axial
    	// 	float m1 = pL->pVNeg->mat->mass(),  m2 = pL->pVPos->mat->mass();
    	// 	float thisMaxFreq2 = pL->axialStiffness()/(m1<m2?m1:m2);
    	// 	if (thisMaxFreq2 > MaxFreq2) MaxFreq2 = thisMaxFreq2;
    
    	// 	//rotational will always be less than or equal
    	// }
    
    
    	// if (MaxFreq2 <= 0.0f){ //didn't find anything (i.e no links) check for individual voxelss
    	// 	for (std::vector<CVX_Voxel*>::const_iterator it=voxelsList.begin(); it != voxelsList.end(); it++){ //for each link
    	// 		float thisMaxFreq2 = (*it)->mat->youngsModulus()*(*it)->mat->nomSize/(*it)->mat->mass(); 
    	// 		if (thisMaxFreq2 > MaxFreq2) MaxFreq2 = thisMaxFreq2;
    	// 	}
    	// }
    	
    	// if (MaxFreq2 <= 0.0f) return 0.0f;
    	// else return 1.0f/(6.283185f*sqrt(MaxFreq2)); //the optimal timestep is to advance one radian of the highest natural frequency
    }
    
    function isXyzIndependent()  {return nu==0.0;} //!< Returns true if poisson's ratio is zero - i.e. deformations in each dimension are independent of those in other dimensions.
    
    
    function isFailed(edge) {
    	// return mat->isFailed(maxStrain);
    }
    
    // function isLocalVelocityValid()  {return boolStates & LOCAL_VELOCITY_VALID ? true : false;} //
    
    // function dampingMultiplier() {return 2*mat->_sqrtMass*mat->zetaInternal/previousDt;} //!< Returns the damping multiplier for this voxel. This would normally be called only internally for the internal damping calculations.
    
    // function setBoolState(linkFlags flag, bool set=true) {set ? boolStates |= (int)flag : boolStates &= ~(int)flag;}
    
    // function setFixedAll(bool fixed=true) {fixed?setDisplacementAll():clearDisplacementAll();} //!< Sets all 6 degrees of freedom to either fixed or free depending on the value of fixed. Either way, sets all displacements to zero. @param[in] fixed Whether all degrees of freedom should be fixed (true) or free (false).
    
    // function setDisplacement(dofComponent dof, double displacement=0.0); //!< Fixes the specified degree of freedom and applies the prescribed displacement if specified. @param[in] dof the degree of freedom in question. @param[in] displacement The displacement in meters (translational dofs) or radians (rotational dofs) to apply. Large fixed displacements may cause instability.
    // function setDisplacementAll(const Vec3D<double>& translation = Vec3D<double>(0,0,0), const Vec3D<double>& rotation = Vec3D<double>(0,0,0)); //!< Fixes the all degrees of freedom and applies the specified translation and rotation. @param[in] translation The translation in meters from this voxel's nominal position to fix it at. @param[in] rotation The rotation (in the form of a rotation vector) from this voxel's nominal orientation to fix it at.
    
    function transverseStrainSum(axis){
    	// if (mat->poissonsRatio() == 0) return 0;
    	
    	// Vec3D<float> psVec = poissonsStrain();
    
    	// switch (axis){
    	// case CVX_Link::X_AXIS: return psVec.y+psVec.z;
    	// case CVX_Link::Y_AXIS: return psVec.x+psVec.z;
    	// case CVX_Link::Z_AXIS: return psVec.x+psVec.y;
    	// default: return 0.0f;
    	// }
    
    }
    
    function transverseStrainSum(axis){
    	// if (mat->poissonsRatio() == 0) return 0;
    	
    	// Vec3D<float> psVec = poissonsStrain();
    
    	// switch (axis){
    	// case CVX_Link::X_AXIS: return psVec.y+psVec.z;
    	// case CVX_Link::Y_AXIS: return psVec.x+psVec.z;
    	// case CVX_Link::Z_AXIS: return psVec.x+psVec.y;
    	// default: return 0.0f;
    	// }
    
    }
    
    function poissonsStrain(node){
    	// if (poissonsStrainInvalid){
    	// 	pStrain = strain(true);
    	// 	poissonsStrainInvalid = false;
    	// }
    	// return pStrain;
    }
    
    function strain( poissonsStrain) {
    	//if no connections in the positive and negative directions of a particular axis, strain is zero
    	//if one connection in positive or negative direction of a particular axis, strain is that strain - ?? and force or constraint?
    	//if connections in both the positive and negative directions of a particular axis, strain is the average. 
    	
    	// Vec3D<float> intStrRet(0,0,0); //intermediate strain return value. axes according to linkAxis enum
    	// int numBondAxis[3] = {0}; //number of bonds in this axis (0,1,2). axes according to linkAxis enum
    	// bool tension[3] = {false};
    	// for (int i=0; i<6; i++){ //cycle through link directions
    	// 	if (links[i]){
    	// 		int axis = toAxis((linkDirection)i);
    	// 		intStrRet[axis] += links[i]->axialStrain(isNegative((linkDirection)i));
    	// 		numBondAxis[axis]++;
    	// 	}
    	// }
    	// for (int i=0; i<3; i++){ //cycle through axes
    	// 	if (numBondAxis[i]==2) intStrRet[i] *= 0.5f; //average
    	// 	if (poissonsStrain){
    	// 		tension[i] = ((numBondAxis[i]==2) || (ext && (numBondAxis[i]==1 && (ext->isFixed((dofComponent)(1<<i)) || ext->force()[i] != 0)))); //if both sides pulling, or just one side and a fixed or forced voxel...
    	// 	}
    
    	// }
    
    	// if (poissonsStrain){
    	// 	if (!(tension[0] && tension[1] && tension[2])){ //if at least one isn't in tension
    	// 		float add = 0;
    	// 		for (int i=0; i<3; i++) if (tension[i]) add+=intStrRet[i];
    	// 		float value = pow( 1.0f + add, -mat->poissonsRatio()) - 1.0f;
    	// 		for (int i=0; i<3; i++) if (!tension[i]) intStrRet[i]=value;
    	// 	}
    	// }
    
    	// return intStrRet;
    }