Skip to content

Commit b545417

Browse files
committed
released 2026.3.13 with fixed firedrake version compatibility issues
1 parent 3f15906 commit b545417

6 files changed

Lines changed: 65 additions & 38 deletions

File tree

src/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ devinstall: specfabpy
8080

8181
# Firedrake/icepack docker enviroment
8282
icepack: specfabpy
83-
@echo "*** You can also just run: pip3 install specfabpy ***"
84-
#pip3 install setuptools==61 cartopy cmasher
85-
#pip3 install .
83+
@echo "*** Alternatively: pip3 install specfabpy ***"
84+
pip3 install cmasher tabulate termcolor cartopy scipy
8685
python3 setup.py install
86+
#pip3 install .
8787

8888
specfabpy: $(SPECFAB).o
8989
@echo "*** Archiving objects into $(PWD)/libspecfab.a";

src/specfabpy/fenics/steadyCPO.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import os, sys, copy, code # code.interact(local=locals())
99
import numpy as np
10+
from scipy.spatial.transform import Rotation as R
1011
import xarray, pickle, pyproj # pyproj needed!
1112
from tabulate import tabulate
1213

@@ -195,7 +196,7 @@ def get_mesh(self, mapscale=1):
195196
cells = mesh.cells()
196197
return (mesh, boundaries, Q,Q2,V, coords,cells)
197198

198-
def triang(self, coords, cells, mapscale=1):
199+
def get_triang(self, coords, cells, mapscale=1):
199200

200201
return tri.Triangulation(mapscale*coords[0], mapscale*coords[1], triangles=cells)
201202

@@ -316,7 +317,28 @@ def set_solution(self, probname):
316317
def set_inputs(self):
317318

318319
self.coords,self.cells, self.ux,self.uy,self.umag,self.epsE, self.S,self.B,self.H,self.mask = self.npinputs()
319-
self.triang = self.triang(self.coords, self.cells, mapscale=self.mapscale)
320+
self.triang = self.get_triang(self.coords, self.cells, mapscale=self.mapscale)
321+
322+
def set_adjustedcoords(self, xoffset=0, yoffset=0, rotang=0):
323+
324+
### Translate points so that (x0,y0) is new origin
325+
326+
xt, yt = self.coords[0]-xoffset, self.coords[1]-yoffset # translated coords
327+
x0t, y0t = self.x0-xoffset, self.y0-yoffset # mesh corners
328+
x1t, y1t = self.x1-xoffset, self.y1-yoffset # mesh corners
329+
330+
# rotate points around new origin
331+
if rotang:
332+
Q = R.from_euler('z', rotang, degrees=True).as_matrix()[0:2,0:2]
333+
xf, yf = np.array([ np.matmul(Q,[xt[ii],yt[ii]]) for ii in range(len(xt[:])) ]).T
334+
self.ux, self.uy = np.array([ np.matmul(Q,[self.ux[ii],self.uy[ii]]) for ii in range(len(self.ux[:])) ]).T
335+
else:
336+
xf, yf = xt, yt
337+
338+
self.coords[0,:], self.coords[1,:] = xf, yf
339+
self.triang = self.get_triang(self.coords, self.cells, mapscale=self.mapscale)
340+
341+
return Q
320342

321343
def bmesh(self, mapscale=1):
322344

@@ -386,6 +408,7 @@ def plot_generic(self, ax, F, kw_tcf=dict(), kw_cb=dict(), kw_cax=dict()):
386408
kw_tcf.pop('vcenter')
387409
cs = ax.tricontourf(self.triang, F, **kw_tcf)
388410
hcb = plt.colorbar(cs, cax=self.newcax(ax, **kw_cax), **kw_cb)
411+
hcb.ax.yaxis.label.set_multialignment('center')
389412
return (cs, hcb)
390413

