From 77548a9f6a11714aa5fc98dea106bdceb613bacb Mon Sep 17 00:00:00 2001
From: acrovato <a.crovato@uliege.be>
Date: Fri, 8 Mar 2024 10:21:36 +0100
Subject: [PATCH] Remove ASCII body results writter, only write aerodynamic
 loads.

---
 dart/src/wAdjoint.cpp |  5 +--
 dart/src/wBody.cpp    | 81 +------------------------------------------
 dart/src/wBody.h      |  4 +--
 dart/src/wSolver.cpp  | 29 +++++++++++++---
 4 files changed, 28 insertions(+), 91 deletions(-)

diff --git a/dart/src/wAdjoint.cpp b/dart/src/wAdjoint.cpp
index d93f766..1d75d8a 100644
--- a/dart/src/wAdjoint.cpp
+++ b/dart/src/wAdjoint.cpp
@@ -739,16 +739,13 @@ void Adjoint::save(MshExport *mshWriter, std::string const &suffix)
               << sol->pbl->alpha * 180 / 3.14159 << " deg AoA, "
               << sol->pbl->beta * 180 / 3.14159 << " deg AoS)"
               << std::endl;
-    // setup results
+    // save results
     Results results;
     results.scalars_at_nodes["lambdaClPhi"] = &lamClFlo;
     results.scalars_at_nodes["lambdaCdPhi"] = &lamCdFlo;
     results.vectors_at_nodes["gradClMsh"] = &dClMsh;
     results.vectors_at_nodes["gradCdMsh"] = &dCdMsh;
-    // save (whole mesh and bodies)
     mshWriter->save(sol->pbl->msh->name + "_adjoint" + suffix, results);
-    for (auto bnd : sol->pbl->bodies)
-        bnd->save(sol->pbl->msh->name + '_' + bnd->groups[0]->tag->name + "_adjoint" + suffix, results);
 }
 
 void Adjoint::write(std::ostream &out) const
diff --git a/dart/src/wBody.cpp b/dart/src/wBody.cpp
index 511e9be..d0ed003 100644
--- a/dart/src/wBody.cpp
+++ b/dart/src/wBody.cpp
@@ -22,8 +22,6 @@
 #include "wElement.h"
 #include "wNode.h"
 #include <unordered_set>
-#include <iomanip>
-#include <fstream>
 using namespace tbox;
 using namespace dart;
 
@@ -111,84 +109,7 @@ void Body::create()
     nLoads.resize(nodes.size(), Eigen::Vector3d::Zero());
 }
 
-/**
- * @brief Save nodal data for further post-processing
- */
-void Body::save(std::string const &name, Results const &res)
-{
-    // Write to file
-    std::cout << "writing file: " << name + ".dat"
-              << "... " << std::flush;
-    std::ofstream outfile;
-    outfile.open(name + ".dat");
-    // Header
-    outfile << "$Body data" << std::endl;
-    // Aerodynamic coefficients
-    outfile << "$Aerodynamic coefficients" << std::endl;
-    outfile << "!" << std::fixed
-            << std::setw(14) << "Cl"
-            << std::setw(15) << "Cd"
-            << std::setw(15) << "Cs"
-            << std::setw(15) << "Cm"
-            << std::endl;
-    outfile << std::fixed
-            << std::setw(15) << Cl
-            << std::setw(15) << Cd
-            << std::setw(15) << Cs
-            << std::setw(15) << Cm
-            << std::endl;
-    // Elements (connectvity)
-    outfile << "$Elements" << std::endl;
-    outfile << groups[0]->tag->elems.size() << std::endl;
-    for (auto e : groups[0]->tag->elems)
-    {
-        outfile << std::fixed
-                << std::setw(10) << e->no;
-        for (auto n : e->nodes)
-            outfile << std::setw(10) << n->no;
-        outfile << std::endl;
-    }
-    //Nodes (data)
-    outfile << "$Nodal data" << std::endl;
-    outfile << nodes.size() << std::endl;
-    outfile << "!" << std::fixed
-            << std::setw(9) << "no"
-            << std::setw(15) << "x"
-            << std::setw(15) << "y"
-            << std::setw(15) << "z";
-    for (auto &p : res.scalars_at_nodes)
-        outfile << std::setw(15) << p.first;
-    for (auto &p : res.vectors_at_nodes)
-    {
-        outfile << std::setw(14) << p.first << "x"
-                << std::setw(14) << p.first << "y"
-                << std::setw(14) << p.first << "z";
-    }
-    outfile << std::endl;
-    for (auto n : nodes)
-    {
-        outfile << std::fixed
-                << std::setw(10) << n->no
-                << std::scientific << std::setprecision(6)
-                << std::setw(15) << n->pos(0)
-                << std::setw(15) << n->pos(1)
-                << std::setw(15) << n->pos(2);
-        for (auto &p : res.scalars_at_nodes)
-            outfile << std::setw(15) << (*(p.second))[n->row];
-        for (auto &p : res.vectors_at_nodes)
-            outfile << std::setw(15) << (*(p.second))[n->row](0)
-                    << std::setw(15) << (*(p.second))[n->row](1)
-                    << std::setw(15) << (*(p.second))[n->row](2);
-        outfile << std::endl;
-    }
-    // Footer
-    outfile << std::endl;
-    // Close file
-    outfile.close();
-    std::cout << "done" << std::endl;
-}
-
 void Body::write(std::ostream &out) const
 {
     out << *groups[0]->tag << " is a Body immersed in " << *groups[1]->tag << std::endl;
-}
\ No newline at end of file
+}
diff --git a/dart/src/wBody.h b/dart/src/wBody.h
index 31b8dc1..c95931b 100644
--- a/dart/src/wBody.h
+++ b/dart/src/wBody.h
@@ -49,8 +49,6 @@ public:
     Body(std::shared_ptr<tbox::MshData> _msh, std::vector<std::string> const &names);
     virtual ~Body() { std::cout << "~Body()\n"; }
 
