Commit 0127284b authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

missing files

parent 6aced34c
Pipeline #9831 failed with stages
in 7 minutes
import numpy as np
class CSR :
def __init__(self, idx, rhsidx,constraints):
pairs = np.ndarray([idx.shape[0],idx.shape[1],idx.shape[1]],dtype=([('i0',np.int32),('i1',np.int32)]))
pairs['i0'][:,:,:] = idx[:,:,None]
pairs['i1'][:,:,:] = idx[:,None,:]
pairs = pairs.reshape([-1])
allpairs = [pairs.reshape([-1])]
num = np.max(idx)
self.ndof = num+1
self.constraints = constraints
for c in constraints :
num += 1
pairs = np.ndarray([c.size*2+1],dtype=([('i0',np.int32),('i1',np.int32)]))
pairs['i0'][:c.size] = c
pairs['i1'][:c.size] = num
pairs['i0'][c.size:c.size*2] = num
pairs['i1'][c.size:c.size*2] = c
pairs['i0'][c.size*2] = num
pairs['i1'][c.size*2] = num
allpairs.append(pairs)
pairs = np.concatenate(allpairs)
pairs, pmap = np.unique(pairs,return_inverse=True)
self.map = []
count = 0
for p in allpairs :
self.map.append(pmap[count:count+p.size])
count += p.size
self.row = np.hstack([np.array([0],dtype=np.int32),
np.cumsum(np.bincount(pairs["i0"]),
dtype=np.int32)])
self.col = pairs['i1'].copy()
self.size = self.row.size-1
self.rhsidx = rhsidx
def assemble_rhs(self, localv, u, constraints_value) :
rhs = np.bincount(self.rhsidx,localv,self.size)
for i, (c, cv) in enumerate(zip(self.constraints, constraints_value)):
rhs[i+self.ndof] = cv[1] + np.sum(u[c]*cv[0])
return rhs
def assemble_mat(self, localm, constraints_value, v) :
v[:] = np.bincount(self.map[0],localm,self.col.size)
for cmap, cv in zip (self.map[1:], constraints_value) :
v += np.bincount(cmap, np.concatenate((cv[0],cv[0],[0])), self.col.size)
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