| 44 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
| 45 | |
| 46 | int main(int argc, char *argv[]) |
| 47 | { |
| 48 | dictionary springDict(IFstream("spring")()); |
| 49 | |
| 50 | // Create the spring model from dictionary |
| 51 | rigidBodyMotion spring(springDict); |
| 52 | |
| 53 | label nIter(readLabel(springDict.lookup("nIter"))); |
| 54 | |
| 55 | Info<< spring << endl; |
| 56 | |
| 57 | // Create the joint-space force field |
| 58 | scalarField tau(spring.nDoF(), Zero); |
| 59 | |
| 60 | // Create the external body force field |
| 61 | Field<spatialVector> fx(spring.nBodies(), Zero); |
| 62 | |
| 63 | OFstream qFile("qVsTime"); |
| 64 | OFstream qDotFile("qDotVsTime"); |
| 65 | |
| 66 | // Integrate the motion of the spring for 4s |
| 67 | scalar deltaT = 0.002; |
| 68 | for (scalar t=0; t<4; t+=deltaT) |
| 69 | { |
| 70 | spring.newTime(); |
| 71 | |
| 72 | for (label i=0; i<nIter; i++) |
| 73 | { |
| 74 | spring.solve(deltaT, tau, fx); |
| 75 | } |
| 76 | |
| 77 | // Write the results for graph generation |
| 78 | // using 'gnuplot spring.gnuplot' |
| 79 | qFile << t << " " << spring.state().q()[0] << endl; |
| 80 | qDotFile << t << " " << spring.state().qDot()[0] << endl; |
| 81 | } |
| 82 | |
| 83 | Info<< "\nEnd\n" << endl; |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | // ************************************************************************* // |