def nodalSum(val,elems,avg=False,return_all=True,direction_treshold=None): """Compute the nodal sum of values defined on elements. val is a (nelems,nplex,nval) array of values defined at points of elements. elems is a (nelems,nplex) array with nodal ids of all points of elements. The return value is a (nelems,nplex,nval) array where each value is replaced with the sum of its value at that node. If avg=True, the values are replaced with the average instead. (DOES NOT WORK YET) If return_all==True(default), returns an array with shape (nelems,nplex,3), else, returns an array with shape (maxnodenr+1,3). In the latter case, nodes not occurring in elems will have all zero values. If a direction_tolerance is specified and nval > 1, values will only be summed if their direction is close (projection of one onto the other is higher than the specified tolerance). """ if val.ndim != 3: val.reshape(val.shape+(1,)) if elems.shape != val.shape[:2]: raise RuntimeError,"shape of val and elems does not match" work = zeros((elems.max()+1,val.shape[2])) if GD.options.safelib: val = val.astype(float32) elems = elems.astype(int32) work = work.astype(float32) if val.shape[2] > 1 and direction_treshold is not None: misc.nodalSum2(val,elems,direction_treshold) else: misc.nodalSum(val,elems,work,avg) if return_all: return val else: return work
def nodalSum(val,elems,avg=False): """Compute the nodal sum of values defined on elements. val is a (nelems,nplex,nval) array of values defined at points of elements. elems is a (nelems,nplex) array with nodal ids of all points of elements. The return value is a (nelems,nplex,nval) array where each value is replaced with the sum of its value at that node. If avg=True, the values are replaced with the average instead. """ if val.ndim != 3: val.reshape(val.shape+(1,)) if elems.shape != val.shape[:2]: raise RuntimeError,"shape of val and elems does not match" nodes = unique1d(elems) work = zeros((nodes.max()+1,val.shape[2])) if GD.options.safelib: val = val.astype(float32) elems = elems.astype(int32) nodes = nodes.astype(int32) work = work.astype(float32) misc.nodalSum(val,elems,nodes,work,avg) return val