From c98140c4651f99e34203a65e7af9a64da9f97be9 Mon Sep 17 00:00:00 2001
From: Paul Dechamps <paul.dechamps@uliege.be>
Date: Fri, 21 Apr 2023 16:12:35 +0200
Subject: [PATCH] Fixed bug in wake BC for VII + Minor improvements.

---
 vii/coupler.py                       | 12 ++++++------
 vii/interfaces/dart/DartInterface.py |  7 +++++--
 vii/src/DDriver.cpp                  |  2 +-
 vii/tests/bli2D.py                   | 10 +++++-----
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/vii/coupler.py b/vii/coupler.py
index 7c6ead6..c60a22a 100644
--- a/vii/coupler.py
+++ b/vii/coupler.py
@@ -52,7 +52,7 @@ class Coupler:
             
             # Write inviscid Cp distribution.
             if couplIter == 0:
-                self.iSolverAPI.writeCp()
+                self.iSolverAPI.writeCp(sfx='_Inviscid')
 
             # Impose inviscid boundary in the viscous solver.
             self.tms['processing'].start()
@@ -74,16 +74,16 @@ class Coupler:
             # Check convergence status.
             error = abs((self.vSolver.Cdt - cdPrev) / self.vSolver.Cdt) if self.vSolver.Cdt != 0 else 1
             if error <= self.couplTol:
-                print(ccolors.ANSI_GREEN, '{:>4.0f}| {:>10.5f} {:>10.5f} | {:>10.4f} {:>8.4f} {:>8.2f}\n'.format(couplIter, self.iSolverAPI.getCl(), self.vSolver.Cdt, self.vSolver.getxtr(0, 0), self.vSolver.getxtr(0, 1), np.log10(error)), ccolors.ANSI_RESET)
+                print(ccolors.ANSI_GREEN, '{:>4.0f}| {:>7.5f} {:>7.5f} {:>7.5f} | {:>6.4f} {:>6.4f} | {:>6.3f}\n'.format(couplIter, self.iSolverAPI.getCl(), self.iSolverAPI.getCd()+self.vSolver.Cdf, self.vSolver.Cdt, self.vSolver.getxoctr(0, 0), self.vSolver.getxoctr(0, 1), np.log10(error)), ccolors.ANSI_RESET)
                 return aeroCoeffs
             cdPrev = self.vSolver.Cdt
 
             if couplIter == 0:
                 print('- AoA: {:<2.2f} Mach: {:<1.1f} Re: {:<2.1f}e6'.format(self.iSolverAPI.getAoA()*180/math.pi, self.iSolverAPI.getMinf(), self.vSolver.getRe()/1e6))
-                print('{:>5s}| {:>10s} {:>10s} | {:>10s} {:>8s} {:>8s}'.format('It', 'Cl', 'Cd', 'xtrT', 'xtrB', 'Error'))
+                print('{:>5s}| {:>7s} {:>7s} {:>7s} | {:>6s} {:>6s} | {:>6s}'.format('It', 'Cl', 'Cd', 'Cdwake', 'xtrT', 'xtrB', 'Error'))
                 print('  ----------------------------------------------------------')
             if couplIter % self.iterPrint == 0:
-                print(' {:>4.0f}| {:>10.4f} {:>10.4f} | {:>10.4f} {:>8.4f} {:>8.3f}'.format(couplIter, self.iSolverAPI.getCl(), self.vSolver.Cdt, self.vSolver.getxtr(0, 0), self.vSolver.getxtr(0, 1), np.log10(error)))
+                print(' {:>4.0f}| {:>7.4f} {:>7.4f} {:>7.4f} | {:>6.4f} {:>6.4f} | {:>6.3f}'.format(couplIter, self.iSolverAPI.getCl(), self.iSolverAPI.getCd()+self.vSolver.Cdf, self.vSolver.Cdt, self.vSolver.getxoctr(0, 0), self.vSolver.getxoctr(0, 1), np.log10(error)))
                 if self.iSolverAPI.getVerbose() != 0 or self.vSolver.verbose != 0:
                     print('')
             couplIter += 1
@@ -91,7 +91,7 @@ class Coupler:
         else:
             print(ccolors.ANSI_RED, 'Maximum number of {:<.0f} coupling iterations reached'.format(self.maxCouplIter), ccolors.ANSI_RESET)
             print('')
-            print('{:>5s}| {:>10s} {:>10s} | {:>10s} {:>8s} {:>8s}'.format('It', 'Cl', 'Cd', 'xtrT', 'xtrB', 'Error'))
+            print('{:>5s}| {:>7s} {:>7s} {:>7s} | {:>6s} {:>8s} | {:>6s}'.format('It', 'Cl', 'Cd', 'Cdwake', 'xtrT', 'xtrB', 'Error'))
             print('  ----------------------------------------------------------')
