int CFeasibilityMap::test_feasible_test_fn(CData &Data, ColumnVector &x_tilde_i, ColumnVector &s_i){ int is_feasible = 0 ; int n_var = x_tilde_i.nrows() ; int n_EditVec = Data.EditVec.nrows() ; int sum_s_1 = s_i.sum() ; int sum_s_0 = n_var - sum_s_1 ; ColumnVector x_0(sum_s_0); x_0 = 0; Matrix A_0(n_EditVec,sum_s_0) ; A_0 = 0; Matrix A_1(n_EditVec,sum_s_1) ; A_1 = 0; int count0 = 0; int count1 = 0; for (int j_var=1; j_var<=n_var; j_var++){ if ((int)s_i(j_var)==0){ count0++; x_0(count0) = x_tilde_i(j_var) ; A_0.column(count0) = Data.EditMat.column(j_var) ; } else { count1++; A_1.column(count1) = Data.EditMat.column(j_var) ; } } ColumnVector which_rows(n_EditVec); which_rows = 0 ; for (int i_row=1; i_row<=n_EditVec; i_row++){ int n_zero = 0 ; for (int j=1; j<=sum_s_1; j++){ if (A_1(i_row,j)==0) n_zero++; } if (n_zero<sum_s_1) which_rows(i_row) = 1 ; } Matrix A_1_red(which_rows.sum(),sum_s_1); ColumnVector b_1_red(which_rows.sum()); Matrix A_0_red(which_rows.sum(),sum_s_0); for (int i_row=1, count_row = 0; i_row<=n_EditVec; i_row++){ if (which_rows(i_row)==1){ count_row++; A_1_red.row(count_row) = A_1.row(i_row) ; // Constraints b_1_red.row(count_row) = Data.EditVec.row(i_row) ; A_0_red.row(count_row) = A_0.row(i_row) ; } } ColumnVector EditVec_shr = b_1_red - A_0_red * x_0 ; is_feasible = SolveLP(A_1_red, EditVec_shr); return is_feasible?1:0; }
void BeamElement::CalculateSectionProperties() { KRATOS_TRY array_1d<double, 3> x_0; array_1d<double, 3> x_1; // Vector que contiene coordenadas de los nodos. array_1d<double, 3> length; // Vector que contiene la direccion de la barra. // double minimo, maximo, B; // const double b = GetProperties()[BASE]; // const double h = GetProperties()[HEIGHT]; if( GetProperties().Has(CROSS_AREA) ) mArea = GetProperties()[CROSS_AREA]; else mArea = GetValue(AREA); Matrix* inertia; if( GetProperties().Has(LOCAL_INERTIA) ) { inertia = &(GetProperties()[LOCAL_INERTIA]); } else if( GetProperties().Has(INERTIA) ) { inertia = &(GetProperties()[INERTIA]); } else if( Has(LOCAL_INERTIA) ) { inertia = &(GetValue(LOCAL_INERTIA)); } else if( Has(INERTIA) ) { inertia = &(GetValue(INERTIA)); } else KRATOS_THROW_ERROR(std::logic_error, "The Inertia is not fully defined for the element", "") mInertia_x = (*inertia)(0,0); mInertia_y = (*inertia)(1,1); mInertia_Polar = (*inertia)(0,1); // mInertia_x = b * h * h * h / 12.0; // mInertia_y = b * b * b * h / 12.0; // minimo = std::min( b, h ); // maximo = std::max( b, h ); // B = ( 1.00 - 0.63 * ( minimo / maximo ) * ( 1 - ( pow( minimo, 4 ) / ( 12 * pow( maximo, 4 ) ) ) ) ) / 3; // constante torsional. Solo para secciones rectangulares. // mInertia_Polar = B * minimo * minimo * minimo * maximo; // mArea = b * h; x_0( 0 ) = GetGeometry()[0].X0(); x_0( 1 ) = GetGeometry()[0].Y0(); x_0( 2 ) = GetGeometry()[0].Z0(); x_1( 0 ) = GetGeometry()[1].X0(); x_1( 1 ) = GetGeometry()[1].Y0(); x_1( 2 ) = GetGeometry()[1].Z0(); noalias( length ) = x_1 - x_0; mlength = std::sqrt( inner_prod( length, length ) ); if (mlength == 0.00) KRATOS_THROW_ERROR(std::invalid_argument, "Zero length found in elemnet #", this->Id()); KRATOS_CATCH( "" ) }
int CFeasibilityMap::feasible_test_fn(CData &Data, ColumnVector &x_tilde_i, ColumnVector &s_i, int i_original, bool initD_S, float epsilon, ColumnVector &x){ int is_feasible = 0 ; if (initD_S) { if (!Data.PassStep0_for_init(x_tilde_i,s_i,epsilon)) { return is_feasible;} } else { // Step 0 - check balance edits hold, but only one s_ij has the value 1. if (!Data.PassStep0(s_i,i_original)) { return is_feasible;} } // Step 1 int n_var = x_tilde_i.nrows() ; int n_EditVec = Data.EditVec.nrows() ; int sum_s_1 = s_i.sum() ; int sum_s_0 = n_var - sum_s_1 ; ColumnVector x_0(sum_s_0); x_0 = 0; Matrix A_0(n_EditVec,sum_s_0) ; A_0 = 0; Matrix A_1(n_EditVec,sum_s_1) ; A_1 = 0; int count0 = 0; int count1 = 0; for (int j_var=1; j_var<=n_var; j_var++){ if ((int)s_i(j_var)==0){ count0++; x_0(count0) = x_tilde_i(j_var) ; A_0.column(count0) = Data.EditMat.column(j_var) ; } else { count1++; A_1.column(count1) = Data.EditMat.column(j_var) ; } } Data.Debug = Debug; if (!Data.PassStep1(s_i, A_0, x_0)) { return is_feasible;} // Step 2: lpSolve to check whether s_i has a feasible solution of x_i ColumnVector which_rows(n_EditVec); which_rows = 0 ; for (int i_row=1; i_row<=n_EditVec; i_row++){ int n_zero = 0 ; for (int j=1; j<=sum_s_1; j++){ if (A_1(i_row,j)==0) n_zero++; } if (n_zero<sum_s_1) which_rows(i_row) = 1 ; } Matrix A_1_red(which_rows.sum(),sum_s_1); ColumnVector b_1_red(which_rows.sum()); Matrix A_0_red(which_rows.sum(),sum_s_0); for (int i_row=1, count_row = 0; i_row<=n_EditVec; i_row++){ if (which_rows(i_row)==1){ count_row++; A_1_red.row(count_row) = A_1.row(i_row) ; // Constraints b_1_red.row(count_row) = Data.EditVec.row(i_row) ; A_0_red.row(count_row) = A_0.row(i_row) ; } } ColumnVector EditVec_shr = b_1_red - A_0_red * x_0 ; if (initD_S) { is_feasible = SolveLP(A_1_red, EditVec_shr,x); } else { is_feasible = SolveLP(A_1_red, EditVec_shr); } return is_feasible?1:0; }