Commit 9b1a78fc authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

minor polishing

parent 13c3b511
Pipeline #9836 passed with stages
in 7 minutes and 48 seconds
......@@ -82,19 +82,19 @@ class LinearSystem :
n_nodes = np.max(elements)+1
self.globalsize = n_nodes*n_fields+len(constraints)
self.localsize = elements.shape[1]*n_fields
self.idx = (elements[:,None,:]*n_fields+np.arange(n_fields)[None,:,None]).reshape([-1])
idxf = ((elements[:,:,None]*n_fields+np.arange(n_fields)[None,None,:]).reshape([-1])+1).astype(np.int32)
eltptr = np.arange(1,elements.size*n_fields+2,self.localsize)
self.idx = (elements[:,None,:]*n_fields+np.arange(n_fields)[None,:,None])
idxf = [self.idx.swapaxes(1,2)+1]
eltptr = [np.arange(1,elements.size*n_fields+2,self.localsize)]
self.ndof = n_nodes*n_fields
num = self.ndof
self.n_fields = n_fields
self.constraints = constraints
for constraint in constraints:
idxc = np.c_[np.full(constraint.shape[0], num+1), constraint[:,0]*n_fields+constraint[:,1]+1].flatten()
idxf = np.concatenate((idxf,idxc))
eltptr = np.concatenate((eltptr, eltptr[-1]+np.arange(2,constraint.shape[0]*2+2,2)))
num += 1
for i,constraint in enumerate(constraints):
idxc = np.c_[np.full(constraint.shape[0], self.ndof+i+1), constraint[:,0]*n_fields+constraint[:,1]+1].flatten()
idxf.append(idxc)
eltptr.append(eltptr[-1][-1]+np.arange(2,constraint.shape[0]*2+2,2))
lib2.mumps_element_new.restype = ctypes.c_void_p
eltptr = np.concatenate([i.flat for i in eltptr])
idxf = np.concatenate([i.flat for i in idxf])
self.mumps_ptr = ctypes.c_void_p(lib2.mumps_element_new(ctypes.c_int(self.globalsize),ctypes.c_int(eltptr.size-1),_np2c(eltptr,np.int32),_np2c(idxf,np.int32)))
options = None if options=="" else options
if options is not None:
......@@ -108,15 +108,18 @@ class LinearSystem :
@timeit
def local_to_global(self,localv,localm,u, constraints_values):
rhs = np.bincount(self.idx,localv,self.globalsize)
rhs = np.bincount(self.idx.flatten(),localv,self.globalsize)
for i, (c, cv) in enumerate(zip(self.constraints,constraints_values)):
rhs[i+self.ndof] = cv[1] + np.sum(u[c[:,0]*self.n_fields+c[:,1]]*cv[0])
self.v = localm.reshape([-1])
self.v = np.empty(localm.size+sum(c.shape[0]*4 for c in self.constraints))
p = localm.size
self.v[:p] = localm.flat
for constraint, cv in constraints_values:
localc = np.zeros((constraint.shape[0],4))
localc[:,1] = constraint
localc[:,2] = constraint
self.v = np.concatenate([self.v,localc.flatten()])
self.v[p:localc.size+p] = localc.flat
p += localc
return rhs
@timeit
......
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