From 3467f2565af6d389e551896e0e8cccbcbf1abebd Mon Sep 17 00:00:00 2001 From: Paul Dechamps <paul.dechamps@uliege.be> Date: Thu, 27 Feb 2025 18:39:18 +0100 Subject: [PATCH] (feat) Update dart interface for new data structures --- blast/interfaces/dart/blDartInterface.py | 73 +++++++++++++----------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/blast/interfaces/dart/blDartInterface.py b/blast/interfaces/dart/blDartInterface.py index aae4b22..e872063 100644 --- a/blast/interfaces/dart/blDartInterface.py +++ b/blast/interfaces/dart/blDartInterface.py @@ -168,12 +168,17 @@ class DartInterface(SolversInterface): for bodyName in self.blw.keys(): ibody = self.mapBodyNameToIndex[bodyName] for ireg in range(len(self.iBnd[ibody])): - for iRow, row in enumerate(self.iBnd[ibody][ireg].nodesCoord[:,3]): - row=int(row) - for iDim in range(3): - self.iBnd[ibody][ireg].V[iRow,iDim] = self.solver.U[row][iDim] - self.iBnd[ibody][ireg].M[iRow] = self.solver.M[row] - self.iBnd[ibody][ireg].Rho[iRow] = self.solver.rho[row] + reg = self.iBnd[ibody][ireg] + V = np.empty((reg.getnNodes(), self.getnDim())) + M = np.empty(reg.getnNodes()) + Rho = np.empty(reg.getnNodes()) + for iRow, row in enumerate(self.iBnd[ibody][ireg].getNodeRows()): + row = int(row) # From np.int64 to int + for iDim in range(self.getnDim()): + V[iRow,iDim] = self.solver.U[row][iDim] + M[iRow] = self.solver.M[row] + Rho[iRow] = self.solver.rho[row] + self.iBnd[ibody][ireg].updateVariables(M, V, Rho) def setBlowingVelocity(self): """Impose the blowing boundary condition @@ -185,7 +190,7 @@ class DartInterface(SolversInterface): b = self.blw[bodyName][self.mapBlwIndexToBlwName[bodyName][ireg]] if self.getnDim() == 2: self.iBnd[ibody][ireg].connectBlowingVel() - for i, blw in enumerate(self.iBnd[ibody][ireg].blowingVel): + for i, blw in enumerate(self.iBnd[ibody][ireg].getBlowingVelocity()): b.setU(i, blw) # TODO: Remove the fact that getWing has to set iBnd. @@ -281,8 +286,6 @@ class DartInterface(SolversInterface): Name of the body. """ ibody = self.mapBodyNameToIndex[name] - # Initialize boundary - self.iBnd[ibody][0].initStructures(self.blw[name]['wing'].nodes.size(), self.blw[name]['wing'].tag.elems.size()) # Node number N1 = np.zeros(self.blw[name]['wing'].nodes.size(), dtype=int) # Index in boundary.nodes @@ -387,19 +390,21 @@ class DartInterface(SolversInterface): for i, e in enumerate(self.blw[name]['wing'].tag.elems): connect2[connectListElems[i]] = i - self.iBnd[ibody][0].nodesCoord = np.column_stack((data[:,1], data[:,2],\ - data[:,3], data[:,4])) - self.iBnd[ibody][0].setConnectList(connectListNodes, connect2) - elemCoord = np.zeros((len(self.iBnd[ibody][0].nodesCoord)-1, 4)) + elemCoord = np.zeros((len(data)-1, 4)) + elemsRows = np.zeros((len(data)-1), dtype=int) for i in range(len(elemCoord[:,0])): - elemCoord[i,0] = 0.5 * (self.iBnd[ibody][0].nodesCoord[i,0] + self.iBnd[ibody][0].nodesCoord[i+1,0]) - elemCoord[i,1] = 0.5 * (self.iBnd[ibody][0].nodesCoord[i,1] + self.iBnd[ibody][0].nodesCoord[i+1,1]) - elemCoord[i,2] = 0.5 * (self.iBnd[ibody][0].nodesCoord[i,2] + self.iBnd[ibody][0].nodesCoord[i+1,2]) - elemCoord[i,3] = i - self.iBnd[ibody][0].elemsCoord = elemCoord + elemCoord[i,0] = 0.5 * (data[i,1] + data[i+1,1]) + elemCoord[i,1] = 0.5 * (data[i,2] + data[i+1,2]) + elemCoord[i,2] = 0.5 * (data[i,3] + data[i+1,3]) + elemsRows[i] = i + + nodesCoord = np.column_stack((data[:,1], data[:,2],\ + data[:,3])) + self.iBnd[ibody][0].setMesh(nodesCoord, elemCoord[:,:3]) + self.iBnd[ibody][0].setConnectLists(connectListNodes, connect2) + self.iBnd[ibody][0].setRows(data[:,4], elemsRows) # Wake - self.iBnd[ibody][1].initStructures(self.blw[name]['wake'].nodes.size(), self.blw[name]['wake'].tag.elems.size()) # Node number N1 = np.zeros(self.blw[name]['wake'].nodes.size(), dtype=int) # Index in boundary.nodes @@ -432,21 +437,23 @@ class DartInterface(SolversInterface): dataW[:,2] = dataW[connectListNodes,2] dataW[:,3] = dataW[connectListNodes,3] dataW[:,4] = dataW[connectListNodes,4] - self.iBnd[ibody][1].nodesCoord = np.column_stack((dataW[:,1], dataW[:,2], \ - dataW[:,3], dataW[:,4])) connect2_w = np.zeros((len(connectListElems)), dtype=int) for i, e in enumerate(self.blw[name]['wake'].tag.elems): connect2_w[connectListElems[i]] = i - self.iBnd[ibody][1].setConnectList(connectListNodes, connect2_w) + nodesCoord_w = np.column_stack((dataW[:,1], dataW[:,2], \ + dataW[:,3])) - elemCoordW = np.zeros((len(self.iBnd[ibody][1].nodesCoord)-1, 4)) + elemCoordW = np.zeros((len(dataW)-1, 3)) + elemsRows_w = np.zeros((len(dataW)-1), dtype=int) for i in range(len(elemCoordW[:,0])): - elemCoordW[i,0] = 0.5 * (self.iBnd[ibody][1].nodesCoord[i,0] + self.iBnd[ibody][1].nodesCoord[i+1,0]) - elemCoordW[i,1] = 0.5 * (self.iBnd[ibody][1].nodesCoord[i,1] + self.iBnd[ibody][1].nodesCoord[i+1,1]) - elemCoordW[i,2] = 0.5 * (self.iBnd[ibody][1].nodesCoord[i,2] + self.iBnd[ibody][1].nodesCoord[i+1,2]) - elemCoordW[i,3] = i - self.iBnd[ibody][1].elemsCoord = elemCoordW + elemCoordW[i,0] = 0.5 * (dataW[i,1] + dataW[i+1,1]) + elemCoordW[i,1] = 0.5 * (dataW[i,2] + dataW[i+1,2]) + elemCoordW[i,2] = 0.5 * (dataW[i,3] + dataW[i+1,3]) + elemsRows_w[i] = i + self.iBnd[ibody][1].setMesh(nodesCoord_w, elemCoordW) + self.iBnd[ibody][1].setConnectLists(connectListNodes, connect2_w) + self.iBnd[ibody][1].setRows(dataW[:,4], elemsRows_w) def __getWing3D(self, name:str): """Obtain the nodes' location and row and cg of all elements. @@ -478,10 +485,9 @@ class DartInterface(SolversInterface): i += 1 for n in range(len(data)): - self.iBnd[ibody][n].initStructures(data[n].shape[0], cg[n].shape[0]) - self.iBnd[ibody][n].nodesCoord = data[n] - self.iBnd[ibody][n].elemsCoord = cg[n] - self.iBnd[ibody][n].setConnectList(data[n][:,3], cg[n][:,3]) + self.iBnd[ibody][n].setMesh(data[n][:,:3], cg[n][:,:3]) + self.iBnd[ibody][n].setConnectLists(data[n][:,3], cg[n][:,3]) + self.iBnd[ibody][n].setRows(data[n][:,3], cg[n][:,3]) ### Getters def getAoA(self): @@ -571,7 +577,8 @@ class DartInterface(SolversInterface): return 1.0 elif self.getnDim() == 3: ibody = self.mapBodyNameToIndex[name] - return np.max(self.iBnd[ibody][0].nodesCoord[:,1]) - np.min(self.iBnd[ibody][0].nodesCoord[:,1]) + nodes = self.iBnd[ibody][0].getNodes('all') + return np.max(nodes[:,1]) - np.min(nodes[:,1]) else: raise RuntimeError('Incorrect number of dimensions') -- GitLab