Skip to content
Snippets Groups Projects
Select Git revision
  • a2911a658b6bcc388b94d0566749b8be885f0cc2
  • master default protected
  • corrections-enonce
  • 1-test-vec-to-coordinates
  • patch-1
5 results

main.c

Blame
  • Forked from orestis.malaspin / isc_physics
    Source project has a limited visibility.
    main.c 1.64 KiB
    #include "rc.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <plplot.h>
    
    #define NSIZE 5000
    
    int main(int argc, char *argv[]) {
        rc_state rc = rc_state_create(1.0, 1.0, 1.0);
    
    
    // ============================================================ //
    // RC with constant != 0 tension at input and 0 initial tension //
    // ============================================================ //
        double v, v_ini;
        v = v_ini = 0.0;
    
        double dt = 0.001;
        double max_t = 5.0;
    
        PLFLT x[NSIZE], y[NSIZE];
        PLFLT xmin = 0., xmax = max_t, ymin = rc.eps-1, ymax = rc.eps+1;
    
        for (double t = 0.0; t < max_t; t += dt) {
            double ve = exact_solution(t, v_ini, &rc);
            printf("t = %f, v = %f, v_e = %f, diff = %f\n", t, v, ve, ve - v);
            v = rc_advance(v, dt, &rc);
        }
    
        v = v_ini = 1.0;
        double omega_low = 1.0;
        double omega = 100.0;
        int i = 0;
        for (double t = 0.0; t < max_t; t += dt) {
            rc.eps = v_ini * (1.0 + cos(omega * t) + cos(omega_low * t));
            double ve = exact_solution(t, v_ini, &rc);
            printf("t = %f, v = %f, v_e = %f, diff = %f\n", t, v, ve, ve - v);
            x[i] = t;
            y[i] = v;
            v = rc_advance(v, dt, &rc);
            i += 1;
        }
    
        // Parse and process command line arguments
        plparseopts( &argc, argv, PL_PARSE_FULL );
    
        // Initialize plplot
        plinit();
    
        // Create a labelled box to hold the plot.
        plenv( xmin, xmax, ymin, ymax, 0, 0 );
        pllab( "t", "v", "Simple PLplot demo of of the charge of a capacitor" );
    
        // Plot the data that was prepared above.
        plline( NSIZE, x, y );
    
        // Close PLplot library
        plend();
    
        return EXIT_SUCCESS;
    }