Skip to content

Commit

Permalink
Setting micro driver class and sketching integrators
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcortesortuno committed May 19, 2021
1 parent eaccbf5 commit ec0e239
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
29 changes: 26 additions & 3 deletions native/include/m_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include<iostream>
#include "c_micro_sim.h"

class Integrator; // forward declaration
// Base class for the drivers
class Driver {
public:
Expand All @@ -13,15 +14,37 @@ class Driver {
double * alpha;
double gamma;
double t;
MicroSim * sim;
Integrator * integrator;

virtual void run_until(double t) {};
};


class Integrator_RK4 {
// Abstract class
class Integrator {
public:
Integrator() {};
virtual void _setup(int N) {};
// Allow magnetisation to update (via LLG + effective field)
// TODO: figure out how to set the update function in Driver class
virtual void compute_RHS(void (* f) (double * m, double t)) {};
}

// Integrators should be independent of any driver/sim class
class Integrator_RK4: public Integrator {
public:
Integrator_RK4() {};
virtual ~Integrator_RK4() {std::cout << "Killing RK4 integrator\n";};
// Will get the parameters from a simulation class
// void _setup(MicroSim * sim, Driver * driver);
std::vector<double> rk_steps; // N * 4 array
void integration_step(double (*f)(double t, double y));
std::vector<double> rk1; // N array
std::vector<double> rk2; // N array
std::vector<double> rk3; // N array
std::vector<double> rk4; // N array
void integration_step(double (*f)(double t, double m)); // compute_RHS ??
void _setup(int N);
int N;
double t;
double dt;
};
5 changes: 5 additions & 0 deletions native/src/m_driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "m_driver.h"

void Integrator_RK4::_setup(int N) {
this->rk_steps(N * 4, 0.0);
}

1 comment on commit ec0e239

@rpep
Copy link
Member

@rpep rpep commented on ec0e239 May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make the RK4 arrays sequential to make the memory layout more compact, so something like (this won't compile I think, needs more thought)

class Integrator {
Integrator(size_t N) = 0; // No constructor so people can't use the base class
public:
   size_t N;
private:
    std::vector<double> integratorData;
};

class RK4Integrator : private Integrator {
    RK4Integrator(size_t N) : Integrator(N) { 
        // Know we need 4xN for RK4
        integratorData.resize(4 * N);
    };
};

class RK54Integrator : private Integrator {
    RK54Integrator(size_t N) : Integrator(N) { 
        // Know we need 5xN for RK54
        integratorData.resize(5 * N);
    };
};

Please sign in to comment.