Skip to content

Commit

Permalink
Implemented compute eff field in sim class. Simplified interactions a…
Browse files Browse the repository at this point in the history
…rray. Fixed circular dependency in sim and energy class headers
  • Loading branch information
davidcortesortuno committed Jun 12, 2019
1 parent 5268274 commit aa2aa4b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
8 changes: 2 additions & 6 deletions fidimag/common/c_clib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ cdef class PyEnergy:
return self.thisptr.compute_energy()

def add_interaction_to_sim(self, PyMicroSim sim):
sim.thisptr.add_interaction(<void *> self.thisptr,
self.thisptr.interaction_id)
sim.thisptr.add_interaction(<Energy *> self.thisptr)

def get_interaction_id(self):
return self._thisptr.interaction_id
Expand Down Expand Up @@ -375,8 +374,7 @@ cdef extern from "c_micro_sim.h":
double *energy, double *field, int *pins
)

void add_interaction(void * interaction, int int_id)
void print_interactions_id()
void add_interaction(Energy * interaction)


cdef class PyMicroSim(object):
Expand Down Expand Up @@ -406,5 +404,3 @@ cdef class PyMicroSim(object):

def add_interaction(self, Interaction):
Interaction.add_interaction_to_sim(self)
self.thisptr.print_interactions_id()

4 changes: 2 additions & 2 deletions native/include/c_energy.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AnisotropyEnergy : public Energy {
public:
AnisotropyEnergy() {
std::cout << "Instatiating AnisotropyEnergy class; at " << this << "\n";
this->interaction_id = 1;
this->interaction_id = UNIAXIAL_ANISOTROPY;
};
~AnisotropyEnergy() {std::cout << "Killing Anisotropy\n";};
double *Ku;
Expand All @@ -64,7 +64,7 @@ class DMIEnergy : public Energy {
public:
DMIEnergy() {
std::cout << "Instatiating DMIEnergy class; at " << this << "\n";
this->interaction_id = 1;
this->interaction_id = DMI;
};
~DMIEnergy() {std::cout << "Killing DMI\n";};
double *D;
Expand Down
25 changes: 16 additions & 9 deletions native/include/c_micro_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#include<cmath>
#include<iostream>
#include<vector>
#include<memory>
// #define MAX_ENERGY_TERMS 20

class Energy; // forward declaration; Energy is defined in c_energy.h
class MicroSim {
public:
MicroSim() {std::cout << "Instatiating MicroSim class; at " << this << "\n";};
Expand All @@ -28,22 +30,27 @@ class MicroSim {
// Array with interactions
// void * interactions;
// int interactions_id[MAX_ENERGY_TERMS];
std::vector<void *> interactions;
std::vector<int> interactions_id;
// Should we use a vector of weak_ptr? : std::vector<std::weak_ptr<Energy>> interactions;
std::vector<Energy *> interactions;

// Not necessary at least we re creating an array of void pointers:
// std::vector<int> interactions_id;

// Methods
void setup(int nx, int ny, int nz, double dx, double dy, double dz,
double unit_length, double *coordinates, int *ngbs,
double *spin, double *Ms, double *Ms_inv,
double unit_length, double *coordinates, int *ngbs,
double *spin, double *Ms, double *Ms_inv,
double *energy, double *field, int *pins
);

void add_interaction(void * interaction, int int_id);
void add_interaction(Energy * interaction);

// void print_interactions_id() {
// for(int i : interactions_id) std::cout << i << "\n";
// for(auto i : interactions) std::cout << i << "\n";
// }

void print_interactions_id() {
for(int i : interactions_id) std::cout << i << "\n";
for(auto i : interactions) std::cout << i << "\n";
}
void compute_effective_field(double t);
};

enum EnergyTermIDs {
Expand Down
20 changes: 15 additions & 5 deletions native/src/c_micro_sim.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "c_energy.h"
#include "c_micro_sim.h"
#include "c_constants.h"


void MicroSim::setup(int nx, int ny, int nz, double dx, double dy, double dz,
double unit_length, double *coordinates, int *ngbs,
double *spin, double *Ms, double *Ms_inv,
double unit_length, double *coordinates, int *ngbs,
double *spin, double *Ms, double *Ms_inv,
double *energy, double *field, int *pins
) {

Expand All @@ -29,9 +30,18 @@ void MicroSim::setup(int nx, int ny, int nz, double dx, double dy, double dz,
set_up = true;
}

void MicroSim::add_interaction(void * interaction_ptr, int int_id) {
void MicroSim::add_interaction(Energy * interaction_ptr) {

interactions.push_back(interaction_ptr);
interactions_id.push_back(int_id);
// interactions_id.push_back(int_id);

}

void MicroSim::compute_effective_field(double t) {

// Using indices
std::vector<Energy *>::iterator it;
for(it = interactions.begin(); it != interactions.end(); it++) {
(*it)->compute_field(t);
}
}
1 change: 1 addition & 0 deletions native/src/m_dmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ void dmi_field(double * m, double * field,

void DMIEnergy::compute_field(double t) {

// Should use: std::unique_ptr<int[]> dxs ??
/* These are for the DMI prefactor or coefficient */
double dxs[6] = {dx, dx, dy, dy, dz, dz};

Expand Down

0 comments on commit aa2aa4b

Please sign in to comment.