void BeamElement::CalculateTransformationMatrix(Matrix& Rotation) { KRATOS_TRY Vector Normal_zero(9); // vector que contiene los cosenos directores. Vector x_zero(6); Vector Vector_zero(3); noalias(Normal_zero) = zero_vector<double>(9); noalias(x_zero) = zero_vector<double>(6); noalias(Vector_zero) = zero_vector<double>(3); noalias(Rotation) = zero_matrix<double> (12,12); double nx, ny, nz,teta/*, phi*/; x_zero(0)= GetGeometry()[0].X0(); x_zero(1)= GetGeometry()[0].Y0(); x_zero(2)= GetGeometry()[0].Z0(); x_zero(3)= GetGeometry()[1].X0(); x_zero(4)= GetGeometry()[1].Y0(); x_zero(5)= GetGeometry()[1].Z0(); for (unsigned int i=0; i<3; i++) { Vector_zero[i] = x_zero[i+3] - x_zero[i]; } double length_inverse = ( 1.00 / mlength ); for ( unsigned int i = 0; i < 3; i++ ) { Normal_zero[i] = Vector_zero[i] * length_inverse; } nx = Normal_zero[0]; ny = Normal_zero[1]; nz = Normal_zero[2]; if (nx ==0.0) { teta = PI/2; if (ny == 0.0) { teta = 0.0; // phi = PI/2.0; } // else // { // phi = atan(nz/sqrt(nx*nx+ny*ny)); // } } else { teta = atan(ny/nx); // phi = atan(nz/sqrt(nx*nx+ny*ny)); } if(nx < 0.0) teta = teta + PI; Normal_zero[3] = -sin(teta); Normal_zero[4] = cos(teta); Normal_zero[5] = 0.0; Normal_zero[6] = -nz*cos(teta); Normal_zero[7] = -nz*sin(teta); Normal_zero[8] = nx*cos(teta) + ny*sin(teta); // Creacion de la matriz de transformacion. for (unsigned int kk=0; kk < 12; kk += 3) { for (unsigned int i=0; i<3; i++) { for(unsigned int j=0; j<3; j++) { Rotation(i+kk,j+kk)=Normal_zero(3*j+i); } } } KRATOS_CATCH("") }
static ParseResult parse_vertex_data( json_value *vertex, int *o_id, VectorPointer o_pos, char *o_label, int *o_fixed ) { ParseResult result; unsigned int fields = vertex->u.object.length; if (fields != 3) { result.status = PS_VALUE_LENGTH_ERR; result.emsg = "Each vertex specified in the input file needs to have exactly 3 fields"; return result; } char *fst_fieldname, *snd_fieldname, *thrd_fieldname; json_value *ident, *position, *label; fst_fieldname = vertex->u.object.values[0].name; snd_fieldname = vertex->u.object.values[1].name; thrd_fieldname = vertex->u.object.values[2].name; ident = vertex->u.object.values[0].value; position = vertex->u.object.values[1].value; label = vertex->u.object.values[2].value; if (strcmp(fst_fieldname, "id")) { result.status = PS_NAME_SPELL_ERR; result.emsg = "First field of a vertex needs to be named 'id'"; return result; } else if (strcmp(snd_fieldname, "fixed")) { result.status = PS_NAME_SPELL_ERR; result.emsg = "Second field of a vertex needs to be named 'fixed'"; return result; } else if (strcmp(thrd_fieldname, "label")) { result.status = PS_NAME_SPELL_ERR; result.emsg = "Third field of a vertex needs to be named 'label'"; return result; } int id, fixed; id = -99; if (ident->type == json_integer) { id = ident->u.integer; } else { result.status = PS_VALUE_TYPE_ERROR; result.emsg = "Field id does not have an integer as value"; return result; } *o_id = id; fixed = 0; Vector pos; pos = Vector_zero(); if (position->type == json_array) { fixed = 1; int length; length = position->u.array.length; if (length != 2) { result.status = PS_VALUE_LENGTH_ERR; result.emsg = "Position coordinates != 2"; return result; } json_value *j_x, *j_y; j_x = position->u.array.values[0]; j_y = position->u.array.values[1]; double fixed_x, fixed_y; fixed_x = fixed_y = 0; if (j_x->type == json_double) { if (Util_in_range(0, 1, (double) j_x->u.dbl)) { fixed_x = (double) j_x->u.dbl; } else { result.status = PS_VALUE_RANGE_ERROR; result.emsg = "X-coordinate must lie in range (0, 1)"; return result; } } else { result.status = PS_VALUE_TYPE_ERROR; result.emsg = "X-coordinate be of type double"; return result; } if (j_y->type == json_double) { if (Util_in_range(0, 1, (double) j_y->u.dbl)) { fixed_y = (double) j_y->u.dbl; } else { result.status = PS_VALUE_RANGE_ERROR; result.emsg = "Y-coordinate must lie in range (0, 1)"; return result; } } else { result.status = PS_VALUE_TYPE_ERROR; result.emsg = "Y-coordinate be of type double"; return result; } pos = Vector_initialize(fixed_x, fixed_y); } else if (position->type != json_null) { result.status = PS_VALUE_TYPE_ERROR; result.emsg = "The value fixed must be an array with 2 elements or null"; return result; } *o_pos = pos; *o_fixed = fixed; char vertex_label[MAX_LABEL_LENGTH]; if (label->type == json_string) { strcpy(vertex_label, label->u.string.ptr); } else if (label->type == json_null) { vertex_label[0] = 0; } else { result.status = PS_VALUE_TYPE_ERROR; result.emsg = "Label must be of type string"; return result; } strcpy(o_label, vertex_label); result.status = PS_SUCCESS; result.emsg = NULL; return result; }