void ConsumingBorderCalculator::doCalc(CalcNode& cur_node, CalcNode& new_node, RheologyMatrixPtr matrix, vector<CalcNode>& previousNodes, bool inner[], float outer_normal[], float scale) { assert_eq(previousNodes.size(), 9); int outer_count = 3; // Tmp value for GSL solver int s; // Here we will store (omega = Matrix_OMEGA * u) float omega[9]; for(int i = 0; i < 9; i++) { // If omega is 'inner' one if(inner[i]) { // Calculate omega value omega[i] = 0; for(int j = 0; j < 9; j++) { omega[i] += matrix->getU(i,j) * previousNodes[i].values[j]; } // Load appropriate values into GSL containers gsl_vector_set(om_gsl, i, omega[i]); for(int j = 0; j < 9; j++) gsl_matrix_set(U_gsl, i, j, matrix->getU(i,j)); } // If omega is 'outer' one else { // Load appropriate values into GSL containers gsl_vector_set(om_gsl, i, 0); for(int j = 0; j < 9; j++) gsl_matrix_set(U_gsl, i, j, matrix->getU(i,j)); } } LOG_TRACE("F*****g FBC: outer_count = " << outer_count << "\nMatrix:\n"); for(int i = 0; i < 9; i++) { for(int j = 0; j < 9; j++) { LOG_TRACE(gsl_matrix_get(U_gsl, i, j) << "\t"); } LOG_TRACE("\n"); } // Solve linear equations using GSL tools gsl_linalg_LU_decomp (U_gsl, p_gsl, &s); gsl_linalg_LU_solve (U_gsl, p_gsl, om_gsl, x_gsl); for(int j = 0; j < 9; j++) new_node.values[j] = gsl_vector_get(x_gsl, j); };
void AdhesionContactCalculator::doCalc(CalcNode& cur_node, CalcNode& new_node, CalcNode& virt_node, RheologyMatrixPtr matrix, vector<CalcNode>& previousNodes, bool inner[], RheologyMatrixPtr virt_matrix, vector<CalcNode>& virtPreviousNodes, bool virt_inner[], float outer_normal[], float scale) { assert_eq(previousNodes.size(), 9); assert_eq(virtPreviousNodes.size(), 9); // Here we will store (omega = Matrix_OMEGA * u) float omega[9]; float virt_omega[9]; int posInEq18 = 0; int curNN = 0; // For all omegas of real node for(int i = 0; i < 9; i++) { // If omega is 'inner' if(inner[i]) { // omega on new time layer is equal to omega on previous time layer along characteristic omega[i] = 0; for( int j = 0; j < 9; j++ ) { omega[i] += matrix->getU(i,j) * previousNodes[i].values[j]; } // then we must set the corresponding values of the 18x18 matrix gsl_vector_set( om_gsl, 6 * curNN + posInEq18, omega[i] ); for( int j = 0; j < 9; j++ ) { gsl_matrix_set( U_gsl, 6 * curNN + posInEq18, j, matrix->getU( i, j ) ); } for( int j = 9; j < 18; j++ ) { gsl_matrix_set( U_gsl, 6 * curNN + posInEq18, j, 0 ); } posInEq18++; } } posInEq18 = 0; curNN = 1; // For all omegas of virtual node for(int i = 0; i < 9; i++) { // If omega is 'inner' if(virt_inner[i]) { // omega on new time layer is equal to omega on previous time layer along characteristic virt_omega[i] = 0; for( int j = 0; j < 9; j++ ) { virt_omega[i] += virt_matrix->getU(i,j) * virtPreviousNodes[i].values[j]; } // then we must set the corresponding values of the 18x18 matrix gsl_vector_set( om_gsl, 6 * curNN + posInEq18, virt_omega[i] ); for( int j = 0; j < 9; j++ ) { gsl_matrix_set( U_gsl, 6 * curNN + posInEq18, j, 0 ); } for( int j = 9; j < 18; j++ ) { gsl_matrix_set( U_gsl, 6 * curNN + posInEq18, j, virt_matrix->getU( i, j - 9 ) ); } posInEq18++; } } // Clear the rest 6 rows of the matrix for( int strN = 12; strN < 18; strN++ ) { for( int colN = 0; colN < 18; colN++ ) { gsl_matrix_set( U_gsl, strN, colN, 0 ); } } for( int strN = 12; strN < 18; strN++ ) { gsl_vector_set( om_gsl, strN, 0 ); } // Equality of velocities gsl_matrix_set( U_gsl, 12, 0, 1 ); gsl_matrix_set( U_gsl, 12, 9, -1 ); gsl_matrix_set( U_gsl, 13, 1, 1 ); gsl_matrix_set( U_gsl, 13, 10, -1 ); gsl_matrix_set( U_gsl, 14, 2, 1 ); gsl_matrix_set( U_gsl, 14, 11, -1 ); // Equality of normal and tangential stress // We use outer normal to find total stress vector (sigma * n) - sum of normal and shear - and tell it is equal // TODO - is it ok? // TODO - never-ending questions - is everything ok with (x-y-z) and (ksi-eta-dzeta) basises? // TODO FIXME - it works now because exactly the first axis is the only one where contact is possible // and it coincides with outer normal gsl_matrix_set(U_gsl, 15, 3, outer_normal[0]); gsl_matrix_set(U_gsl, 15, 4, outer_normal[1]); gsl_matrix_set(U_gsl, 15, 5, outer_normal[2]); gsl_matrix_set(U_gsl, 15, 12, -outer_normal[0]); gsl_matrix_set(U_gsl, 15, 13, -outer_normal[1]); gsl_matrix_set(U_gsl, 15, 14, -outer_normal[2]); gsl_matrix_set(U_gsl, 16, 4, outer_normal[0]); gsl_matrix_set(U_gsl, 16, 6, outer_normal[1]); gsl_matrix_set(U_gsl, 16, 7, outer_normal[2]); gsl_matrix_set(U_gsl, 16, 13, -outer_normal[0]); gsl_matrix_set(U_gsl, 16, 15, -outer_normal[1]); gsl_matrix_set(U_gsl, 16, 16, -outer_normal[2]); gsl_matrix_set(U_gsl, 17, 5, outer_normal[0]); gsl_matrix_set(U_gsl, 17, 7, outer_normal[1]); gsl_matrix_set(U_gsl, 17, 8, outer_normal[2]); gsl_matrix_set(U_gsl, 17, 14, -outer_normal[0]); gsl_matrix_set(U_gsl, 17, 16, -outer_normal[1]); gsl_matrix_set(U_gsl, 17, 17, -outer_normal[2]); // Tmp value for GSL solver int s; gsl_linalg_LU_decomp (U_gsl, p_gsl, &s); gsl_linalg_LU_solve (U_gsl, p_gsl, om_gsl, x_gsl); // Just get first 9 values (real node) and dump the rest 9 (virt node) for(int j = 0; j < 9; j++) new_node.values[j] = gsl_vector_get(x_gsl, j); };
void SlidingContactCalculator::doCalc(CalcNode& cur_node, CalcNode& new_node, CalcNode& virt_node, RheologyMatrixPtr matrix, vector<CalcNode>& previousNodes, bool inner[], RheologyMatrixPtr virt_matrix, vector<CalcNode>& virtPreviousNodes, bool virt_inner[], float outer_normal[], float scale) { assert_eq(previousNodes.size(), 9); assert_eq(virtPreviousNodes.size(), 9); if (isFreeBorder(cur_node, virt_node, outer_normal)) { fbc->doCalc(cur_node, new_node, matrix, previousNodes, inner, outer_normal, scale); return; } // Here we will store (omega = Matrix_OMEGA * u) float omega[9]; float virt_omega[9]; int posInEq18 = 0; int curNN = 0; // For all omegas of real node for(int i = 0; i < 9; i++) { LOG_TRACE("PrNode: " << previousNodes[i]); // If omega is 'inner' if(inner[i]) { LOG_TRACE("INNER"); // omega on new time layer is equal to omega on previous time layer along characteristic omega[i] = 0; for( int j = 0; j < 9; j++ ) { omega[i] += matrix->getU(i,j) * previousNodes[i].values[j]; } // then we must set the corresponding values of the 18x18 matrix gsl_vector_set( om_gsl, 6 * curNN + posInEq18, omega[i] ); for( int j = 0; j < 9; j++ ) { gsl_matrix_set( U_gsl, 6 * curNN + posInEq18, j, matrix->getU( i, j ) ); } for( int j = 9; j < 18; j++ ) { gsl_matrix_set( U_gsl, 6 * curNN + posInEq18, j, 0 ); } posInEq18++; } } posInEq18 = 0; curNN = 1; // For all omegas of virtual node for(int i = 0; i < 9; i++) { LOG_TRACE("VirtPrNode: " << virtPreviousNodes[i]); // If omega is 'inner' if(virt_inner[i]) { LOG_TRACE("INNER"); // omega on new time layer is equal to omega on previous time layer along characteristic virt_omega[i] = 0; for( int j = 0; j < 9; j++ ) { virt_omega[i] += virt_matrix->getU(i,j) * virtPreviousNodes[i].values[j]; } // then we must set the corresponding values of the 18x18 matrix gsl_vector_set( om_gsl, 6 * curNN + posInEq18, virt_omega[i] ); for( int j = 0; j < 9; j++ ) { gsl_matrix_set( U_gsl, 6 * curNN + posInEq18, j, 0 ); } for( int j = 9; j < 18; j++ ) { gsl_matrix_set( U_gsl, 6 * curNN + posInEq18, j, virt_matrix->getU( i, j - 9 ) ); } posInEq18++; } } // Clear the rest 6 rows of the matrix for( int strN = 12; strN < 18; strN++ ) { for( int colN = 0; colN < 18; colN++ ) { gsl_matrix_set( U_gsl, strN, colN, 0 ); } } for( int strN = 12; strN < 18; strN++ ) { gsl_vector_set( om_gsl, strN, 0 ); } float local_n[3][3]; local_n[0][0] = outer_normal[0]; local_n[0][1] = outer_normal[1]; local_n[0][2] = outer_normal[2]; createLocalBasis(local_n[0], local_n[1], local_n[2]); // Normal velocities are equal gsl_matrix_set( U_gsl, 12, 0, local_n[0][0]); gsl_matrix_set( U_gsl, 12, 1, local_n[0][1]); gsl_matrix_set( U_gsl, 12, 2, local_n[0][2]); gsl_matrix_set( U_gsl, 12, 9, - local_n[0][0]); gsl_matrix_set( U_gsl, 12, 10, - local_n[0][1]); gsl_matrix_set( U_gsl, 12, 11, - local_n[0][2]); // We use outer normal to find total stress vector (sigma * n) - sum of normal and shear - and tell it is equal // TODO - is it ok? // TODO - never-ending questions - is everything ok with (x-y-z) and (ksi-eta-dzeta) basises? // TODO FIXME - it works now because exactly the first axis is the only one where contact is possible // and it coincides with outer normal // Normal stresses are equal gsl_matrix_set(U_gsl, 13, 3, local_n[0][0] * local_n[0][0]); gsl_matrix_set(U_gsl, 13, 4, 2 * local_n[0][1] * local_n[0][0]); gsl_matrix_set(U_gsl, 13, 5, 2 * local_n[0][2] * local_n[0][0]); gsl_matrix_set(U_gsl, 13, 6, local_n[0][1] * local_n[0][1]); gsl_matrix_set(U_gsl, 13, 7, 2 * local_n[0][2] * local_n[0][1]); gsl_matrix_set(U_gsl, 13, 8, local_n[0][2] * local_n[0][2]); gsl_matrix_set(U_gsl, 13, 12, - local_n[0][0] * local_n[0][0]); gsl_matrix_set(U_gsl, 13, 13, - 2 * local_n[0][1] * local_n[0][0]); gsl_matrix_set(U_gsl, 13, 14, - 2 * local_n[0][2] * local_n[0][0]); gsl_matrix_set(U_gsl, 13, 15, - local_n[0][1] * local_n[0][1]); gsl_matrix_set(U_gsl, 13, 16, - 2 * local_n[0][2] * local_n[0][1]); gsl_matrix_set(U_gsl, 13, 17, - local_n[0][2] * local_n[0][2]); // Tangential stresses are zero gsl_matrix_set(U_gsl, 14, 3, - (local_n[0][0] * local_n[1][0]) ); gsl_matrix_set(U_gsl, 14, 4, - (local_n[0][1] * local_n[1][0] + local_n[0][0] * local_n[1][1]) ); gsl_matrix_set(U_gsl, 14, 5, - (local_n[0][2] * local_n[1][0] + local_n[0][0] * local_n[1][2]) ); gsl_matrix_set(U_gsl, 14, 6, - (local_n[0][1] * local_n[1][1]) ); gsl_matrix_set(U_gsl, 14, 7, - (local_n[0][2] * local_n[1][1] + local_n[0][1] * local_n[1][2]) ); gsl_matrix_set(U_gsl, 14, 8, - (local_n[0][2] * local_n[1][2]) ); gsl_matrix_set(U_gsl, 15, 3, - (local_n[0][0] * local_n[2][0]) ); gsl_matrix_set(U_gsl, 15, 4, - (local_n[0][1] * local_n[2][0] + local_n[0][0] * local_n[2][1]) ); gsl_matrix_set(U_gsl, 15, 5, - (local_n[0][2] * local_n[2][0] + local_n[0][0] * local_n[2][2]) ); gsl_matrix_set(U_gsl, 15, 6, - (local_n[0][1] * local_n[2][1]) ); gsl_matrix_set(U_gsl, 15, 7, - (local_n[0][2] * local_n[2][1] + local_n[0][1] * local_n[2][2]) ); gsl_matrix_set(U_gsl, 15, 8, - (local_n[0][2] * local_n[2][2]) ); gsl_matrix_set(U_gsl, 16, 12, - (local_n[0][0] * local_n[1][0]) ); gsl_matrix_set(U_gsl, 16, 13, - (local_n[0][1] * local_n[1][0] + local_n[0][0] * local_n[1][1]) ); gsl_matrix_set(U_gsl, 16, 14, - (local_n[0][2] * local_n[1][0] + local_n[0][0] * local_n[1][2]) ); gsl_matrix_set(U_gsl, 16, 15, - (local_n[0][1] * local_n[1][1]) ); gsl_matrix_set(U_gsl, 16, 16, - (local_n[0][2] * local_n[1][1] + local_n[0][1] * local_n[1][2]) ); gsl_matrix_set(U_gsl, 16, 17, - (local_n[0][2] * local_n[1][2]) ); gsl_matrix_set(U_gsl, 17, 12, - (local_n[0][0] * local_n[2][0]) ); gsl_matrix_set(U_gsl, 17, 13, - (local_n[0][1] * local_n[2][0] + local_n[0][0] * local_n[2][1]) ); gsl_matrix_set(U_gsl, 17, 14, - (local_n[0][2] * local_n[2][0] + local_n[0][0] * local_n[2][2]) ); gsl_matrix_set(U_gsl, 17, 15, - (local_n[0][1] * local_n[2][1]) ); gsl_matrix_set(U_gsl, 17, 16, - (local_n[0][2] * local_n[2][1] + local_n[0][1] * local_n[2][2]) ); gsl_matrix_set(U_gsl, 17, 17, - (local_n[0][2] * local_n[2][2]) ); // Tmp value for GSL solver int s; gsl_linalg_LU_decomp (U_gsl, p_gsl, &s); try { gsl_linalg_LU_solve (U_gsl, p_gsl, om_gsl, x_gsl); } catch (Exception& e) { cur_node.setContactCalculationError(); for(int i = 0; i < 18; i++) { std::stringstream matStr; for(int j = 0; j < 18; j++) matStr << gsl_matrix_get(U_gsl, i, j) << " "; LOG_TRACE(matStr.str()); } LOG_ERROR("Bad node: " << cur_node); LOG_ERROR("Normal: " << outer_normal[0] << " " << outer_normal[1] << " " << outer_normal[2]); LOG_ERROR("Delta: " << virt_node.coords[0] - cur_node.coords[0] << " " << virt_node.coords[1] - cur_node.coords[1] << " " << virt_node.coords[2] - cur_node.coords[2]); throw; } // Just get first 9 values (real node) and dump the rest 9 (virt node) for(int j = 0; j < 9; j++) new_node.values[j] = gsl_vector_get(x_gsl, j); CalcNode new_virt_node; for(int j = 0; j < 9; j++) new_virt_node.values[j] = gsl_vector_get(x_gsl, j + 9); if (isFreeBorder(new_node, new_virt_node, outer_normal)) { fbc->doCalc(cur_node, new_node, matrix, previousNodes, inner, outer_normal, scale); return; } };
void FreeBorderCalculator::doCalc(CalcNode& cur_node, CalcNode& new_node, RheologyMatrixPtr matrix, vector<CalcNode>& previousNodes, bool inner[], float outer_normal[], float scale) { assert_eq(previousNodes.size(), 9); int outer_count = 3; // Tmp value for GSL solver int s; // Here we will store (omega = Matrix_OMEGA * u) float omega[9]; for(int i = 0; i < 9; i++) { // If omega is 'inner' one if(inner[i]) { // Calculate omega value omega[i] = 0; for(int j = 0; j < 9; j++) { omega[i] += matrix->getU(i,j) * previousNodes[i].values[j]; } // Load appropriate values into GSL containers gsl_vector_set(om_gsl, i, omega[i]); for(int j = 0; j < 9; j++) gsl_matrix_set(U_gsl, i, j, matrix->getU(i,j)); } // If omega is 'outer' one else { // omega (as right-hand part of OLE) is zero - it is free border, no external stress gsl_vector_set(om_gsl, i, 0); // corresponding string in matrix is zero ... for(int j = 0; j < 9; j++) gsl_matrix_set(U_gsl, i, j, 0); // ... except normal and tangential stress // We use outer normal to find total stress vector (sigma * n) - sum of normal and shear - and tell it is zero // TODO - never-ending questions - is everything ok with (x-y-z) and (ksi-eta-dzeta) basises? if ( outer_count == 3 ) { gsl_matrix_set(U_gsl, i, 3, outer_normal[0]); gsl_matrix_set(U_gsl, i, 4, outer_normal[1]); gsl_matrix_set(U_gsl, i, 5, outer_normal[2]); outer_count--; } else if ( outer_count == 2 ) { gsl_matrix_set(U_gsl, i, 4, outer_normal[0]); gsl_matrix_set(U_gsl, i, 6, outer_normal[1]); gsl_matrix_set(U_gsl, i, 7, outer_normal[2]); outer_count--; } else if ( outer_count == 1 ) { gsl_matrix_set(U_gsl, i, 5, outer_normal[0]); gsl_matrix_set(U_gsl, i, 7, outer_normal[1]); gsl_matrix_set(U_gsl, i, 8, outer_normal[2]); outer_count--; } } } // Solve linear equations using GSL tools gsl_linalg_LU_decomp (U_gsl, p_gsl, &s); gsl_linalg_LU_solve (U_gsl, p_gsl, om_gsl, x_gsl); for(int j = 0; j < 9; j++) new_node.values[j] = gsl_vector_get(x_gsl, j); };