-    void save(std::string const &name, tbox::Results const &res);
-
 #ifndef SWIG
     virtual void write(std::ostream &out) const override;
 #endif
@@ -61,4 +59,4 @@ private:
 
 } // namespace dart
 
-#endif //WBODY_H
+#endif // WBODY_H
diff --git a/dart/src/wSolver.cpp b/dart/src/wSolver.cpp
index 11f4d80..73579c7 100644
--- a/dart/src/wSolver.cpp
+++ b/dart/src/wSolver.cpp
@@ -36,6 +36,7 @@
 #include <tbb/spin_mutex.h>
 
 #include <iomanip>
+#include <fstream>
 
 using namespace tbox;
 using namespace dart;
@@ -170,7 +171,7 @@ void Solver::save(MshExport *mshWriter, std::string const &suffix)
               << pbl->alpha * 180 / 3.14159 << "deg AoA, "
               << pbl->beta * 180 / 3.14159 << "deg AoS)"
               << std::endl;
-    // setup results
+    // save results
     Results results;
     results.scalars_at_nodes["phi"] = &phi;
     results.scalars_at_nodes["varPhi"] = &vPhi;
@@ -179,10 +180,30 @@ void Solver::save(MshExport *mshWriter, std::string const &suffix)
     results.scalars_at_nodes["rho"] = &rho;
     results.scalars_at_nodes["Mach"] = &M;
     results.scalars_at_nodes["Cp"] = &Cp;
-    // save (whole mesh and bodies)
     mshWriter->save(pbl->msh->name + suffix, results);
-    for (auto bnd : pbl->bodies)
-        bnd->save(pbl->msh->name + '_' + bnd->groups[0]->tag->name + suffix, results);
+    // save aerodynamic loads
+    std::cout << "writing file: aeroloads" << suffix << ".dat... " << std::flush;
+    std::ofstream outfile;
+    outfile.open("aeroloads" + suffix + ".dat");
+    // total
+    outfile << "# Total - " << pbl->msh->name << std::endl;
+    outfile << std::fixed << std::setprecision(12)
+            << "Cl = " << Cl << "\n"
+            << "Cd = " << Cd << "\n"
+            << "Cs = " << Cs << "\n"
+            << "Cm = " << Cm << "\n";
+    // breakdown
+    for (auto b : pbl->bodies)
+    {
+        outfile << "# Body - " << b->groups[0]->tag->name << " (" << b->groups[0]->tag->elems.size() << " elements)" << std::endl;
+        outfile << std::fixed << std::setprecision(12)
+                << "Cl = " << b->Cl << "\n"
+                << "Cd = " << b->Cd << "\n"
+                << "Cs = " << b->Cs << "\n"
+                << "Cm = " << b->Cm << "\n";
+    }
+    outfile.close();
+    std::cout << "done." << std::endl;
 }
 
 /**
-- 
GitLab