From 4a170fa86563cd58fb4bc1920fcca979e527e94c Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:01:29 +0200 Subject: [PATCH 01/10] Add mirco_postprocess.cpp to micro_io library --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56b29195..8c54679a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ target_link_libraries(mirco_core PUBLIC Trilinos::all_selected_libs OpenMP::Open add_library(mirco_io src/mirco_setparameters.cpp + src/mirco_postprocess.cpp ) target_link_libraries(mirco_io PUBLIC Trilinos::all_selected_libs) From c758ab75a1d084b9a79dcbe553a6b7c7c0a518cc Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:02:19 +0200 Subject: [PATCH 02/10] Fix tests due to command line argument addition --- TestingFramework.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestingFramework.cmake b/TestingFramework.cmake index e4130c33..090a779b 100644 --- a/TestingFramework.cmake +++ b/TestingFramework.cmake @@ -2,7 +2,7 @@ macro(mirco_framework_test name_of_input_file) set (input_location ${PROJECT_SOURCE_DIR}/Input/${name_of_input_file}) add_test(NAME ${name_of_input_file} - COMMAND ./mirco ${input_location}) + COMMAND ./mirco ${input_location} nametest) endmacro(mirco_framework_test) From 4dd08df73bc07a86976001940b654febd635c825 Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:03:59 +0200 Subject: [PATCH 03/10] Define new variables, add PostProcess method --- src/main.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 015e8665..92b9e2d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,16 +7,20 @@ #include "mirco_setparameters.h" #include "mirco_topology.h" #include "mirco_topologyutilities.h" +#include "mirco_postprocess.h" +#include "mirco_filesystem_utils.h" int main(int argc, char* argv[]) { TEUCHOS_TEST_FOR_EXCEPTION( - argc != 2, std::invalid_argument, "The code expects (only) an input file as argument"); + argc != 3, std::invalid_argument, "The code expects input and output file as arguments. Full paths must be given"); // reading the input file name from the command line std::string inputFileName = argv[1]; - - const auto start = std::chrono::high_resolution_clock::now(); + std::string outputFileName = argv[2]; + + // following function generates the actual path of the output file. + UTILS::ChangeRelativePath(outputFileName, inputFileName); bool WarmStartingFlag = false; int Resolution = 0; @@ -55,17 +59,24 @@ int main(int argc, char* argv[]) auto max_and_mean = MIRCO::ComputeMaxAndMean(topology); - // Initialise Pressure - double pressure = 0.0; + // Number of contact points + int nf = 0; + // Coordinates of the points in contact in the last iteration. + std::vector xvf, yvf; + // Contact force at (xLast,yLast) calculated in the last iteration. + std::vector pf; + + // Set start time + const auto start = std::chrono::high_resolution_clock::now(); - MIRCO::Evaluate(pressure, Delta, LateralLength, GridSize, Tolerance, MaxIteration, + MIRCO::Evaluate(Delta, LateralLength, GridSize, Tolerance, MaxIteration, CompositeYoungs, WarmStartingFlag, ElasticComplianceCorrection, topology, max_and_mean.max_, - meshgrid); - - std::cout << "Mean pressure is: " << std::to_string(pressure) << std::endl; - + meshgrid, xvf, yvf, pf, nf); + + // Total MIRCO simulation time const auto finish = std::chrono::high_resolution_clock::now(); - const double elapsedTime = - std::chrono::duration_cast(finish - start).count(); - std::cout << "Elapsed time is: " + std::to_string(elapsedTime) + "s." << std::endl; + const double elapsedTime = std::chrono::duration_cast(finish - start).count(); + + MIRCO::PostProcess(xvf, yvf, pf, nf, GridSize, ngrid, meshgrid, LateralLength, + elapsedTime, outputFileName); } From f4f2a1e9dc4218a19ac785f6744028b6b85ade26 Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:05:18 +0200 Subject: [PATCH 04/10] Move and introduce new variables --- src/mirco_evaluate.cpp | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/mirco_evaluate.cpp b/src/mirco_evaluate.cpp index 6bfa7100..c1ace7ae 100644 --- a/src/mirco_evaluate.cpp +++ b/src/mirco_evaluate.cpp @@ -21,10 +21,11 @@ #include "mirco_nonlinearsolver.h" -void MIRCO::Evaluate(double& pressure, double Delta, double LateralLength, double GridSize, +void MIRCO::Evaluate(double Delta, double LateralLength, double GridSize, double Tolerance, int MaxIteration, double CompositeYoungs, bool WarmStartingFlag, double ElasticComplianceCorrection, Teuchos::SerialDenseMatrix& topology, - double zmax, std::vector& meshgrid) + double zmax, std::vector& meshgrid, std::vector& xvf, + std::vector& yvf, std::vector& pf, int& nf) { omp_set_num_threads(6); // 6 seems to be optimal @@ -40,21 +41,14 @@ void MIRCO::Evaluate(double& pressure, double Delta, double LateralLength, doubl // Coordinates of the points predicted to be in contact. std::vector xv0, yv0; - // Coordinates of the points in contact in the previous iteration. - std::vector xvf, yvf; // Indentation value of the half space at the predicted points of contact. std::vector b0; - // Contact force at (xvf,yvf) predicted in the previous iteration. - std::vector pf; // x0 --> contact forces at (xvf,yvf) predicted in the previous iteration but // are a part of currect predicted contact set. x0 is calculated in the // Warmstart function to be used in the NNLS to accelerate the simulation. Teuchos::SerialDenseMatrix x0; - // The number of nodes in contact in the previous iteration. - int nf = 0; - // The influence coefficient matrix (Discrete version of Green Function) Teuchos::SerialDenseMatrix A; // Solution containing force @@ -121,12 +115,4 @@ void MIRCO::Evaluate(double& pressure, double Delta, double LateralLength, doubl TEUCHOS_TEST_FOR_EXCEPTION(ErrorForce > Tolerance, std::out_of_range, "The solution did not converge in the maximum number of iternations defined"); - // @{ - - // Calculate the final force value at the end of the iteration. - const double force = force0[k - 1]; - - // Mean pressure - double sigmaz = force / pow(LateralLength, 2); - pressure = sigmaz; } From a5afecdf963ed265483359b4e87b2e96bd958078 Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:05:44 +0200 Subject: [PATCH 05/10] Introduce new variables --- src/mirco_evaluate.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mirco_evaluate.h b/src/mirco_evaluate.h index ce120779..b65fc78a 100644 --- a/src/mirco_evaluate.h +++ b/src/mirco_evaluate.h @@ -9,7 +9,6 @@ namespace MIRCO /** * @brief Relate the far-field displacement with pressure * - * @param pressure Pressure * @param Delta Far-field displacement (Gap) * @param LateralLength Lateral side of the surface [micrometers] * @param GridSize Grid size @@ -21,11 +20,16 @@ namespace MIRCO * @param topology Topology matrix containing heights * @param zmax Maximum height * @param meshgrid Meshgrid vector + * @param xvf x-Coordinate vector of points that are in contact, calculated in each iteration + * @param yvf y-Coordinate vector of points that are in contact, calculated in each iteration + * @param pf Contact force vector at (xvf,yvf) calculated in each iteration. + * @param nf Number of contact points */ - void Evaluate(double& pressure, double Delta, double LateralLength, double GridSize, + void Evaluate(double Delta, double LateralLength, double GridSize, double Tolerance, int MaxIteration, double CompositeYoungs, bool WarmStartingFlag, double ElasticComplianceCorrection, Teuchos::SerialDenseMatrix& topology, - double zmax, std::vector& meshgrid); + double zmax, std::vector& meshgrid, std::vector& xvf, + std::vector& yvf, std::vector& pf, int& n); } // namespace MIRCO From 899072c586935c255a3adcf5cd80b6dc9cef16c0 Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:06:24 +0200 Subject: [PATCH 06/10] Introduce PostProcess method --- src/mirco_postprocess.cpp | 82 +++++++++++++++++++++++++++++++++++++++ src/mirco_postprocess.h | 29 ++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/mirco_postprocess.cpp create mode 100644 src/mirco_postprocess.h diff --git a/src/mirco_postprocess.cpp b/src/mirco_postprocess.cpp new file mode 100644 index 00000000..8e839ed3 --- /dev/null +++ b/src/mirco_postprocess.cpp @@ -0,0 +1,82 @@ +#include "mirco_postprocess.h" +#include + +#include +#include +#include +#include +#include + +long findClosestIndex(const std::vector& sorted_array, double x) +{ + auto iter_geq = std::lower_bound( + sorted_array.begin(), + sorted_array.end(), + x + ); + + if (iter_geq == sorted_array.begin()) { + return 0; + } + + double a = *(iter_geq - 1); + double b = *(iter_geq); + + if (fabs(x - a) < fabs(x - b)) { + return iter_geq - sorted_array.begin() - 1; + } + return iter_geq - sorted_array.begin(); +} + +void MIRCO::PostProcess(std::vector xvf, std::vector yvf, std::vector pf, + int nf, double GridSize, int ngrid, std::vector& meshgrid, double LateralLength, + double elapsedTime, std::string outputFileName) +{ + double forceArray[ngrid][ngrid] = {0}; + int ix; + int iy; + double areaContact; + + for (int i = 0; i < nf; i++) + { + ix = findClosestIndex(meshgrid, xvf[i]); + iy = findClosestIndex(meshgrid, yvf[i]); + forceArray[ix][iy] = pf[i]; + // std::cout << ix << "\t" << iy << std::endl; + // std::cout << xvf[i] << "\t" << yvf[i] << "\t" << pf[i] << std::endl; + } + + // Store force at every point (including contact and non-contact points) + std::ofstream outputForceFile(outputFileName+"_force"+".dat"); + + for (int i=0; i +#include + +namespace MIRCO +{ + /** + * @brief Postprocessing of contact force and contact area + * + * @param xvf x-Coordinate vector of points that are in contact, calculated in each iteration + * @param yvf y-Coordinate vector of points that are in contact, calculated in each iteration + * @param pf Contact force vector at (xvf,yvf) calculated in each iteration. + * @param nf Number of contact points + * @param GridSize Grid size + * @param ngrid Number of grids + * @param meshgrid Meshgrid vector + * @param LateralLength Lateral side of the surface [micrometers] + * @param elapsedTimeString Number of contact points + * @param outputFileName Output file to store results + */ + void PostProcess(std::vector xvf, std::vector yvf, std::vector pf, + int nf, double GridSize, int ngrid, std::vector& meshgrid, double LateralLength, + double elapsedTime, std::string outputFileName); +} // namespace MIRCO + + +#endif // SRC_POSTPROCESS_H_ From 2cce89856b4036a910dce22dadc9cc1ffe06ebc6 Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:12:08 +0200 Subject: [PATCH 07/10] Format routines via clang --- src/main.cpp | 30 ++++++++-------- src/mirco_evaluate.cpp | 8 ++--- src/mirco_evaluate.h | 4 +-- src/mirco_postprocess.cpp | 76 +++++++++++++++++++-------------------- src/mirco_postprocess.h | 4 +-- 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 92b9e2d6..78aa85ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,21 +4,20 @@ #include #include "mirco_evaluate.h" +#include "mirco_filesystem_utils.h" +#include "mirco_postprocess.h" #include "mirco_setparameters.h" #include "mirco_topology.h" #include "mirco_topologyutilities.h" -#include "mirco_postprocess.h" - -#include "mirco_filesystem_utils.h" int main(int argc, char* argv[]) { - TEUCHOS_TEST_FOR_EXCEPTION( - argc != 3, std::invalid_argument, "The code expects input and output file as arguments. Full paths must be given"); + TEUCHOS_TEST_FOR_EXCEPTION(argc != 3, std::invalid_argument, + "The code expects input and output file as arguments. Full paths must be given"); // reading the input file name from the command line std::string inputFileName = argv[1]; std::string outputFileName = argv[2]; - + // following function generates the actual path of the output file. UTILS::ChangeRelativePath(outputFileName, inputFileName); @@ -60,23 +59,24 @@ int main(int argc, char* argv[]) auto max_and_mean = MIRCO::ComputeMaxAndMean(topology); // Number of contact points - int nf = 0; + int nf = 0; // Coordinates of the points in contact in the last iteration. std::vector xvf, yvf; // Contact force at (xLast,yLast) calculated in the last iteration. std::vector pf; - + // Set start time const auto start = std::chrono::high_resolution_clock::now(); - MIRCO::Evaluate(Delta, LateralLength, GridSize, Tolerance, MaxIteration, - CompositeYoungs, WarmStartingFlag, ElasticComplianceCorrection, topology, max_and_mean.max_, - meshgrid, xvf, yvf, pf, nf); - + MIRCO::Evaluate(Delta, LateralLength, GridSize, Tolerance, MaxIteration, CompositeYoungs, + WarmStartingFlag, ElasticComplianceCorrection, topology, max_and_mean.max_, meshgrid, xvf, + yvf, pf, nf); + // Total MIRCO simulation time const auto finish = std::chrono::high_resolution_clock::now(); - const double elapsedTime = std::chrono::duration_cast(finish - start).count(); + const double elapsedTime = + std::chrono::duration_cast(finish - start).count(); - MIRCO::PostProcess(xvf, yvf, pf, nf, GridSize, ngrid, meshgrid, LateralLength, - elapsedTime, outputFileName); + MIRCO::PostProcess( + xvf, yvf, pf, nf, GridSize, ngrid, meshgrid, LateralLength, elapsedTime, outputFileName); } diff --git a/src/mirco_evaluate.cpp b/src/mirco_evaluate.cpp index c1ace7ae..b0210891 100644 --- a/src/mirco_evaluate.cpp +++ b/src/mirco_evaluate.cpp @@ -21,11 +21,11 @@ #include "mirco_nonlinearsolver.h" -void MIRCO::Evaluate(double Delta, double LateralLength, double GridSize, - double Tolerance, int MaxIteration, double CompositeYoungs, bool WarmStartingFlag, +void MIRCO::Evaluate(double Delta, double LateralLength, double GridSize, double Tolerance, + int MaxIteration, double CompositeYoungs, bool WarmStartingFlag, double ElasticComplianceCorrection, Teuchos::SerialDenseMatrix& topology, - double zmax, std::vector& meshgrid, std::vector& xvf, - std::vector& yvf, std::vector& pf, int& nf) + double zmax, std::vector& meshgrid, std::vector& xvf, std::vector& yvf, + std::vector& pf, int& nf) { omp_set_num_threads(6); // 6 seems to be optimal diff --git a/src/mirco_evaluate.h b/src/mirco_evaluate.h index b65fc78a..089e88f4 100644 --- a/src/mirco_evaluate.h +++ b/src/mirco_evaluate.h @@ -25,8 +25,8 @@ namespace MIRCO * @param pf Contact force vector at (xvf,yvf) calculated in each iteration. * @param nf Number of contact points */ - void Evaluate(double Delta, double LateralLength, double GridSize, - double Tolerance, int MaxIteration, double CompositeYoungs, bool WarmStartingFlag, + void Evaluate(double Delta, double LateralLength, double GridSize, double Tolerance, + int MaxIteration, double CompositeYoungs, bool WarmStartingFlag, double ElasticComplianceCorrection, Teuchos::SerialDenseMatrix& topology, double zmax, std::vector& meshgrid, std::vector& xvf, std::vector& yvf, std::vector& pf, int& n); diff --git a/src/mirco_postprocess.cpp b/src/mirco_postprocess.cpp index 8e839ed3..e6a3f4b2 100644 --- a/src/mirco_postprocess.cpp +++ b/src/mirco_postprocess.cpp @@ -1,37 +1,35 @@ #include "mirco_postprocess.h" -#include #include #include -#include #include #include +#include +#include -long findClosestIndex(const std::vector& sorted_array, double x) +long findClosestIndex(const std::vector& sorted_array, double x) { - auto iter_geq = std::lower_bound( - sorted_array.begin(), - sorted_array.end(), - x - ); + auto iter_geq = std::lower_bound(sorted_array.begin(), sorted_array.end(), x); - if (iter_geq == sorted_array.begin()) { - return 0; - } + if (iter_geq == sorted_array.begin()) + { + return 0; + } - double a = *(iter_geq - 1); - double b = *(iter_geq); + double a = *(iter_geq - 1); + double b = *(iter_geq); - if (fabs(x - a) < fabs(x - b)) { - return iter_geq - sorted_array.begin() - 1; - } - return iter_geq - sorted_array.begin(); + if (fabs(x - a) < fabs(x - b)) + { + return iter_geq - sorted_array.begin() - 1; + } + return iter_geq - sorted_array.begin(); } void MIRCO::PostProcess(std::vector xvf, std::vector yvf, std::vector pf, - int nf, double GridSize, int ngrid, std::vector& meshgrid, double LateralLength, - double elapsedTime, std::string outputFileName) -{ + int nf, double GridSize, int ngrid, std::vector& meshgrid, double LateralLength, + double elapsedTime, std::string outputFileName) +{ double forceArray[ngrid][ngrid] = {0}; int ix; int iy; @@ -45,38 +43,40 @@ void MIRCO::PostProcess(std::vector xvf, std::vector yvf, std::v // std::cout << ix << "\t" << iy << std::endl; // std::cout << xvf[i] << "\t" << yvf[i] << "\t" << pf[i] << std::endl; } - + // Store force at every point (including contact and non-contact points) - std::ofstream outputForceFile(outputFileName+"_force"+".dat"); + std::ofstream outputForceFile(outputFileName + "_force" + ".dat"); - for (int i=0; i xvf, std::vector yvf, std::vector pf, - int nf, double GridSize, int ngrid, std::vector& meshgrid, double LateralLength, + void PostProcess(std::vector xvf, std::vector yvf, std::vector pf, int nf, + double GridSize, int ngrid, std::vector& meshgrid, double LateralLength, double elapsedTime, std::string outputFileName); } // namespace MIRCO From ebc6e1d69a193a56a6016d9bf19df7b1196c54b0 Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:16:24 +0200 Subject: [PATCH 08/10] Fix exception error message --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 78aa85ed..e3faf5b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ int main(int argc, char* argv[]) { TEUCHOS_TEST_FOR_EXCEPTION(argc != 3, std::invalid_argument, - "The code expects input and output file as arguments. Full paths must be given"); + "The code expects input file with a full path and a prefix for output files."); // reading the input file name from the command line std::string inputFileName = argv[1]; std::string outputFileName = argv[2]; From fc90285b0c78c26c95c9102b62fbba251cde1dab Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Wed, 26 Apr 2023 20:17:54 +0200 Subject: [PATCH 09/10] Fix typo --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e3faf5b0..4b36af79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) int nf = 0; // Coordinates of the points in contact in the last iteration. std::vector xvf, yvf; - // Contact force at (xLast,yLast) calculated in the last iteration. + // Contact force at (xvf,yvf) calculated in the last iteration. std::vector pf; // Set start time From ca1a81fd8f8d10b68e3fa78e10aacc936cdcfb70 Mon Sep 17 00:00:00 2001 From: Tarik Sahin Date: Tue, 29 Aug 2023 15:24:29 +0200 Subject: [PATCH 10/10] Flip the force post-process --- src/mirco_postprocess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mirco_postprocess.cpp b/src/mirco_postprocess.cpp index e6a3f4b2..6f2356cd 100644 --- a/src/mirco_postprocess.cpp +++ b/src/mirco_postprocess.cpp @@ -39,7 +39,7 @@ void MIRCO::PostProcess(std::vector xvf, std::vector yvf, std::v { ix = findClosestIndex(meshgrid, xvf[i]); iy = findClosestIndex(meshgrid, yvf[i]); - forceArray[ix][iy] = pf[i]; + forceArray[ix][ngrid-1-iy] = pf[i]; // std::cout << ix << "\t" << iy << std::endl; // std::cout << xvf[i] << "\t" << yvf[i] << "\t" << pf[i] << std::endl; }