391414
def plot_velocities(self, ax, kw_cb=dict(label=r'$u$ (m/yr)'), kw_cax=dict(), \
@@ -461,8 +484,8 @@ def savefig(self, fig, fname, dpi=150, pad_inches=0.1, bbox_inches='tight'):
461484

462485
fig.savefig(fname, dpi=dpi, pad_inches=pad_inches, bbox_inches=bbox_inches)
463486

464-
def setupaxis(self, ax, boundaries=False, floating=True, mesh=False, bgcolor='0.85', showyaxis=True, \
465-
xlims=None, ylims=None, xticks_major=None, xticks_minor=None, yticks_major=None, yticks_minor=None):
487+
def setupaxis(self, ax, boundaries=False, floating=True, mesh=False, bgcolor='0.85', showxaxis=True, showyaxis=True, axform='square', \
488+
xlims=None, ylims=None, xticks_major=None, xticks_minor=None, yticks_major=None, yticks_minor=None, ylabelpad=None):
466489

467490
legh, legt = [], []
468491

@@ -488,16 +511,19 @@ def setupaxis(self, ax, boundaries=False, floating=True, mesh=False, bgcolor='0.
488511
legh.append(Line2D([0], [0], color=self.c_floating, lw=2))
489512
legt.append('Floating')
490513

491-
ax.axis('square')
492-
ax.set_xlabel(r'$x$ (km)')
514+
if axform is not None: ax.axis(axform)
493515

494-
if xticks_major is not None: ax.set_xticks(xticks_major)
495-
if xticks_minor is not None: ax.set_xticks(xticks_minor, minor=True)
496-
516+
if showxaxis:
517+
if xticks_major is not None: ax.set_xticks(xticks_major)
518+
if xticks_minor is not None: ax.set_xticks(xticks_minor, minor=True)
519+
ax.set_xlabel(r'$x$ (km)')
520+
else:
521+
ax.tick_params('x', labelbottom=False)
522+
497523
if showyaxis:
498524
if yticks_major is not None: ax.set_yticks(yticks_major)
499525
if yticks_minor is not None: ax.set_yticks(yticks_minor, minor=True)
500-
ax.set_ylabel(r'$y$ (km)')
526+
ax.set_ylabel(r'$y$ (km)', labelpad=ylabelpad)
501527
else:
502528
ax.tick_params('y', labelleft=False)
503529

src/specfabpy/firedrake/ice.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ def weakform(self, s, u,S, dt, iota=None, Gamma0=None, Lambda0=None, zeta=0):
189189
ENABLE_REG = True
190190

191191
# Flattened strain-rate and spin tensors for accessing them per node
192-
Df = project( sym(grad(u)), self.G).vector()[:] # strain rate
193-
Wf = project(skew(grad(u)), self.G).vector()[:] # spin
194-
Sf = project(S, self.G).vector()[:] # deviatoric stress
192+
Df = project( sym(grad(u)), self.G).dat.data_ro # strain rate
193+
Wf = project(skew(grad(u)), self.G).dat.data_ro # spin
194+
Sf = project(S, self.G).dat.data_ro # deviatoric stress
195195

196196
# Same but in 3D for fabric problem
197197
D3 = self.mat3d(Df) # [node,3,3]
@@ -205,16 +205,16 @@ def weakform(self, s, u,S, dt, iota=None, Gamma0=None, Lambda0=None, zeta=0):
205205

206206
# Populate entries of dynamical matrices *row-wise* (row index is ii)
207207
for ii in self.srrng:
208-
if ENABLE_LROT: self.Mrr_LROT[ii].vector()[:] = M_LROT[:,ii,:] # all nodes, row=ii, all columns
209-
if ENABLE_DDRX: self.Mrr_DDRX_src[ii].vector()[:] = M_DDRX_src[:,ii,:]
210-
if ENABLE_REG: self.Mrr_REG[ii].vector()[:] = M_REG[:,ii,:]
208+
if ENABLE_LROT: self.Mrr_LROT[ii].dat.data[:] = M_LROT[:,ii,:] # all nodes, row=ii, all columns
209+
if ENABLE_DDRX: self.Mrr_DDRX_src[ii].dat.data[:] = M_DDRX_src[:,ii,:]
210+
if ENABLE_REG: self.Mrr_REG[ii].dat.data[:] = M_REG[:,ii,:]
211211

212212
### Construct weak form
213213

214214
# dummy zero term to make rhs(F) work when solving steady-state problem
215215
# this can probably be removed once the SSA source/sink terms are added
216216
s_null = Function(self.S)
217-
s_null.vector()[:] = 0.0
217+
s_null.dat.data[:] = 0.0
218218
F = dot(s_null, self.w)*dx
219219

220220
# Time derivative
@@ -277,7 +277,7 @@ def _setaux(self, u=None):
277277
Set auxiliary fields
278278
"""
279279
sp = project(self.s, self.Sd)
280-
self.rnlm = np.array([sp.sub(ii).vector()[:] + 0j for ii in self.srrng]) # reduced form (rnlm) per node
280+
self.rnlm = np.array([sp.sub(ii).dat.data_ro + 0j for ii in self.srrng]) # reduced form (rnlm) per node
281281
self.nlm = np.array([self.sf.rnlm_to_nlm(self.rnlm[:,nn], self.nlm_len) for nn in self.dofs0]) # full form (nlm) per node (nlm[node,coef])
282282

283283
if self.setextra:
@@ -302,26 +302,26 @@ def get_pfJ(self, *args, **kwargs):
302302
Pole figure J (pfJ) index
303303
"""
304304
pfJ = Function(self.Rd)
305-
pfJ.vector()[:] = sfcom.pfJ(self.nlm, *args, **kwargs)[:]
305+
pfJ.dat.data[:] = sfcom.pfJ(self.nlm, *args, **kwargs)[:]
306306
return pfJ
307307

308308
def get_E_CAFFE(self, u):
309309
"""
310310
CAFFE model (Placidi et al., 2010)
311311
"""
312-
Df = project(sym(grad(u)), self.Gd).vector()[:]
312+
Df = project(sym(grad(u)), self.Gd).dat.data_ro
313313
E_CAFFE = Function(self.Rd)
314-
E_CAFFE.vector()[:] = self.sf.E_CAFFE_arr(self.nlm, self.mat3d(Df), *self.CAFFE_params)
314+
E_CAFFE.dat.data[:] = self.sf.E_CAFFE_arr(self.nlm, self.mat3d(Df), *self.CAFFE_params)
315315
return E_CAFFE
316316

317317
def get_E_EIE(self, u):
318318
"""
319319
EIE model (Rathmann et al., in prep)
320320
*** Not yet implemented ***
321321
"""
322-
# Df = project(sym(grad(u)), self.Gd).vector()[:]
322+
# Df = project(sym(grad(u)), self.Gd).dat.data_ro
323323
E_EIE = Function(self.Rd)
324-
# E_EIE.vector()[:] = self.sf.E_EIE_arr(...)
324+
# E_EIE.dat.data[:] = self.sf.E_EIE_arr(...)
325325
return E_EIE
326326

327327
def get_Eij(self, ei=(), xyz_sort=False):
@@ -348,12 +348,12 @@ def get_Eij(self, ei=(), xyz_sort=False):
348348
Eij_fs = [Function(self.Rd) for _ in range(6)] # Eij enhancement tensor
349349

350350
for ii in range(3): # mi=m1,m2,m3
351-
lami_fs[ii].vector()[:] = lami[:,ii]
351+
lami_fs[ii].dat.data[:] = lami[:,ii]
352352
for jj in range(3): # j=x,y,z
353-
ei_fs[ii].sub(jj).vector()[:] = ei[ii][:,jj]
353+
ei_fs[ii].sub(jj).dat.data[:] = ei[ii][:,jj]
354354

355355
for kk in range(6):
356-
Eij_fs[kk].vector()[:] = Eij[:,kk]
356+
Eij_fs[kk].dat.data[:] = Eij[:,kk]
357357

358358
return (ei_fs, Eij_fs, lami_fs)
359359

@@ -371,12 +371,12 @@ def get_lamxi(self, s=None):
371371

372372
rows = np.arange(len(lami))
373373
lami_fs = [Function(self.Rd) for _ in range(3)] # a2 eigenvalues (lami)
374-
lami_fs[0].vector()[:] = lami[rows, Ix]
375-
lami_fs[1].vector()[:] = lami[rows, Iy]
376-
lami_fs[2].vector()[:] = lami[rows, Iz]
374+
lami_fs[0].dat.data[:] = lami[rows, Ix]
375+
lami_fs[1].dat.data[:] = lami[rows, Iy]
376+
lami_fs[2].dat.data[:] = lami[rows, Iz]
377377

378378
dlamxy = Function(self.Rd)
379-
dlamxy.vector()[:] = lami[rows, Ix] - lami[rows, Iy]
379+
dlamxy.dat.data[:] = lami[rows, Ix] - lami[rows, Iy]
380380

381381
return lami_fs, dlamxy
382382

src/specfabpy/firedrake/mesh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def print_setup(self):
6666

6767
def dt_CFL(self, u):
6868

69-
ux_max = abs(u.sub(0).vector()[:]).max()
69+
ux_max = abs(u.sub(0).dat.data_ro).max()
7070
dt_CFL = 0.5*self.hx_min/ux_max
7171
return dt_CFL # CFL timestep size
7272

@@ -195,7 +195,7 @@ def print_setup(self):
195195

196196
def dt_CFL(self, u):
197197

198-
ux_max = abs(u.sub(0).vector()[:]).max()
198+
ux_max = abs(u.sub(0).dat.data_ro).max()
199199
dt_CFL = 0.5*self.hx_min/ux_max
200200
return dt_CFL # CFL timestep size
201201

src/specfabpy/plotting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def plotcoordaxes(ax, geo, axislabels='xi', color=c_dred, fontsize=None, negaxes
164164
elif axislabels == 'vuxi': lbls = [r'$\vu{x}$',r'$\vu{y}$',r'$\vu{z}$']
165165
elif axislabels == 'vuei': lbls = [r'$\vu{e}_1$',r'$\vu{e}_2$',r'$\vu{e}_3$']
166166
elif axislabels == 'vmi': lbls = [r'$\vb{m}_1$',r'$\vb{m}_2$',r'$\vb{m}_3$']
167+
elif axislabels == 'vunt': lbls = [r'$\vu{t}$',r'$\vu{n}$',r'$\vu{z}$']
167168
else: raise ValueError('sfplt.plotcoordinateaxes(): Note sure what to do with passed axislabels.')
168169
elif isinstance(axislabels, list) and len(axislabels) == 3:
169170
lbls = axislabels

tests/firedrake/simpleshear.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
iota = +1 # deck-of-cards behaviour for lattice rotation
4242
Tice = -15 # Ice temperature (deg. C) for DDRX rate factor
4343

44-
ENABLE_DDRX = True
44+
ENABLE_DDRX = False
4545

4646
### Viscous anisotropy homogenization parameters
4747

@@ -74,7 +74,7 @@
7474
tau = fd.project(fd.sym(fd.grad(u)), T) # assume driving stress is coaxial to strain-rate (in two-way coupling this should be modelled tau)
7575

7676
h_min = 1/nx
77-
v_max = abs(u.vector()[:]).max()
77+
v_max = abs(u.dat.data_ro).max()
7878
dt_CFL = 0.5*h_min/v_max
7979
dt = 2*dt_CFL # more aggresive time-stepping than CFL
8080

@@ -83,7 +83,7 @@
8383
fabric = IceFabric(mesh, boundaries, L, **kw_num, **kw_VA) # initializes as isotropic fabric field
8484
fabric.set_isotropic_BCs((1,)) # isotropic ice incoming from left-hand boundary, remaining boundaries are free (no fabric fluxes)
8585

86-
Gamma0 = None
86+
Gamma0 = Gamma0_list = None
8787
if ENABLE_DDRX:
8888
Gamma0 = fabric.Gamma0_Lilien23_EDC(u,Tice+273.15)
8989
Gamma0_list = [fabric.Gamma0_Lilien23_EDC(u,_+273.15) for _ in np.linspace(-40,Tice,3)] # list of DDRX rate factors used to gradually approach solution

0 commit comments

Comments
 (0)