Commits

Lisandro Dalcin  committed 289f21a

Now io.VTK.write() supports passing a field array

  • Participants
  • Parent commits 55e4be8

Comments (0)

Files changed (2)

File src/igakit/io.py

         pass
 
     def write(self, filename, nurbs,
-              control=True, sampler=None,
-              scalars=(), vectors=()):
+              control=True, fields=None,
+              scalars=(), vectors=(),
+              sampler=None):
         """
         Parameters
         ----------
         filename : string
         nurbs : NURBS
         control : bool, optional
-        sampler : callable, optional
+        fields : array, optional
         scalars : dict or sequence of 2-tuple, optional
         vectors : dict or sequence or 2-tuple, optional
+        sampler : callable, optional
 
         """
         if sampler is None:
         dim  = nurbs.dim
         uvw = [sampler(u) for u in nurbs.breaks()]
         flag = bool(scalars or vectors)
-        out = nurbs.evaluate(*uvw, **dict(fields=flag))
+        if not flag: fields = flag
+        elif fields is None: fields = flag
+        out = nurbs.evaluate(*uvw, **dict(fields=fields))
         if flag: C, F = out
         else:    C, F = out, out[..., 0:0]
 

File test/test_io.py

         rw.write(fn, V)
         for N in (L, S, V):
             F = np.random.random(N.shape+(4,))
-            N = NURBS(N.knots, N.control, fields=F)
-            for control in (False, True):
-                for sampler in (None, uniform):
-                    rw.write(fn, N,
+            for sampler in (None, uniform):
+                for control in (False, True):
+                    rw.write(fn, N, fields=None,
                              control=control, sampler=sampler)
-                    rw.write(fn, N,
+                    rw.write(fn, N, fields=F,
                              control=control, sampler=sampler,
                              scalars=[(None,0),('',1),("my scalar",2)],
                              vectors=dict(u=[0],v=[0,1],w=[0,1,2]))
+
+            N = NURBS(N.knots, N.control, fields=F)
+            for sampler in (None, uniform):
+                for control in (False, True):
+                    for fields in (None, F):
+                        rw.write(fn, N, fields=fields,
+                                 control=control, sampler=sampler)
+                        rw.write(fn, N, fields=fields,
+                                 control=control, sampler=sampler,
+                                 scalars=[(None,0),('',1),("my scalar",2)],
+                                 vectors=dict(u=[0],v=[0,1],w=[0,1,2]))
+                        rw.write(fn, N, fields=fields,
+                                 control=control, sampler=sampler,
+                                 scalars=[(None,0),('',1),("my scalar",2)],
+                                 vectors=dict(u=[0],v=[0,1],w=[0,1,2]))
+
     finally:
         os.remove(fn)