Skip to content

Commit 0a431b6

Browse files
Added test for new energy class wrapper
1 parent 09ad07e commit 0a431b6

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

fidimag/common/c_clib.pyx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ cdef extern from "c_energy.h":
272272

273273
double *A
274274

275+
# cdef extern from "c_energy.cpp":
276+
# pass
277+
275278
# -----------------------------------------------------------------------------
276279
# Python definitions
277280

@@ -283,17 +286,18 @@ cdef extern from "c_energy.h":
283286
# once upon creation and deletion of the Python instance.
284287

285288
cdef class PyExchangeEnergy:
286-
cdef ExchangeEnergy thisptr
289+
cdef ExchangeEnergy *thisptr
287290
# Try cinit:
288-
def __init__(self, double [:] A):
291+
def __cinit__(self, double [:] A):
292+
# self.thisptr = new ExchangeEnergy()
289293
self.thisptr.init(&A[0])
290-
# cdef ExchangeEnergy *thisptr
294+
291295
# We could use another constructor if we use this method:
292296
# def __cinit__(self):
293-
# if type(self) is PyEnergy:
294-
# self.thisptr = new Energy()
297+
# if type(self) is PyExchangeEnergy:
298+
# self.thisptr = new ExchangeEnergy()
295299
# def __dealloc__(self):
296-
# if type(self) is PyEnergy:
300+
# if type(self) is PyExchangeEnergy:
297301
# del self.thisptr
298302
# Necessary?
299303
def compute_field(self, t):

native/include/c_energy.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include<cmath>
2+
#include<iostream>
23

34
class Energy {
45
public:
@@ -23,8 +24,9 @@ class ExchangeEnergy : public Energy {
2324
public:
2425
ExchangeEnergy() {};
2526
void init(double *A) {
26-
set_up = false;
27-
this->A = A;
27+
std::cout << "Here A[0] = " << A[0] << "\n";
28+
this->set_up = false;
29+
// this->A = A;
2830
}
2931
double *A;
3032
void compute_field(double t);

tests/test_C_classes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fidimag.extensions.c_clib import PyExchangeEnergy
2+
import numpy as np
3+
4+
A = np.ones(9, dtype=np.double)
5+
print(A)
6+
Exch = PyExchangeEnergy(A)

0 commit comments

Comments
 (0)