StVKReducedInternalForces::StVKReducedInternalForces(int r, double * U, VolumetricMesh * volumetricMesh, StVKElementABCD * precomputedABCDIntegrals, int initOnly, bool addGravity_, double g_, int verbose_): precomputedIntegrals(precomputedABCDIntegrals), unitReducedGravityForce(NULL), reducedGravityForce(NULL), addGravity(addGravity_), g(g_), useSingleThread(0), shallowCopy(0), verbose(verbose_) { int numElements = volumetricMesh->getNumElements(); lambdaLame = (double*) malloc (sizeof(double) * numElements); muLame = (double*) malloc (sizeof(double) * numElements); for(int el=0; el<numElements; el++) { VolumetricMesh::Material * material = volumetricMesh->getElementMaterial(el); VolumetricMesh::ENuMaterial * eNuMaterial = downcastENuMaterial(material); if (eNuMaterial == NULL) { printf("Error: StVKReducedInternalForces: mesh does not consist of E, nu materials.\n"); throw 1; } lambdaLame[el] = eNuMaterial->getLambda(); muLame[el] = eNuMaterial->getMu(); } InitComputation(r, U, volumetricMesh); if (!initOnly) ProcessElements(0, volumetricMesh->getNumElements()); InitGravity(); }
StVKInternalForces::StVKInternalForces(VolumetricMesh * volumetricMesh_, StVKElementABCD * precomputedABCDIntegrals_, bool addGravity_, double g_): volumetricMesh(volumetricMesh_), precomputedIntegrals(precomputedABCDIntegrals_), gravityForce(NULL), addGravity(addGravity_), g(g_) { int numElements = volumetricMesh->getNumElements(); lambdaLame = (double*) malloc (sizeof(double) * numElements); muLame = (double*) malloc (sizeof(double) * numElements); for(int el=0; el<numElements; el++) { VolumetricMesh::Material * material = volumetricMesh->getElementMaterial(el); VolumetricMesh::ENuMaterial * eNuMaterial = downcastENuMaterial(material); if (eNuMaterial == NULL) { printf("Error: mesh does not consist of E, nu materials.\n"); throw 1; } lambdaLame[el] = eNuMaterial->getLambda(); muLame[el] = eNuMaterial->getMu(); } buffer = (double*) malloc (sizeof(double) * 3 * volumetricMesh->getNumVertices()); numElementVertices = volumetricMesh->getNumElementVertices(); InitGravity(); }
ReducedStVKCubatureForceModel::ReducedStVKCubatureForceModel(const int &r,VolumetricMesh *volumetricMesh,double *U, const int &cubica_num, const double *cubica_weights,const unsigned int *cubica_elements, double **restpos,bool addGravity, double g) { r_=r; add_gravity_=addGravity; g_=g; cubica_num_=cubica_num; cubica_weights_ = new double[cubica_num_]; cubica_elements_ = new double[cubica_num_]; // std::cout<<"b\n"; for(int i=0;i<cubica_num_;++i) { cubica_weights_[i]=cubica_weights[i]; cubica_elements_[i]=cubica_elements[i]; } // std::cout<<"c\n"; volumetric_mesh_ = volumetricMesh; U_ = new double*[3*volumetricMesh->getNumVertices()]; for(int i=0;i<3*volumetricMesh->getNumVertices();++i) { U_[i] = new double[r_]; for(int j=0;j<r_;++j) U_[i][j]=0.0; } // std::cout<<"d\n"; int num=volumetricMesh->getNumVertices(); //change *U to **U_,U_[vert_idx][basis_idx] // Matrix<double> Umatrix((int)(3*num),(int)r_); // Matrix<double> M((int)(3*num),(int)(3*num)); for(int j=0;j<r_;++j) for(int i=0;i<3*num;++i) { U_[i][j]=U[3*num*j+i]; // Umatrix(i,j)=U_[i][j]; } // for(int i=0;i<3*num;++i) // for(int j=0;j<3*num;++j) // { // if(i==j) // M(i,j)=1.0/8144; // else // M(i,j)=0.0; // } // // Matrix<double> temp=Umatrix.MultiplyT(M); // Matrix<double> temp1=temp*Umatrix; // for(int i=0;i<r_;++i) // { // for(int j=0;j<r_;++j) // { // std::cout<<temp1(i,j)<<","; // } // std::cout<<"\n"; // } // getchar(); //test U is normalized or not // double test=0.0; // for(int i=0;i<3*num;++i) // { // test+=U_[1][i]*U_[2][i]*(1.0/8144); // } // std::cout<<test<<"\n"; restpos_ = new double*[cubica_num_]; for(int i=0;i<cubica_num_;++i) { restpos_[i]=new double[12]; for(int j=0;j<12;++j) restpos_[i][j]=restpos[i][j]; } //init cubica subbasis cubica_subBasis_=new double**[(int)cubica_num_]; for(int i=0;i<cubica_num_;++i) { cubica_subBasis_[i]=new double*[12]; for(int j=0;j<12;++j) { cubica_subBasis_[i][j]=new double[(int)r_]; } } for(int i=0;i<cubica_num_;++i) { int ele=cubica_elements_[i]; for(int j=0;j<4;++j) { int vertID=volumetric_mesh_->getVertexIndex(ele,j); for(int k=0;k<r_;++k) { cubica_subBasis_[i][3*j][k]=U_[3*vertID][k]; cubica_subBasis_[i][3*j+1][k]=U_[3*vertID+1][k]; cubica_subBasis_[i][3*j+2][k]=U_[3*vertID+2][k]; } } } deformed_=new double[12]; memset(deformed_,0.0,sizeof(double)*12); // modal_matrix_ = new ModalMatrix(volumetric_mesh_->getNumVertices(),r_,U); VolumetricMesh::Material * material = volumetric_mesh_->getElementMaterial(0); VolumetricMesh::ENuMaterial * eNuMaterial = downcastENuMaterial(material); if (eNuMaterial == NULL) { std::cout<<"Error: mesh does not consist of E, nu materials.\n"; exit(0); } lamda_ = eNuMaterial->getLambda(); mu_ = eNuMaterial->getMu(); gf_=new double[(int)r]; // std::cout<<"f\n"; InitGravity(U); }