// in global 3D coordinate system py::tuple computeShearAndBending(){ PolyVec Vx, Vy, Fz, Mx, My, Tz; beam->shearAndBending(Vx, Vy, Fz, Mx, My, Tz); int n = beam->getNumNodes() - 1; int nodes = n + 1; Vector Vx0(nodes), Vy0(nodes), Fz0(nodes), Mx0(nodes), My0(nodes), Tz0(nodes); for(int i = 0; i < n; i++) { Vx0[i] = Vx[i].eval(0.0); Vy0[i] = Vy[i].eval(0.0); Fz0[i] = Fz[i].eval(0.0); Mx0[i] = -My[i].eval(0.0); // translate back to global coordinates My0[i] = Mx[i].eval(0.0); // translate back to global coordinates Tz0[i] = Tz[i].eval(0.0); } Vx0[n] = Vx[n-1].eval(1.0); Vy0[n] = Vy[n-1].eval(1.0); Fz0[n] = Fz[n-1].eval(1.0); Mx0[n] = -My[n-1].eval(1.0); // translate back to global coordinates My0[n] = Mx[n-1].eval(1.0); // translate back to global coordinates Tz0[n] = Tz[n-1].eval(1.0); return py::make_tuple(Vx0, Vy0, Fz0, Mx0, My0, Tz0); }
/* Function: mdlInitializeConditions ======================================== * Abstract: * In this function, you should initialize the continuous and discrete * states for your S-function block. The initial states are placed * in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S). * You can also perform any other initialization activities that your * S-function may require. Note, this routine will be called at the * start of simulation and if it is present in an enabled subsystem * configured to reset states, it will be call when the enabled subsystem * restarts execution to reset the states. */ static void mdlInitializeConditions(SimStruct *S) { real_T *xC = ssGetContStates(S); real_T *xD = ssGetRealDiscStates(S); int i; i = mxGetNumberOfElements(Mx0(S)); if (i!= (int) (B(S,"CStates")+B(S,"DStates"))) { ssSetErrorStatus(S,"Number of states and number of IC do not match" ); } for (i=0; i<(int)B(S,"CStates"); i++) { xC[i]=x0(S)[i]; } for (i=0; i<(int)B(S,"DStates"); i++) { xD[i]=x0(S)[(int) (B(S,"CStates"))+i]; } }