-            print(ccolors.ANSI_RED, '{:>4.0f}| {:>10.5f} {:>10.5f} | {:>10.4f} {:>8.4f} {:>8.2f}\n'.format(couplIter, self.iSolverAPI.getCl(), self.vSolver.Cdt, self.vSolver.getxtr(0, 0), self.vSolver.getxtr(0, 1), np.log10(error)), ccolors.ANSI_RESET)
+            print(ccolors.ANSI_RED, '{:>4.0f}| {:>7.5f} {:>7.5f} {:>7.5f} | {:>6.4f} {:>7.4f} | {:>6.3f}\n'.format(couplIter, self.iSolverAPI.getCl(), self.iSolverAPI.getCd()+self.vSolver.Cdf, self.vSolver.Cdt, self.vSolver.getxoctr(0, 0), self.vSolver.getxoctr(0, 1), np.log10(error)), ccolors.ANSI_RESET)
             return aeroCoeffs
\ No newline at end of file
diff --git a/vii/interfaces/dart/DartInterface.py b/vii/interfaces/dart/DartInterface.py
index 217cc44..70b2514 100644
--- a/vii/interfaces/dart/DartInterface.py
+++ b/vii/interfaces/dart/DartInterface.py
@@ -50,11 +50,11 @@ class DartInterface:
     def run(self):
         return self.solver.run()
     
-    def writeCp(self):
+    def writeCp(self, sfx=''):
         """ Write Cp distribution around the airfoil on file.
         """
         Cp = floU.extract(self.group[0].boundary.tag.elems, self.solver.Cp)
-        tboxU.write(Cp, 'Cp_Inviscid.dat', '%1.5e',', ', 'x, y, z, Cp', '')
+        tboxU.write(Cp, 'Cp'+sfx+'.dat', '%1.5e',', ', 'x, y, z, Cp', '')
     
     def save(self, writer):
         self.solver.save(writer)
@@ -67,6 +67,9 @@ class DartInterface:
     
     def getCl(self):
         return self.solver.Cl
+    
+    def getCd(self):
+        return self.solver.Cd
 
     def getCm(self):
         return self.solver.Cm
diff --git a/vii/src/DDriver.cpp b/vii/src/DDriver.cpp
index 8000696..35d8b3c 100644
--- a/vii/src/DDriver.cpp
+++ b/vii/src/DDriver.cpp
@@ -191,7 +191,7 @@ int Driver::run(unsigned int const couplIter)
                 for (size_t k = 0; k < upperConditions.size(); ++k)
                 {
                     upperConditions[k] = sections[iSec][0]->u[(sections[iSec][0]->mesh->getnMarkers() - 1) * sections[iSec][0]->getnVar() + k];
-                    lowerConditions[k] = sections[iSec][0]->u[(sections[iSec][1]->mesh->getnMarkers() - 1) * sections[iSec][1]->getnVar() + k];
+                    lowerConditions[k] = sections[iSec][1]->u[(sections[iSec][1]->mesh->getnMarkers() - 1) * sections[iSec][1]->getnVar() + k];
                 }
                 sections[iSec][iRegion]->setWakeBC(Re, upperConditions, lowerConditions);
                 lockTrans = true;
diff --git a/vii/tests/bli2D.py b/vii/tests/bli2D.py
index f6b29a2..14e5c75 100644
--- a/vii/tests/bli2D.py
+++ b/vii/tests/bli2D.py
@@ -55,7 +55,7 @@ def main():
     Re = 1e7
     alpha = 2.*math.pi/180
     M_inf = 0.2
-    xtrF = [-1, 0.45]
+    xtrF = [-1, 0.40]
     # Numerical parameters.
     CFL0 = 1
 
@@ -112,11 +112,11 @@ def main():
     # Test for n0012 (le=0.01, te=0.01), alpha=2, M=.2, Re=1e7.
     print(ccolors.ANSI_BLUE + 'PyTesting...' + ccolors.ANSI_RESET)
     tests = CTests()
-    tests.add(CTest('Cl', iSolverAPI.getCl(), 0.2344, 5e-3)) # XFOIL 0.2325
-    tests.add(CTest('Cd', vSolution['Cdt'], 0.0055, 1e-3, forceabs=True)) # XFOIL 0.00531
-    tests.add(CTest('Cdp', vSolution['Cdp'], 0.0010, 1e-3, forceabs=True)) # XFOIL 0.00084, Cdf = 0.00447
+    tests.add(CTest('Cl', iSolverAPI.getCl(), 0.235, 5e-3)) # XFOIL 0.2325
+    tests.add(CTest('Cd', vSolution['Cdt'], 0.0051, 1e-3, forceabs=True)) # XFOIL 0.00531
+    tests.add(CTest('Cdp', vSolution['Cdp'], 0.0005, 1e-3, forceabs=True)) # XFOIL 0.00084, Cdf = 0.00447
     tests.add(CTest('xtr_top', vSolution['xtrT'], 0.21, 0.03, forceabs=True)) # XFOIL 0.1877
-    tests.add(CTest('xtr_bot', vSolution['xtrB'], 0.45, 0.01, forceabs=True)) # XFOIL 0.4998
+    tests.add(CTest('xtr_bot', vSolution['xtrB'], 0.40, 0.01, forceabs=True)) # XFOIL 0.4998
     tests.run()
 
     # eof
-- 
GitLab