Commit 4793ad25 authored by Stephan Rave's avatar Stephan Rave Committed by GitHub

Merge pull request #888 from pymor/fenics_numpy

Implement FenicsVectorSpace.from_numpy
parents 07ef191f 94f95c6a
Pipeline #50308 passed with stages
in 56 minutes and 40 seconds
......@@ -34,9 +34,7 @@ if config.HAVE_FENICS:
self.impl = self.impl.copy()
def to_numpy(self, ensure_copy=False):
if ensure_copy:
return self.impl.copy().get_local()
return self.impl.get_local()
return self.impl.get_local() # always returns a copy
def _scal(self, alpha):
self.impl *= alpha
......@@ -157,7 +155,12 @@ if config.HAVE_FENICS:
def real_random_vector(self, distribution, random_state, **kwargs):
impl = df.Function(self.V).vector()
values = _create_random_values(impl.local_size(), distribution, random_state, **kwargs)
impl[:] = values
impl[:] = np.ascontiguousarray(values)
return FenicsVector(impl)
def real_vector_from_numpy(self, data, ensure_copy=False):
impl = df.Function(self.V).vector()
impl[:] = np.ascontiguousarray(data)
return FenicsVector(impl)
def real_make_vector(self, obj):
......@@ -390,7 +393,7 @@ if config.HAVE_FENICS:
assert U in self.source
UU = self.op.source.zeros(len(U))
for uu, u in zip(UU._list, U.data):
uu.real_part.impl[:] = u
uu.real_part.impl[:] = np.ascontiguousarray(u)
VV = self.op.apply(UU, mu=mu)
V = self.range.zeros(len(VV))
for v, vv in zip(V.data, VV._list):
......@@ -400,7 +403,7 @@ if config.HAVE_FENICS:
def jacobian(self, U, mu=None):
assert U in self.source and len(U) == 1
UU = self.op.source.zeros()
UU._list[0].real_part.impl[:] = U.data[0]
UU._list[0].real_part.impl[:] = np.ascontiguousarray(U.data[0])
JJ = self.op.jacobian(UU, mu=mu)
return NumpyMatrixOperator(JJ.matrix.array()[self.restricted_range_dofs, :])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment