#print(i) IntNode.append([node,node.get_node_id()]) IntNode_ID=sorted(IntNode, key = itemgetter(1)) IntNode_Ordered=[node[0] for node in IntNode_ID] #print(IntNode_Ordered,IntNode_Ordered[0].get_node_id()._id_no) # # # for j, node in enumerate(IntNode_Ordered): boundary_sum=[] id1=node.get_node_id() coord=node.get_coord() for endpt in (connect_iterator(grid, id1)): if grid.get_slave(endpt): connect_value=grid.get_matrix_value(id1, endpt) #print(node.get_node_id()._id_no,endpt._id_no) boundary_sum.append(true_soln(grid.get_coord(endpt))*connect_value) load_vector[j]=load_vector[j]-sum(boundary_sum) #print(load_vector) # for i in range(len(IntNode_Ordered)): load_value=IntNode_Ordered[i].get_load() #print(load_value) load_vector[i]= load_vector[i]+load_value # # Enumerate interior NodeID in order of ID NodeID_Load=[]
# Which row corresponds to the current node? i = int(node.get_value()) # Add in the entry to the load vector coord = node.get_coord() load_vector[i] = load_vector[i] + rhs(coord) # Loop over the matrix entries in the current row for endpt1 in connect_iterator(grid, node.get_node_id()): # Which column corresponds to the current node? j = int(grid.get_value(endpt1)) # What is the corresponding matrix value (in the FEM grid) stiffness = grid.get_matrix_value(node.get_node_id(), endpt1)[0] # We must not include slave nodes in the matrix columns if not grid.get_slave(endpt1): fem_matrix[i, j] = stiffness # Update the load vector to take non-zero boundary conditions # into account else: coord = grid.get_coord(endpt1) load_vector[i] = load_vector[i] - stiffness * true_soln(coord) # Solve the system Ax = b value_vector = linalg.solve(fem_matrix, load_vector) # Initialise a vector to keep track of the errors
#print(q) NodeID_Load.append(node.get_node_id()) NodeID_Load.sort() # For every NodeID in NodeID_load, find its connecting nodes, reorder them and assign them in stiffness matrix for i, nodeid in enumerate(NodeID_Load): Endpt=[] for j, endpt1 in enumerate(connect_iterator(grid, nodeid)): Endpt.append(endpt1) Endpt.sort() #B=[] for k,endpt2 in enumerate(Endpt): #B.append([k,endpt2]) stiffness = grid.get_matrix_value(nodeid,endpt2) fem_matrix[i,k]=stiffness*float(64) #print(i,k,nodeid._id_no,endpt2._id_no,stiffness) #print(nodeid._id_no,endpt2._id_no,stiffness) ############################################################## #print(fem_matrix) ############################################################# #Solve for the apprxoimating nodal value and find the true value at those nodes value_vector = linalg.solve(fem_matrix , load_vector) true_vector=[] for i in range(len(IntNode_Ordered)): true_vector.append(true_soln(IntNode_Ordered[i].get_coord()))