From c46ed5054f5f763db3a724ebcb088fd78180e5c0 Mon Sep 17 00:00:00 2001 From: acrovato <39187559+acrovato@users.noreply.github.com> Date: Sun, 18 Nov 2018 15:14:15 +0100 Subject: [PATCH 01/20] Updt INSTALL.txt --- INSTALL.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALL.txt b/INSTALL.txt index b898470..1e75ee4 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -2,9 +2,9 @@ Installation of NativeSolid code Tools required : *CMAKE (~sudo apt-get install cmake) -*LAPACK/LAPACKE (liblapacke.so & lapacke.h) -*CBLAS (libcblas.a & cblas.h) -*C/C++ compiler (GCC) +*LAPACK/LAPACKE (sudo apt-get install liblapacke-dev) +*CBLAS (sudo apt-get install liblatlas-base-dev) +*C/C++ compiler (sudo apt-get install build-essential) *MPI implementatin (OpenMPI) 1. Go to the CMake folder and set the right paths for headers and libraries in the FindCBLAS and FindLAPACKE files From 4a1de833fbe62820224e2dd6e7966863348054ff Mon Sep 17 00:00:00 2001 From: acrovato <39187559+acrovato@users.noreply.github.com> Date: Mon, 19 Nov 2018 14:20:39 +0100 Subject: [PATCH 02/20] Impl Static Computation. Updt API, integration, solver. Corr geometry. Seems to be working. Updt readme --- .gitignore | 3 ++ README.md | 13 ++++++ api/NativeSolid_API.cpp | 29 ++----------- api/NativeSolid_API.h | 2 +- include/integration.h | 2 +- include/solver.h | 16 ++++++- src/geometry.cpp | 2 +- src/integration.cpp | 93 ++++++++++++++++++++++++++++++++--------- src/solver.cpp | 50 ++++++++++++++++++++++ 9 files changed, 161 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index db7a2db..42dfaaa 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ bin/* #Build directory build/* + +# Visual Studio Code files +.vscode/ diff --git a/README.md b/README.md index 85359a6..339ebb6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # NativeSolid Native solid solver for FSI + +## Features +* Meshes in .su2 format (exported from gmsh) +* Configuration + - Airfoil (pitch/plunge) + - Horizontal spring + - Vertical spring +* Dynamic computation + - AlphaGen time integration + - Runge-Kutta (order 4) time integration + - Mass/damping/stiffness/nonlinear effects +* Static Computation + - Stiffness effect only diff --git a/api/NativeSolid_API.cpp b/api/NativeSolid_API.cpp index 74e965f..5c499e9 100644 --- a/api/NativeSolid_API.cpp +++ b/api/NativeSolid_API.cpp @@ -63,9 +63,7 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp):confFile(str){ /*--- Initialize the temporal integrator ---*/ cout << endl << "\n----------------------- Setting integration parameter ----------------------" << endl; integrator = new Integration(config, structure); - if(config->GetUnsteady() == "YES"){ - integrator->SetInitialConditions(config, structure); - } + integrator->SetInitialConditions(config, structure); cout << endl << "\n----------------------- Setting FSI features ----------------------" << endl; q_uM1.Initialize(structure->GetnDof()); @@ -426,34 +424,15 @@ void NativeSolidSolver::setInitialDisplacements(){ computeInterfacePosVel(true); } -/* -void NativeSolidSolver::staticComputation(){ - - int rank = MASTER_NODE; - int size = 1; - -#ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); -#endif - integrator->StaticIteration(config,structure); +void NativeSolidSolver::staticComputation(){ - if(rank == MASTER_NODE){ - if(structure->GetnDof() == 1){ - cout << "Static Displacement : " << (*(integrator->GetDisp()))[0] << endl; - } - else if(structure->GetnDof() == 2){ - cout << "Static Displacement 1 : " << (*(integrator->GetDisp()))[0] << endl; - cout << "Static Displacement 2 : " << (*(integrator->GetDisp()))[1] << endl; - } - } + integrator->StaticIteration(structure); //mapRigidBodyMotion(false,false); computeInterfacePosVel(false); - } -*/ + void NativeSolidSolver::writeSolution(double currentTime, double lastTime, double currentFSIIter, unsigned long ExtIter, unsigned long NbExtIter){ diff --git a/api/NativeSolid_API.h b/api/NativeSolid_API.h index e67a995..f6baa60 100644 --- a/api/NativeSolid_API.h +++ b/api/NativeSolid_API.h @@ -40,7 +40,7 @@ class NativeSolidSolver{ //void mapRigidBodyMotion(bool predicition, bool initialize); void computeInterfacePosVel(bool initialize); void setInitialDisplacements(); - //void staticComputation(); + void staticComputation(); void writeSolution(double currentTime, double lastTime, double currentFSIIter, unsigned long ExtIter, unsigned long NbExtIter); void saveSolution(); void updateSolution(); diff --git a/include/integration.h b/include/integration.h index 0d243d1..1dd6e69 100644 --- a/include/integration.h +++ b/include/integration.h @@ -28,6 +28,6 @@ class Integration{ unsigned long GetExtIter(); void SetInitialConditions(Config* config, Structure* structure); void TemporalIteration(double& t0, double& tf, Structure *structure); - //void StaticIteration(Config *config, Structure *structure); + void StaticIteration(Structure *structure); void UpdateSolution(); }; diff --git a/include/solver.h b/include/solver.h index f806e52..b89be5d 100644 --- a/include/solver.h +++ b/include/solver.h @@ -64,7 +64,6 @@ class AlphaGenSolver : public Solver { }; - class RK4Solver : public Solver { protected: @@ -83,3 +82,18 @@ class RK4Solver : public Solver { CVector SetState_n(); }; + +class StaticSolver : public Solver { + +protected: + unsigned int _nDof; + CMatrix KK; + +public: + StaticSolver(unsigned nDof, bool bool_linear); + ~StaticSolver(); + + virtual void Iterate(double &t0, double &tf, Structure* structure); + virtual void SetInitialState(Config* config, Structure* structure); + +}; diff --git a/src/geometry.cpp b/src/geometry.cpp index 105d525..e224e66 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -165,7 +165,7 @@ Geometry::Geometry(Config* config){ /*--- Open the mesh file and check ---*/ meshFile.open(meshFileName.c_str(), ios::in); if (meshFile.fail()){ - cout << "Enable to open the mesh file " << meshFileName << endl; + cout << "Unable to open the mesh file " << meshFileName << endl; exit(1); } diff --git a/src/integration.cpp b/src/integration.cpp index 6d9bb5e..0425675 100644 --- a/src/integration.cpp +++ b/src/integration.cpp @@ -1,6 +1,7 @@ #include "../include/integration.h" #include "../include/solver.h" #include +#include #include #include #include @@ -15,15 +16,18 @@ Integration::Integration(Config *config, Structure *structure){ linear = (config->GetLinearize()) == "YES"; - if(config->GetIntegrationAlgo() == "ALPHAGEN"){ - solver = new AlphaGenSolver(structure->GetnDof(), config->GetRho(), linear); - } - else if(config->GetIntegrationAlgo() == "RK4"){ - solver = new RK4Solver(structure->GetnDof(), linear); - } - else{ - + if (config->GetUnsteady() == "YES") { + if(config->GetIntegrationAlgo() == "ALPHAGEN"){ + solver = new AlphaGenSolver(structure->GetnDof(), config->GetRho(), linear); + } + else if(config->GetIntegrationAlgo() == "RK4"){ + solver = new RK4Solver(structure->GetnDof(), linear); + } + else{ + } } + else + solver = new StaticSolver(structure->GetnDof(), linear); } Integration::~Integration(){ @@ -76,23 +80,72 @@ void Integration::TemporalIteration(double& t0, double& tf, Structure *structure if(rank == 0){ if(structure->GetnDof() == 1){ - cout << " Time" << "\t" << "Displacement" << "\t" << "Velocity" << "\t" << "Acceleration" << "\t" << endl; - cout << " " << currentTime << "\t" << (solver->GetDisp())[0] << "\t" << (solver->GetVel())[0] << "\t" << (solver->GetAcc())[0] << endl; - } - else if(structure->GetnDof() == 2){ - cout << " Time" << "\t" << "Displacement 1" << "\t" << "Displacement 2" << "\t" << "Velocity 1" << "\t" << "Velocity 2" << "\t" << "Acceleration 1" << "\t" << "Acceleration 2" << endl; - cout << currentTime << "\t" << (solver->GetDisp())[0] << "\t" << (solver->GetDisp())[1] << "\t" << (solver->GetVel())[0] << "\t" << (solver->GetVel())[1] << "\t" << (solver->GetAcc())[0] << "\t" << (solver->GetAcc())[1] << endl; + cout << fixed + << setw(10) << "Time" + << setw(15) << "Displacement" + << setw(15) << "Velocity" + << setw(15) << "Acceleration" << endl; + cout << fixed + << setw(10) << currentTime + << setw(15) << (solver->GetDisp())[0] + << setw(15) << (solver->GetVel())[0] + << setw(15) << (solver->GetAcc())[0] << endl; } + else if(structure->GetnDof() == 2){cout << fixed + << setw(10) << "Time" + << setw(15) << "Displacement1" + << setw(15) << "Displacement2" + << setw(15) << "Velocity1" + << setw(15) << "Velocity2" + << setw(15) << "Acceleration1" + << setw(15) << "Acceleration2" << endl; + cout << fixed + << setw(10) << currentTime + << setw(15) << (solver->GetDisp())[0] + << setw(15) << (solver->GetDisp())[1] + << setw(15) << (solver->GetVel())[0] + << setw(15) << (solver->GetVel())[1] + << setw(15) << (solver->GetAcc())[0] + << setw(15) << (solver->GetAcc())[1] << endl;} } } -/* -void Integration::StaticIteration(Config *config, Structure *structure){ - q->Reset(); - *q += *Loads; - SolveSys(structure->GetK(),q); //q will be updated with the new solution... + +void Integration::StaticIteration(Structure *structure){ + + int rank = 0; + +#ifdef HAVE_MPI + MPI_Comm_rank(MPI_COMM_WORLD, &rank); +#endif + + double t0 = 0.; + double tf = 0.; + deltaT = 0.; + solver->Iterate(t0, tf, structure); + + if(rank == 0){ + if(structure->GetnDof() == 1){ + cout << fixed + << setw(10) << "Time" + << setw(15) << "Displacement" << endl; + cout << fixed + << setw(10) << tf + << setw(15) << (solver->GetDisp())[0] << endl; + } + else if(structure->GetnDof() == 2){ + cout << fixed + << setw(10) << "Time" + << setw(15) << "Displacement1" + << setw(15) << "Displacement2" << endl; + cout << fixed + << setw(10) << tf + << setw(15) << (solver->GetDisp())[0] + << setw(15) << (solver->GetDisp())[1] << endl; + } + } } -*/ + void Integration::UpdateSolution(){ diff --git a/src/solver.cpp b/src/solver.cpp index 6ae3af9..89a8321 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -646,3 +646,53 @@ CVector RK4Solver::SetState_n(){ return state; } + +/*CLASS STATIC SOLVER*/ +StaticSolver::StaticSolver(unsigned nDof, bool bool_linear) : Solver(nDof, bool_linear) +{ + _nDof = nDof; + KK.Initialize(_nDof, _nDof, 0.0); +} + +StaticSolver::~StaticSolver() +{ + std::cout << "NativeSolid::~StaticSolver()" << std::endl; +} + +void StaticSolver::SetInitialState(Config *config, Structure *structure){ + // Reset displacement, velocity and acceleration + if (config->GetRestartSol() == "YES"){ + } + else{ + cout << "Setting basic initial conditions for Static" << endl; + q.Reset(); + q_n.Reset(); + cout << "Read initial configuration" << endl; + q[0] = config->GetInitialDisp(); + if(_nDof == 2) q[1] = config->GetInitialAngle(); + cout << "Initial plunging displacement : " << q[0] << endl; + cout << "Initial pitching displacement : " << q[1] << endl; + qdot.Reset(); + qddot.Reset(); + } + // Fill stiffness matrix + if(_nDof == 1) + KK.SetElm(1,1,structure->Get_Kh()); + else if(_nDof == 2) { + KK.SetElm(1,1,structure->Get_Kh()); + KK.SetElm(2,2,structure->Get_Ka()); + } + else { + cerr << "Error in NativeSolid::StaticSolver: Number of degrees of freedom is out of range. nDof = " << _nDof << endl; + throw(-1); + } +} + +void StaticSolver::Iterate(double &t0, double &tf, Structure* structure) +{ + // Solve KK*q = Loads + CVector RHS(_nDof, 0.); + RHS += Loads; + SolveSys(KK, RHS); + q = RHS; +} \ No newline at end of file From 74ef6f56ac358ec721011fccd412e997e8b350d2 Mon Sep 17 00:00:00 2001 From: acrovato <39187559+acrovato@users.noreply.github.com> Date: Sun, 25 Nov 2018 14:04:01 +0100 Subject: [PATCH 03/20] Refact README --- INSTALL.txt | 24 ------------------------ README.md | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 27 deletions(-) delete mode 100644 INSTALL.txt diff --git a/INSTALL.txt b/INSTALL.txt deleted file mode 100644 index 1e75ee4..0000000 --- a/INSTALL.txt +++ /dev/null @@ -1,24 +0,0 @@ -Installation of NativeSolid code - -Tools required : -*CMAKE (~sudo apt-get install cmake) -*LAPACK/LAPACKE (sudo apt-get install liblapacke-dev) -*CBLAS (sudo apt-get install liblatlas-base-dev) -*C/C++ compiler (sudo apt-get install build-essential) -*MPI implementatin (OpenMPI) - -1. Go to the CMake folder and set the right paths for headers and libraries in the FindCBLAS and FindLAPACKE files -2. Create and go to the build folder - $ mkdir build - $ cd build - and check that it is empty. If not : - $ rm -r * -3. Execute : - $ cmake .. - for configuration. -4. If no error, execute : - $ make (you can do : $ make -j numthreads , for multi-threads compilation) -5. Set your environment variable in you .bashrc file as : - export NATIVE_RUN="INSTALL_PATH/NativeSolid/bin" - export PATH=$PATH:$NATIVE_RUN - export PYTHONPATH=$PYTHONPATH:$NATIVE_RUN diff --git a/README.md b/README.md index 339ebb6..50b8e97 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,10 @@ Native solid solver for FSI ## Features -* Meshes in .su2 format (exported from gmsh) +Compute static or dynamic displacements for several 2D configurations. + +* Meshes + - .su2 format (can be built and exported from gmsh) * Configuration - Airfoil (pitch/plunge) - Horizontal spring @@ -10,6 +13,34 @@ Native solid solver for FSI * Dynamic computation - AlphaGen time integration - Runge-Kutta (order 4) time integration - - Mass/damping/stiffness/nonlinear effects + - Mass/damping/stiffness/nonlinear terms * Static Computation - - Stiffness effect only + - Stiffness term only + +## Compilation (linux -gcc) +Installation of NativeSolid code + +Required packages +``` +sudo apt-get install build-essential +sudo apt-get install cmake +sudo apt-get install liblapacke-dev +sudo apt-get install liblatlas-base-dev +``` +Optional packages (parallel build) +``` +sudo apt-get install openmpi-bin openmpi-common libopenmpi-dev +``` +Compilation (you might need to set paths for headers and libraries in the FindCBLAS and FindLAPACKE files) +``` +mkdir build && cd build +cmake .. +make -j4 +``` +Environment variables +``` +gedit /home/"username"/.bashrc +export NATIVE_RUN="INSTALL_PATH/NativeSolid/bin" +export PATH=$PATH:$NATIVE_RUN +export PYTHONPATH=$PYTHONPATH:$NATIVE_RUN + From e98e92836d6e6dc4ceac69c4b6a4afa79097017c Mon Sep 17 00:00:00 2001 From: acrovato <39187559+acrovato@users.noreply.github.com> Date: Wed, 28 Nov 2018 11:02:15 +0100 Subject: [PATCH 04/20] Add writeSolution() based on CUPyDO current implementation --- api/NativeSolid_API.cpp | 73 ++++++++++++++++++++++++++++++++++++++--- api/NativeSolid_API.h | 1 + 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/api/NativeSolid_API.cpp b/api/NativeSolid_API.cpp index 5c499e9..4125b0a 100644 --- a/api/NativeSolid_API.cpp +++ b/api/NativeSolid_API.cpp @@ -1,5 +1,6 @@ #include "NativeSolid_API.h" #include +#include using namespace std; @@ -72,18 +73,36 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp):confFile(str){ if(rank == MASTER_NODE){ if(structure->GetnDof() == 1){ if(config->GetUnsteady() == "YES"){ - historyFile << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << endl; + historyFile << fixed + << setw(10) << "Time" + << setw(10) << "FSI iter" + << setw(15) << "Displacement" + << setw(15) << "Velocity" + << setw(15) << "Acceleration" << endl; } else{ - historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement\"" << endl; + historyFile << fixed + << setw(10) << "FSI iter" + << setw(15) << "Displacement" << endl; } } else if(structure->GetnDof() == 2){ if(config->GetUnsteady() == "YES"){ - historyFile << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << endl; + historyFile << fixed + << setw(10) << "Time" + << setw(10) << "FSI iter" + << setw(15) << "Displacement 1" + << setw(15) << "Displacement 2" + << setw(15) << "Velocity 1" + << setw(15) << "Velocity 2" + << setw(15) << "Acceleration 1" + << setw(15) << "Acceleration 2" << endl; } else{ - historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 1\"" << endl; + historyFile << fixed + << setw(10) << "FSI iter" + << setw(15) << "Displacement 1" + << setw(15) << "Displacement 2" << endl; } } } @@ -525,6 +544,52 @@ void NativeSolidSolver::saveSolution(){ } } +void NativeSolidSolver::writeSolution(double time, int FSIter){ + + int rank = MASTER_NODE; + + #ifdef HAVE_MPI + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + #endif + + if(rank == MASTER_NODE){ + if(structure->GetnDof() == 1){ + if(config->GetUnsteady() == "YES"){ + historyFile << fixed + << setw(10) << time + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; + } + else{ + historyFile << fixed + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; + } + } + else if(structure->GetnDof() == 2){ + if(config->GetUnsteady() == "YES"){ + historyFile << fixed + << setw(10) << time + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[1] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; + } + else{ + historyFile << fixed + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; + } + } + } +} + void NativeSolidSolver::updateSolution(){ if(config->GetUnsteady() == "YES"){ diff --git a/api/NativeSolid_API.h b/api/NativeSolid_API.h index f6baa60..ab4f7be 100644 --- a/api/NativeSolid_API.h +++ b/api/NativeSolid_API.h @@ -42,6 +42,7 @@ class NativeSolidSolver{ void setInitialDisplacements(); void staticComputation(); void writeSolution(double currentTime, double lastTime, double currentFSIIter, unsigned long ExtIter, unsigned long NbExtIter); + void writeSolution(double time, int FSIter); void saveSolution(); void updateSolution(); //void updateGeometry(); From 3f4aa92be3e1eb2a56f2fcca95ab985fefe0c77f Mon Sep 17 00:00:00 2001 From: acrovato <39187559+acrovato@users.noreply.github.com> Date: Mon, 3 Dec 2018 10:56:31 +0100 Subject: [PATCH 05/20] Refact output. Now using 2 history files --- api/NativeSolid_API.cpp | 123 +++++++++++++++++++++++++++------------- api/NativeSolid_API.h | 1 + 2 files changed, 86 insertions(+), 38 deletions(-) diff --git a/api/NativeSolid_API.cpp b/api/NativeSolid_API.cpp index 4125b0a..d3e0ad5 100644 --- a/api/NativeSolid_API.cpp +++ b/api/NativeSolid_API.cpp @@ -12,6 +12,7 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp):confFile(str){ int rank = MASTER_NODE; historyFile.open("NativeHistory.dat", ios::out); + historyFile2.open("NativeHistoryFSI.dat", ios::out); /*--- MPI initialization, and buffer setting ---*/ #ifdef HAVE_MPI @@ -74,22 +75,32 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp):confFile(str){ if(structure->GetnDof() == 1){ if(config->GetUnsteady() == "YES"){ historyFile << fixed - << setw(10) << "Time" + << setw(10) << "Delta_t" << setw(10) << "FSI iter" << setw(15) << "Displacement" << setw(15) << "Velocity" << setw(15) << "Acceleration" << endl; + historyFile2 << fixed + << setw(10) << "Time" + << setw(10) << "FSI iter" + << setw(15) << "Displacement" + << setw(15) << "Velocity" + << setw(15) << "Acceleration" << endl; } else{ historyFile << fixed + << setw(10) << "Delta_t" << setw(10) << "FSI iter" << setw(15) << "Displacement" << endl; + historyFile2 << fixed + << setw(10) << "FSI iter" + << setw(15) << "Displacement" << endl; } } else if(structure->GetnDof() == 2){ if(config->GetUnsteady() == "YES"){ historyFile << fixed - << setw(10) << "Time" + << setw(10) << "Delta_t" << setw(10) << "FSI iter" << setw(15) << "Displacement 1" << setw(15) << "Displacement 2" @@ -97,12 +108,26 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp):confFile(str){ << setw(15) << "Velocity 2" << setw(15) << "Acceleration 1" << setw(15) << "Acceleration 2" << endl; + historyFile2 << fixed + << setw(10) << "Time" + << setw(10) << "FSI iter" + << setw(15) << "Displacement 1" + << setw(15) << "Displacement 2" + << setw(15) << "Velocity 1" + << setw(15) << "Velocity 2" + << setw(15) << "Acceleration 1" + << setw(15) << "Acceleration 2" << endl; } else{ historyFile << fixed + << setw(10) << "Delta_t" << setw(10) << "FSI iter" << setw(15) << "Displacement 1" << setw(15) << "Displacement 2" << endl; + historyFile2 << fixed + << setw(10) << "FSI iter" + << setw(15) << "Displacement 1" + << setw(15) << "Displacement 2" << endl; } } } @@ -525,23 +550,45 @@ void NativeSolidSolver::saveSolution(){ #endif if(rank == MASTER_NODE){ - if(structure->GetnDof() == 1){ - if(config->GetUnsteady() == "YES"){ - historyFile << ExtIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << endl; - } - else{ - historyFile << ExtIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << endl; - } - } - else if(structure->GetnDof() == 2){ - if(config->GetUnsteady() == "YES"){ - historyFile << ExtIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << endl; + if(structure->GetnDof() == 1){ + if(config->GetUnsteady() == "YES"){ + historyFile << fixed + << setw(10) << DeltaT + << setw(10) << ExtIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; + } + else{ + historyFile << fixed + << setw(10) << DeltaT + << setw(10) << ExtIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; + } } - else{ - historyFile << ExtIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << endl; + else if(structure->GetnDof() == 2){ + if(config->GetUnsteady() == "YES"){ + historyFile << fixed + << setw(10) << DeltaT + << setw(10) << ExtIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[1] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; + } + else{ + historyFile << fixed + << setw(10) << DeltaT + << setw(10) << ExtIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; + } } } - } + + } void NativeSolidSolver::writeSolution(double time, int FSIter){ @@ -555,36 +602,36 @@ void NativeSolidSolver::writeSolution(double time, int FSIter){ if(rank == MASTER_NODE){ if(structure->GetnDof() == 1){ if(config->GetUnsteady() == "YES"){ - historyFile << fixed - << setw(10) << time - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; + historyFile2 << fixed + << setw(10) << time + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; } else{ - historyFile << fixed - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; + historyFile2 << fixed + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; } } else if(structure->GetnDof() == 2){ if(config->GetUnsteady() == "YES"){ - historyFile << fixed - << setw(10) << time - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[1] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; + historyFile2 << fixed + << setw(10) << time + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[1] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; } else{ - historyFile << fixed - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; + historyFile2 << fixed + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; } } } diff --git a/api/NativeSolid_API.h b/api/NativeSolid_API.h index ab4f7be..e3ec1b4 100644 --- a/api/NativeSolid_API.h +++ b/api/NativeSolid_API.h @@ -22,6 +22,7 @@ class NativeSolidSolver{ Integration* integrator; Output* output; std::ofstream historyFile; + std::ofstream historyFile2; std::ofstream restartFile; CVector q_uM1; //The displacement at the previous FSI iteration double omega; From 257b7ec4d1ba2911b6a115a0059931540e08bb43 Mon Sep 17 00:00:00 2001 From: acrovato <39187559+acrovato@users.noreply.github.com> Date: Fri, 7 Dec 2018 10:54:44 +0100 Subject: [PATCH 06/20] Add save q in staticSolver to correctly map the displacements --- src/solver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/solver.cpp b/src/solver.cpp index 89a8321..42026e6 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -691,8 +691,9 @@ void StaticSolver::SetInitialState(Config *config, Structure *structure){ void StaticSolver::Iterate(double &t0, double &tf, Structure* structure) { // Solve KK*q = Loads + q_n = q; // save previous state (used to compute rotation in NativeSolidSolver::computeInterfacePosVel) CVector RHS(_nDof, 0.); RHS += Loads; SolveSys(KK, RHS); q = RHS; -} \ No newline at end of file +} From 48ccac025b48a3fa4a3c9777e1559dfd3570e5e6 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Mon, 15 Apr 2019 13:57:23 +0200 Subject: [PATCH 07/20] cleaning --- CMakeLists.txt | 39 ++++++++++++++++++--------------------- _api/CMakeLists.txt | 8 +++++++- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87de427..52b4d35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,53 +1,50 @@ # Main CMake file for NativeSolid project PROJECT(NativeSolid) -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +CMAKE_MINIMUM_REQUIRED(VERSION 3.1) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin CACHE PATH "Single output directory for building all libraries.") SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin CACHE PATH "Single output directory for building all executables.") +MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH) set(CMAKE_MACOSX_RPATH ON) set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) -MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH) -if( NOT CMAKE_BUILD_TYPE ) - set( CMAKE_BUILD_TYPE Release CACHE STRING - "Choose the type of build, options are: None Debug Release RelWithDebInfo -MinSizeRel." - FORCE ) -endif() +# Type of build +IF( NOT CMAKE_BUILD_TYPE ) + SET( CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE ) +ENDIF() +MESSAGE(STATUS "Build type : ${CMAKE_BUILD_TYPE}") LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake") -# -- C++11 -- -INCLUDE(CheckCXXCompilerFlag) -CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) -CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) -IF(COMPILER_SUPPORTS_CXX11) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -ELSEIF(COMPILER_SUPPORTS_CXX0X) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") -ELSE() - MESSAGE(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") -ENDIF() +# -- C++11 +SET(CMAKE_CXX_STANDARD 11) # newer way to set C++11 (requires cmake>=3.1) +SET(CMAKE_CXX_STANDARD_REQUIRED ON) # -- CBLAS/LAPACKE -- FIND_PACKAGE(LAPACKE REQUIRED) FIND_PACKAGE(CBLAS REQUIRED) # -- Python -- +FIND_PACKAGE(PythonInterp REQUIRED) FIND_PACKAGE(PythonLibs REQUIRED) - MESSAGE(STATUS "PYTHON_INCLUDE_PATH=${PYTHON_INCLUDE_PATH}") +MESSAGE(STATUS "PYTHON_INCLUDE_PATH=${PYTHON_INCLUDE_PATH}") # -- SWIG -- FIND_PACKAGE(SWIG REQUIRED) SET(CMAKE_SWIG_OUTDIR "${EXECUTABLE_OUTPUT_PATH}") -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/api ${LAPACKE_INCLUDE_DIR} ${CBLAS_INCLUDE_DIR} ${PYTHON_INCLUDE_PATH}) +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/api + ${LAPACKE_INCLUDE_DIR} + ${CBLAS_INCLUDE_DIR} + ${PYTHON_INCLUDE_PATH} +) # -- Sub directories -- ADD_SUBDIRECTORY( src ) diff --git a/_api/CMakeLists.txt b/_api/CMakeLists.txt index f9a5495..bda59bb 100644 --- a/_api/CMakeLists.txt +++ b/_api/CMakeLists.txt @@ -14,6 +14,12 @@ SET(SWINCFLAGS SET_SOURCE_FILES_PROPERTIES(${ISRCS} PROPERTIES SWIG_FLAGS "${SWINCFLAGS}") -SWIG_ADD_MODULE(NativeSolid python ${ISRCS} ${SRCS}) +IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(NativeSolid python ${ISRCS} ${SRCS}) +ELSE() + SWIG_ADD_LIBRARY(NativeSolid + LANGUAGE python + SOURCES ${ISRCS} ${SRCS}) +ENDIF() SWIG_LINK_LIBRARIES(NativeSolid Native ${PYTHON_LIBRARIES}) From e7c99ae5ae8a34d3ba21f35bfbdbb50b14ece6c8 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Mon, 29 Apr 2019 16:16:13 +0200 Subject: [PATCH 08/20] look for python 2.7 instead of latest --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52b4d35..24622d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,8 @@ FIND_PACKAGE(LAPACKE REQUIRED) FIND_PACKAGE(CBLAS REQUIRED) # -- Python -- -FIND_PACKAGE(PythonInterp REQUIRED) -FIND_PACKAGE(PythonLibs REQUIRED) +FIND_PACKAGE(PythonInterp 2.7 REQUIRED) +FIND_PACKAGE(PythonLibs 2.7 REQUIRED) MESSAGE(STATUS "PYTHON_INCLUDE_PATH=${PYTHON_INCLUDE_PATH}") # -- SWIG -- From 792ed94930c4997ba45c6d0490dc4fb5812427b8 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Mon, 28 Feb 2022 10:43:07 +0100 Subject: [PATCH 09/20] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 50b8e97..955495a 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Required packages sudo apt-get install build-essential sudo apt-get install cmake sudo apt-get install liblapacke-dev -sudo apt-get install liblatlas-base-dev +sudo apt-get install libatlas-base-dev ``` Optional packages (parallel build) ``` From e06ed80cf9be3ac838b0707e327d870d222e4a7f Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Mon, 28 Feb 2022 16:30:59 +0100 Subject: [PATCH 10/20] use blas.so instead of cblas.so if cblas.so is not found (ubuntu 20.04) --- CMake/FindCBLAS.cmake | 4 +++- CMakeLists.txt | 24 +++++++++++++++++++----- src/CMakeLists.txt | 30 +++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/CMake/FindCBLAS.cmake b/CMake/FindCBLAS.cmake index b729bd7..4298060 100644 --- a/CMake/FindCBLAS.cmake +++ b/CMake/FindCBLAS.cmake @@ -1,6 +1,8 @@ FIND_PATH(CBLAS_INCLUDE_DIR NAMES cblas.h HINTS ${CBLAS_INCLUDE_CUSTOM_PATHS} PATHS ${CBLAS_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(CBLAS_LIBRARIES NAMES cblas HINTS ${CBLAS_LIB_CUSTOM_PATHS} PATHS ${CBLAS_LIB_SEARCH_PATHS}) +# on Ubuntu 20.04, +# cblas.so has been merged into blas.so (libblas-dev or libopenblas-dev package) +FIND_LIBRARY(CBLAS_LIBRARIES NAMES cblas blas HINTS ${CBLAS_LIB_CUSTOM_PATHS} PATHS ${CBLAS_LIB_SEARCH_PATHS}) FIND_LIBRARY(BLAS_LIBRARIES NAMES blas HINTS ${BLAS_LIB_CUSTOM_PATHS} PATHS ${BLAS_LIB_SEARCH_PATHS}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24622d5..269188f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,17 +23,31 @@ MESSAGE(STATUS "Build type : ${CMAKE_BUILD_TYPE}") LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake") # -- C++11 -SET(CMAKE_CXX_STANDARD 11) # newer way to set C++11 (requires cmake>=3.1) +SET(CMAKE_CXX_STANDARD 11) SET(CMAKE_CXX_STANDARD_REQUIRED ON) # -- CBLAS/LAPACKE -- FIND_PACKAGE(LAPACKE REQUIRED) -FIND_PACKAGE(CBLAS REQUIRED) +FIND_PACKAGE(CBLAS) # -- Python -- -FIND_PACKAGE(PythonInterp 2.7 REQUIRED) -FIND_PACKAGE(PythonLibs 2.7 REQUIRED) -MESSAGE(STATUS "PYTHON_INCLUDE_PATH=${PYTHON_INCLUDE_PATH}") +IF (CMAKE_VERSION VERSION_LESS 3.12.0) + FIND_PACKAGE(PythonInterp 3.6 REQUIRED) + FIND_PACKAGE(PythonLibs 3.6 REQUIRED) +ELSE() + find_package (Python3 COMPONENTS Interpreter Development) + # use Python3_ROOT_DIR if wrong python found (e.g. anaconda) + SET(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) + SET(PYTHON_LIBRARIES ${Python3_LIBRARIES}) + SET(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS}) + SET(PYTHONLIBS_VERSION_STRING ${Python3_VERSION}) +ENDIF() +MESSAGE(STATUS "PYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}") +MESSAGE(STATUS "PYTHON_LIBRARIES:FILEPATH=${PYTHON_LIBRARIES}") +MESSAGE(STATUS "PYTHON_INCLUDE_PATH:FILEPATH=${PYTHON_INCLUDE_PATH}") +MESSAGE(STATUS "PYTHON_FRAMEWORK_INCLUDES=${PYTHON_FRAMEWORK_INCLUDES}") +MESSAGE(STATUS "PYTHONLIBS_VERSION_STRING=${PYTHONLIBS_VERSION_STRING}") +MESSAGE(STATUS "Python_FRAMEWORKS=${Python_FRAMEWORKS}") # -- SWIG -- FIND_PACKAGE(SWIG REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c16a27..7800dde 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,9 +1,33 @@ # Compilation of the source code # Generation of a shared librairy libNative.so -ADD_LIBRARY(Native SHARED ../include/config.h ../include/geometry.h ../include/integration.h ../include/MatVec.h ../include/output.h ../include/structure.h ../include/solver.h config.cpp geometry.cpp integration.cpp MatVec.cpp output.cpp structure.cpp solver.cpp ../api/NativeSolid_API.h ../api/NativeSolid_API.cpp) +ADD_LIBRARY(Native SHARED + ../include/config.h + ../include/geometry.h + ../include/integration.h + ../include/MatVec.h + ../include/output.h + ../include/structure.h + ../include/solver.h + config.cpp + geometry.cpp + integration.cpp + MatVec.cpp + output.cpp + structure.cpp + solver.cpp + ../api/NativeSolid_API.h + ../api/NativeSolid_API.cpp +) -TARGET_LINK_LIBRARIES(Native ${LAPACKE_LIBRARIES} ${CBLAS_LIBRARIES} ${BLAS_LIBRARIES}) +TARGET_LINK_LIBRARIES(Native ${LAPACKE_LIBRARIES} + ${CBLAS_LIBRARIES} + ${BLAS_LIBRARIES}) ADD_EXECUTABLE(TestCVector ../include/MatVec.h MatVec.cpp testcvector.cpp) -TARGET_LINK_LIBRARIES(TestCVector ${LAPACKE_LIBRARIES} ${CBLAS_LIBRARIES} ${BLAS_LIBRARIES}) + +TARGET_LINK_LIBRARIES(TestCVector ${LAPACKE_LIBRARIES} + ${CBLAS_LIBRARIES} + ${BLAS_LIBRARIES}) + + From a6bbb0fe65c39a4653c08ce31837784b399f85fb Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Mon, 28 Feb 2022 16:51:51 +0100 Subject: [PATCH 11/20] add doc --- CMake/FindCBLAS.cmake | 3 ++- README.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMake/FindCBLAS.cmake b/CMake/FindCBLAS.cmake index 4298060..8e336ab 100644 --- a/CMake/FindCBLAS.cmake +++ b/CMake/FindCBLAS.cmake @@ -1,7 +1,8 @@ FIND_PATH(CBLAS_INCLUDE_DIR NAMES cblas.h HINTS ${CBLAS_INCLUDE_CUSTOM_PATHS} PATHS ${CBLAS_INCLUDE_SEARCH_PATHS}) # on Ubuntu 20.04, -# cblas.so has been merged into blas.so (libblas-dev or libopenblas-dev package) +# - cblas.so has been merged into blas.so (libblas-dev or libopenblas-dev package) +# - libatlas-dev cannot be used because cblas.h does not contain an extern "C" section FIND_LIBRARY(CBLAS_LIBRARIES NAMES cblas blas HINTS ${CBLAS_LIB_CUSTOM_PATHS} PATHS ${CBLAS_LIB_SEARCH_PATHS}) FIND_LIBRARY(BLAS_LIBRARIES NAMES blas HINTS ${BLAS_LIB_CUSTOM_PATHS} PATHS ${BLAS_LIB_SEARCH_PATHS}) diff --git a/README.md b/README.md index 955495a..8dc0b83 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ Required packages sudo apt-get install build-essential sudo apt-get install cmake sudo apt-get install liblapacke-dev -sudo apt-get install libatlas-base-dev +sudo apt-get install libatlas-base-dev # old debian / old ubuntu +sudo apt-get install libopenblas-dev # debian 10 / ubuntu 20.04 ``` Optional packages (parallel build) ``` From f0c87489781d7ea19ddeb9986bd9dedf32752ae8 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Thu, 3 Mar 2022 13:57:23 +0100 Subject: [PATCH 12/20] add basic CI --- .github/workflows/build-test.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/build-test.yml diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..bc41196 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,32 @@ +name: build-test + +on: [ push ] + # push: + # branches: [ main ] + # pull_request: + # branches: [ main ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + # - name: Test + # working-directory: ${{github.workspace}}/build + # # Execute tests defined by the CMake configuration. + # # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + # run: ctest -C ${{env.BUILD_TYPE}} + From 715a9820502c6695ba599b8217a16fbfb87e198a Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Thu, 3 Mar 2022 14:01:41 +0100 Subject: [PATCH 13/20] update workflow --- .github/workflows/build-test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index bc41196..d8f6233 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -17,6 +17,12 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Update repositories + run: sudo apt update + + - name: Install dependencies + run: sudo apt install libopenblas-dev liblapacke-dev libpython3-dev swig + - name: Configure CMake run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} From 8aa69e2aed714349909dd5093950c370c9cf8bc5 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Thu, 3 Mar 2022 14:29:17 +0100 Subject: [PATCH 14/20] indent / clean --- .clang-format | 11 + .editorconfig | 8 + .github/workflows/build-test.yml | 1 - CMakeLists.txt | 2 + README.md | 10 +- api/NativeSolid_API.cpp | 1066 ++++++++++++++------------ include/MatVec.h | 135 ++-- include/config.h | 18 +- include/geometry.h | 120 +-- include/integration.h | 16 +- include/output.h | 14 +- include/solver.h | 84 +-- include/structure.h | 11 +- src/CMakeLists.txt | 4 +- src/MatVec.cpp | 891 +++++++++++----------- src/config.cpp | 205 +++-- src/geometry.cpp | 514 +++++++------ src/integration.cpp | 229 +++--- src/output.cpp | 12 +- src/solver.cpp | 1201 ++++++++++++++++-------------- src/structure.cpp | 256 ++++--- src/testcvector.cpp | 239 +++--- 22 files changed, 2699 insertions(+), 2348 deletions(-) create mode 100644 .clang-format create mode 100644 .editorconfig diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..60cf9d5 --- /dev/null +++ b/.clang-format @@ -0,0 +1,11 @@ +--- +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html# +# the "Visual Studio" style is similar to: +BasedOnStyle: LLVM +UseTab: Never +IndentWidth: 4 +BreakBeforeBraces: Allman +AccessModifierOffset: -4 +SortIncludes: false +ColumnLimit: 0 +... diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..de6044b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +# EditorConfig is awesome: https://EditorConfig.org + +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 4 diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index d8f6233..13207b2 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -7,7 +7,6 @@ on: [ push ] # branches: [ main ] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release jobs: diff --git a/CMakeLists.txt b/CMakeLists.txt index 269188f..56b96d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,8 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include ${PYTHON_INCLUDE_PATH} ) +ENABLE_TESTING() + # -- Sub directories -- ADD_SUBDIRECTORY( src ) ADD_SUBDIRECTORY( _api ) diff --git a/README.md b/README.md index 8dc0b83..0f83afd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# NativeSolid +# NativeSolid / RBM Native solid solver for FSI ## Features @@ -18,6 +18,7 @@ Compute static or dynamic displacements for several 2D configurations. - Stiffness term only ## Compilation (linux -gcc) + Installation of NativeSolid code Required packages @@ -25,8 +26,7 @@ Required packages sudo apt-get install build-essential sudo apt-get install cmake sudo apt-get install liblapacke-dev -sudo apt-get install libatlas-base-dev # old debian / old ubuntu -sudo apt-get install libopenblas-dev # debian 10 / ubuntu 20.04 +sudo apt-get install libopenblas-dev ``` Optional packages (parallel build) ``` @@ -36,7 +36,7 @@ Compilation (you might need to set paths for headers and libraries in the FindCB ``` mkdir build && cd build cmake .. -make -j4 +make -j 4 ``` Environment variables ``` @@ -44,4 +44,4 @@ gedit /home/"username"/.bashrc export NATIVE_RUN="INSTALL_PATH/NativeSolid/bin" export PATH=$PATH:$NATIVE_RUN export PYTHONPATH=$PYTHONPATH:$NATIVE_RUN - +``` diff --git a/api/NativeSolid_API.cpp b/api/NativeSolid_API.cpp index d3e0ad5..654831f 100644 --- a/api/NativeSolid_API.cpp +++ b/api/NativeSolid_API.cpp @@ -6,23 +6,28 @@ using namespace std; const int MASTER_NODE = 0; +NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp) : confFile(str) +{ -NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp):confFile(str){ - - int rank = MASTER_NODE; + int rank = MASTER_NODE; - historyFile.open("NativeHistory.dat", ios::out); - historyFile2.open("NativeHistoryFSI.dat", ios::out); + historyFile.open("NativeHistory.dat", ios::out); + historyFile2.open("NativeHistoryFSI.dat", ios::out); /*--- MPI initialization, and buffer setting ---*/ #ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif - if(rank == MASTER_NODE){ - if(FSIComp)cout << endl << "***************************** Setting NativeSolid for FSI simulation *****************************" << endl; - else cout << endl <<"***************************** Setting NativeSolid for CSD simulation *****************************" << endl; - } + if (rank == MASTER_NODE) + { + if (FSIComp) + cout << endl + << "***************************** Setting NativeSolid for FSI simulation *****************************" << endl; + else + cout << endl + << "***************************** Setting NativeSolid for CSD simulation *****************************" << endl; + } config = NULL; output = NULL; @@ -35,27 +40,33 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp):confFile(str){ output = new Output(); /*--- Read CSD configuration file ---*/ - cout << endl << "\n----------------------- Reading Native configuration file ----------------------" << endl; + cout << endl + << "\n----------------------- Reading Native configuration file ----------------------" << endl; config->ReadConfig(); /*--- Read a SU2 native mesh file ---*/ - cout << endl << "\n----------------------- Reading SU2 based mesh file ----------------------" << endl; + cout << endl + << "\n----------------------- Reading SU2 based mesh file ----------------------" << endl; geometry = new Geometry(config); /*--- Initialize structural container and create the structural model ---*/ - cout << endl << "\n----------------------- Creating the structural model ----------------------" << endl; + cout << endl + << "\n----------------------- Creating the structural model ----------------------" << endl; structure = new Structure(config); - cout << endl << "\n----------------------- Creating the FSI interface ----------------------" << endl; - double* Coord; + cout << endl + << "\n----------------------- Creating the FSI interface ----------------------" << endl; + double *Coord; unsigned long iMarker(0), iPoint; - while(iMarker < geometry->GetnMarkers()){ - if(geometry->GetMarkersMoving(iMarker)){ - nSolidInterfaceVertex = geometry->nVertex[iMarker]; - break; - } - iMarker++; + while (iMarker < geometry->GetnMarkers()) + { + if (geometry->GetMarkersMoving(iMarker)) + { + nSolidInterfaceVertex = geometry->nVertex[iMarker]; + break; + } + iMarker++; } varCoordNorm = 0.0; @@ -63,118 +74,139 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp):confFile(str){ cout << nSolidInterfaceVertex << " nodes on the moving interface have to be tracked." << endl; /*--- Initialize the temporal integrator ---*/ - cout << endl << "\n----------------------- Setting integration parameter ----------------------" << endl; + cout << endl + << "\n----------------------- Setting integration parameter ----------------------" << endl; integrator = new Integration(config, structure); integrator->SetInitialConditions(config, structure); - cout << endl << "\n----------------------- Setting FSI features ----------------------" << endl; + cout << endl + << "\n----------------------- Setting FSI features ----------------------" << endl; q_uM1.Initialize(structure->GetnDof()); q_uM1.Reset(); - if(rank == MASTER_NODE){ - if(structure->GetnDof() == 1){ - if(config->GetUnsteady() == "YES"){ - historyFile << fixed - << setw(10) << "Delta_t" - << setw(10) << "FSI iter" - << setw(15) << "Displacement" - << setw(15) << "Velocity" - << setw(15) << "Acceleration" << endl; - historyFile2 << fixed - << setw(10) << "Time" - << setw(10) << "FSI iter" - << setw(15) << "Displacement" - << setw(15) << "Velocity" - << setw(15) << "Acceleration" << endl; - } - else{ - historyFile << fixed - << setw(10) << "Delta_t" - << setw(10) << "FSI iter" - << setw(15) << "Displacement" << endl; - historyFile2 << fixed - << setw(10) << "FSI iter" - << setw(15) << "Displacement" << endl; - } - } - else if(structure->GetnDof() == 2){ - if(config->GetUnsteady() == "YES"){ - historyFile << fixed - << setw(10) << "Delta_t" - << setw(10) << "FSI iter" - << setw(15) << "Displacement 1" - << setw(15) << "Displacement 2" - << setw(15) << "Velocity 1" - << setw(15) << "Velocity 2" - << setw(15) << "Acceleration 1" - << setw(15) << "Acceleration 2" << endl; - historyFile2 << fixed - << setw(10) << "Time" - << setw(10) << "FSI iter" - << setw(15) << "Displacement 1" - << setw(15) << "Displacement 2" - << setw(15) << "Velocity 1" - << setw(15) << "Velocity 2" - << setw(15) << "Acceleration 1" - << setw(15) << "Acceleration 2" << endl; + if (rank == MASTER_NODE) + { + if (structure->GetnDof() == 1) + { + if (config->GetUnsteady() == "YES") + { + historyFile << fixed + << setw(10) << "Delta_t" + << setw(10) << "FSI iter" + << setw(15) << "Displacement" + << setw(15) << "Velocity" + << setw(15) << "Acceleration" << endl; + historyFile2 << fixed + << setw(10) << "Time" + << setw(10) << "FSI iter" + << setw(15) << "Displacement" + << setw(15) << "Velocity" + << setw(15) << "Acceleration" << endl; + } + else + { + historyFile << fixed + << setw(10) << "Delta_t" + << setw(10) << "FSI iter" + << setw(15) << "Displacement" << endl; + historyFile2 << fixed + << setw(10) << "FSI iter" + << setw(15) << "Displacement" << endl; + } } - else{ - historyFile << fixed - << setw(10) << "Delta_t" - << setw(10) << "FSI iter" - << setw(15) << "Displacement 1" - << setw(15) << "Displacement 2" << endl; - historyFile2 << fixed - << setw(10) << "FSI iter" - << setw(15) << "Displacement 1" - << setw(15) << "Displacement 2" << endl; + else if (structure->GetnDof() == 2) + { + if (config->GetUnsteady() == "YES") + { + historyFile << fixed + << setw(10) << "Delta_t" + << setw(10) << "FSI iter" + << setw(15) << "Displacement 1" + << setw(15) << "Displacement 2" + << setw(15) << "Velocity 1" + << setw(15) << "Velocity 2" + << setw(15) << "Acceleration 1" + << setw(15) << "Acceleration 2" << endl; + historyFile2 << fixed + << setw(10) << "Time" + << setw(10) << "FSI iter" + << setw(15) << "Displacement 1" + << setw(15) << "Displacement 2" + << setw(15) << "Velocity 1" + << setw(15) << "Velocity 2" + << setw(15) << "Acceleration 1" + << setw(15) << "Acceleration 2" << endl; + } + else + { + historyFile << fixed + << setw(10) << "Delta_t" + << setw(10) << "FSI iter" + << setw(15) << "Displacement 1" + << setw(15) << "Displacement 2" << endl; + historyFile2 << fixed + << setw(10) << "FSI iter" + << setw(15) << "Displacement 1" + << setw(15) << "Displacement 2" << endl; + } } - } } - if(rank == MASTER_NODE){ - if(FSIComp)cout << endl << "***************************** NativeSolid is set for FSI simulation *****************************" << endl; - else cout << endl <<"***************************** NativeSolid is set for CSD simulation *****************************" << endl; - } - + if (rank == MASTER_NODE) + { + if (FSIComp) + cout << endl + << "***************************** NativeSolid is set for FSI simulation *****************************" << endl; + else + cout << endl + << "***************************** NativeSolid is set for CSD simulation *****************************" << endl; + } } -NativeSolidSolver::~NativeSolidSolver(){} +NativeSolidSolver::~NativeSolidSolver() {} -void NativeSolidSolver::exit(){ +void NativeSolidSolver::exit() +{ - int rank = MASTER_NODE; + int rank = MASTER_NODE; #ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif - historyFile.close(); - if(rank == MASTER_NODE){ - cout << "Solid history file is closed." << endl; - cout << endl << "***************************** Exit NativeSolid *****************************" << endl; - } - - if (config != NULL) delete config; - if (geometry != NULL) delete geometry; - if (structure != NULL) delete structure; - if (integrator != NULL) delete integrator; - if (output != NULL) delete output; + historyFile.close(); + if (rank == MASTER_NODE) + { + cout << "Solid history file is closed." << endl; + cout << endl + << "***************************** Exit NativeSolid *****************************" << endl; + } + if (config != NULL) + delete config; + if (geometry != NULL) + delete geometry; + if (structure != NULL) + delete structure; + if (integrator != NULL) + delete integrator; + if (output != NULL) + delete output; } -void NativeSolidSolver::preprocessIteration(unsigned long ExtIter){ +void NativeSolidSolver::preprocessIteration(unsigned long ExtIter) +{ integrator->SetExtIter(ExtIter); } -void NativeSolidSolver::timeIteration(double t0, double tf){ - - integrator->TemporalIteration(t0, tf, structure); +void NativeSolidSolver::timeIteration(double t0, double tf) +{ - //mapRigidBodyMotion(false, false); - computeInterfacePosVel(false); + integrator->TemporalIteration(t0, tf, structure); + // mapRigidBodyMotion(false, false); + computeInterfacePosVel(false); } /* @@ -324,11 +356,11 @@ void NativeSolidSolver::mapRigidBodyMotion(bool prediction, bool initialize){ } */ -void NativeSolidSolver::computeInterfacePosVel(bool initialize){ - +void NativeSolidSolver::computeInterfacePosVel(bool initialize) +{ double *Coord, *Coord_n, newCoord[3], newVel[3], Center[3], Center_n[3], newCenter[3], centerVel[3], rotCoord[3], r[3]; double varCoord[3] = {0.0, 0.0, 0.0}; - double rotMatrix[3][3] = {{0.0,0.0,0.0}, {0.0,0.0,0.0}, {0.0,0.0,0.0}}; + double rotMatrix[3][3] = {{0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}}; double dTheta, dPhi, dPsi; double psidot; double cosTheta, sinTheta, cosPhi, sinPhi, cosPsi, sinPsi; @@ -348,110 +380,120 @@ void NativeSolidSolver::computeInterfacePosVel(bool initialize){ dTheta = 0.0; dPhi = 0.0; - if (config->GetStructType() == "AIRFOIL"){ - dPsi = -( (integrator->GetSolver()->GetDisp())[1] - (integrator->GetSolver()->GetDisp_n())[1] ); - psidot = (integrator->GetSolver()->GetVel())[1]; - newCenter[0] = Center[0]; - newCenter[1] = -(integrator->GetSolver()->GetDisp())[0]; - newCenter[2] = Center[2]; - centerVel[0] = 0.0; - centerVel[1] = -(integrator->GetSolver()->GetVel())[0]; - centerVel[2] = 0.0; + if (config->GetStructType() == "AIRFOIL") + { + dPsi = -((integrator->GetSolver()->GetDisp())[1] - (integrator->GetSolver()->GetDisp_n())[1]); + psidot = (integrator->GetSolver()->GetVel())[1]; + newCenter[0] = Center[0]; + newCenter[1] = -(integrator->GetSolver()->GetDisp())[0]; + newCenter[2] = Center[2]; + centerVel[0] = 0.0; + centerVel[1] = -(integrator->GetSolver()->GetVel())[0]; + centerVel[2] = 0.0; } - else if(config->GetStructType() == "SPRING_HOR"){ - dPsi = 0.0; - psidot = 0.0; - newCenter[0] = (integrator->GetSolver()->GetDisp())[0]; - newCenter[1] = Center[1]; - newCenter[2] = Center[2]; - centerVel[0] = (integrator->GetSolver()->GetVel())[0]; - centerVel[1] = 0.0; - centerVel[2] = 0.0; + else if (config->GetStructType() == "SPRING_HOR") + { + dPsi = 0.0; + psidot = 0.0; + newCenter[0] = (integrator->GetSolver()->GetDisp())[0]; + newCenter[1] = Center[1]; + newCenter[2] = Center[2]; + centerVel[0] = (integrator->GetSolver()->GetVel())[0]; + centerVel[1] = 0.0; + centerVel[2] = 0.0; } - else if(config->GetStructType() == "SPRING_VER"){ - dPsi = 0.0; - psidot = 0.0; - newCenter[0] = Center[0]; - newCenter[1] = (integrator->GetSolver()->GetDisp())[0]; - newCenter[2] = Center[2]; - centerVel[0] = 0.0; - centerVel[1] = (integrator->GetSolver()->GetVel())[0]; - centerVel[2] = 0.0; + else if (config->GetStructType() == "SPRING_VER") + { + dPsi = 0.0; + psidot = 0.0; + newCenter[0] = Center[0]; + newCenter[1] = (integrator->GetSolver()->GetDisp())[0]; + newCenter[2] = Center[2]; + centerVel[0] = 0.0; + centerVel[1] = (integrator->GetSolver()->GetVel())[0]; + centerVel[2] = 0.0; + } + else + { } - else { } - cosTheta = cos(dTheta); cosPhi = cos(dPhi); cosPsi = cos(dPsi); - sinTheta = sin(dTheta); sinPhi = sin(dPhi); sinPsi = sin(dPsi); + cosTheta = cos(dTheta); + cosPhi = cos(dPhi); + cosPsi = cos(dPsi); + sinTheta = sin(dTheta); + sinPhi = sin(dPhi); + sinPsi = sin(dPsi); /*--- Compute the rotation matrix. The implicit ordering is rotation about the x-axis, y-axis, then z-axis. ---*/ - rotMatrix[0][0] = cosPhi*cosPsi; - rotMatrix[1][0] = cosPhi*sinPsi; + rotMatrix[0][0] = cosPhi * cosPsi; + rotMatrix[1][0] = cosPhi * sinPsi; rotMatrix[2][0] = -sinPhi; - rotMatrix[0][1] = sinTheta*sinPhi*cosPsi - cosTheta*sinPsi; - rotMatrix[1][1] = sinTheta*sinPhi*sinPsi + cosTheta*cosPsi; - rotMatrix[2][1] = sinTheta*cosPhi; - - rotMatrix[0][2] = cosTheta*sinPhi*cosPsi + sinTheta*sinPsi; - rotMatrix[1][2] = cosTheta*sinPhi*sinPsi - sinTheta*cosPsi; - rotMatrix[2][2] = cosTheta*cosPhi; - - - for(iMarker = 0; iMarker < geometry->GetnMarkers(); iMarker++){ - if (geometry->markersMoving[iMarker] == true){ - for(iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++){ - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - Coord_n = geometry->node[iPoint]->GetCoord_n(); - - if(config->GetUnsteady() == "YES"){ - for (int iDim=0; iDim < nDim; iDim++){ - r[iDim] = Coord_n[iDim] - Center_n[iDim]; + rotMatrix[0][1] = sinTheta * sinPhi * cosPsi - cosTheta * sinPsi; + rotMatrix[1][1] = sinTheta * sinPhi * sinPsi + cosTheta * cosPsi; + rotMatrix[2][1] = sinTheta * cosPhi; + + rotMatrix[0][2] = cosTheta * sinPhi * cosPsi + sinTheta * sinPsi; + rotMatrix[1][2] = cosTheta * sinPhi * sinPsi - sinTheta * cosPsi; + rotMatrix[2][2] = cosTheta * cosPhi; + + for (iMarker = 0; iMarker < geometry->GetnMarkers(); iMarker++) + { + if (geometry->markersMoving[iMarker] == true) + { + for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) + { + iPoint = geometry->vertex[iMarker][iVertex]; + Coord = geometry->node[iPoint]->GetCoord(); + Coord_n = geometry->node[iPoint]->GetCoord_n(); + + if (config->GetUnsteady() == "YES") + { + for (int iDim = 0; iDim < nDim; iDim++) + { + r[iDim] = Coord_n[iDim] - Center_n[iDim]; + } + } + else + { + for (int iDim = 0; iDim < nDim; iDim++) + { + r[iDim] = Coord[iDim] - Center[iDim]; + } + } + + rotCoord[0] = rotMatrix[0][0] * r[0] + rotMatrix[0][1] * r[1] + rotMatrix[0][2] * r[2]; + + rotCoord[1] = rotMatrix[1][0] * r[0] + rotMatrix[1][1] * r[1] + rotMatrix[1][2] * r[2]; + + rotCoord[2] = rotMatrix[2][0] * r[0] + rotMatrix[2][1] * r[1] + rotMatrix[2][2] * r[2]; + + for (int iDim = 0; iDim < nDim; iDim++) + { + newCoord[iDim] = newCenter[iDim] + rotCoord[iDim]; + varCoord[iDim] = newCoord[iDim] - Coord[iDim]; + } + + newVel[0] = centerVel[0] + psidot * (newCoord[1] - newCenter[1]); + newVel[1] = centerVel[1] - psidot * (newCoord[0] - newCenter[0]); + newVel[2] = centerVel[2] + 0.0; + + varCoordNorm2 += varCoord[0] * varCoord[0] + varCoord[1] * varCoord[1] + varCoord[2] * varCoord[2]; + + /*--- Apply change of coordinates to the node on the moving interface ---*/ + geometry->node[iPoint]->SetCoord(newCoord); + geometry->node[iPoint]->SetVel(newVel); + + /*--- At initialisation, propagate the initial position of the inteface in the past ---*/ + if (initialize) + { + geometry->node[iPoint]->SetCoord_n(newCoord); + geometry->node[iPoint]->SetVel_n(newVel); + } } - } - else{ - for (int iDim=0; iDim < nDim; iDim++){ - r[iDim] = Coord[iDim] - Center[iDim]; - } - } - - rotCoord[0] = rotMatrix[0][0]*r[0] - + rotMatrix[0][1]*r[1] - + rotMatrix[0][2]*r[2]; - - rotCoord[1] = rotMatrix[1][0]*r[0] - + rotMatrix[1][1]*r[1] - + rotMatrix[1][2]*r[2]; - - rotCoord[2] = rotMatrix[2][0]*r[0] - + rotMatrix[2][1]*r[1] - + rotMatrix[2][2]*r[2]; - - for(int iDim=0; iDim < nDim; iDim++){ - newCoord[iDim] = newCenter[iDim] + rotCoord[iDim]; - varCoord[iDim] = newCoord[iDim] - Coord[iDim]; - } - - newVel[0] = centerVel[0] + psidot*(newCoord[1]-newCenter[1]); - newVel[1] = centerVel[1] - psidot*(newCoord[0]-newCenter[0]); - newVel[2] = centerVel[2] + 0.0; - - varCoordNorm2 += varCoord[0]*varCoord[0] + varCoord[1]*varCoord[1] + varCoord[2]*varCoord[2]; - - /*--- Apply change of coordinates to the node on the moving interface ---*/ - geometry->node[iPoint]->SetCoord(newCoord); - geometry->node[iPoint]->SetVel(newVel); - - /*--- At initialisation, propagate the initial position of the inteface in the past ---*/ - if(initialize){ - geometry->node[iPoint]->SetCoord_n(newCoord); - geometry->node[iPoint]->SetVel_n(newVel); - } } - } } varCoordNorm = sqrt(varCoordNorm2); @@ -460,194 +502,243 @@ void NativeSolidSolver::computeInterfacePosVel(bool initialize){ structure->SetCenterOfRotation_X(newCenter[0]); structure->SetCenterOfRotation_Y(newCenter[1]); structure->SetCenterOfRotation_Z(newCenter[2]); - } -void NativeSolidSolver::setInitialDisplacements(){ - //mapRigidBodyMotion(false, true); - computeInterfacePosVel(true); +void NativeSolidSolver::setInitialDisplacements() +{ + // mapRigidBodyMotion(false, true); + computeInterfacePosVel(true); } +void NativeSolidSolver::staticComputation() +{ -void NativeSolidSolver::staticComputation(){ + integrator->StaticIteration(structure); - integrator->StaticIteration(structure); - - //mapRigidBodyMotion(false,false); - computeInterfacePosVel(false); + // mapRigidBodyMotion(false,false); + computeInterfacePosVel(false); } +void NativeSolidSolver::writeSolution(double currentTime, double lastTime, double currentFSIIter, unsigned long ExtIter, unsigned long NbExtIter) +{ -void NativeSolidSolver::writeSolution(double currentTime, double lastTime, double currentFSIIter, unsigned long ExtIter, unsigned long NbExtIter){ - - int rank = MASTER_NODE; - double DeltaT; - string restartFileName; - unsigned long DeltaIter = config->GetDeltaIterWrite(); + int rank = MASTER_NODE; + double DeltaT; + string restartFileName; + unsigned long DeltaIter = config->GetDeltaIterWrite(); - DeltaT = currentTime-lastTime; + DeltaT = currentTime - lastTime; #ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif - if(rank == MASTER_NODE){ - if(structure->GetnDof() == 1){ - if(config->GetUnsteady() == "YES"){ - //if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << "\"Acceleration variable\"" << endl; - historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << endl; - } - else{ - //if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement\"" << endl; - historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << endl; - } - } - else if(structure->GetnDof() == 2){ - if(config->GetUnsteady() == "YES"){ - //if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << "\t" << "\"Acceleration variable 1\"" << "\t" << "\"Acceleration variable 2\"" << endl; - historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << endl; - } - else{ - //if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 1\"" << endl; - historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << endl; + if (rank == MASTER_NODE) + { + if (structure->GetnDof() == 1) + { + if (config->GetUnsteady() == "YES") + { + // if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << "\"Acceleration variable\"" << endl; + historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << endl; + } + else + { + // if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement\"" << endl; + historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << endl; + } + } + else if (structure->GetnDof() == 2) + { + if (config->GetUnsteady() == "YES") + { + // if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << "\t" << "\"Acceleration variable 1\"" << "\t" << "\"Acceleration variable 2\"" << endl; + historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << endl; + } + else + { + // if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 1\"" << endl; + historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << endl; + } + } } - } - } - - - if(config->GetUnsteady() == "YES"){ - if ( ExtIter%DeltaIter == 0 || ExtIter == NbExtIter ){ - restartFileName = config->GetRestartFile(); - restartFile.open(restartFileName.c_str(), ios::out); - if (structure->GetnDof() == 1){ - restartFile << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << "\"Acceleration variable\"" << endl; - restartFile << currentTime-DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << endl; - restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << endl; - } - else if (structure->GetnDof() == 2){ - restartFile << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << "\t" << "\"Acceleration variable 1\"" << "\t" << "\"Acceleration variable 2\"" << endl; - restartFile << currentTime-DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetDisp_n())[1] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[1] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[1] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[1] << endl; - restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << endl; - } - restartFile.close(); - } - } + if (config->GetUnsteady() == "YES") + { + if (ExtIter % DeltaIter == 0 || ExtIter == NbExtIter) + { + restartFileName = config->GetRestartFile(); + restartFile.open(restartFileName.c_str(), ios::out); + if (structure->GetnDof() == 1) + { + restartFile << "\"Time\"" + << "\t" + << "\"Displacement\"" + << "\t" + << "\"Velocity\"" + << "\t" + << "\"Acceleration\"" + << "\t" + << "\"Acceleration variable\"" << endl; + restartFile << currentTime - DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << endl; + restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << endl; + } + else if (structure->GetnDof() == 2) + { + restartFile << "\"Time\"" + << "\t" + << "\"Displacement 1\"" + << "\t" + << "\"Displacement 2\"" + << "\t" + << "\"Velocity 1\"" + << "\t" + << "\"Velocity 2\"" + << "\t" + << "\"Acceleration 1\"" + << "\t" + << "\"Acceleration 2\"" + << "\t" + << "\"Acceleration variable 1\"" + << "\t" + << "\"Acceleration variable 2\"" << endl; + restartFile << currentTime - DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetDisp_n())[1] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[1] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[1] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[1] << endl; + restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << endl; + } + restartFile.close(); + } + } } -void NativeSolidSolver::saveSolution(){ +void NativeSolidSolver::saveSolution() +{ int rank = MASTER_NODE; double DeltaT; - //string restartFileName; - //unsigned long DeltaIter = config->GetDeltaIterWrite(); + // string restartFileName; + // unsigned long DeltaIter = config->GetDeltaIterWrite(); unsigned long ExtIter = integrator->GetExtIter(); DeltaT = config->GetDeltaT(); - #ifdef HAVE_MPI +#ifdef HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); - #endif +#endif - if(rank == MASTER_NODE){ - if(structure->GetnDof() == 1){ - if(config->GetUnsteady() == "YES"){ - historyFile << fixed - << setw(10) << DeltaT - << setw(10) << ExtIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; - } - else{ - historyFile << fixed - << setw(10) << DeltaT - << setw(10) << ExtIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; - } - } - else if(structure->GetnDof() == 2){ - if(config->GetUnsteady() == "YES"){ - historyFile << fixed - << setw(10) << DeltaT - << setw(10) << ExtIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[1] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; + if (rank == MASTER_NODE) + { + if (structure->GetnDof() == 1) + { + if (config->GetUnsteady() == "YES") + { + historyFile << fixed + << setw(10) << DeltaT + << setw(10) << ExtIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; + } + else + { + historyFile << fixed + << setw(10) << DeltaT + << setw(10) << ExtIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; + } } - else{ - historyFile << fixed - << setw(10) << DeltaT - << setw(10) << ExtIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; + else if (structure->GetnDof() == 2) + { + if (config->GetUnsteady() == "YES") + { + historyFile << fixed + << setw(10) << DeltaT + << setw(10) << ExtIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[1] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; + } + else + { + historyFile << fixed + << setw(10) << DeltaT + << setw(10) << ExtIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; + } } - } } - - } -void NativeSolidSolver::writeSolution(double time, int FSIter){ +void NativeSolidSolver::writeSolution(double time, int FSIter) +{ int rank = MASTER_NODE; - #ifdef HAVE_MPI +#ifdef HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); - #endif - - if(rank == MASTER_NODE){ - if(structure->GetnDof() == 1){ - if(config->GetUnsteady() == "YES"){ - historyFile2 << fixed - << setw(10) << time - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; - } - else{ - historyFile2 << fixed - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; - } - } - else if(structure->GetnDof() == 2){ - if(config->GetUnsteady() == "YES"){ - historyFile2 << fixed - << setw(10) << time - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[1] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; - } - else{ - historyFile2 << fixed - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; - } - } +#endif + + if (rank == MASTER_NODE) + { + if (structure->GetnDof() == 1) + { + if (config->GetUnsteady() == "YES") + { + historyFile2 << fixed + << setw(10) << time + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; + } + else + { + historyFile2 << fixed + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; + } + } + else if (structure->GetnDof() == 2) + { + if (config->GetUnsteady() == "YES") + { + historyFile2 << fixed + << setw(10) << time + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] + << setw(15) << (integrator->GetSolver()->GetVel())[0] + << setw(15) << (integrator->GetSolver()->GetVel())[1] + << setw(15) << (integrator->GetSolver()->GetAcc())[0] + << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; + } + else + { + historyFile2 << fixed + << setw(10) << FSIter + << setw(15) << (integrator->GetSolver()->GetDisp())[0] + << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; + } + } } } -void NativeSolidSolver::updateSolution(){ +void NativeSolidSolver::updateSolution() +{ - if(config->GetUnsteady() == "YES"){ - integrator->UpdateSolution(); - geometry->UpdateGeometry(); - structure->SetCenterOfRotation_n_X(structure->GetCenterOfRotation_x()); - structure->SetCenterOfRotation_n_Y(structure->GetCenterOfRotation_y()); - structure->SetCenterOfRotation_n_Z(structure->GetCenterOfRotation_z()); - } - else - q_uM1 = (integrator->GetSolver()->GetDisp()); + if (config->GetUnsteady() == "YES") + { + integrator->UpdateSolution(); + geometry->UpdateGeometry(); + structure->SetCenterOfRotation_n_X(structure->GetCenterOfRotation_x()); + structure->SetCenterOfRotation_n_Y(structure->GetCenterOfRotation_y()); + structure->SetCenterOfRotation_n_Z(structure->GetCenterOfRotation_z()); + } + else + q_uM1 = (integrator->GetSolver()->GetDisp()); } /* @@ -668,35 +759,40 @@ void NativeSolidSolver::displacementPredictor(){ }*/ -unsigned short NativeSolidSolver::getFSIMarkerID(){ - - unsigned short iMarker(0), IDtoSend; +unsigned short NativeSolidSolver::getFSIMarkerID() +{ + unsigned short iMarker(0), IDtoSend; - while(iMarker < geometry->GetnMarkers()){ - if(geometry->GetMarkersMoving(iMarker)){ - IDtoSend = iMarker; - break; - } - iMarker++; - } - return IDtoSend; + while (iMarker < geometry->GetnMarkers()) + { + if (geometry->GetMarkersMoving(iMarker)) + { + IDtoSend = iMarker; + break; + } + iMarker++; + } + return IDtoSend; } -unsigned long NativeSolidSolver::getNumberOfSolidInterfaceNodes(unsigned short iMarker){ - return nSolidInterfaceVertex; +unsigned long NativeSolidSolver::getNumberOfSolidInterfaceNodes(unsigned short iMarker) +{ + return nSolidInterfaceVertex; } -unsigned int NativeSolidSolver::getInterfaceNodeGlobalIndex(unsigned short iMarker, unsigned short iVertex){ +unsigned int NativeSolidSolver::getInterfaceNodeGlobalIndex(unsigned short iMarker, unsigned short iVertex) +{ - unsigned long iPoint; + unsigned long iPoint; - iPoint = geometry->vertex[iMarker][iVertex]; + iPoint = geometry->vertex[iMarker][iVertex]; - return iPoint; + return iPoint; } -double NativeSolidSolver::getInterfaceNodePosX(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodePosX(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord; @@ -707,7 +803,8 @@ double NativeSolidSolver::getInterfaceNodePosX(unsigned short iMarker, unsigned return Coord[0]; } -double NativeSolidSolver::getInterfaceNodePosY(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodePosY(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord; @@ -718,7 +815,8 @@ double NativeSolidSolver::getInterfaceNodePosY(unsigned short iMarker, unsigned return Coord[1]; } -double NativeSolidSolver::getInterfaceNodePosZ(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodePosZ(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord; @@ -726,10 +824,11 @@ double NativeSolidSolver::getInterfaceNodePosZ(unsigned short iMarker, unsigned iPoint = geometry->vertex[iMarker][iVertex]; Coord = geometry->node[iPoint]->GetCoord(); - return 0.0; //3D is not really implemented in this solver... + return 0.0; // 3D is not really implemented in this solver... } -double NativeSolidSolver::getInterfaceNodePosX0(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodePosX0(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord; @@ -740,7 +839,8 @@ double NativeSolidSolver::getInterfaceNodePosX0(unsigned short iMarker, unsigned return Coord[0]; } -double NativeSolidSolver::getInterfaceNodePosY0(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodePosY0(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord; @@ -751,7 +851,8 @@ double NativeSolidSolver::getInterfaceNodePosY0(unsigned short iMarker, unsigned return Coord[1]; } -double NativeSolidSolver::getInterfaceNodePosZ0(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodePosZ0(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord; @@ -762,7 +863,8 @@ double NativeSolidSolver::getInterfaceNodePosZ0(unsigned short iMarker, unsigned return 0.0; } -double NativeSolidSolver::getInterfaceNodeDispX(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeDispX(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord, *Coord0; @@ -774,7 +876,8 @@ double NativeSolidSolver::getInterfaceNodeDispX(unsigned short iMarker, unsigned return Coord[0] - Coord0[0]; } -double NativeSolidSolver::getInterfaceNodeDispY(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeDispY(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord, *Coord0; @@ -785,7 +888,8 @@ double NativeSolidSolver::getInterfaceNodeDispY(unsigned short iMarker, unsigned return Coord[1] - Coord0[1]; } -double NativeSolidSolver::getInterfaceNodeDispZ(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeDispZ(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Coord, *Coord0; @@ -797,7 +901,8 @@ double NativeSolidSolver::getInterfaceNodeDispZ(unsigned short iMarker, unsigned return Coord[2] - Coord0[2]; } -double NativeSolidSolver::getInterfaceNodeVelX(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeVelX(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Vel; @@ -807,7 +912,8 @@ double NativeSolidSolver::getInterfaceNodeVelX(unsigned short iMarker, unsigned return Vel[0]; } -double NativeSolidSolver::getInterfaceNodeVelY(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeVelY(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Vel; @@ -817,7 +923,8 @@ double NativeSolidSolver::getInterfaceNodeVelY(unsigned short iMarker, unsigned return Vel[1]; } -double NativeSolidSolver::getInterfaceNodeVelZ(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeVelZ(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Vel; @@ -827,7 +934,8 @@ double NativeSolidSolver::getInterfaceNodeVelZ(unsigned short iMarker, unsigned return Vel[2]; } -double NativeSolidSolver::getInterfaceNodeVelXNm1(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeVelXNm1(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Vel_n; @@ -837,7 +945,8 @@ double NativeSolidSolver::getInterfaceNodeVelXNm1(unsigned short iMarker, unsign return Vel_n[0]; } -double NativeSolidSolver::getInterfaceNodeVelYNm1(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeVelYNm1(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Vel_n; @@ -847,7 +956,8 @@ double NativeSolidSolver::getInterfaceNodeVelYNm1(unsigned short iMarker, unsign return Vel_n[1]; } -double NativeSolidSolver::getInterfaceNodeVelZNm1(unsigned short iMarker, unsigned short iVertex){ +double NativeSolidSolver::getInterfaceNodeVelZNm1(unsigned short iMarker, unsigned short iVertex) +{ unsigned long iPoint; double *Vel_n; @@ -857,117 +967,144 @@ double NativeSolidSolver::getInterfaceNodeVelZNm1(unsigned short iMarker, unsign return Vel_n[2]; } -double NativeSolidSolver::getRotationCenterPosX(){ +double NativeSolidSolver::getRotationCenterPosX() +{ return structure->GetCenterOfRotation_x(); - } -double NativeSolidSolver::getRotationCenterPosY(){ +double NativeSolidSolver::getRotationCenterPosY() +{ return structure->GetCenterOfRotation_y(); } -double NativeSolidSolver::getRotationCenterPosZ(){ +double NativeSolidSolver::getRotationCenterPosZ() +{ return structure->GetCenterOfRotation_z(); } -void NativeSolidSolver::setGeneralisedForce(){ +void NativeSolidSolver::setGeneralisedForce() +{ - unsigned short iVertex, iMarker; - unsigned long iPoint; - double ForceX(0.0), ForceY(0.0), ForceZ(0.0); - double* force; - - iMarker = getFSIMarkerID(); + unsigned short iVertex, iMarker; + unsigned long iPoint; + double ForceX(0.0), ForceY(0.0), ForceZ(0.0); + double *force; - for(iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++){ - iPoint = geometry->vertex[iMarker][iVertex]; - force = geometry->node[iPoint]->GetForce(); - ForceX += force[0]; - ForceY += force[1]; - ForceZ += force[2]; - } + iMarker = getFSIMarkerID(); - if(config->GetStructType() == "SPRING_HOR"){ - (integrator->GetSolver()->GetLoads())[0] = ForceX; - } - else if(config->GetStructType() == "SPRING_VER"){ - (integrator->GetSolver()->GetLoads())[0] = ForceY; - } - else if(config->GetStructType() == "AIRFOIL"){ - (integrator->GetSolver()->GetLoads())[0] = -ForceY; - } - else{ - cerr << "Wrong structural type for applying global fluild loads !" << endl; - throw(-1); - } + for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) + { + iPoint = geometry->vertex[iMarker][iVertex]; + force = geometry->node[iPoint]->GetForce(); + ForceX += force[0]; + ForceY += force[1]; + ForceZ += force[2]; + } + if (config->GetStructType() == "SPRING_HOR") + { + (integrator->GetSolver()->GetLoads())[0] = ForceX; + } + else if (config->GetStructType() == "SPRING_VER") + { + (integrator->GetSolver()->GetLoads())[0] = ForceY; + } + else if (config->GetStructType() == "AIRFOIL") + { + (integrator->GetSolver()->GetLoads())[0] = -ForceY; + } + else + { + cerr << "Wrong structural type for applying global fluild loads !" << endl; + throw(-1); + } } -void NativeSolidSolver::setGeneralisedForce(double Fx, double Fy){ +void NativeSolidSolver::setGeneralisedForce(double Fx, double Fy) +{ - if(config->GetStructType() == "SPRING_HOR"){ - (integrator->GetSolver()->GetLoads())[0] = Fx; - } - else if(config->GetStructType() == "SPRING_VER"){ - (integrator->GetSolver()->GetLoads())[0] = Fy; - } - else if(config->GetStructType() == "AIRFOIL"){ - (integrator->GetSolver()->GetLoads())[0] = -Fy; - } - else{ - cerr << "Wrong structural type for applying global fluild loads !" << endl; - throw(-1); - } + if (config->GetStructType() == "SPRING_HOR") + { + (integrator->GetSolver()->GetLoads())[0] = Fx; + } + else if (config->GetStructType() == "SPRING_VER") + { + (integrator->GetSolver()->GetLoads())[0] = Fy; + } + else if (config->GetStructType() == "AIRFOIL") + { + (integrator->GetSolver()->GetLoads())[0] = -Fy; + } + else + { + cerr << "Wrong structural type for applying global fluild loads !" << endl; + throw(-1); + } } -void NativeSolidSolver::setGeneralisedMoment(){ +void NativeSolidSolver::setGeneralisedMoment() +{ - unsigned short iVertex, iMarker; - unsigned long iPoint; - double Moment(0.0), CenterX, CenterY, CenterZ; - double* Force; - double* Coord; - - iMarker = getFSIMarkerID(); - - for(iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++){ - iPoint = geometry->vertex[iMarker][iVertex]; - Force = geometry->node[iPoint]->GetForce(); - Coord = geometry->node[iPoint]->GetCoord(); - CenterX = getRotationCenterPosX(); - CenterY = getRotationCenterPosY(); - Moment += (Force[1]*(Coord[0]-CenterX) - Force[0]*(Coord[1]-CenterY)); - } + unsigned short iVertex, iMarker; + unsigned long iPoint; + double Moment(0.0), CenterX, CenterY, CenterZ; + double *Force; + double *Coord; - if(config->GetStructType() == "AIRFOIL"){ - (integrator->GetSolver()->GetLoads())[1] = -Moment; - } - else if(config->GetStructType() == "SPRING_VER"){} - else if(config->GetStructType() == "SPRING_HOR"){} - else{ - cerr << "Wrong structural type for applying global fluild loads !" << endl; - throw(-1); - } + iMarker = getFSIMarkerID(); + + for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) + { + iPoint = geometry->vertex[iMarker][iVertex]; + Force = geometry->node[iPoint]->GetForce(); + Coord = geometry->node[iPoint]->GetCoord(); + CenterX = getRotationCenterPosX(); + CenterY = getRotationCenterPosY(); + Moment += (Force[1] * (Coord[0] - CenterX) - Force[0] * (Coord[1] - CenterY)); + } + if (config->GetStructType() == "AIRFOIL") + { + (integrator->GetSolver()->GetLoads())[1] = -Moment; + } + else if (config->GetStructType() == "SPRING_VER") + { + } + else if (config->GetStructType() == "SPRING_HOR") + { + } + else + { + cerr << "Wrong structural type for applying global fluild loads !" << endl; + throw(-1); + } } -void NativeSolidSolver::setGeneralisedMoment(double M){ +void NativeSolidSolver::setGeneralisedMoment(double M) +{ - if(config->GetStructType() == "AIRFOIL"){ - (integrator->GetSolver()->GetLoads())[1] = -M; - } - else if(config->GetStructType() == "SPRING_VER"){} - else if(config->GetStructType() == "SPRING_HOR"){} - else{ - cerr << "Wrong structural type for applying global fluild loads !" << endl; - throw(-1); - } + if (config->GetStructType() == "AIRFOIL") + { + (integrator->GetSolver()->GetLoads())[1] = -M; + } + else if (config->GetStructType() == "SPRING_VER") + { + } + else if (config->GetStructType() == "SPRING_HOR") + { + } + else + { + cerr << "Wrong structural type for applying global fluild loads !" << endl; + throw(-1); + } } -void NativeSolidSolver::applyload(unsigned short iVertex, double Fx, double Fy, double Fz){ +void NativeSolidSolver::applyload(unsigned short iVertex, double Fx, double Fy, double Fz) +{ unsigned short iMarker; unsigned long iPoint; @@ -980,5 +1117,4 @@ void NativeSolidSolver::applyload(unsigned short iVertex, double Fx, double Fy, iMarker = getFSIMarkerID(); iPoint = geometry->vertex[iMarker][iVertex]; geometry->node[iPoint]->SetForce(Force); - } diff --git a/include/MatVec.h b/include/MatVec.h index 364ffe9..dc5ba00 100644 --- a/include/MatVec.h +++ b/include/MatVec.h @@ -6,34 +6,35 @@ #define ROW_MAJ 0 #define COL_MAJ 1 -class CVector { - +class CVector +{ protected: unsigned long nElm; - double* vec_val; + double *vec_val; public: CVector(void); - CVector(const unsigned long & size, const double & val = 0.0); - CVector(const CVector & u); + CVector(const unsigned long &size, const double &val = 0.0); + CVector(const CVector &u); ~CVector(); unsigned long GetSize() const; - double* GetVec() const; + double *GetVec() const; void print() const; - void Initialize(const unsigned long & size, const double & val = 0.0); - void SetAllValues(const double & val); - CVector & operator=(const CVector & u); - CVector & operator+=(const CVector & u); - CVector & operator-=(const CVector & u); - CVector & operator*=(const double & val); - CVector & operator/=(const double & val); - double & operator[](const unsigned long & i) const; + void Initialize(const unsigned long &size, const double &val = 0.0); + void SetAllValues(const double &val); + CVector &operator=(const CVector &u); + CVector &operator+=(const CVector &u); + CVector &operator-=(const CVector &u); + CVector &operator*=(const double &val); + CVector &operator/=(const double &val); + double &operator[](const unsigned long &i) const; double norm() const; - double dotProd(const CVector & v) const; + double dotProd(const CVector &v) const; void Reset(); }; -class CMatrix { +class CMatrix +{ protected: unsigned long nEq; @@ -42,65 +43,63 @@ class CMatrix { public: CMatrix(void); - CMatrix(const unsigned long & val_nEq, const unsigned long & val_nVar, const double & val = 0.0); - CMatrix(const CMatrix & A); + CMatrix(const unsigned long &val_nEq, const unsigned long &val_nVar, const double &val = 0.0); + CMatrix(const CMatrix &A); ~CMatrix(); - void Initialize(const unsigned long & val_nEq, const unsigned long & val_nVar, const double & val = 0.0); + void Initialize(const unsigned long &val_nEq, const unsigned long &val_nVar, const double &val = 0.0); void print() const; - CMatrix & operator=(const CMatrix & a); - CMatrix & operator+=(const CMatrix & a); - CMatrix & operator-=(const CMatrix & a); - CMatrix & operator*=(const double & val); - CMatrix & operator/=(const double & val); + CMatrix &operator=(const CMatrix &a); + CMatrix &operator+=(const CMatrix &a); + CMatrix &operator-=(const CMatrix &a); + CMatrix &operator*=(const double &val); + CMatrix &operator/=(const double &val); unsigned long GetnEq() const; unsigned long GetnVar() const; - double* GetMat() const; + double *GetMat() const; CVector GetCVec() const; - void SetElm(const int & i, const int & j, double val); - double GetElm(const int & i, const int & j) const; + void SetElm(const int &i, const int &j, double val); + double GetElm(const int &i, const int &j) const; double DiagProduct() const; double ComputeDet() const; void Reset(); }; -CVector MatVecProd(const CMatrix & A, const CVector & b); -CVector ScalVecProd(const double & scal, const CVector & b); -CMatrix ScalMatProd(const double & scal, const CMatrix & A); -int SolveSys(const CMatrix & A, CVector & b); - -void MatrixToVec(int order, double** matrix, double* vecteur, int Nrow, int Ncol, int sizeVec); -void VecToMatrix(int order, double** matrix, double* vecteur, int Nrow, int Ncol, int sizeVec); - -/*OPERATOR +*/ -CVector operator+(CVector & vecA, CVector & vecB); -CVector operator+(const CVector & vecA, const CVector & vecB); -CVector operator+(CVector & vecA, const CVector & vecB); -CVector operator+(const CVector & vecA, CVector & vecB); -CMatrix operator+(const CMatrix & matA, const CMatrix & matB); - - -/*OPERATOR -*/ -CVector operator-(CVector & vecA, CVector & vecB); -CVector operator-(const CVector & vecA, CVector & vecB); -CVector operator-(CVector & vecA, const CVector & vecB); -CVector operator-(const CVector & vecA, const CVector & vecB); -CMatrix operator-(const CMatrix & matA, const CMatrix & matB); - -/*OPERATOR * */ -CVector operator*(CVector & vecA, double & val_mult); -CVector operator*(CVector & vecA, const double & val_mult); -CVector operator*(const CVector & vecA, double & val_mult); -CVector operator*(const CVector & vecA, const double & val_mult); -CVector operator*(double & val_mult, CVector & vecA); -CVector operator*(const double & val_mult, CVector & vecA); -CVector operator*(double & val_mult, const CVector & vecA); -CVector operator*(const double & val_mult, const CVector & vecA); -CMatrix operator*(CMatrix matA, double & val); -CMatrix operator*(double & val, CMatrix matA); - - -/*OPERATOR / */ -CVector operator/(CVector & vecA, double & val_mult); -CVector operator/(CVector & vecA, const double & val_mult); -CVector operator/(const CVector & vecA, double & val_mult); -CVector operator/(const CVector & vecA, const double & val_mult); +CVector MatVecProd(const CMatrix &A, const CVector &b); +CVector ScalVecProd(const double &scal, const CVector &b); +CMatrix ScalMatProd(const double &scal, const CMatrix &A); +int SolveSys(const CMatrix &A, CVector &b); + +void MatrixToVec(int order, double **matrix, double *vecteur, int Nrow, int Ncol, int sizeVec); +void VecToMatrix(int order, double **matrix, double *vecteur, int Nrow, int Ncol, int sizeVec); + +// OPERATOR + +CVector operator+(CVector &vecA, CVector &vecB); +CVector operator+(const CVector &vecA, const CVector &vecB); +CVector operator+(CVector &vecA, const CVector &vecB); +CVector operator+(const CVector &vecA, CVector &vecB); +CMatrix operator+(const CMatrix &matA, const CMatrix &matB); + +// OPERATOR - +CVector operator-(CVector &vecA, CVector &vecB); +CVector operator-(const CVector &vecA, CVector &vecB); +CVector operator-(CVector &vecA, const CVector &vecB); +CVector operator-(const CVector &vecA, const CVector &vecB); +CMatrix operator-(const CMatrix &matA, const CMatrix &matB); + +// OPERATOR * +CVector operator*(CVector &vecA, double &val_mult); +CVector operator*(CVector &vecA, const double &val_mult); +CVector operator*(const CVector &vecA, double &val_mult); +CVector operator*(const CVector &vecA, const double &val_mult); +CVector operator*(double &val_mult, CVector &vecA); +CVector operator*(const double &val_mult, CVector &vecA); +CVector operator*(double &val_mult, const CVector &vecA); +CVector operator*(const double &val_mult, const CVector &vecA); +CMatrix operator*(CMatrix matA, double &val); +CMatrix operator*(double &val, CMatrix matA); + +// OPERATOR / +CVector operator/(CVector &vecA, double &val_mult); +CVector operator/(CVector &vecA, const double &val_mult); +CVector operator/(const CVector &vecA, double &val_mult); +CVector operator/(const CVector &vecA, const double &val_mult); diff --git a/include/config.h b/include/config.h index 087f6b8..b0e9bd7 100644 --- a/include/config.h +++ b/include/config.h @@ -2,13 +2,12 @@ #include - -class Config{ - +class Config +{ public: Config(std::string filename); virtual ~Config(); - virtual Config* GetAddress(); + virtual Config *GetAddress(); virtual void ReadConfig(); virtual std::string GetMeshFile(); virtual std::string GetUnsteady(); @@ -39,8 +38,13 @@ class Config{ protected: std::string ConfigFileName; - std::string MESH_FILE, UNSTEADY_SIMULATION, CSD_SOLVER, STRUCT_TYPE, LINEARIZE, INTEGRATION_ALGO, RESTART_SOL, RESTART_FILE, MOVING_MARKER; - double SPRING_STIFFNESS, SPRING_MASS, INERTIA_CG, INERTIA_FLEXURAL, SPRING_DAMPING, TORSIONAL_STIFFNESS, TORSIONAL_DAMPING, CORD, FLEXURAL_AXIS, GRAVITY_CENTER, INITIAL_DISP, INITIAL_ANGLE, START_TIME, DELTA_T, STOP_TIME, RHO; + std::string MESH_FILE, UNSTEADY_SIMULATION, CSD_SOLVER, + STRUCT_TYPE, LINEARIZE, INTEGRATION_ALGO, + RESTART_SOL, RESTART_FILE, MOVING_MARKER; + double SPRING_STIFFNESS, SPRING_MASS, INERTIA_CG, + INERTIA_FLEXURAL, SPRING_DAMPING, TORSIONAL_STIFFNESS, + TORSIONAL_DAMPING, CORD, FLEXURAL_AXIS, GRAVITY_CENTER, + INITIAL_DISP, INITIAL_ANGLE, START_TIME, + DELTA_T, STOP_TIME, RHO; unsigned long DELTAITERWRITE; - }; diff --git a/include/geometry.h b/include/geometry.h index 2b255bd..04e10f0 100644 --- a/include/geometry.h +++ b/include/geometry.h @@ -3,92 +3,54 @@ #include "config.h" #include -class Point{ - +class Point +{ protected: - double* Coord0; - double* Coord; - double* Coord_n; - double* Vel; - double* Vel_n; - double* Force; + double *Coord0; + double *Coord; + double *Coord_n; + double *Vel; + double *Vel_n; + double *Force; public: - Point(); - ~Point(); - double* GetCoord0() const; - double* GetCoord() const; - double* GetCoord_n() const; - double* GetVel() const; - double* GetVel_n() const; - double* GetForce() const; - void PrintCoord() const; - void SetCoord0(double* newCoord); - void SetCoord(double* newCoord); - void SetCoord_n(double* newCoord); - void SetVel(double* newVel); - void SetVel_n(double* newVel_n); - void SetForce(double* newForce); - void UpdateCoord(); - void UpdateVel(); + Point(); + ~Point(); + double *GetCoord0() const; + double *GetCoord() const; + double *GetCoord_n() const; + double *GetVel() const; + double *GetVel_n() const; + double *GetForce() const; + void PrintCoord() const; + void SetCoord0(double *newCoord); + void SetCoord(double *newCoord); + void SetCoord_n(double *newCoord); + void SetVel(double *newVel); + void SetVel_n(double *newVel_n); + void SetForce(double *newForce); + void UpdateCoord(); + void UpdateVel(); }; -/*class Vertex{ - -protected: - double* Coord; - -public: - Vertex(); - ~Vertex(); - double* GetCoord() const; - void SetCoord(double* newCoord); - -}*/ - -/*class Element{ - -protected: - Point** pointElem; - unsigned short nPointElem; - -public: - Element(); - ~Element(); -}*/ - -/*class Marker{ - -protected: - std::string MarkerTag; - unsigned long nElem; - -public: - Marker(std::string Tag, unsigned long nElem_value); - ~Marker(); - Vertex** vertex; - Element** element; - -}*/ - -class Geometry{ - +class Geometry +{ protected: - unsigned short nDim; - unsigned long nElem, nPoint, nMarkers; - unsigned long* nElemMarker; + unsigned short nDim; + unsigned long nElem, nPoint, nMarkers; + unsigned long *nElemMarker; public: - Geometry(Config* config); - ~Geometry(); - unsigned long GetnMarkers() const; - bool GetMarkersMoving(unsigned long iMarker) const; - void UpdateGeometry(); - unsigned long** vertex; //vertex[iMarker][iPoint] - unsigned long* nVertex; //nVertex[iMarker] - bool* markersMoving; - Point** node; //node[iPoint] returns a pointeur to a Point object so e.g. node[iPoint]->PrintCoord(); + Geometry(Config *config); + ~Geometry(); + unsigned long GetnMarkers() const; + bool GetMarkersMoving(unsigned long iMarker) const; + void UpdateGeometry(); + unsigned long **vertex; // vertex[iMarker][iPoint] + unsigned long *nVertex; // nVertex[iMarker] + bool *markersMoving; + Point **node; // node[iPoint] returns a pointeur to a Point object so e.g. node[iPoint]->PrintCoord(); }; -bool isInVec(std::vector const& inputVector, int dummyInt); -void vecCopy(std::vector const& sourceVector, unsigned long* destinationTab); +bool isInVec(std::vector const &inputVector, int dummyInt); +void vecCopy(std::vector const &sourceVector, unsigned long *destinationTab); diff --git a/include/integration.h b/include/integration.h index 1dd6e69..8a3e547 100644 --- a/include/integration.h +++ b/include/integration.h @@ -1,33 +1,31 @@ #pragma once -//#include "MatVec.h" #include "config.h" #include "structure.h" #include "solver.h" #define PI 3.14159265 - -class Integration{ - +class Integration +{ protected: double totTime; double deltaT; unsigned long ExtIter; std::string algo; - Solver* solver; + Solver *solver; public: - Integration(Config* config, Structure* structure); + Integration(Config *config, Structure *structure); ~Integration(); - Solver* GetSolver(); + Solver *GetSolver(); double GettotTime(); double GetdeltaT(); void SetExtIter(unsigned long val_ExtIter); unsigned long GetExtIter(); - void SetInitialConditions(Config* config, Structure* structure); - void TemporalIteration(double& t0, double& tf, Structure *structure); + void SetInitialConditions(Config *config, Structure *structure); + void TemporalIteration(double &t0, double &tf, Structure *structure); void StaticIteration(Structure *structure); void UpdateSolution(); }; diff --git a/include/output.h b/include/output.h index 44ba131..fc0e823 100644 --- a/include/output.h +++ b/include/output.h @@ -7,13 +7,13 @@ #include "structure.h" #include "integration.h" -class Output{ - +class Output +{ public: - Output(void); + Output(); ~Output(); - //void WriteHistory(Integration* solver, Structure* structure, std::ofstream* outputfile, const double & time); - //void WriteRestart(Integration* solver, Structure* structure); - //void WriteStaticSolution(Config* config, Integration* solver, Structure* structure, std::ofstream* outputfile); - //void WriteRestart(); + // void WriteHistory(Integration* solver, Structure* structure, std::ofstream* outputfile, const double & time); + // void WriteRestart(Integration* solver, Structure* structure); + // void WriteStaticSolution(Config* config, Integration* solver, Structure* structure, std::ofstream* outputfile); + // void WriteRestart(); }; diff --git a/include/solver.h b/include/solver.h index b89be5d..ea9244f 100644 --- a/include/solver.h +++ b/include/solver.h @@ -4,8 +4,8 @@ #include "structure.h" #include "config.h" -class Solver{ - +class Solver +{ protected: CVector q; CVector qdot; @@ -22,24 +22,23 @@ class Solver{ public: Solver(unsigned int nDof, bool bool_linear); virtual ~Solver(); - virtual void Iterate(double& t0, double& tf, Structure* structure); - virtual CVector & GetDisp(); - virtual CVector & GetVel(); - virtual CVector & GetAcc(); - virtual CVector & GetDisp_n(); - virtual CVector & GetVel_n(); - virtual CVector & GetAcc_n(); - virtual CVector & GetLoads(); - virtual CVector & GetAccVar(); - virtual CVector & GetAccVar_n(); + virtual void Iterate(double &t0, double &tf, Structure *structure); + virtual CVector &GetDisp(); + virtual CVector &GetVel(); + virtual CVector &GetAcc(); + virtual CVector &GetDisp_n(); + virtual CVector &GetVel_n(); + virtual CVector &GetAcc_n(); + virtual CVector &GetLoads(); + virtual CVector &GetAccVar(); + virtual CVector &GetAccVar_n(); virtual void ResetSolution(); virtual void SaveToThePast(); - virtual void SetInitialState(Config *config, Structure* structure); - + virtual void SetInitialState(Config *config, Structure *structure); }; -class AlphaGenSolver : public Solver { - +class AlphaGenSolver : public Solver +{ protected: double beta; double gamma; @@ -50,41 +49,41 @@ class AlphaGenSolver : public Solver { double betaPrime; public: - AlphaGenSolver(unsigned int nDof, double val_rho, bool bool_linear); - ~AlphaGenSolver(); - CVector & GetAccVar(); - CVector & GetAccVar_n(); - virtual void Iterate(double& t0, double& tf, Structure* structure); - void ComputeRHS(Structure* structure, CVector &RHS); - void ComputeResidual(Structure* structure, CVector &res); - void ComputeTangentOperator(Structure* structure, CMatrix & St); - void ResetSolution(); - void SaveToThePast(); - virtual void SetInitialState(Config *config, Structure* structure); - + AlphaGenSolver(unsigned int nDof, double val_rho, bool bool_linear); + ~AlphaGenSolver(); + CVector &GetAccVar(); + CVector &GetAccVar_n(); + virtual void Iterate(double &t0, double &tf, Structure *structure); + void ComputeRHS(Structure *structure, CVector &RHS); + void ComputeResidual(Structure *structure, CVector &res); + void ComputeTangentOperator(Structure *structure, CMatrix &St); + void ResetSolution(); + void SaveToThePast(); + virtual void SetInitialState(Config *config, Structure *structure); }; -class RK4Solver : public Solver { - +class RK4Solver : public Solver +{ protected: - unsigned int size; - double lastTime; - double currentTime; + unsigned int size; + double lastTime; + double currentTime; public: RK4Solver(unsigned nDof, bool bool_linear); ~RK4Solver(); - virtual void Iterate(double &t0, double &tf, Structure* structure); - void EvaluateStateDerivative(double tCurrent, CVector& state, CVector& stateDerivative, Structure* structure); - void interpLoads(double& tCurrent, CVector& val_loads); - virtual void SetInitialState(Config* config, Structure* structure); + virtual void Iterate(double &t0, double &tf, Structure *structure); + void EvaluateStateDerivative(double tCurrent, CVector &state, + CVector &stateDerivative, + Structure *structure); + void interpLoads(double &tCurrent, CVector &val_loads); + virtual void SetInitialState(Config *config, Structure *structure); CVector SetState(); CVector SetState_n(); - }; -class StaticSolver : public Solver { - +class StaticSolver : public Solver +{ protected: unsigned int _nDof; CMatrix KK; @@ -93,7 +92,6 @@ class StaticSolver : public Solver { StaticSolver(unsigned nDof, bool bool_linear); ~StaticSolver(); - virtual void Iterate(double &t0, double &tf, Structure* structure); - virtual void SetInitialState(Config* config, Structure* structure); - + virtual void Iterate(double &t0, double &tf, Structure *structure); + virtual void SetInitialState(Config *config, Structure *structure); }; diff --git a/include/structure.h b/include/structure.h index 5f473f5..437b11e 100644 --- a/include/structure.h +++ b/include/structure.h @@ -3,9 +3,8 @@ #include "MatVec.h" #include "config.h" - -class Structure{ - +class Structure +{ protected: unsigned int nDof; double m; @@ -23,9 +22,8 @@ class Structure{ double centerOfRotation[3]; double centerOfRotation_n[3]; - public: - Structure(Config* config); + Structure(Config *config); virtual ~Structure(); void SetCenterOfRotation_X(double coord_x); void SetCenterOfRotation_Y(double coord_y); @@ -33,7 +31,7 @@ class Structure{ double GetCenterOfRotation_x() const; double GetCenterOfRotation_y() const; double GetCenterOfRotation_z() const; - const double* GetCenterOfRotation() const; + const double *GetCenterOfRotation() const; void SetCenterOfRotation_n_X(double coord_x); void SetCenterOfRotation_n_Y(double coord_y); void SetCenterOfRotation_n_Z(double coord_z); @@ -48,5 +46,4 @@ class Structure{ double Get_Ca() const; double Get_S() const; double Get_If() const; - }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7800dde..0eb628c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,4 +30,6 @@ TARGET_LINK_LIBRARIES(TestCVector ${LAPACKE_LIBRARIES} ${CBLAS_LIBRARIES} ${BLAS_LIBRARIES}) - +ADD_TEST(NAME TestCVector COMMAND ${EXECUTABLE_OUTPUT_PATH}/TestCVector + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) + diff --git a/src/MatVec.cpp b/src/MatVec.cpp index 2f614af..457940f 100644 --- a/src/MatVec.cpp +++ b/src/MatVec.cpp @@ -1,579 +1,636 @@ -#include "../include/MatVec.h" +#include "MatVec.h" #include #include using namespace std; -/*--- Definition of the CVector class ---*/ - -CVector::CVector(void):nElm(0){ - - vec_val = NULL; - -} - -CVector::CVector(const unsigned long & size, const double & val){ - - vec_val = NULL; - if(size <= 0){ - nElm = 0; - cerr << "CVector:CVector(const unsigned long &, const double): " << "invalid input : size = " << size << endl; - throw(-1); - } - else{ - nElm = size; - vec_val = new double[nElm]; - for(unsigned int i=0; i < nElm; i++) - vec_val[i] = val; - } +CVector::CVector(void) : nElm(0) +{ + vec_val = NULL; } -CVector::CVector(const CVector & u){ - - nElm = u.nElm; - vec_val = NULL; - vec_val = new double[nElm]; - for(unsigned int i = 0; i < nElm; i++) - vec_val[i] = u.vec_val[i]; -} - -CVector::~CVector(){ - - if (vec_val != NULL) delete [] vec_val; +CVector::CVector(const unsigned long &size, const double &val) +{ + vec_val = NULL; + if (size <= 0) + { + nElm = 0; + cerr << "CVector:CVector(const unsigned long &, const double): " + << "invalid input : size = " << size << endl; + throw(-1); + } + else + { + nElm = size; + vec_val = new double[nElm]; + for (unsigned int i = 0; i < nElm; i++) + vec_val[i] = val; + } } -void CVector::Initialize(const unsigned long &size, const double & val){ - - if(vec_val == NULL){ - if(size <= 0){ - nElm = 0; - cerr << "CVector::Initialize(const unsigned long &, const double &): " << "invalid number of element" << nElm << endl; - throw(-1); +CVector::CVector(const CVector &u) +{ + nElm = u.nElm; + vec_val = NULL; + vec_val = new double[nElm]; + for (unsigned int i = 0; i < nElm; i++) + vec_val[i] = u.vec_val[i]; +} + +CVector::~CVector() +{ + if (vec_val != NULL) + delete[] vec_val; +} + +void CVector::Initialize(const unsigned long &size, const double &val) +{ + if (vec_val == NULL) + { + if (size <= 0) + { + nElm = 0; + cerr << "CVector::Initialize(const unsigned long &, const double &): " + << "invalid number of element" << nElm << endl; + throw(-1); + } + else + { + nElm = size; + vec_val = new double[nElm]; + for (unsigned int ii = 0; ii < nElm; ii++) + { + vec_val[ii] = val; + } + } } - else{ - nElm = size; - vec_val = new double[nElm]; - for(unsigned int ii=0; ii #include #include @@ -7,17 +7,15 @@ using namespace std; -Config::Config(string filename):ConfigFileName(filename) +Config::Config(string filename) : ConfigFileName(filename) { - } Config::~Config() { - } -Config* Config::GetAddress() +Config *Config::GetAddress() { return this; } @@ -29,64 +27,99 @@ void Config::ReadConfig() string text_line, option; ifstream InputFile; InputFile.open(ConfigFileName.c_str(), ios::in); - if(InputFile.fail()){ - cerr << "Invalid configuration file name : " << ConfigFileName << endl; - throw(-1); + if (InputFile.fail()) + { + cerr << "Invalid configuration file name : " << ConfigFileName << endl; + throw(-1); } char caract; - while (getline(InputFile,text_line)) + while (getline(InputFile, text_line)) { caract = text_line[0]; if (caract == '%') - { - } - else - { - pos = text_line.find(delimiter); - option = text_line.substr(0,pos); - text_line.erase(0,pos+delimiter.length()); - option.erase(remove(option.begin(), option.end(), ' '), option.end()); - text_line.erase(remove(text_line.begin(), text_line.end(),' '),text_line.end()); - if (option == "CSD_SOLVER") CSD_SOLVER = text_line; - else if (option == "MESH_FILE") MESH_FILE = text_line; - else if (option == "UNSTEADY_SIMULATION") UNSTEADY_SIMULATION = text_line; - else if (option == "STRUCT_TYPE") STRUCT_TYPE = text_line; - else if (option == "LINEARIZE") LINEARIZE = text_line; - else if (option == "INTEGRATION_ALGO") INTEGRATION_ALGO = text_line; - else if (option == "RESTART_SOL") RESTART_SOL = text_line; - else if (option == "RESTART_FILE") RESTART_FILE = text_line; - else if (option == "MOVING_MARKER") MOVING_MARKER = text_line; - else if (option == "SPRING_MASS") SPRING_MASS = atof(text_line.c_str()); - else if (option == "INERTIA_CG") INERTIA_CG = atof(text_line.c_str()); - else if (option == "INERTIA_FLEXURAL") INERTIA_FLEXURAL = atof(text_line.c_str()); - else if (option == "SPRING_STIFFNESS") SPRING_STIFFNESS = atof(text_line.c_str()); - else if (option == "SPRING_DAMPING") SPRING_DAMPING = atof(text_line.c_str()); - else if (option == "TORSIONAL_STIFFNESS") TORSIONAL_STIFFNESS = atof(text_line.c_str()); - else if (option == "TORSIONAL_DAMPING") TORSIONAL_DAMPING = atof(text_line.c_str()); - else if (option == "CORD") CORD = atof(text_line.c_str()); - else if (option == "FLEXURAL_AXIS") FLEXURAL_AXIS = atof(text_line.c_str()); - else if (option == "GRAVITY_CENTER") GRAVITY_CENTER = atof(text_line.c_str()); - else if (option == "INITIAL_DISP") INITIAL_DISP = atof(text_line.c_str()); - else if (option == "INITIAL_ANGLE") INITIAL_ANGLE = atof(text_line.c_str()); - else if (option == "START_TIME") START_TIME = atof(text_line.c_str()); - else if (option == "DELTA_T") DELTA_T = atof(text_line.c_str()); - else if (option == "DELTA_ITER_WRITE") DELTAITERWRITE = atol(text_line.c_str()); - else if (option == "STOP_TIME") STOP_TIME = atof(text_line.c_str()); - else if (option == "RHO") RHO = atof(text_line.c_str()); - else cout << "The option " + option + " is not recognized !" << endl; - } + { + } + else + { + pos = text_line.find(delimiter); + option = text_line.substr(0, pos); + text_line.erase(0, pos + delimiter.length()); + option.erase(remove(option.begin(), option.end(), ' '), option.end()); + text_line.erase(remove(text_line.begin(), text_line.end(), ' '), text_line.end()); + if (option == "CSD_SOLVER") + CSD_SOLVER = text_line; + else if (option == "MESH_FILE") + MESH_FILE = text_line; + else if (option == "UNSTEADY_SIMULATION") + UNSTEADY_SIMULATION = text_line; + else if (option == "STRUCT_TYPE") + STRUCT_TYPE = text_line; + else if (option == "LINEARIZE") + LINEARIZE = text_line; + else if (option == "INTEGRATION_ALGO") + INTEGRATION_ALGO = text_line; + else if (option == "RESTART_SOL") + RESTART_SOL = text_line; + else if (option == "RESTART_FILE") + RESTART_FILE = text_line; + else if (option == "MOVING_MARKER") + MOVING_MARKER = text_line; + else if (option == "SPRING_MASS") + SPRING_MASS = atof(text_line.c_str()); + else if (option == "INERTIA_CG") + INERTIA_CG = atof(text_line.c_str()); + else if (option == "INERTIA_FLEXURAL") + INERTIA_FLEXURAL = atof(text_line.c_str()); + else if (option == "SPRING_STIFFNESS") + SPRING_STIFFNESS = atof(text_line.c_str()); + else if (option == "SPRING_DAMPING") + SPRING_DAMPING = atof(text_line.c_str()); + else if (option == "TORSIONAL_STIFFNESS") + TORSIONAL_STIFFNESS = atof(text_line.c_str()); + else if (option == "TORSIONAL_DAMPING") + TORSIONAL_DAMPING = atof(text_line.c_str()); + else if (option == "CORD") + CORD = atof(text_line.c_str()); + else if (option == "FLEXURAL_AXIS") + FLEXURAL_AXIS = atof(text_line.c_str()); + else if (option == "GRAVITY_CENTER") + GRAVITY_CENTER = atof(text_line.c_str()); + else if (option == "INITIAL_DISP") + INITIAL_DISP = atof(text_line.c_str()); + else if (option == "INITIAL_ANGLE") + INITIAL_ANGLE = atof(text_line.c_str()); + else if (option == "START_TIME") + START_TIME = atof(text_line.c_str()); + else if (option == "DELTA_T") + DELTA_T = atof(text_line.c_str()); + else if (option == "DELTA_ITER_WRITE") + DELTAITERWRITE = atol(text_line.c_str()); + else if (option == "STOP_TIME") + STOP_TIME = atof(text_line.c_str()); + else if (option == "RHO") + RHO = atof(text_line.c_str()); + else + cout << "The option " + option + " is not recognized !" << endl; + } } InputFile.close(); - if (CSD_SOLVER == "NATIVE") cout << "The Native solver has been chosen" << endl; - else cout << "Cannot run the solver with other value than NATIVE for CSD_SOLVER option !" << endl; + if (CSD_SOLVER == "NATIVE") + cout << "The Native solver has been chosen" << endl; + else + cout << "Cannot run the solver with other value than NATIVE for CSD_SOLVER option !" << endl; - if (UNSTEADY_SIMULATION == "YES") cout << "Dynamic structure computation" << endl; - else cout << "Static structure computation" << endl; + if (UNSTEADY_SIMULATION == "YES") + cout << "Dynamic structure computation" << endl; + else + cout << "Static structure computation" << endl; - if (STRUCT_TYPE == "SPRING_HOR" || STRUCT_TYPE == "SPRING_VER") cout << "Structural model is a plunging spring" << endl; - else if (STRUCT_TYPE == "AIRFOIL") cout << "Structural model is a pitching plunging airfoil" << endl; - else cout << "The specified structural model is not recognized or implemented yet !" << endl; + if (STRUCT_TYPE == "SPRING_HOR" || STRUCT_TYPE == "SPRING_VER") + cout << "Structural model is a plunging spring" << endl; + else if (STRUCT_TYPE == "AIRFOIL") + cout << "Structural model is a pitching plunging airfoil" << endl; + else + cout << "The specified structural model is not recognized or implemented yet !" << endl; } std::string Config::GetMeshFile() @@ -109,7 +142,8 @@ std::string Config::GetStructType() return STRUCT_TYPE; } -std::string Config::GetLinearize(){ +std::string Config::GetLinearize() +{ return LINEARIZE; } @@ -133,70 +167,87 @@ std::string Config::GetMovingMarker() return MOVING_MARKER; } -double Config::GetStartTime(){ +double Config::GetStartTime() +{ return START_TIME; } -double Config::GetDeltaT(){ +double Config::GetDeltaT() +{ return DELTA_T; } -unsigned long Config::GetDeltaIterWrite(){ +unsigned long Config::GetDeltaIterWrite() +{ return DELTAITERWRITE; } -double Config::GetStopTime(){ +double Config::GetStopTime() +{ return STOP_TIME; } -double Config::GetSpringStiffness(){ +double Config::GetSpringStiffness() +{ return SPRING_STIFFNESS; } -double Config::GetSpringMass(){ +double Config::GetSpringMass() +{ return SPRING_MASS; } -double Config::GetInertiaCG(){ +double Config::GetInertiaCG() +{ return INERTIA_CG; } -double Config::GetInertiaFlexural(){ +double Config::GetInertiaFlexural() +{ return INERTIA_FLEXURAL; } -double Config::GetSpringDamping(){ +double Config::GetSpringDamping() +{ return SPRING_DAMPING; } -double Config::GetTorsionalStiffness(){ - return TORSIONAL_STIFFNESS; +double Config::GetTorsionalStiffness() +{ + return TORSIONAL_STIFFNESS; } -double Config::GetTorsionalDamping(){ - return TORSIONAL_DAMPING; +double Config::GetTorsionalDamping() +{ + return TORSIONAL_DAMPING; } -double Config::GetCord(){ - return CORD; +double Config::GetCord() +{ + return CORD; } -double Config::GetFlexuralAxis(){ - return FLEXURAL_AXIS; +double Config::GetFlexuralAxis() +{ + return FLEXURAL_AXIS; } -double Config::GetGravityCenter(){ +double Config::GetGravityCenter() +{ return GRAVITY_CENTER; } -double Config::GetInitialDisp(){ - return INITIAL_DISP; +double Config::GetInitialDisp() +{ + return INITIAL_DISP; } -double Config::GetInitialAngle(){ - return INITIAL_ANGLE; +double Config::GetInitialAngle() +{ + return INITIAL_ANGLE; } -double Config::GetRho(){ +double Config::GetRho() +{ return RHO; } diff --git a/src/geometry.cpp b/src/geometry.cpp index e224e66..2b22e92 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -1,5 +1,5 @@ -#include "../include/geometry.h" -#include "../include/config.h" +#include "geometry.h" +#include "config.h" #include #include #include @@ -9,323 +9,363 @@ using namespace std; -Point::Point(){ - - Coord0 = new double[3]; - Coord0[0] = 0.0; - Coord0[1] = 0.0; - Coord0[2] = 0.0; - - Coord = new double[3]; - Coord[0] = 0.0; - Coord[1]= 0.0; - Coord[2] = 0.0; - - Coord_n = new double[3]; - Coord_n[0] = 0.0; - Coord_n[1] = 0.0; - Coord_n[2] = 0.0; - - Vel = new double[3]; - Vel[0] = 0.0; - Vel[1] = 0.0; - Vel[2] = 0.0; - - Vel_n = new double[3]; - Vel_n[0] = 0.0; - Vel_n[1] = 0.0; - Vel_n[2] = 0.0; - - Force = new double[3]; - Force[0] = 0.0; - Force[1] = 0.0; - Force[2] = 0.0; - +Point::Point() +{ + Coord0 = new double[3]; + Coord0[0] = 0.0; + Coord0[1] = 0.0; + Coord0[2] = 0.0; + + Coord = new double[3]; + Coord[0] = 0.0; + Coord[1] = 0.0; + Coord[2] = 0.0; + + Coord_n = new double[3]; + Coord_n[0] = 0.0; + Coord_n[1] = 0.0; + Coord_n[2] = 0.0; + + Vel = new double[3]; + Vel[0] = 0.0; + Vel[1] = 0.0; + Vel[2] = 0.0; + + Vel_n = new double[3]; + Vel_n[0] = 0.0; + Vel_n[1] = 0.0; + Vel_n[2] = 0.0; + + Force = new double[3]; + Force[0] = 0.0; + Force[1] = 0.0; + Force[2] = 0.0; } -Point::~Point(){ - delete [] Coord0; - Coord0 = NULL; +Point::~Point() +{ + delete[] Coord0; + Coord0 = NULL; - delete [] Coord; - Coord = NULL; + delete[] Coord; + Coord = NULL; - delete [] Coord_n; - Coord_n = NULL; + delete[] Coord_n; + Coord_n = NULL; - delete [] Vel; - Vel = NULL; + delete[] Vel; + Vel = NULL; - delete [] Vel_n; - Vel_n = NULL; + delete[] Vel_n; + Vel_n = NULL; - delete [] Force; - Force = NULL; + delete[] Force; + Force = NULL; } -double* Point::GetCoord0() const{ - return Coord0; +double *Point::GetCoord0() const +{ + return Coord0; } -double* Point::GetCoord() const{ - return Coord; +double *Point::GetCoord() const +{ + return Coord; } -double* Point::GetCoord_n() const{ - return Coord_n; +double *Point::GetCoord_n() const +{ + return Coord_n; } -double* Point::GetVel() const{ +double *Point::GetVel() const +{ return Vel; } -double* Point::GetVel_n() const{ +double *Point::GetVel_n() const +{ return Vel_n; } -double* Point::GetForce() const{ +double *Point::GetForce() const +{ return Force; } -void Point::PrintCoord() const{ - cout << Coord[0] << " ; " << Coord[1] << " ; " << Coord[2] << endl; +void Point::PrintCoord() const +{ + cout << Coord[0] << " ; " << Coord[1] << " ; " << Coord[2] << endl; } -void Point::SetCoord0(double* newCoord){ - Coord0[0] = newCoord[0]; - Coord0[1] = newCoord[1]; - Coord0[2] = newCoord[2]; +void Point::SetCoord0(double *newCoord) +{ + Coord0[0] = newCoord[0]; + Coord0[1] = newCoord[1]; + Coord0[2] = newCoord[2]; } -void Point::SetCoord(double* newCoord){ - Coord[0] = newCoord[0]; - Coord[1] = newCoord[1]; - Coord[2] = newCoord[2]; +void Point::SetCoord(double *newCoord) +{ + Coord[0] = newCoord[0]; + Coord[1] = newCoord[1]; + Coord[2] = newCoord[2]; } -void Point::SetCoord_n(double* newCoord){ - Coord_n[0] = newCoord[0]; - Coord_n[1] = newCoord[1]; - Coord_n[2] = newCoord[2]; +void Point::SetCoord_n(double *newCoord) +{ + Coord_n[0] = newCoord[0]; + Coord_n[1] = newCoord[1]; + Coord_n[2] = newCoord[2]; } -void Point::SetVel(double *newVel){ +void Point::SetVel(double *newVel) +{ Vel[0] = newVel[0]; Vel[1] = newVel[1]; Vel[2] = newVel[2]; } -void Point::SetVel_n(double *newVel_n){ +void Point::SetVel_n(double *newVel_n) +{ Vel_n[0] = newVel_n[0]; Vel_n[1] = newVel_n[1]; Vel_n[2] = newVel_n[2]; } -void Point::SetForce(double* newForce){ +void Point::SetForce(double *newForce) +{ Force[0] = newForce[0]; Force[1] = newForce[1]; Force[2] = newForce[2]; } -void Point::UpdateCoord(){ - Coord_n[0] = Coord[0]; - Coord_n[1] = Coord[1]; - Coord_n[2] = Coord[2]; +void Point::UpdateCoord() +{ + Coord_n[0] = Coord[0]; + Coord_n[1] = Coord[1]; + Coord_n[2] = Coord[2]; } -void Point::UpdateVel(){ +void Point::UpdateVel() +{ Vel_n[0] = Vel[0]; Vel_n[1] = Vel[1]; Vel_n[2] = Vel[2]; } -Geometry::Geometry(Config* config){ - - string meshFileName, textLine, tampon; - ifstream meshFile; - string::size_type position; - double Coord[3]; - double* TempCoord; - unsigned long iMarker(0); - int elemType(0), dummyInt(0); - int iPoint; - - Coord[0] = 0.0; - Coord[1] = 0.0; - Coord[2] = 0.0; - - nDim = 0; - nElem = 0; - nPoint = 0; - nMarkers = 0; - //strcpy(cstr, config->GetMeshFile()); - - meshFileName = config->GetMeshFile(); - - /*--- Open the mesh file and check ---*/ - meshFile.open(meshFileName.c_str(), ios::in); - if (meshFile.fail()){ - cout << "Unable to open the mesh file " << meshFileName << endl; - exit(1); - } - - cout << "Mesh file " << meshFileName << " is open." << endl; - cout << "Constructing the mesh..." << endl; - while(getline(meshFile, textLine)){ - - position = textLine.find("NDIME=",0); - if (position != string::npos){ - textLine.erase(0,6); - nDim = atoi(textLine.c_str()); - cout << "Number of dimensions : " << nDim << endl; +Geometry::Geometry(Config *config) +{ + + string meshFileName, textLine, tampon; + ifstream meshFile; + string::size_type position; + double Coord[3]; + double *TempCoord; + unsigned long iMarker(0); + int elemType(0), dummyInt(0); + int iPoint; + + Coord[0] = 0.0; + Coord[1] = 0.0; + Coord[2] = 0.0; + + nDim = 0; + nElem = 0; + nPoint = 0; + nMarkers = 0; + // strcpy(cstr, config->GetMeshFile()); + + meshFileName = config->GetMeshFile(); + + /*--- Open the mesh file and check ---*/ + meshFile.open(meshFileName.c_str(), ios::in); + if (meshFile.fail()) + { + cout << "Unable to open the mesh file " << meshFileName << endl; + exit(1); } - position = textLine.find("NELEM=",0); - if (position != string::npos){ - textLine.erase(0,6); - nElem = atoi(textLine.c_str()); - cout << "Number of elements : " << nElem << endl; - for(int iElem=0; iElem < nElem; iElem++){ - getline(meshFile, textLine); - } - } + cout << "Mesh file " << meshFileName << " is open." << endl; + cout << "Constructing the mesh..." << endl; + while (getline(meshFile, textLine)) + { + + position = textLine.find("NDIME=", 0); + if (position != string::npos) + { + textLine.erase(0, 6); + nDim = atoi(textLine.c_str()); + cout << "Number of dimensions : " << nDim << endl; + } - position = textLine.find("NPOIN=", 0); - if (position != string::npos){ - textLine.erase(0,6); - nPoint = atoi(textLine.c_str()); - cout << "Number of points : " << nPoint << endl; - node = new Point*[nPoint]; - //cout << "JE VAIS REMPLIR" << endl; - for(iPoint=0; iPoint < nPoint; iPoint++){ - getline(meshFile, textLine); - //if(iPoint == 1) cout << textLine << endl; - node[iPoint] = new Point(); - istringstream point_line(textLine); - point_line >> Coord[0]; - //if(iPoint == 1) cout << Coord[0] << endl; - point_line >> Coord[1]; - //if(iPoint == 1) cout << Coord[1] << endl; - if(nDim == 3) point_line >> Coord[2]; - node[iPoint]->SetCoord0(Coord); - node[iPoint]->SetCoord(Coord); - node[iPoint]->SetCoord_n(Coord); - TempCoord = node[iPoint]->GetCoord(); - //cout << iPoint << endl; - } - } + position = textLine.find("NELEM=", 0); + if (position != string::npos) + { + textLine.erase(0, 6); + nElem = atoi(textLine.c_str()); + cout << "Number of elements : " << nElem << endl; + for (int iElem = 0; iElem < nElem; iElem++) + { + getline(meshFile, textLine); + } + } - position = textLine.find("NMARK=", 0); - if (position != string::npos){ - textLine.erase(0,6); - nMarkers = atoi(textLine.c_str()); - cout << "Number of markers : " << nMarkers << endl; - vertex = new unsigned long*[nMarkers]; - nVertex = new unsigned long[nMarkers]; - markersMoving = new bool[nMarkers]; - nElemMarker = new unsigned long[nMarkers]; - } + position = textLine.find("NPOIN=", 0); + if (position != string::npos) + { + textLine.erase(0, 6); + nPoint = atoi(textLine.c_str()); + cout << "Number of points : " << nPoint << endl; + node = new Point *[nPoint]; + // cout << "JE VAIS REMPLIR" << endl; + for (iPoint = 0; iPoint < nPoint; iPoint++) + { + getline(meshFile, textLine); + // if(iPoint == 1) cout << textLine << endl; + node[iPoint] = new Point(); + istringstream point_line(textLine); + point_line >> Coord[0]; + // if(iPoint == 1) cout << Coord[0] << endl; + point_line >> Coord[1]; + // if(iPoint == 1) cout << Coord[1] << endl; + if (nDim == 3) + point_line >> Coord[2]; + node[iPoint]->SetCoord0(Coord); + node[iPoint]->SetCoord(Coord); + node[iPoint]->SetCoord_n(Coord); + TempCoord = node[iPoint]->GetCoord(); + // cout << iPoint << endl; + } + } - position = textLine.find("MARKER_TAG=",0); - if (position != string::npos){ - textLine.erase(0,12); - cout << "Reading elements for marker : " << textLine << endl; - if (textLine == config->GetMovingMarker()){ - cout << "Marker " << textLine << " is a moving marker." << endl; - markersMoving[iMarker] = true; - } - else markersMoving[iMarker] = false; - } + position = textLine.find("NMARK=", 0); + if (position != string::npos) + { + textLine.erase(0, 6); + nMarkers = atoi(textLine.c_str()); + cout << "Number of markers : " << nMarkers << endl; + vertex = new unsigned long *[nMarkers]; + nVertex = new unsigned long[nMarkers]; + markersMoving = new bool[nMarkers]; + nElemMarker = new unsigned long[nMarkers]; + } - position = textLine.find("MARKER_ELEMS=",0); - if (position != string::npos){ - textLine.erase(0,13); - nElemMarker[iMarker] = atoi(textLine.c_str()); - cout << "Number of elements on the marker : " << nElemMarker[iMarker] << endl; - vector tempVertexMarker; - for(int iElem=0; iElem < nElemMarker[iMarker]; iElem++){ - getline(meshFile,textLine); - istringstream point_line(textLine); - point_line >> elemType; - if (elemType == 3){ - point_line >> dummyInt; - if (!isInVec(tempVertexMarker, dummyInt)){ - tempVertexMarker.push_back(dummyInt); - } - point_line >> dummyInt; - if (!isInVec(tempVertexMarker, dummyInt)){ - tempVertexMarker.push_back(dummyInt); - } + position = textLine.find("MARKER_TAG=", 0); + if (position != string::npos) + { + textLine.erase(0, 12); + cout << "Reading elements for marker : " << textLine << endl; + if (textLine == config->GetMovingMarker()) + { + cout << "Marker " << textLine << " is a moving marker." << endl; + markersMoving[iMarker] = true; + } + else + markersMoving[iMarker] = false; } - else{ - cout << "Elem type " << elemType << " is not recognized !" << endl; - exit(1); + + position = textLine.find("MARKER_ELEMS=", 0); + if (position != string::npos) + { + textLine.erase(0, 13); + nElemMarker[iMarker] = atoi(textLine.c_str()); + cout << "Number of elements on the marker : " << nElemMarker[iMarker] << endl; + vector tempVertexMarker; + for (int iElem = 0; iElem < nElemMarker[iMarker]; iElem++) + { + getline(meshFile, textLine); + istringstream point_line(textLine); + point_line >> elemType; + if (elemType == 3) + { + point_line >> dummyInt; + if (!isInVec(tempVertexMarker, dummyInt)) + { + tempVertexMarker.push_back(dummyInt); + } + point_line >> dummyInt; + if (!isInVec(tempVertexMarker, dummyInt)) + { + tempVertexMarker.push_back(dummyInt); + } + } + else + { + cout << "Elem type " << elemType << " is not recognized !" << endl; + exit(1); + } + } + nVertex[iMarker] = tempVertexMarker.size(); + vertex[iMarker] = new unsigned long[nVertex[iMarker]]; + vecCopy(tempVertexMarker, vertex[iMarker]); + iMarker++; } - } - nVertex[iMarker] = tempVertexMarker.size(); - vertex[iMarker] = new unsigned long[nVertex[iMarker]]; - vecCopy(tempVertexMarker,vertex[iMarker]); - iMarker++; } - } - - meshFile.close(); - - /*for (int iVertex = 0; iVertex < nVertex[0]; iVertex++){ - //cout << vertex[0][iVertex] << endl; - iPoint = vertex[0][iVertex]; - node[iPoint]->PrintCoord(); - }*/ - - + meshFile.close(); + /*for (int iVertex = 0; iVertex < nVertex[0]; iVertex++){ + //cout << vertex[0][iVertex] << endl; + iPoint = vertex[0][iVertex]; + node[iPoint]->PrintCoord(); + }*/ } -Geometry::~Geometry(){ - - for(int iPoint=0; iPoint < nPoint; iPoint++){ - delete node[iPoint]; - } +Geometry::~Geometry() +{ - for(int iMarker=0; iMarker < nMarkers; iMarker++){ - delete [] vertex[iMarker]; - } + for (int iPoint = 0; iPoint < nPoint; iPoint++) + { + delete node[iPoint]; + } - delete [] vertex; + for (int iMarker = 0; iMarker < nMarkers; iMarker++) + { + delete[] vertex[iMarker]; + } - delete [] node; + delete[] vertex; - delete [] nElemMarker; + delete[] node; + delete[] nElemMarker; } -unsigned long Geometry::GetnMarkers() const{ - return nMarkers; +unsigned long Geometry::GetnMarkers() const +{ + return nMarkers; } -bool Geometry::GetMarkersMoving(unsigned long iMarker) const{ - return markersMoving[iMarker]; +bool Geometry::GetMarkersMoving(unsigned long iMarker) const +{ + return markersMoving[iMarker]; } -void Geometry::UpdateGeometry(){ +void Geometry::UpdateGeometry() +{ - unsigned long iPoint; + unsigned long iPoint; - for(iPoint=0; iPoint < nPoint; iPoint++){ - node[iPoint]->UpdateCoord(); - node[iPoint]->UpdateVel(); - } + for (iPoint = 0; iPoint < nPoint; iPoint++) + { + node[iPoint]->UpdateCoord(); + node[iPoint]->UpdateVel(); + } } -bool isInVec(vector const& inputVector, int dummyInt){ - int i = 0; - while(i const &inputVector, int dummyInt) +{ + int i = 0; + while (i < inputVector.size() && inputVector[i] != dummyInt) + i++; + return i < inputVector.size(); } -void vecCopy(vector const& sourceVector, unsigned long* destinationTab){ - for(int i=0; i const &sourceVector, unsigned long *destinationTab) +{ + for (int i = 0; i < sourceVector.size(); i++) + { + destinationTab[i] = sourceVector[i]; + } } diff --git a/src/integration.cpp b/src/integration.cpp index 0425675..c3e3dbe 100644 --- a/src/integration.cpp +++ b/src/integration.cpp @@ -1,5 +1,5 @@ -#include "../include/integration.h" -#include "../include/solver.h" +#include "integration.h" +#include "solver.h" #include #include #include @@ -9,146 +9,157 @@ using namespace std; -Integration::Integration(Config *config, Structure *structure){ - - solver = NULL; - bool linear; - - linear = (config->GetLinearize()) == "YES"; - - if (config->GetUnsteady() == "YES") { - if(config->GetIntegrationAlgo() == "ALPHAGEN"){ - solver = new AlphaGenSolver(structure->GetnDof(), config->GetRho(), linear); - } - else if(config->GetIntegrationAlgo() == "RK4"){ - solver = new RK4Solver(structure->GetnDof(), linear); +Integration::Integration(Config *config, Structure *structure) +{ + solver = NULL; + bool linear; + + linear = (config->GetLinearize()) == "YES"; + + if (config->GetUnsteady() == "YES") + { + if (config->GetIntegrationAlgo() == "ALPHAGEN") + { + solver = new AlphaGenSolver(structure->GetnDof(), config->GetRho(), linear); + } + else if (config->GetIntegrationAlgo() == "RK4") + { + solver = new RK4Solver(structure->GetnDof(), linear); + } } - else{ - } - } - else - solver = new StaticSolver(structure->GetnDof(), linear); + else + solver = new StaticSolver(structure->GetnDof(), linear); } -Integration::~Integration(){ - - if (solver != NULL) delete solver; +Integration::~Integration() +{ + if (solver != NULL) + delete solver; } -Solver* Integration::GetSolver(){ +Solver *Integration::GetSolver() +{ - return solver; + return solver; } -double Integration::GettotTime(){ - return totTime; +double Integration::GettotTime() +{ + return totTime; } -double Integration::GetdeltaT(){ - return deltaT; +double Integration::GetdeltaT() +{ + return deltaT; } -void Integration::SetExtIter(unsigned long val_ExtIter){ +void Integration::SetExtIter(unsigned long val_ExtIter) +{ ExtIter = val_ExtIter; } -unsigned long Integration::GetExtIter(){ +unsigned long Integration::GetExtIter() +{ return ExtIter; } -void Integration::SetInitialConditions(Config* config, Structure* structure){ - - ExtIter = 0; - solver->SetInitialState(config, structure); - structure->SetCenterOfRotation_Y((solver->GetDisp())[0]); - +void Integration::SetInitialConditions(Config *config, Structure *structure) +{ + ExtIter = 0; + solver->SetInitialState(config, structure); + structure->SetCenterOfRotation_Y((solver->GetDisp())[0]); } -void Integration::TemporalIteration(double& t0, double& tf, Structure *structure){ - - int rank = 0; +void Integration::TemporalIteration(double &t0, double &tf, Structure *structure) +{ + int rank = 0; #ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif - double currentTime(tf); - deltaT = tf - t0; - solver->Iterate(t0, tf, structure); - - if(rank == 0){ - if(structure->GetnDof() == 1){ - cout << fixed - << setw(10) << "Time" - << setw(15) << "Displacement" - << setw(15) << "Velocity" - << setw(15) << "Acceleration" << endl; - cout << fixed - << setw(10) << currentTime - << setw(15) << (solver->GetDisp())[0] - << setw(15) << (solver->GetVel())[0] - << setw(15) << (solver->GetAcc())[0] << endl; - } - else if(structure->GetnDof() == 2){cout << fixed - << setw(10) << "Time" - << setw(15) << "Displacement1" - << setw(15) << "Displacement2" - << setw(15) << "Velocity1" - << setw(15) << "Velocity2" - << setw(15) << "Acceleration1" - << setw(15) << "Acceleration2" << endl; - cout << fixed - << setw(10) << currentTime - << setw(15) << (solver->GetDisp())[0] - << setw(15) << (solver->GetDisp())[1] - << setw(15) << (solver->GetVel())[0] - << setw(15) << (solver->GetVel())[1] - << setw(15) << (solver->GetAcc())[0] - << setw(15) << (solver->GetAcc())[1] << endl;} - } + double currentTime(tf); + deltaT = tf - t0; + solver->Iterate(t0, tf, structure); + + if (rank == 0) + { + if (structure->GetnDof() == 1) + { + cout << fixed + << setw(10) << "Time" + << setw(15) << "Displacement" + << setw(15) << "Velocity" + << setw(15) << "Acceleration" << endl; + cout << fixed + << setw(10) << currentTime + << setw(15) << (solver->GetDisp())[0] + << setw(15) << (solver->GetVel())[0] + << setw(15) << (solver->GetAcc())[0] << endl; + } + else if (structure->GetnDof() == 2) + { + cout << fixed + << setw(10) << "Time" + << setw(15) << "Displacement1" + << setw(15) << "Displacement2" + << setw(15) << "Velocity1" + << setw(15) << "Velocity2" + << setw(15) << "Acceleration1" + << setw(15) << "Acceleration2" << endl; + cout << fixed + << setw(10) << currentTime + << setw(15) << (solver->GetDisp())[0] + << setw(15) << (solver->GetDisp())[1] + << setw(15) << (solver->GetVel())[0] + << setw(15) << (solver->GetVel())[1] + << setw(15) << (solver->GetAcc())[0] + << setw(15) << (solver->GetAcc())[1] << endl; + } + } } - -void Integration::StaticIteration(Structure *structure){ - - int rank = 0; +void Integration::StaticIteration(Structure *structure) +{ + int rank = 0; #ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif - double t0 = 0.; - double tf = 0.; - deltaT = 0.; - solver->Iterate(t0, tf, structure); - - if(rank == 0){ - if(structure->GetnDof() == 1){ - cout << fixed - << setw(10) << "Time" - << setw(15) << "Displacement" << endl; - cout << fixed - << setw(10) << tf - << setw(15) << (solver->GetDisp())[0] << endl; + double t0 = 0.; + double tf = 0.; + deltaT = 0.; + solver->Iterate(t0, tf, structure); + + if (rank == 0) + { + if (structure->GetnDof() == 1) + { + cout << fixed + << setw(10) << "Time" + << setw(15) << "Displacement" << endl; + cout << fixed + << setw(10) << tf + << setw(15) << (solver->GetDisp())[0] << endl; + } + else if (structure->GetnDof() == 2) + { + cout << fixed + << setw(10) << "Time" + << setw(15) << "Displacement1" + << setw(15) << "Displacement2" << endl; + cout << fixed + << setw(10) << tf + << setw(15) << (solver->GetDisp())[0] + << setw(15) << (solver->GetDisp())[1] << endl; + } } - else if(structure->GetnDof() == 2){ - cout << fixed - << setw(10) << "Time" - << setw(15) << "Displacement1" - << setw(15) << "Displacement2" << endl; - cout << fixed - << setw(10) << tf - << setw(15) << (solver->GetDisp())[0] - << setw(15) << (solver->GetDisp())[1] << endl; - } - } } - -void Integration::UpdateSolution(){ - - solver->SaveToThePast(); - +void Integration::UpdateSolution() +{ + solver->SaveToThePast(); } diff --git a/src/output.cpp b/src/output.cpp index da7bc8a..268812e 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -1,11 +1,17 @@ -#include "../include/output.h" +#include "output.h" #include using namespace std; -Output::Output(){} +Output::Output() +{ + +} + +Output::~Output() +{ -Output::~Output(){} +} /* void Output::WriteHistory(Integration* solver, Structure* structure, ofstream* outputfile, const double & time){ diff --git a/src/solver.cpp b/src/solver.cpp index 42026e6..36b61df 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -1,699 +1,752 @@ -#include "../include/solver.h" -#include "../include/structure.h" -#include "../include/MatVec.h" - +#include "solver.h" +#include "structure.h" +#include "MatVec.h" #include #include #include using namespace std; -/* CLASS SOLVER*/ -Solver::Solver(unsigned int nDof, bool bool_linear){ - - q.Initialize(nDof, 0.0); - qdot.Initialize(nDof, 0.0); - qddot.Initialize(nDof, 0.0); - q_n.Initialize(nDof, 0.0); - qdot_n.Initialize(nDof, 0.0); - qddot_n.Initialize(nDof, 0.0); - Loads.Initialize(nDof, 0.0); - Loads_n.Initialize(nDof, 0.0); - - ResetSolution(); - Loads.Reset(); - Loads_n.Reset(); +Solver::Solver(unsigned int nDof, bool bool_linear) +{ + q.Initialize(nDof, 0.0); + qdot.Initialize(nDof, 0.0); + qddot.Initialize(nDof, 0.0); + q_n.Initialize(nDof, 0.0); + qdot_n.Initialize(nDof, 0.0); + qddot_n.Initialize(nDof, 0.0); + Loads.Initialize(nDof, 0.0); + Loads_n.Initialize(nDof, 0.0); - linear = bool_linear; + ResetSolution(); + Loads.Reset(); + Loads_n.Reset(); + linear = bool_linear; } -Solver::~Solver(){} +Solver::~Solver() +{ +} -void Solver::Iterate(double &t0, double &tf, Structure* structure){} +void Solver::Iterate(double &t0, double &tf, Structure *structure) +{ +} -CVector & Solver::GetDisp(){ - return q; +CVector &Solver::GetDisp() +{ + return q; } -CVector & Solver::GetVel(){ - return qdot; +CVector &Solver::GetVel() +{ + return qdot; } -CVector & Solver::GetAcc(){ - return qddot; +CVector &Solver::GetAcc() +{ + return qddot; } -CVector & Solver::GetDisp_n(){ - return q_n; +CVector &Solver::GetDisp_n() +{ + return q_n; } -CVector & Solver::GetVel_n(){ - return qdot_n; +CVector &Solver::GetVel_n() +{ + return qdot_n; } -CVector & Solver::GetAcc_n(){ - return qddot_n; +CVector &Solver::GetAcc_n() +{ + return qddot_n; } -CVector & Solver::GetLoads(){ - return Loads; +CVector &Solver::GetLoads() +{ + return Loads; } -CVector & Solver::GetAccVar(){ - return a; +CVector &Solver::GetAccVar() +{ + return a; } -CVector & Solver::GetAccVar_n(){ - return a_n; +CVector &Solver::GetAccVar_n() +{ + return a_n; } -void Solver::ResetSolution(){ - q.Reset(); - qdot.Reset(); - qddot.Reset(); - q_n.Reset(); - qdot_n.Reset(); - qddot_n.Reset(); +void Solver::ResetSolution() +{ + q.Reset(); + qdot.Reset(); + qddot.Reset(); + q_n.Reset(); + qdot_n.Reset(); + qddot_n.Reset(); } -void Solver::SaveToThePast(){ - q_n = q; - qdot_n = qdot; - qddot_n = qddot; - Loads_n = Loads; +void Solver::SaveToThePast() +{ + q_n = q; + qdot_n = qdot; + qddot_n = qddot; + Loads_n = Loads; } -void Solver::SetInitialState(Config *config, Structure* structure){} +void Solver::SetInitialState(Config *config, Structure *structure) +{ +} /*CLASS ALPHAGENSOLVER*/ -AlphaGenSolver::AlphaGenSolver(unsigned int nDof, double val_rho, bool bool_linear) : Solver(nDof, bool_linear) { +AlphaGenSolver::AlphaGenSolver(unsigned int nDof, double val_rho, + bool bool_linear) : Solver(nDof, bool_linear) +{ - a.Initialize(nDof, 0.0); - a_n.Initialize(nDof, 0.0); + a.Initialize(nDof, 0.0); + a_n.Initialize(nDof, 0.0); - rho = val_rho; - alpha_m = (2*rho-1)/(rho+1); - alpha_f = rho/(rho+1); - gamma = 0.5+alpha_f-alpha_m; - beta = 0.25*pow((gamma+0.5),2); - cout << "Integration with the alpha-generalized algorithm :" << endl; - cout << "rho : " << rho << endl; - cout << "alpha_m : " << alpha_m << endl; - cout << "alpha_f : " << alpha_f << endl; - cout << "gamma : " << gamma << endl; - cout << "beta : " << beta << endl; + rho = val_rho; + alpha_m = (2 * rho - 1) / (rho + 1); + alpha_f = rho / (rho + 1); + gamma = 0.5 + alpha_f - alpha_m; + beta = 0.25 * pow((gamma + 0.5), 2); + cout << "Integration with the alpha-generalized algorithm :" << endl; + cout << "rho : " << rho << endl; + cout << "alpha_m : " << alpha_m << endl; + cout << "alpha_f : " << alpha_f << endl; + cout << "gamma : " << gamma << endl; + cout << "beta : " << beta << endl; } -AlphaGenSolver::~AlphaGenSolver() {} +AlphaGenSolver::~AlphaGenSolver() +{ +} -CVector & AlphaGenSolver::GetAccVar(){ - return a; +CVector &AlphaGenSolver::GetAccVar() +{ + return a; } -CVector & AlphaGenSolver::GetAccVar_n(){ - return a_n; +CVector &AlphaGenSolver::GetAccVar_n() +{ + return a_n; } -void AlphaGenSolver::Iterate(double &t0, double &tf, Structure *structure){ +void AlphaGenSolver::Iterate(double &t0, double &tf, Structure *structure) +{ - double deltaT(tf-t0), epsilon(1e-6); - int nMaxIter(1000), nIter(0); + double deltaT(tf - t0), epsilon(1e-6); + int nMaxIter(1000), nIter(0); - gammaPrime = gamma/(deltaT*beta); - betaPrime = (1-alpha_m)/(pow(deltaT,2)*beta*(1-alpha_f)); + gammaPrime = gamma / (deltaT * beta); + betaPrime = (1 - alpha_m) / (pow(deltaT, 2) * beta * (1 - alpha_f)); - /*--- Prediction phase ---*/ - qddot.Reset(); - a.Reset(); + /*--- Prediction phase ---*/ + qddot.Reset(); + a.Reset(); + + a += ScalVecProd(alpha_f / (1 - alpha_m), qddot_n); + a -= ScalVecProd(alpha_m / (1 - alpha_m), a_n); + + q = q_n; + q += ScalVecProd(deltaT, qdot_n); + q += ScalVecProd((0.5 - beta) * deltaT * deltaT, a_n); + q += ScalVecProd(deltaT * deltaT * beta, a); + + qdot = qdot_n; + qdot += ScalVecProd((1 - gamma) * deltaT, a_n); + qdot += ScalVecProd(deltaT * gamma, a); + + /*--- Tangent operator and corrector computation ---*/ + CVector res(qddot.GetSize(), 0.0); + CVector Deltaq(qddot.GetSize(), 0.0); + CMatrix St(qddot.GetSize(), qddot.GetSize(), 0.0); + ComputeResidual(structure, res); + while (res.norm() >= epsilon && nIter < nMaxIter) + { + St.Reset(); + ComputeTangentOperator(structure, St); + SolveSys(St, res); + //*res -= ScalVecProd(double(2),res); //=deltaq + Deltaq.Reset(); + Deltaq += ScalVecProd(-1, res); + q += Deltaq; + qdot += ScalVecProd(gammaPrime, Deltaq); + qddot += ScalVecProd(betaPrime, Deltaq); + res.Reset(); + ComputeResidual(structure, res); + nIter++; + } + a += ScalVecProd((1 - alpha_f) / (1 - alpha_m), qddot); +} - a += ScalVecProd(alpha_f/(1-alpha_m),qddot_n); - a -= ScalVecProd(alpha_m/(1-alpha_m),a_n); +void AlphaGenSolver::ComputeRHS(Structure *structure, CVector &RHS) +{ - q = q_n; - q += ScalVecProd(deltaT,qdot_n); - q += ScalVecProd((0.5-beta)*deltaT*deltaT,a_n); - q += ScalVecProd(deltaT*deltaT*beta,a); + unsigned long size = q.GetSize(); + CMatrix CC(size, size, 0.0); + CMatrix KK(size, size, 0.0); + CVector NonLinTerm(size, 0.0); - qdot = qdot_n; - qdot += ScalVecProd((1-gamma)*deltaT,a_n); - qdot += ScalVecProd(deltaT*gamma,a); + double cos_a; - /*--- Tangent operator and corrector computation ---*/ - CVector res(qddot.GetSize(), 0.0); - CVector Deltaq(qddot.GetSize(), 0.0); - CMatrix St(qddot.GetSize(), qddot.GetSize(), 0.0); - ComputeResidual(structure,res); - while (res.norm() >= epsilon && nIter < nMaxIter){ - St.Reset(); - ComputeTangentOperator(structure,St); - SolveSys(St,res); - //*res -= ScalVecProd(double(2),res); //=deltaq - Deltaq.Reset(); - Deltaq += ScalVecProd(-1,res); - q += Deltaq; - qdot += ScalVecProd(gammaPrime,Deltaq); - qddot += ScalVecProd(betaPrime,Deltaq); - res.Reset(); - ComputeResidual(structure,res); - nIter++; - } - a += ScalVecProd((1-alpha_f)/(1-alpha_m),qddot); + if (structure->GetnDof() == 1) + { + KK.SetElm(1, 1, structure->Get_Kh()); + CC.SetElm(1, 1, structure->Get_Ch()); + } + else if (structure->GetnDof() == 2) + { + if (linear) + { + cos_a = 1.0; + } + else + { + cos_a = cos(q[1]); + NonLinTerm[0] = (structure->Get_S()) * sin(q[1]) * pow(qdot[1], 2); + } + CC.SetElm(1, 1, structure->Get_Ch()); + CC.SetElm(2, 2, structure->Get_Ca()); + KK.SetElm(1, 1, structure->Get_Kh()); + KK.SetElm(2, 2, structure->Get_Ka()); + } + RHS += Loads; + RHS -= MatVecProd(CC, qdot); + RHS -= MatVecProd(KK, q); + RHS += NonLinTerm; } -void AlphaGenSolver::ComputeRHS(Structure* structure, CVector &RHS){ - - unsigned long size = q.GetSize(); - CMatrix CC(size, size, 0.0); - CMatrix KK(size, size, 0.0); - CVector NonLinTerm(size, 0.0); +void AlphaGenSolver::ComputeResidual(Structure *structure, CVector &res) +{ - double cos_a; + res.Reset(); + unsigned long size = q.GetSize(); + CMatrix MM(size, size, 0.0); + double cos_a; - if(structure->GetnDof() == 1){ - KK.SetElm(1,1,structure->Get_Kh()); - CC.SetElm(1,1,structure->Get_Ch()); - } - else if(structure->GetnDof() == 2){ - if(linear){ - cos_a = 1.0; + if (structure->GetnDof() == 1) + { + MM.SetElm(1, 1, structure->Get_m()); } - else{ - cos_a = cos(q[1]); - NonLinTerm[0] = (structure->Get_S())*sin(q[1])*pow(qdot[1],2); + else if (structure->GetnDof() == 2) + { + if (linear) + { + cos_a = 1.0; + } + else + { + cos_a = cos(q[1]); + } + MM.SetElm(1, 1, structure->Get_m()); + MM.SetElm(1, 2, (structure->Get_S()) * cos_a); + MM.SetElm(2, 1, (structure->Get_S()) * cos_a); + MM.SetElm(2, 2, structure->Get_If()); } - CC.SetElm(1,1,structure->Get_Ch()); - CC.SetElm(2,2,structure->Get_Ca()); - KK.SetElm(1,1,structure->Get_Kh()); - KK.SetElm(2,2,structure->Get_Ka()); - } - else{ - } + CVector RHS(size, 0.0); + ComputeRHS(structure, RHS); - RHS += Loads; - RHS -= MatVecProd(CC, qdot); - RHS -= MatVecProd(KK, q); - RHS += NonLinTerm; + res = MatVecProd(MM, qddot) - RHS; } -void AlphaGenSolver::ComputeResidual(Structure *structure, CVector & res){ - - res.Reset(); - - unsigned long size = q.GetSize(); - CMatrix MM(size, size, 0.0); - double cos_a; +void AlphaGenSolver::ComputeTangentOperator(Structure *structure, CMatrix &St) +{ + St.Reset(); - if(structure->GetnDof() == 1){ - MM.SetElm(1,1, structure->Get_m()); - } - else if(structure->GetnDof() == 2){ - if(linear){ - cos_a = 1.0; - } - else{ - cos_a = cos(q[1]); - } - MM.SetElm(1,1, structure->Get_m()); - MM.SetElm(1,2,(structure->Get_S())*cos_a); - MM.SetElm(2,1,(structure->Get_S())*cos_a); - MM.SetElm(2,2,structure->Get_If()); - } - else{ - - } - - CVector RHS(size, 0.0); - ComputeRHS(structure, RHS); - - res = MatVecProd(MM, qddot) - RHS; -} - -void AlphaGenSolver::ComputeTangentOperator(Structure* structure, CMatrix &St){ - - St.Reset(); - - unsigned long size = q.GetSize(); - CMatrix MM(size, size, 0.0); - CMatrix Ct(size, size, 0.0); - CMatrix Kt(size, size, 0.0); - - if(structure->GetnDof() == 1){ - MM.SetElm(1,1, structure->Get_m()); - Kt.SetElm(1,1,(structure->Get_Kh())); - Ct.SetElm(1,1,(structure->Get_Ch())); - } - else if(structure->GetnDof() == 2){ - if(linear){ - MM.SetElm(1,1, structure->Get_m()); - MM.SetElm(1,2,(structure->Get_S())); - MM.SetElm(2,1,(structure->Get_S())); - MM.SetElm(2,2,structure->Get_If()); - Ct.SetElm(1,1,(structure->Get_Ch())); - Ct.SetElm(2,2,(structure->Get_Ca())); - Kt.SetElm(1,1,(structure->Get_Kh())); - Kt.SetElm(2,2,(structure->Get_Ka())); + unsigned long size = q.GetSize(); + CMatrix MM(size, size, 0.0); + CMatrix Ct(size, size, 0.0); + CMatrix Kt(size, size, 0.0); + + if (structure->GetnDof() == 1) + { + MM.SetElm(1, 1, structure->Get_m()); + Kt.SetElm(1, 1, (structure->Get_Kh())); + Ct.SetElm(1, 1, (structure->Get_Ch())); } - else{ - MM.SetElm(1,1, structure->Get_m()); - MM.SetElm(1,2,(structure->Get_S())*cos(q[1])); - MM.SetElm(2,1,(structure->Get_S())*cos(q[1])); - MM.SetElm(2,2,structure->Get_If()); - Ct.SetElm(1,1,-(structure->Get_Ch())); - Ct.SetElm(1,2,(structure->Get_S())*sin(q[1])*2*qdot[1]); - Ct.SetElm(2,2,-(structure->Get_Ca())); - Kt.SetElm(1,1,-(structure->Get_Kh())); - Kt.SetElm(1,2,(structure->Get_S())*cos(q[1])*pow(qdot[1],2)); - Kt.SetElm(2,2,-(structure->Get_Ka())); + else if (structure->GetnDof() == 2) + { + if (linear) + { + MM.SetElm(1, 1, structure->Get_m()); + MM.SetElm(1, 2, (structure->Get_S())); + MM.SetElm(2, 1, (structure->Get_S())); + MM.SetElm(2, 2, structure->Get_If()); + Ct.SetElm(1, 1, (structure->Get_Ch())); + Ct.SetElm(2, 2, (structure->Get_Ca())); + Kt.SetElm(1, 1, (structure->Get_Kh())); + Kt.SetElm(2, 2, (structure->Get_Ka())); + } + else + { + MM.SetElm(1, 1, structure->Get_m()); + MM.SetElm(1, 2, (structure->Get_S()) * cos(q[1])); + MM.SetElm(2, 1, (structure->Get_S()) * cos(q[1])); + MM.SetElm(2, 2, structure->Get_If()); + Ct.SetElm(1, 1, -(structure->Get_Ch())); + Ct.SetElm(1, 2, (structure->Get_S()) * sin(q[1]) * 2 * qdot[1]); + Ct.SetElm(2, 2, -(structure->Get_Ca())); + Kt.SetElm(1, 1, -(structure->Get_Kh())); + Kt.SetElm(1, 2, (structure->Get_S()) * cos(q[1]) * pow(qdot[1], 2)); + Kt.SetElm(2, 2, -(structure->Get_Ka())); + } } - } - else{ - - } - - St += ScalMatProd(betaPrime, MM); - St += ScalMatProd(gammaPrime, Ct); - St += Kt; - + St += ScalMatProd(betaPrime, MM); + St += ScalMatProd(gammaPrime, Ct); + St += Kt; } -void AlphaGenSolver::ResetSolution(){ - - Solver::ResetSolution(); - a.Reset(); - a_n.Reset(); +void AlphaGenSolver::ResetSolution() +{ + Solver::ResetSolution(); + a.Reset(); + a_n.Reset(); } -void AlphaGenSolver::SaveToThePast(){ - - Solver::SaveToThePast(); - a_n = a; +void AlphaGenSolver::SaveToThePast() +{ + Solver::SaveToThePast(); + a_n = a; } -void AlphaGenSolver::SetInitialState(Config* config, Structure* structure){ +void AlphaGenSolver::SetInitialState(Config *config, Structure *structure) +{ - if(config->GetRestartSol() == "YES"){ - string InputFileName = config->GetRestartFile(); - string text_line; - string token, tempString; - size_t pos; - string delimiter = "\t"; - ifstream InputFile; - InputFile.open(InputFileName.c_str(), ios::in); - double buffer[(4*structure->GetnDof())+1]; - int kk = 0; - int jj; - while (getline(InputFile,text_line)){ - tempString = text_line; - jj = 0; - if (kk == 1){ - while ((pos = tempString.find(delimiter)) != string::npos){ - token = tempString.substr(0,pos); - tempString.erase(0,pos+delimiter.length()); - buffer[jj] = atof(token.c_str()); - jj += 1; + if (config->GetRestartSol() == "YES") + { + string InputFileName = config->GetRestartFile(); + string text_line; + string token, tempString; + size_t pos; + string delimiter = "\t"; + ifstream InputFile; + InputFile.open(InputFileName.c_str(), ios::in); + double buffer[(4 * structure->GetnDof()) + 1]; + int kk = 0; + int jj; + while (getline(InputFile, text_line)) + { + tempString = text_line; + jj = 0; + if (kk == 1) + { + while ((pos = tempString.find(delimiter)) != string::npos) + { + token = tempString.substr(0, pos); + tempString.erase(0, pos + delimiter.length()); + buffer[jj] = atof(token.c_str()); + jj += 1; + } + buffer[jj] = atof(tempString.c_str()); + + if (structure->GetnDof() == 1) + { + q_n[0] = buffer[1]; + qdot_n[0] = buffer[2]; + qddot_n[0] = buffer[3]; + a_n[0] = buffer[4]; + } + else if (structure->GetnDof() == 2) + { + q_n[0] = buffer[1]; + q_n[1] = buffer[2]; + qdot_n[0] = buffer[3]; + qdot_n[1] = buffer[4]; + qddot_n[0] = buffer[5]; + qddot_n[1] = buffer[6]; + a_n[0] = buffer[7]; + a_n[1] = buffer[8]; + } + q_n.print(); + qdot_n.print(); + qddot_n.print(); + a_n.print(); + } + else if (kk == 2) + { + while ((pos = tempString.find(delimiter)) != string::npos) + { + token = tempString.substr(0, pos); + tempString.erase(0, pos + delimiter.length()); + buffer[jj] = atof(token.c_str()); + jj += 1; + } + buffer[jj] = atof(tempString.c_str()); + + if (structure->GetnDof() == 1) + { + q[0] = buffer[1]; + qdot[0] = buffer[2]; + qddot[0] = buffer[3]; + a[0] = buffer[4]; + } + else if (structure->GetnDof() == 2) + { + q[0] = buffer[1]; + q[1] = buffer[2]; + qdot[0] = buffer[3]; + qdot[1] = buffer[4]; + qddot[0] = buffer[5]; + qddot[1] = buffer[6]; + a[0] = buffer[7]; + a[1] = buffer[8]; + } + q.print(); + qdot.print(); + qddot.print(); + a.print(); + } + kk += 1; } - buffer[jj] = atof(tempString.c_str()); - - if(structure->GetnDof() == 1){ - q_n[0] = buffer[1]; - qdot_n[0] = buffer[2]; - qddot_n[0] = buffer[3]; - a_n[0] = buffer[4]; + InputFile.close(); + } + else + { + cout << "Setting basic initial conditions for alpha-Gen" << endl; + q.Reset(); + q_n.Reset(); + cout << "Read initial configuration" << endl; + q[0] = config->GetInitialDisp(); + if (structure->GetnDof() == 2) + q[1] = config->GetInitialAngle(); + cout << "Initial plunging displacement : " << q[0] << endl; + cout << "Initial pitching displacement : " << q[1] << endl; + + qdot.Reset(); + qddot.Reset(); + + unsigned long size = q.GetSize(); + CVector RHS(size, 0.0); + CMatrix MM(size, size, 0.0); + + double cos_a; + + if (structure->GetnDof() == 1) + { + MM.SetElm(1, 1, structure->Get_m()); } - else if (structure->GetnDof() == 2){ - q_n[0] = buffer[1]; - q_n[1] = buffer[2]; - qdot_n[0] = buffer[3]; - qdot_n[1] = buffer[4]; - qddot_n[0] = buffer[5]; - qddot_n[1] = buffer[6]; - a_n[0] = buffer[7]; - a_n[1] = buffer[8]; + else if (structure->GetnDof() == 2) + { + if (linear) + { + cos_a = 1.0; + } + else + { + cos_a = cos(q[1]); + } + MM.SetElm(1, 1, structure->Get_m()); + MM.SetElm(1, 2, (structure->Get_S()) * cos_a); + MM.SetElm(2, 1, (structure->Get_S()) * cos_a); + MM.SetElm(2, 2, structure->Get_If()); } - q_n.print(); - qdot_n.print(); - qddot_n.print(); - a_n.print(); - } - else if (kk == 2){ - while ((pos = tempString.find(delimiter)) != string::npos){ - token = tempString.substr(0,pos); - tempString.erase(0,pos+delimiter.length()); - buffer[jj] = atof(token.c_str()); - jj += 1; + else + { } - buffer[jj] = atof(tempString.c_str()); - if(structure->GetnDof() == 1){ - q[0] = buffer[1]; - qdot[0] = buffer[2]; - qddot[0] = buffer[3]; - a[0] = buffer[4]; - } - else if (structure->GetnDof() == 2){ - q[0] = buffer[1]; - q[1] = buffer[2]; - qdot[0] = buffer[3]; - qdot[1] = buffer[4]; - qddot[0] = buffer[5]; - qddot[1] = buffer[6]; - a[0] = buffer[7]; - a[1] = buffer[8]; - } - q.print(); - qdot.print(); - qddot.print(); - a.print(); - } - kk += 1; + ComputeRHS(structure, RHS); + SolveSys(MM, RHS); + qddot = RHS; + a = qddot; } - InputFile.close(); - } - else{ - cout << "Setting basic initial conditions for alpha-Gen" << endl; - q.Reset(); - q_n.Reset(); - cout << "Read initial configuration" << endl; - q[0] = config->GetInitialDisp(); - if(structure->GetnDof() == 2) q[1] = config->GetInitialAngle(); - cout << "Initial plunging displacement : " << q[0] << endl; - cout << "Initial pitching displacement : " << q[1] << endl; +} - qdot.Reset(); - qddot.Reset(); +/*CLASS RK4 SOLVER*/ +RK4Solver::RK4Solver(unsigned nDof, bool bool_linear) : Solver(nDof, bool_linear) +{ + size = nDof; + lastTime = 0.0; + currentTime = 0.0; +} - unsigned long size = q.GetSize(); - CVector RHS(size, 0.0); - CMatrix MM(size, size, 0.0); +RK4Solver::~RK4Solver() {} - double cos_a; +void RK4Solver::Iterate(double &t0, double &tf, Structure *structure) +{ + double h = tf - t0; + lastTime = t0; + currentTime = tf; - if(structure->GetnDof() == 1){ - MM.SetElm(1,1, structure->Get_m()); - } - else if(structure->GetnDof() == 2){ - if(linear){ - cos_a = 1.0; - } - else{ - cos_a = cos(q[1]); - } - MM.SetElm(1,1, structure->Get_m()); - MM.SetElm(1,2,(structure->Get_S())*cos_a); - MM.SetElm(2,1,(structure->Get_S())*cos_a); - MM.SetElm(2,2,structure->Get_If()); - } - else{ + CVector k1(2 * size); + CVector k2(2 * size); + CVector k3(2 * size); + CVector k4(2 * size); - } + CVector state0(2 * size); + CVector statef(2 * size); + CVector statef_dot(2 * size); + state0 = SetState_n(); - ComputeRHS(structure, RHS); - SolveSys(MM, RHS); - qddot = RHS; - a = qddot; + CVector TEMP(2 * size); - } -} + EvaluateStateDerivative(lastTime, state0, k1, structure); + TEMP = state0 + (k1 * (h / 2.0)); + EvaluateStateDerivative(lastTime + h / 2.0, TEMP, k2, structure); + TEMP = state0 + (k2 * (h / 2.0)); + EvaluateStateDerivative(lastTime + h / 2.0, TEMP, k3, structure); + TEMP = state0 + (k3 * h); + EvaluateStateDerivative(lastTime + h, TEMP, k4, structure); -/*CLASS RK4 SOLVER*/ -RK4Solver::RK4Solver(unsigned nDof, bool bool_linear) : Solver(nDof, bool_linear){ - size = nDof; - lastTime = 0.0; - currentTime = 0.0; -} - -RK4Solver::~RK4Solver(){} - -void RK4Solver::Iterate(double& t0, double& tf, Structure *structure){ - - double h = tf-t0; - lastTime = t0; - currentTime = tf; - - CVector k1(2*size); - CVector k2(2*size); - CVector k3(2*size); - CVector k4(2*size); - - CVector state0(2*size); - CVector statef(2*size); - CVector statef_dot(2*size); - state0 = SetState_n(); - - CVector TEMP(2*size); - - EvaluateStateDerivative(lastTime, state0, k1, structure); - TEMP = state0+(k1*(h/2.0)); - EvaluateStateDerivative(lastTime+h/2.0, TEMP, k2, structure); - TEMP = state0+(k2*(h/2.0)); - EvaluateStateDerivative(lastTime+h/2.0, TEMP, k3, structure); - TEMP = state0+(k3*h); - EvaluateStateDerivative(lastTime+h, TEMP, k4, structure); - - statef = state0 + ((k1 + k2*2.0 + k3*2.0 + k4)*(h/6.0)); - - EvaluateStateDerivative(lastTime+h, statef, statef_dot, structure); - - if(structure->GetnDof() == 1){ - q[0] = statef[0]; - qdot[0] = statef[1]; - qddot[0] = statef_dot[1]; - } - else if (structure->GetnDof() == 2){ - q[0] = statef[0]; - q[1] = statef[1]; - qdot[0] = statef[2]; - qdot[1] = statef[3]; - qddot[0] = statef_dot[2]; - qddot[1] = statef_dot[3]; - } - else{ - - } -} - -void RK4Solver::EvaluateStateDerivative(double tCurrent, CVector &state, CVector &stateDerivative, Structure* structure){ - - CVector stateLoads(size, 0.0); - interpLoads(tCurrent, stateLoads); - - CMatrix MM(size, size, 0.0); - CMatrix CC(size, size, 0.0); - CMatrix KK(size, size, 0.0); - CVector NonLinTerm(size, 0.0); - CVector RHS(size, 0.0); - - CVector q_current(size, 0.0); - CVector qdot_current(size, 0.0); - CVector qddot_current(size, 0.0); - - if(structure->GetnDof() == 1){ - MM.SetElm(1,1, structure->Get_m()); - KK.SetElm(1,1,structure->Get_Kh()); - CC.SetElm(1,1,structure->Get_Ch()); - q_current[0] = state[0]; - qdot_current[0] = state[1]; - stateDerivative[0] = state[1]; - } - else if (structure->GetnDof() == 2){ - double cos_a; - if(linear){ - cos_a = 1.0; + statef = state0 + ((k1 + k2 * 2.0 + k3 * 2.0 + k4) * (h / 6.0)); + + EvaluateStateDerivative(lastTime + h, statef, statef_dot, structure); + + if (structure->GetnDof() == 1) + { + q[0] = statef[0]; + qdot[0] = statef[1]; + qddot[0] = statef_dot[1]; } - else{ - cos_a = cos(state[1]); - NonLinTerm[0] = (structure->Get_S())*sin(state[1])*pow(state[3],2); + else if (structure->GetnDof() == 2) + { + q[0] = statef[0]; + q[1] = statef[1]; + qdot[0] = statef[2]; + qdot[1] = statef[3]; + qddot[0] = statef_dot[2]; + qddot[1] = statef_dot[3]; } - MM.SetElm(1,1, structure->Get_m()); - MM.SetElm(1,2,(structure->Get_S())*cos_a); - MM.SetElm(2,1,(structure->Get_S())*cos_a); - MM.SetElm(2,2,structure->Get_If()); - CC.SetElm(1,1,structure->Get_Ch()); - CC.SetElm(2,2,structure->Get_Ca()); - KK.SetElm(1,1,structure->Get_Kh()); - KK.SetElm(2,2,structure->Get_Ka()); - q_current[0] = state[0]; - q_current[1] = state[1]; - qdot_current[0] = state[2]; - qdot_current[1] = state[3]; - stateDerivative[0] = state[2]; - stateDerivative[1] = state[3]; - } - else{ - - } - - RHS += stateLoads; - RHS -= MatVecProd(CC, qdot_current); - RHS -= MatVecProd(KK, q_current); - RHS += NonLinTerm; - - SolveSys(MM, RHS); - qddot_current = RHS; - - if(structure->GetnDof() == 1){ - stateDerivative[1] = qddot_current[0]; - } - else if (structure->GetnDof() == 2){ - stateDerivative[2] = qddot_current[0]; - stateDerivative[3] = qddot_current[1]; - } - else{ - - } - -} - -void RK4Solver::interpLoads(double &tCurrent, CVector &val_loads){ - - if (lastTime != currentTime){ - val_loads[0] = (Loads[0] - Loads_n[0])/(currentTime-lastTime)*(tCurrent - lastTime) + Loads_n[0]; - if(size == 2) val_loads[1] = (Loads[1] - Loads_n[1])/(currentTime-lastTime)*(tCurrent - lastTime) + Loads_n[1]; - } - else{ - val_loads[0] = Loads[0]; - if(size == 2) val_loads[1] = Loads[1]; - } -} - -void RK4Solver::SetInitialState(Config *config, Structure *structure){ - - if (config->GetRestartSol() == "YES"){ - - } - else{ - cout << "Setting basic initial conditions for RK4" << endl; - q.Reset(); - q_n.Reset(); - cout << "Read initial configuration" << endl; - q[0] = config->GetInitialDisp(); - if(structure->GetnDof() == 2) q[1] = config->GetInitialAngle(); - cout << "Initial plunging displacement : " << q[0] << endl; - cout << "Initial pitching displacement : " << q[1] << endl; - qdot.Reset(); +} - lastTime = 0.0; - currentTime = 0.0; +void RK4Solver::EvaluateStateDerivative(double tCurrent, CVector &state, CVector &stateDerivative, Structure *structure) +{ - qddot.Reset(); - CVector state(2*size); - CVector state_dot(2*size); + CVector stateLoads(size, 0.0); + interpLoads(tCurrent, stateLoads); - state = SetState(); - EvaluateStateDerivative(0.0, state, state_dot, structure); + CMatrix MM(size, size, 0.0); + CMatrix CC(size, size, 0.0); + CMatrix KK(size, size, 0.0); + CVector NonLinTerm(size, 0.0); + CVector RHS(size, 0.0); - if(structure->GetnDof() == 1){ - qddot[0] = state_dot[1]; + CVector q_current(size, 0.0); + CVector qdot_current(size, 0.0); + CVector qddot_current(size, 0.0); + + if (structure->GetnDof() == 1) + { + MM.SetElm(1, 1, structure->Get_m()); + KK.SetElm(1, 1, structure->Get_Kh()); + CC.SetElm(1, 1, structure->Get_Ch()); + q_current[0] = state[0]; + qdot_current[0] = state[1]; + stateDerivative[0] = state[1]; } - else if (structure->GetnDof() == 2){ - qddot[0] = state_dot[2]; - qddot[1] = state_dot[3]; + else if (structure->GetnDof() == 2) + { + double cos_a; + if (linear) + { + cos_a = 1.0; + } + else + { + cos_a = cos(state[1]); + NonLinTerm[0] = (structure->Get_S()) * sin(state[1]) * pow(state[3], 2); + } + MM.SetElm(1, 1, structure->Get_m()); + MM.SetElm(1, 2, (structure->Get_S()) * cos_a); + MM.SetElm(2, 1, (structure->Get_S()) * cos_a); + MM.SetElm(2, 2, structure->Get_If()); + CC.SetElm(1, 1, structure->Get_Ch()); + CC.SetElm(2, 2, structure->Get_Ca()); + KK.SetElm(1, 1, structure->Get_Kh()); + KK.SetElm(2, 2, structure->Get_Ka()); + q_current[0] = state[0]; + q_current[1] = state[1]; + qdot_current[0] = state[2]; + qdot_current[1] = state[3]; + stateDerivative[0] = state[2]; + stateDerivative[1] = state[3]; } - else{ - } + RHS += stateLoads; + RHS -= MatVecProd(CC, qdot_current); + RHS -= MatVecProd(KK, q_current); + RHS += NonLinTerm; + + SolveSys(MM, RHS); + qddot_current = RHS; - } + if (structure->GetnDof() == 1) + { + stateDerivative[1] = qddot_current[0]; + } + else if (structure->GetnDof() == 2) + { + stateDerivative[2] = qddot_current[0]; + stateDerivative[3] = qddot_current[1]; + } } -CVector RK4Solver::SetState(){ +void RK4Solver::interpLoads(double &tCurrent, CVector &val_loads) +{ - CVector state(2*size); + if (lastTime != currentTime) + { + val_loads[0] = (Loads[0] - Loads_n[0]) / (currentTime - lastTime) * (tCurrent - lastTime) + Loads_n[0]; + if (size == 2) + val_loads[1] = (Loads[1] - Loads_n[1]) / (currentTime - lastTime) * (tCurrent - lastTime) + Loads_n[1]; + } + else + { + val_loads[0] = Loads[0]; + if (size == 2) + val_loads[1] = Loads[1]; + } +} - if(size == 1){ - state[0] = q[0]; - state[1] = qdot[0]; - } - else if (size == 2){ - state[0] = q[0]; - state[1] = q[1]; - state[2] = qdot[0]; - state[3] = qdot[1]; - } - else{ +void RK4Solver::SetInitialState(Config *config, Structure *structure) +{ + if (config->GetRestartSol() == "YES") + { + } + else + { + cout << "Setting basic initial conditions for RK4" << endl; + q.Reset(); + q_n.Reset(); + cout << "Read initial configuration" << endl; + q[0] = config->GetInitialDisp(); + if (structure->GetnDof() == 2) + q[1] = config->GetInitialAngle(); + cout << "Initial plunging displacement : " << q[0] << endl; + cout << "Initial pitching displacement : " << q[1] << endl; + qdot.Reset(); + + lastTime = 0.0; + currentTime = 0.0; + + qddot.Reset(); + CVector state(2 * size); + CVector state_dot(2 * size); + + state = SetState(); + EvaluateStateDerivative(0.0, state, state_dot, structure); + + if (structure->GetnDof() == 1) + { + qddot[0] = state_dot[1]; + } + else if (structure->GetnDof() == 2) + { + qddot[0] = state_dot[2]; + qddot[1] = state_dot[3]; + } + } +} - } +CVector RK4Solver::SetState() +{ + CVector state(2 * size); - return state; + if (size == 1) + { + state[0] = q[0]; + state[1] = qdot[0]; + } + else if (size == 2) + { + state[0] = q[0]; + state[1] = q[1]; + state[2] = qdot[0]; + state[3] = qdot[1]; + } + else + { + } + return state; } -CVector RK4Solver::SetState_n(){ - - CVector state(2*size); - - if(size == 1){ - state[0] = q_n[0]; - state[1] = qdot_n[0]; - } - else if (size == 2){ - state[0] = q_n[0]; - state[1] = q_n[1]; - state[2] = qdot_n[0]; - state[3] = qdot_n[1]; - } - else{ +CVector RK4Solver::SetState_n() +{ + CVector state(2 * size); - } + if (size == 1) + { + state[0] = q_n[0]; + state[1] = qdot_n[0]; + } + else if (size == 2) + { + state[0] = q_n[0]; + state[1] = q_n[1]; + state[2] = qdot_n[0]; + state[3] = qdot_n[1]; + } + else + { + } - return state; + return state; } /*CLASS STATIC SOLVER*/ StaticSolver::StaticSolver(unsigned nDof, bool bool_linear) : Solver(nDof, bool_linear) { - _nDof = nDof; - KK.Initialize(_nDof, _nDof, 0.0); + _nDof = nDof; + KK.Initialize(_nDof, _nDof, 0.0); } StaticSolver::~StaticSolver() { - std::cout << "NativeSolid::~StaticSolver()" << std::endl; + std::cout << "NativeSolid::~StaticSolver()" << std::endl; } -void StaticSolver::SetInitialState(Config *config, Structure *structure){ - // Reset displacement, velocity and acceleration - if (config->GetRestartSol() == "YES"){ - } - else{ - cout << "Setting basic initial conditions for Static" << endl; - q.Reset(); - q_n.Reset(); - cout << "Read initial configuration" << endl; - q[0] = config->GetInitialDisp(); - if(_nDof == 2) q[1] = config->GetInitialAngle(); - cout << "Initial plunging displacement : " << q[0] << endl; - cout << "Initial pitching displacement : " << q[1] << endl; - qdot.Reset(); - qddot.Reset(); - } - // Fill stiffness matrix - if(_nDof == 1) - KK.SetElm(1,1,structure->Get_Kh()); - else if(_nDof == 2) { - KK.SetElm(1,1,structure->Get_Kh()); - KK.SetElm(2,2,structure->Get_Ka()); - } - else { - cerr << "Error in NativeSolid::StaticSolver: Number of degrees of freedom is out of range. nDof = " << _nDof << endl; - throw(-1); - } -} - -void StaticSolver::Iterate(double &t0, double &tf, Structure* structure) -{ - // Solve KK*q = Loads - q_n = q; // save previous state (used to compute rotation in NativeSolidSolver::computeInterfacePosVel) - CVector RHS(_nDof, 0.); - RHS += Loads; - SolveSys(KK, RHS); - q = RHS; +void StaticSolver::SetInitialState(Config *config, Structure *structure) +{ + // Reset displacement, velocity and acceleration + if (config->GetRestartSol() == "YES") + { + } + else + { + cout << "Setting basic initial conditions for Static" << endl; + q.Reset(); + q_n.Reset(); + cout << "Read initial configuration" << endl; + q[0] = config->GetInitialDisp(); + if (_nDof == 2) + q[1] = config->GetInitialAngle(); + cout << "Initial plunging displacement : " << q[0] << endl; + cout << "Initial pitching displacement : " << q[1] << endl; + qdot.Reset(); + qddot.Reset(); + } + // Fill stiffness matrix + if (_nDof == 1) + KK.SetElm(1, 1, structure->Get_Kh()); + else if (_nDof == 2) + { + KK.SetElm(1, 1, structure->Get_Kh()); + KK.SetElm(2, 2, structure->Get_Ka()); + } + else + { + cerr << "Error in NativeSolid::StaticSolver: Number of degrees of freedom is out of range. nDof = " << _nDof << endl; + throw(-1); + } +} + +void StaticSolver::Iterate(double &t0, double &tf, Structure *structure) +{ + // Solve KK*q = Loads + q_n = q; // save previous state (used to compute rotation in NativeSolidSolver::computeInterfacePosVel) + CVector RHS(_nDof, 0.); + RHS += Loads; + SolveSys(KK, RHS); + q = RHS; } diff --git a/src/structure.cpp b/src/structure.cpp index fedd2e5..b0b2014 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -1,172 +1,190 @@ -#include "../include/structure.h" +#include "structure.h" #include #include #include #include #include - using namespace std; -Structure::Structure(Config* config){ - - centerOfRotation[0] = 0.0; - centerOfRotation[1] = 0.0; - centerOfRotation[2] = 0.0; - - centerOfRotation_n[0] = 0.0; - centerOfRotation_n[1] = 0.0; - centerOfRotation_n[2] = 0.0; - - - if(config->GetStructType() == "SPRING_HOR" || config->GetStructType() == "SPRING_VER" ){ - nDof = 1; - m = config->GetSpringMass(); - Kh = config->GetSpringStiffness(); - Ch = config->GetSpringDamping(); - Ka = 0; - Ca = 0; - xf = 0; - xCG = 0; - c = 0; - b = 0; - S = 0; - ICG = 0; - If = 0; - cout << "Setting mass-spring-damper system" << endl; - cout << "Number of DOF : " << nDof << endl; - cout << "Plunging mass : " << m << " [kg]" << endl; - cout << "Plunging damping : " << Ch << " [Ns/m]" << endl; - cout << "Plunging stiffness : " << Kh << " [N/m]" << endl; - } - else if (config->GetStructType() == "AIRFOIL"){ - nDof = 2; - m = config->GetSpringMass(); - Kh = config->GetSpringStiffness(); - Ch = config->GetSpringDamping(); - Ka = config->GetTorsionalStiffness(); - Ca = config->GetTorsionalDamping(); - xf = config->GetFlexuralAxis(); - xCG = config->GetGravityCenter(); - c = config->GetCord(); - b = c/2.0; - S = m*(xCG-xf); - //If = ICG + m*pow((xCG-xf),2); - If = config->GetInertiaFlexural(); - //S = m*(c/2.0-xf); - //Ia = 1.0/3.0*m*(c*c-3*c*xf+3*xf*xf); - cout << "Setting pitching-plunging airfoil system" << endl; - cout << "Number of DOF : " << nDof << endl; - cout << "Airfoil mass : " << m << " [kg]" << endl; - cout << "Airfoil cord : " << c << " [m]" << endl; - cout << "Position of the flexural axis : " << xf << " [m]" << endl; - cout << "Inertia around the flexural axis : " << If << " [kg m²]" << endl; - cout << "Plunging damping : " << Ch << " [Ns/m]" << endl; - cout << "Plunging stiffness : " << Kh << " [N/m]" << endl; - cout << "Pitching damping : " << Ca << " [Ns]" << endl; - cout << "Pitching stiffness : " << Ka << " [N]" << endl; - cout << "Position of the center of gravity : " << xCG << " [m]" << endl; - cout << "Static unbalance : " << S << " [kg m]" << endl; +Structure::Structure(Config *config) +{ + centerOfRotation[0] = 0.0; + centerOfRotation[1] = 0.0; + centerOfRotation[2] = 0.0; + + centerOfRotation_n[0] = 0.0; + centerOfRotation_n[1] = 0.0; + centerOfRotation_n[2] = 0.0; + + if (config->GetStructType() == "SPRING_HOR" || + config->GetStructType() == "SPRING_VER") + { + nDof = 1; + m = config->GetSpringMass(); + Kh = config->GetSpringStiffness(); + Ch = config->GetSpringDamping(); + Ka = 0; + Ca = 0; + xf = 0; + xCG = 0; + c = 0; + b = 0; + S = 0; + ICG = 0; + If = 0; + cout << "Setting mass-spring-damper system" << endl; + cout << "Number of DOF : " << nDof << endl; + cout << "Plunging mass : " << m << " [kg]" << endl; + cout << "Plunging damping : " << Ch << " [Ns/m]" << endl; + cout << "Plunging stiffness : " << Kh << " [N/m]" << endl; + } + else if (config->GetStructType() == "AIRFOIL") + { + nDof = 2; + m = config->GetSpringMass(); + Kh = config->GetSpringStiffness(); + Ch = config->GetSpringDamping(); + Ka = config->GetTorsionalStiffness(); + Ca = config->GetTorsionalDamping(); + xf = config->GetFlexuralAxis(); + xCG = config->GetGravityCenter(); + c = config->GetCord(); + b = c / 2.0; + S = m * (xCG - xf); + // If = ICG + m*pow((xCG-xf),2); + If = config->GetInertiaFlexural(); + // S = m*(c/2.0-xf); + // Ia = 1.0/3.0*m*(c*c-3*c*xf+3*xf*xf); + cout << "Setting pitching-plunging airfoil system" << endl; + cout << "Number of DOF : " << nDof << endl; + cout << "Airfoil mass : " << m << " [kg]" << endl; + cout << "Airfoil cord : " << c << " [m]" << endl; + cout << "Position of the flexural axis : " << xf << " [m]" << endl; + cout << "Inertia around the flexural axis : " << If << " [kg m²]" << endl; + cout << "Plunging damping : " << Ch << " [Ns/m]" << endl; + cout << "Plunging stiffness : " << Kh << " [N/m]" << endl; + cout << "Pitching damping : " << Ca << " [Ns]" << endl; + cout << "Pitching stiffness : " << Ka << " [N]" << endl; + cout << "Position of the center of gravity : " << xCG << " [m]" << endl; + cout << "Static unbalance : " << S << " [kg m]" << endl; - centerOfRotation[0] = xf; - centerOfRotation_n[0] = xf; - } - else{ - nDof = 0; - cerr << "Invalid structural type. Available choices are : SPRIN_HOR, SPRING_VER and AIRFOIL." << endl; - throw(-1); - } + centerOfRotation[0] = xf; + centerOfRotation_n[0] = xf; + } + else + { + nDof = 0; + cerr << "Invalid structural type. Available choices are : SPRIN_HOR, SPRING_VER and AIRFOIL." << endl; + throw(-1); + } } -Structure::~Structure(){} - -void Structure::SetCenterOfRotation_X(double coord_x){ - centerOfRotation[0] = coord_x; +Structure::~Structure() +{ } -void Structure::SetCenterOfRotation_Y(double coord_y){ - centerOfRotation[1] = coord_y; +void Structure::SetCenterOfRotation_X(double coord_x) +{ + centerOfRotation[0] = coord_x; } -void Structure::SetCenterOfRotation_Z(double coord_z){ - centerOfRotation[2] = coord_z; +void Structure::SetCenterOfRotation_Y(double coord_y) +{ + centerOfRotation[1] = coord_y; } -double Structure::GetCenterOfRotation_x() const{ - return centerOfRotation[0]; +void Structure::SetCenterOfRotation_Z(double coord_z) +{ + centerOfRotation[2] = coord_z; } -double Structure::GetCenterOfRotation_y() const{ - return centerOfRotation[1]; +double Structure::GetCenterOfRotation_x() const +{ + return centerOfRotation[0]; } -double Structure::GetCenterOfRotation_z() const{ - return centerOfRotation[2]; +double Structure::GetCenterOfRotation_y() const +{ + return centerOfRotation[1]; } -const double* Structure::GetCenterOfRotation() const{ - return centerOfRotation; +double Structure::GetCenterOfRotation_z() const +{ + return centerOfRotation[2]; } -void Structure::SetCenterOfRotation_n_X(double coord_x){ - centerOfRotation_n[0] = coord_x; +const double *Structure::GetCenterOfRotation() const +{ + return centerOfRotation; } -void Structure::SetCenterOfRotation_n_Y(double coord_y){ - centerOfRotation_n[1] = coord_y; +void Structure::SetCenterOfRotation_n_X(double coord_x) +{ + centerOfRotation_n[0] = coord_x; } -void Structure::SetCenterOfRotation_n_Z(double coord_z){ - centerOfRotation_n[2] = coord_z; +void Structure::SetCenterOfRotation_n_Y(double coord_y) +{ + centerOfRotation_n[1] = coord_y; } -double Structure::GetCenterOfRotation_n_x() const{ - return centerOfRotation_n[0]; +void Structure::SetCenterOfRotation_n_Z(double coord_z) +{ + centerOfRotation_n[2] = coord_z; } -double Structure::GetCenterOfRotation_n_y() const{ - return centerOfRotation_n[1]; +double Structure::GetCenterOfRotation_n_x() const +{ + return centerOfRotation_n[0]; } -double Structure::GetCenterOfRotation_n_z() const{ - return centerOfRotation_n[2]; +double Structure::GetCenterOfRotation_n_y() const +{ + return centerOfRotation_n[1]; } -unsigned int Structure::GetnDof() const{ - return nDof; +double Structure::GetCenterOfRotation_n_z() const +{ + return centerOfRotation_n[2]; } -double Structure::Get_m() const{ - - return m; +unsigned int Structure::GetnDof() const +{ + return nDof; } -double Structure::Get_Kh() const{ - - return Kh; +double Structure::Get_m() const +{ + return m; } -double Structure::Get_Ka() const{ - - return Ka; +double Structure::Get_Kh() const +{ + return Kh; } -double Structure::Get_Ch() const{ - - return Ch; +double Structure::Get_Ka() const +{ + return Ka; } -double Structure::Get_Ca() const{ - - return Ca; +double Structure::Get_Ch() const +{ + return Ch; } -double Structure::Get_S() const{ - - return S; +double Structure::Get_Ca() const +{ + return Ca; } -double Structure::Get_If() const{ +double Structure::Get_S() const +{ + return S; +} - return If; +double Structure::Get_If() const +{ + return If; } diff --git a/src/testcvector.cpp b/src/testcvector.cpp index 9773ec5..37531ee 100644 --- a/src/testcvector.cpp +++ b/src/testcvector.cpp @@ -1,122 +1,121 @@ #include - -#include "../include/MatVec.h" - -int main(int argc, char** argv){ - - //Test initialization - CVector myVec(5, 5.0); - - //Test copy - CVector myVec2(myVec); - - //Test initiate - std::cout << "initiate()"<< std::endl; - CVector myVec4; - myVec4.Initialize(5,7.0); - myVec4.print(); - - //Test getSize() - std::cout << "getSize()"<< std::endl; - std::cout << myVec.GetSize() << std::endl; - std::cout << myVec2.GetSize() << std::endl; - - //Test dotProduct() - std::cout << "dot()"<< std::endl; - CVector myVec3(5,1.0); - double dotProduct(0.0), dotProduct2(0.0); - dotProduct = myVec.dotProd(myVec3); - dotProduct2 = myVec3.dotProd(myVec); - std::cout << dotProduct << std::endl; - std::cout << dotProduct2 << std::endl; - - //Test norm() - std::cout << "norm()"<< std::endl; - std::cout << myVec.norm() << std::endl; - - //Test display() - std::cout << "display()"<< std::endl; - myVec.print(); - - //Test reset(); - std::cout << "reset()"<< std::endl; - myVec2.Reset(); - myVec2.print(); - - //Test operator[] as member - std::cout << "operator[]"<< std::endl; - std::cout << myVec[3] << std::endl; - myVec[3] = 100.0; - myVec.print(); - - //Test operator= as member - std::cout << "operator="<< std::endl; - myVec2 = myVec; - myVec2.print(); - - //Test operator += as member - std::cout << "operator+="<< std::endl; - myVec.SetAllValues(2.0); - myVec2.SetAllValues(3.0); - myVec2 += myVec; - myVec2.print(); - - //Test operator -= as member - std::cout << "operator-="<< std::endl; - myVec2 -= myVec; - myVec2.print(); - - //Test operator *= as member - std::cout << "operator*="<< std::endl; - myVec.SetAllValues(2.0); - myVec *= 2.0; - myVec.print(); - - //Test operator /= as member - std::cout << "operator/="<< std::endl; - myVec /= 2.0; - myVec.print(); - - //Test addition - std::cout << "addition"<< std::endl; - myVec.SetAllValues(2.0); - myVec2.SetAllValues(3.0); - CVector vecSum(5, 0.0); - vecSum = myVec + myVec2; - vecSum.print(); - - //Test multiplication - std::cout << "multiplication"<< std::endl; - myVec.SetAllValues(2.0); - CVector vecMul(5, 0.0); - vecMul = myVec*2.0; - vecMul = 3.0*myVec; - vecMul.print(); - - //Test linear combination - std::cout << "linear combination"<< std::endl; - myVec.SetAllValues(1.0); - myVec2.SetAllValues(1.0); - myVec3.SetAllValues(1.0); - myVec4 = myVec + (2.0*myVec2 + 5.0*myVec3)*2.0; - myVec4.print(); - - std::cout << "Pointers..."<< std::endl; - CVector* myVecPoint = NULL; - CVector* myVecPoint2 = NULL; - myVecPoint = new CVector(5,10.0); - myVecPoint->print(); - std::cout << (*myVecPoint)[3] << std::endl; - myVecPoint2 = new CVector(*myVecPoint); - myVecPoint2->print(); - myVecPoint->Reset(); - *myVecPoint2 = *myVecPoint; - myVecPoint2->print(); - - - if(myVecPoint != NULL) delete myVecPoint; - if(myVecPoint2 != NULL) delete myVecPoint2; - - return 0; +#include "MatVec.h" + +int main(int argc, char **argv) +{ + // Test initialization + CVector myVec(5, 5.0); + + // Test copy + CVector myVec2(myVec); + + // Test initiate + std::cout << "initiate()" << std::endl; + CVector myVec4; + myVec4.Initialize(5, 7.0); + myVec4.print(); + + // Test getSize() + std::cout << "getSize()" << std::endl; + std::cout << myVec.GetSize() << std::endl; + std::cout << myVec2.GetSize() << std::endl; + + // Test dotProduct() + std::cout << "dot()" << std::endl; + CVector myVec3(5, 1.0); + double dotProduct(0.0), dotProduct2(0.0); + dotProduct = myVec.dotProd(myVec3); + dotProduct2 = myVec3.dotProd(myVec); + std::cout << dotProduct << std::endl; + std::cout << dotProduct2 << std::endl; + + // Test norm() + std::cout << "norm()" << std::endl; + std::cout << myVec.norm() << std::endl; + + // Test display() + std::cout << "display()" << std::endl; + myVec.print(); + + // Test reset(); + std::cout << "reset()" << std::endl; + myVec2.Reset(); + myVec2.print(); + + // Test operator[] as member + std::cout << "operator[]" << std::endl; + std::cout << myVec[3] << std::endl; + myVec[3] = 100.0; + myVec.print(); + + // Test operator = as member + std::cout << "operator=" << std::endl; + myVec2 = myVec; + myVec2.print(); + + // Test operator += as member + std::cout << "operator+=" << std::endl; + myVec.SetAllValues(2.0); + myVec2.SetAllValues(3.0); + myVec2 += myVec; + myVec2.print(); + + // Test operator -= as member + std::cout << "operator-=" << std::endl; + myVec2 -= myVec; + myVec2.print(); + + // Test operator *= as member + std::cout << "operator*=" << std::endl; + myVec.SetAllValues(2.0); + myVec *= 2.0; + myVec.print(); + + // Test operator /= as member + std::cout << "operator/=" << std::endl; + myVec /= 2.0; + myVec.print(); + + // Test addition + std::cout << "addition" << std::endl; + myVec.SetAllValues(2.0); + myVec2.SetAllValues(3.0); + CVector vecSum(5, 0.0); + vecSum = myVec + myVec2; + vecSum.print(); + + // Test multiplication + std::cout << "multiplication" << std::endl; + myVec.SetAllValues(2.0); + CVector vecMul(5, 0.0); + vecMul = myVec * 2.0; + vecMul = 3.0 * myVec; + vecMul.print(); + + // Test linear combination + std::cout << "linear combination" << std::endl; + myVec.SetAllValues(1.0); + myVec2.SetAllValues(1.0); + myVec3.SetAllValues(1.0); + myVec4 = myVec + (2.0 * myVec2 + 5.0 * myVec3) * 2.0; + myVec4.print(); + + std::cout << "Pointers..." << std::endl; + CVector *myVecPoint = NULL; + CVector *myVecPoint2 = NULL; + myVecPoint = new CVector(5, 10.0); + myVecPoint->print(); + std::cout << (*myVecPoint)[3] << std::endl; + myVecPoint2 = new CVector(*myVecPoint); + myVecPoint2->print(); + myVecPoint->Reset(); + *myVecPoint2 = *myVecPoint; + myVecPoint2->print(); + + if (myVecPoint != NULL) + delete myVecPoint; + if (myVecPoint2 != NULL) + delete myVecPoint2; + + return 0; } - From 6c26412e99967f3a586552184445a367fe81edc8 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Thu, 3 Mar 2022 14:53:49 +0100 Subject: [PATCH 15/20] more cleaning --- CMakeLists.txt | 2 +- api/NativeSolid_API.cpp | 285 ++++++++++++++++++++-------------------- api/NativeSolid_API.h | 15 +-- include/MatVec.h | 3 - include/config.h | 23 ++-- include/geometry.h | 2 - include/integration.h | 2 - include/output.h | 10 +- include/solver.h | 3 - include/structure.h | 1 - src/CMakeLists.txt | 1 - src/MatVec.cpp | 54 ++++---- src/config.cpp | 30 ++--- src/geometry.cpp | 68 +++++----- src/integration.cpp | 82 ++++++------ src/output.cpp | 164 ++++++++++++++++------- src/solver.cpp | 56 ++++---- src/structure.cpp | 38 +++--- 18 files changed, 439 insertions(+), 400 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56b96d8..e8c2c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Type of build IF( NOT CMAKE_BUILD_TYPE ) - SET( CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE ) + SET( CMAKE_BUILD_TYPE Release CACHE std::string "" FORCE ) ENDIF() MESSAGE(STATUS "Build type : ${CMAKE_BUILD_TYPE}") diff --git a/api/NativeSolid_API.cpp b/api/NativeSolid_API.cpp index 654831f..fe6a12a 100644 --- a/api/NativeSolid_API.cpp +++ b/api/NativeSolid_API.cpp @@ -2,19 +2,16 @@ #include #include -using namespace std; - const int MASTER_NODE = 0; -NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp) : confFile(str) +NativeSolidSolver::NativeSolidSolver(std::string str, bool FSIComp) : confFile(str) { - int rank = MASTER_NODE; - historyFile.open("NativeHistory.dat", ios::out); - historyFile2.open("NativeHistoryFSI.dat", ios::out); + historyFile.open("NativeHistory.dat", std::ios::out); + historyFile2.open("NativeHistoryFSI.dat", std::ios::out); -/*--- MPI initialization, and buffer setting ---*/ + // --- MPI initialization, and buffer setting --- #ifdef HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif @@ -22,11 +19,11 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp) : confFile(str) if (rank == MASTER_NODE) { if (FSIComp) - cout << endl - << "***************************** Setting NativeSolid for FSI simulation *****************************" << endl; + std::cout << std::endl + << "***************************** Setting NativeSolid for FSI simulation *****************************" << std::endl; else - cout << endl - << "***************************** Setting NativeSolid for CSD simulation *****************************" << endl; + std::cout << std::endl + << "***************************** Setting NativeSolid for CSD simulation *****************************" << std::endl; } config = NULL; @@ -40,22 +37,22 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp) : confFile(str) output = new Output(); /*--- Read CSD configuration file ---*/ - cout << endl - << "\n----------------------- Reading Native configuration file ----------------------" << endl; + std::cout << std::endl + << "\n----------------------- Reading Native configuration file ----------------------" << std::endl; config->ReadConfig(); /*--- Read a SU2 native mesh file ---*/ - cout << endl - << "\n----------------------- Reading SU2 based mesh file ----------------------" << endl; + std::cout << std::endl + << "\n----------------------- Reading SU2 based mesh file ----------------------" << std::endl; geometry = new Geometry(config); /*--- Initialize structural container and create the structural model ---*/ - cout << endl - << "\n----------------------- Creating the structural model ----------------------" << endl; + std::cout << std::endl + << "\n----------------------- Creating the structural model ----------------------" << std::endl; structure = new Structure(config); - cout << endl - << "\n----------------------- Creating the FSI interface ----------------------" << endl; + std::cout << std::endl + << "\n----------------------- Creating the FSI interface ----------------------" << std::endl; double *Coord; unsigned long iMarker(0), iPoint; @@ -71,16 +68,16 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp) : confFile(str) varCoordNorm = 0.0; - cout << nSolidInterfaceVertex << " nodes on the moving interface have to be tracked." << endl; + std::cout << nSolidInterfaceVertex << " nodes on the moving interface have to be tracked." << std::endl; /*--- Initialize the temporal integrator ---*/ - cout << endl - << "\n----------------------- Setting integration parameter ----------------------" << endl; + std::cout << std::endl + << "\n----------------------- Setting integration parameter ----------------------" << std::endl; integrator = new Integration(config, structure); integrator->SetInitialConditions(config, structure); - cout << endl - << "\n----------------------- Setting FSI features ----------------------" << endl; + std::cout << std::endl + << "\n----------------------- Setting FSI features ----------------------" << std::endl; q_uM1.Initialize(structure->GetnDof()); q_uM1.Reset(); @@ -90,64 +87,64 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp) : confFile(str) { if (config->GetUnsteady() == "YES") { - historyFile << fixed - << setw(10) << "Delta_t" - << setw(10) << "FSI iter" - << setw(15) << "Displacement" - << setw(15) << "Velocity" - << setw(15) << "Acceleration" << endl; - historyFile2 << fixed - << setw(10) << "Time" - << setw(10) << "FSI iter" - << setw(15) << "Displacement" - << setw(15) << "Velocity" - << setw(15) << "Acceleration" << endl; + historyFile << std::fixed + << std::setw(10) << "Delta_t" + << std::setw(10) << "FSI iter" + << std::setw(15) << "Displacement" + << std::setw(15) << "Velocity" + << std::setw(15) << "Acceleration" << std::endl; + historyFile2 << std::fixed + << std::setw(10) << "Time" + << std::setw(10) << "FSI iter" + << std::setw(15) << "Displacement" + << std::setw(15) << "Velocity" + << std::setw(15) << "Acceleration" << std::endl; } else { - historyFile << fixed - << setw(10) << "Delta_t" - << setw(10) << "FSI iter" - << setw(15) << "Displacement" << endl; - historyFile2 << fixed - << setw(10) << "FSI iter" - << setw(15) << "Displacement" << endl; + historyFile << std::fixed + << std::setw(10) << "Delta_t" + << std::setw(10) << "FSI iter" + << std::setw(15) << "Displacement" << std::endl; + historyFile2 << std::fixed + << std::setw(10) << "FSI iter" + << std::setw(15) << "Displacement" << std::endl; } } else if (structure->GetnDof() == 2) { if (config->GetUnsteady() == "YES") { - historyFile << fixed - << setw(10) << "Delta_t" - << setw(10) << "FSI iter" - << setw(15) << "Displacement 1" - << setw(15) << "Displacement 2" - << setw(15) << "Velocity 1" - << setw(15) << "Velocity 2" - << setw(15) << "Acceleration 1" - << setw(15) << "Acceleration 2" << endl; - historyFile2 << fixed - << setw(10) << "Time" - << setw(10) << "FSI iter" - << setw(15) << "Displacement 1" - << setw(15) << "Displacement 2" - << setw(15) << "Velocity 1" - << setw(15) << "Velocity 2" - << setw(15) << "Acceleration 1" - << setw(15) << "Acceleration 2" << endl; + historyFile << std::fixed + << std::setw(10) << "Delta_t" + << std::setw(10) << "FSI iter" + << std::setw(15) << "Displacement 1" + << std::setw(15) << "Displacement 2" + << std::setw(15) << "Velocity 1" + << std::setw(15) << "Velocity 2" + << std::setw(15) << "Acceleration 1" + << std::setw(15) << "Acceleration 2" << std::endl; + historyFile2 << std::fixed + << std::setw(10) << "Time" + << std::setw(10) << "FSI iter" + << std::setw(15) << "Displacement 1" + << std::setw(15) << "Displacement 2" + << std::setw(15) << "Velocity 1" + << std::setw(15) << "Velocity 2" + << std::setw(15) << "Acceleration 1" + << std::setw(15) << "Acceleration 2" << std::endl; } else { - historyFile << fixed - << setw(10) << "Delta_t" - << setw(10) << "FSI iter" - << setw(15) << "Displacement 1" - << setw(15) << "Displacement 2" << endl; - historyFile2 << fixed - << setw(10) << "FSI iter" - << setw(15) << "Displacement 1" - << setw(15) << "Displacement 2" << endl; + historyFile << std::fixed + << std::setw(10) << "Delta_t" + << std::setw(10) << "FSI iter" + << std::setw(15) << "Displacement 1" + << std::setw(15) << "Displacement 2" << std::endl; + historyFile2 << std::fixed + << std::setw(10) << "FSI iter" + << std::setw(15) << "Displacement 1" + << std::setw(15) << "Displacement 2" << std::endl; } } } @@ -155,11 +152,11 @@ NativeSolidSolver::NativeSolidSolver(string str, bool FSIComp) : confFile(str) if (rank == MASTER_NODE) { if (FSIComp) - cout << endl - << "***************************** NativeSolid is set for FSI simulation *****************************" << endl; + std::cout << std::endl + << "***************************** NativeSolid is set for FSI simulation *****************************" << std::endl; else - cout << endl - << "***************************** NativeSolid is set for CSD simulation *****************************" << endl; + std::cout << std::endl + << "***************************** NativeSolid is set for CSD simulation *****************************" << std::endl; } } @@ -177,9 +174,9 @@ void NativeSolidSolver::exit() historyFile.close(); if (rank == MASTER_NODE) { - cout << "Solid history file is closed." << endl; - cout << endl - << "***************************** Exit NativeSolid *****************************" << endl; + std::cout << "Solid history file is closed." << std::endl; + std::cout << std::endl + << "***************************** Exit NativeSolid *****************************" << std::endl; } if (config != NULL) @@ -524,7 +521,7 @@ void NativeSolidSolver::writeSolution(double currentTime, double lastTime, doubl int rank = MASTER_NODE; double DeltaT; - string restartFileName; + std::string restartFileName; unsigned long DeltaIter = config->GetDeltaIterWrite(); DeltaT = currentTime - lastTime; @@ -539,26 +536,26 @@ void NativeSolidSolver::writeSolution(double currentTime, double lastTime, doubl { if (config->GetUnsteady() == "YES") { - // if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << "\"Acceleration variable\"" << endl; - historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << endl; + // if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << "\"Acceleration variable\"" << std::endl; + historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << std::endl; } else { - // if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement\"" << endl; - historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << endl; + // if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement\"" << std::endl; + historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << std::endl; } } else if (structure->GetnDof() == 2) { if (config->GetUnsteady() == "YES") { - // if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << "\t" << "\"Acceleration variable 1\"" << "\t" << "\"Acceleration variable 2\"" << endl; - historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << endl; + // if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << "\t" << "\"Acceleration variable 1\"" << "\t" << "\"Acceleration variable 2\"" << std::endl; + historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << std::endl; } else { - // if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 1\"" << endl; - historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << endl; + // if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 1\"" << std::endl; + historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << std::endl; } } } @@ -568,7 +565,7 @@ void NativeSolidSolver::writeSolution(double currentTime, double lastTime, doubl if (ExtIter % DeltaIter == 0 || ExtIter == NbExtIter) { restartFileName = config->GetRestartFile(); - restartFile.open(restartFileName.c_str(), ios::out); + restartFile.open(restartFileName.c_str(), std::ios::out); if (structure->GetnDof() == 1) { restartFile << "\"Time\"" @@ -579,9 +576,9 @@ void NativeSolidSolver::writeSolution(double currentTime, double lastTime, doubl << "\t" << "\"Acceleration\"" << "\t" - << "\"Acceleration variable\"" << endl; - restartFile << currentTime - DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << endl; - restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << endl; + << "\"Acceleration variable\"" << std::endl; + restartFile << currentTime - DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << std::endl; + restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << std::endl; } else if (structure->GetnDof() == 2) { @@ -601,9 +598,9 @@ void NativeSolidSolver::writeSolution(double currentTime, double lastTime, doubl << "\t" << "\"Acceleration variable 1\"" << "\t" - << "\"Acceleration variable 2\"" << endl; - restartFile << currentTime - DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetDisp_n())[1] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[1] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[1] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[1] << endl; - restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << endl; + << "\"Acceleration variable 2\"" << std::endl; + restartFile << currentTime - DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetDisp_n())[1] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[1] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[1] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[1] << std::endl; + restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << std::endl; } restartFile.close(); } @@ -615,7 +612,7 @@ void NativeSolidSolver::saveSolution() int rank = MASTER_NODE; double DeltaT; - // string restartFileName; + // std::string restartFileName; // unsigned long DeltaIter = config->GetDeltaIterWrite(); unsigned long ExtIter = integrator->GetExtIter(); @@ -631,42 +628,42 @@ void NativeSolidSolver::saveSolution() { if (config->GetUnsteady() == "YES") { - historyFile << fixed - << setw(10) << DeltaT - << setw(10) << ExtIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; + historyFile << std::fixed + << std::setw(10) << DeltaT + << std::setw(10) << ExtIter + << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] + << std::setw(15) << (integrator->GetSolver()->GetVel())[0] + << std::setw(15) << (integrator->GetSolver()->GetAcc())[0] << std::endl; } else { - historyFile << fixed - << setw(10) << DeltaT - << setw(10) << ExtIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; + historyFile << std::fixed + << std::setw(10) << DeltaT + << std::setw(10) << ExtIter + << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] << std::endl; } } else if (structure->GetnDof() == 2) { if (config->GetUnsteady() == "YES") { - historyFile << fixed - << setw(10) << DeltaT - << setw(10) << ExtIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[1] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; + historyFile << std::fixed + << std::setw(10) << DeltaT + << std::setw(10) << ExtIter + << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] + << std::setw(15) << (integrator->GetSolver()->GetDisp())[1] + << std::setw(15) << (integrator->GetSolver()->GetVel())[0] + << std::setw(15) << (integrator->GetSolver()->GetVel())[1] + << std::setw(15) << (integrator->GetSolver()->GetAcc())[0] + << std::setw(15) << (integrator->GetSolver()->GetAcc())[1] << std::endl; } else { - historyFile << fixed - << setw(10) << DeltaT - << setw(10) << ExtIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; + historyFile << std::fixed + << std::setw(10) << DeltaT + << std::setw(10) << ExtIter + << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] + << std::setw(15) << (integrator->GetSolver()->GetDisp())[1] << std::endl; } } } @@ -687,40 +684,40 @@ void NativeSolidSolver::writeSolution(double time, int FSIter) { if (config->GetUnsteady() == "YES") { - historyFile2 << fixed - << setw(10) << time - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] << endl; + historyFile2 << std::fixed + << std::setw(10) << time + << std::setw(10) << FSIter + << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] + << std::setw(15) << (integrator->GetSolver()->GetVel())[0] + << std::setw(15) << (integrator->GetSolver()->GetAcc())[0] << std::endl; } else { - historyFile2 << fixed - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] << endl; + historyFile2 << std::fixed + << std::setw(10) << FSIter + << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] << std::endl; } } else if (structure->GetnDof() == 2) { if (config->GetUnsteady() == "YES") { - historyFile2 << fixed - << setw(10) << time - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] - << setw(15) << (integrator->GetSolver()->GetVel())[0] - << setw(15) << (integrator->GetSolver()->GetVel())[1] - << setw(15) << (integrator->GetSolver()->GetAcc())[0] - << setw(15) << (integrator->GetSolver()->GetAcc())[1] << endl; + historyFile2 << std::fixed + << std::setw(10) << time + << std::setw(10) << FSIter + << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] + << std::setw(15) << (integrator->GetSolver()->GetDisp())[1] + << std::setw(15) << (integrator->GetSolver()->GetVel())[0] + << std::setw(15) << (integrator->GetSolver()->GetVel())[1] + << std::setw(15) << (integrator->GetSolver()->GetAcc())[0] + << std::setw(15) << (integrator->GetSolver()->GetAcc())[1] << std::endl; } else { - historyFile2 << fixed - << setw(10) << FSIter - << setw(15) << (integrator->GetSolver()->GetDisp())[0] - << setw(15) << (integrator->GetSolver()->GetDisp())[1] << endl; + historyFile2 << std::fixed + << std::setw(10) << FSIter + << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] + << std::setw(15) << (integrator->GetSolver()->GetDisp())[1] << std::endl; } } } @@ -1018,7 +1015,7 @@ void NativeSolidSolver::setGeneralisedForce() } else { - cerr << "Wrong structural type for applying global fluild loads !" << endl; + std::cerr << "Wrong structural type for applying global fluild loads !" << std::endl; throw(-1); } } @@ -1040,7 +1037,7 @@ void NativeSolidSolver::setGeneralisedForce(double Fx, double Fy) } else { - cerr << "Wrong structural type for applying global fluild loads !" << endl; + std::cerr << "Wrong structural type for applying global fluild loads !" << std::endl; throw(-1); } } @@ -1078,7 +1075,7 @@ void NativeSolidSolver::setGeneralisedMoment() } else { - cerr << "Wrong structural type for applying global fluild loads !" << endl; + std::cerr << "Wrong structural type for applying global fluild loads !" << std::endl; throw(-1); } } @@ -1098,7 +1095,7 @@ void NativeSolidSolver::setGeneralisedMoment(double M) } else { - cerr << "Wrong structural type for applying global fluild loads !" << endl; + std::cerr << "Wrong structural type for applying global fluild loads !" << std::endl; throw(-1); } } diff --git a/api/NativeSolid_API.h b/api/NativeSolid_API.h index e3ec1b4..87746c0 100644 --- a/api/NativeSolid_API.h +++ b/api/NativeSolid_API.h @@ -1,16 +1,15 @@ #pragma once -#include -#include "../include/config.h" -#include "../include/structure.h" -#include "../include/integration.h" -#include "../include/output.h" -#include "../include/MatVec.h" -#include "../include/geometry.h" +#include "config.h" +#include "structure.h" +#include "integration.h" +#include "MatVec.h" +#include "geometry.h" +#include "output.h" #include #include #include - +#include class NativeSolidSolver{ diff --git a/include/MatVec.h b/include/MatVec.h index dc5ba00..4c8adab 100644 --- a/include/MatVec.h +++ b/include/MatVec.h @@ -8,7 +8,6 @@ class CVector { -protected: unsigned long nElm; double *vec_val; @@ -35,8 +34,6 @@ class CVector class CMatrix { - -protected: unsigned long nEq; unsigned long nVar; CVector mat_val; diff --git a/include/config.h b/include/config.h index b0e9bd7..aee6c2b 100644 --- a/include/config.h +++ b/include/config.h @@ -4,6 +4,17 @@ class Config { + std::string ConfigFileName; + std::string MESH_FILE, UNSTEADY_SIMULATION, CSD_SOLVER, + STRUCT_TYPE, LINEARIZE, INTEGRATION_ALGO, + RESTART_SOL, RESTART_FILE, MOVING_MARKER; + double SPRING_STIFFNESS, SPRING_MASS, INERTIA_CG, + INERTIA_FLEXURAL, SPRING_DAMPING, TORSIONAL_STIFFNESS, + TORSIONAL_DAMPING, CORD, FLEXURAL_AXIS, GRAVITY_CENTER, + INITIAL_DISP, INITIAL_ANGLE, START_TIME, + DELTA_T, STOP_TIME, RHO; + unsigned long DELTAITERWRITE; + public: Config(std::string filename); virtual ~Config(); @@ -35,16 +46,4 @@ class Config virtual unsigned long GetDeltaIterWrite(); virtual double GetStopTime(); virtual double GetRho(); - -protected: - std::string ConfigFileName; - std::string MESH_FILE, UNSTEADY_SIMULATION, CSD_SOLVER, - STRUCT_TYPE, LINEARIZE, INTEGRATION_ALGO, - RESTART_SOL, RESTART_FILE, MOVING_MARKER; - double SPRING_STIFFNESS, SPRING_MASS, INERTIA_CG, - INERTIA_FLEXURAL, SPRING_DAMPING, TORSIONAL_STIFFNESS, - TORSIONAL_DAMPING, CORD, FLEXURAL_AXIS, GRAVITY_CENTER, - INITIAL_DISP, INITIAL_ANGLE, START_TIME, - DELTA_T, STOP_TIME, RHO; - unsigned long DELTAITERWRITE; }; diff --git a/include/geometry.h b/include/geometry.h index 04e10f0..0702773 100644 --- a/include/geometry.h +++ b/include/geometry.h @@ -5,7 +5,6 @@ class Point { -protected: double *Coord0; double *Coord; double *Coord_n; @@ -35,7 +34,6 @@ class Point class Geometry { -protected: unsigned short nDim; unsigned long nElem, nPoint, nMarkers; unsigned long *nElemMarker; diff --git a/include/integration.h b/include/integration.h index 8a3e547..fdee320 100644 --- a/include/integration.h +++ b/include/integration.h @@ -8,12 +8,10 @@ class Integration { -protected: double totTime; double deltaT; unsigned long ExtIter; std::string algo; - Solver *solver; public: diff --git a/include/output.h b/include/output.h index fc0e823..72f1f77 100644 --- a/include/output.h +++ b/include/output.h @@ -12,8 +12,10 @@ class Output public: Output(); ~Output(); - // void WriteHistory(Integration* solver, Structure* structure, std::ofstream* outputfile, const double & time); - // void WriteRestart(Integration* solver, Structure* structure); - // void WriteStaticSolution(Config* config, Integration* solver, Structure* structure, std::ofstream* outputfile); - // void WriteRestart(); + void WriteHistory(Integration *solver, Structure *structure, + std::ofstream *outputfile, const double &time); + void WriteRestart(Integration *solver, Structure *structure); + void WriteStaticSolution(Config *config, Integration *solver, + Structure *structure, std::ofstream *outputfile); + void WriteRestart(); }; diff --git a/include/solver.h b/include/solver.h index ea9244f..c9430c0 100644 --- a/include/solver.h +++ b/include/solver.h @@ -39,7 +39,6 @@ class Solver class AlphaGenSolver : public Solver { -protected: double beta; double gamma; double alpha_m; @@ -64,7 +63,6 @@ class AlphaGenSolver : public Solver class RK4Solver : public Solver { -protected: unsigned int size; double lastTime; double currentTime; @@ -84,7 +82,6 @@ class RK4Solver : public Solver class StaticSolver : public Solver { -protected: unsigned int _nDof; CMatrix KK; diff --git a/include/structure.h b/include/structure.h index 437b11e..4cc945c 100644 --- a/include/structure.h +++ b/include/structure.h @@ -5,7 +5,6 @@ class Structure { -protected: unsigned int nDof; double m; double Kh; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0eb628c..02544e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,6 @@ ADD_LIBRARY(Native SHARED ../include/geometry.h ../include/integration.h ../include/MatVec.h - ../include/output.h ../include/structure.h ../include/solver.h config.cpp diff --git a/src/MatVec.cpp b/src/MatVec.cpp index 457940f..a130f03 100644 --- a/src/MatVec.cpp +++ b/src/MatVec.cpp @@ -2,8 +2,6 @@ #include #include -using namespace std; - CVector::CVector(void) : nElm(0) { vec_val = NULL; @@ -15,8 +13,8 @@ CVector::CVector(const unsigned long &size, const double &val) if (size <= 0) { nElm = 0; - cerr << "CVector:CVector(const unsigned long &, const double): " - << "invalid input : size = " << size << endl; + std::cerr << "CVector:CVector(const unsigned long &, const double): " + << "invalid input : size = " << size << std::endl; throw(-1); } else @@ -50,8 +48,8 @@ void CVector::Initialize(const unsigned long &size, const double &val) if (size <= 0) { nElm = 0; - cerr << "CVector::Initialize(const unsigned long &, const double &): " - << "invalid number of element" << nElm << endl; + std::cerr << "CVector::Initialize(const unsigned long &, const double &): " + << "invalid number of element" << nElm << std::endl; throw(-1); } else @@ -76,8 +74,8 @@ unsigned long CVector::GetSize() const { if (nElm <= 0) { - cerr << "CVector::GetSize() const: " - << "invalid number of element" << nElm << endl; + std::cerr << "CVector::GetSize() const: " + << "invalid number of element" << nElm << std::endl; throw(-1); } return nElm; @@ -90,10 +88,10 @@ double *CVector::GetVec() const void CVector::print() const { - cout << "**********" << endl; + std::cout << "**********" << std::endl; for (unsigned int i = 0; i < nElm; i++) - cout << vec_val[i] << endl; - cout << "**********" << endl; + std::cout << vec_val[i] << std::endl; + std::cout << "**********" << std::endl; } void CVector::SetAllValues(const double &val) @@ -109,7 +107,7 @@ CVector &CVector::operator=(const CVector &u) if (nElm != u.nElm) { - cerr << "Sizes do not match for operator = : size1 = " << nElm << " & size2 = " << u.nElm << endl; + std::cerr << "Sizes do not match for operator = : size1 = " << nElm << " & size2 = " << u.nElm << std::endl; throw(-1); } else @@ -125,8 +123,8 @@ CVector &CVector::operator+=(const CVector &u) { if (nElm != u.nElm) { - cerr << "CVector::operator+=(const CVector &) const: " - << "sizes do not match" << endl; + std::cerr << "CVector::operator+=(const CVector &) const: " + << "sizes do not match" << std::endl; throw(-1); } @@ -140,8 +138,8 @@ CVector &CVector::operator-=(const CVector &u) { if (nElm != u.nElm) { - cerr << "CVector::operator-=const CVector &) const: " - << "sizes do not match" << endl; + std::cerr << "CVector::operator-=const CVector &) const: " + << "sizes do not match" << std::endl; throw(-1); } @@ -176,8 +174,8 @@ double CVector::dotProd(const CVector &v) const { if (nElm != v.nElm) { - cerr << "CVector::dotProd(const CVector &, const CVector &): " - << "sizes do not math" << endl; + std::cerr << "CVector::dotProd(const CVector &, const CVector &): " + << "sizes do not math" << std::endl; throw(-1); } @@ -195,8 +193,8 @@ double CVector::norm() const if (tempVal < 0) { - cerr << "CVector::norm(): " - << "computed dot product is negative: " << tempVal << endl; + std::cerr << "CVector::norm(): " + << "computed dot product is negative: " << tempVal << std::endl; throw(-1); } @@ -261,9 +259,9 @@ CMatrix &CMatrix::operator=(const CMatrix &a) if (nEq != a.nEq || nVar != a.nVar) { - cerr << "Sizes do not match for operator = : nEq1 = " << nEq + std::cerr << "Sizes do not match for operator = : nEq1 = " << nEq << " & nEq2 = " << a.nEq << " ; nVar1 = " << nVar - << " & nVar2 = " << a.nVar << endl; + << " & nVar2 = " << a.nVar << std::endl; throw(-1); } else @@ -277,8 +275,8 @@ CMatrix &CMatrix::operator+=(const CMatrix &a) { if (nEq != a.nEq || nVar != a.nVar) { - cerr << "CMatrix::operator+=(const CMatrix &): " - << "sizes do not match" << endl; + std::cerr << "CMatrix::operator+=(const CMatrix &): " + << "sizes do not match" << std::endl; throw(-1); } else @@ -292,8 +290,8 @@ CMatrix &CMatrix::operator-=(const CMatrix &a) { if (nEq != a.nEq || nVar != a.nVar) { - cerr << "CMatrix::operator+=(const CMatrix &): " - << "sizes do not match" << endl; + std::cerr << "CMatrix::operator+=(const CMatrix &): " + << "sizes do not match" << std::endl; throw(-1); } else @@ -439,7 +437,7 @@ void MatrixToVec(int order, double **matrix, double *vecteur, int Nrow, int Ncol } else { - cerr << "Wrong storage order" << endl; + std::cerr << "Wrong storage order" << std::endl; throw(-1); } } @@ -461,7 +459,7 @@ void VecToMatrix(int order, double **matrix, double *vecteur, } else { - cerr << "Wrong storage order" << endl; + std::cerr << "Wrong storage order" << std::endl; throw(-1); } } diff --git a/src/config.cpp b/src/config.cpp index 32598de..a955b27 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -5,9 +5,7 @@ #include #include -using namespace std; - -Config::Config(string filename) : ConfigFileName(filename) +Config::Config(std::string filename) : ConfigFileName(filename) { } @@ -22,14 +20,14 @@ Config *Config::GetAddress() void Config::ReadConfig() { - string delimiter = "="; + std::string delimiter = "="; size_t pos; - string text_line, option; - ifstream InputFile; - InputFile.open(ConfigFileName.c_str(), ios::in); + std::string text_line, option; + std::ifstream InputFile; + InputFile.open(ConfigFileName.c_str(), std::ios::in); if (InputFile.fail()) { - cerr << "Invalid configuration file name : " << ConfigFileName << endl; + std::cerr << "Invalid configuration file name : " << ConfigFileName << std::endl; throw(-1); } char caract; @@ -99,27 +97,27 @@ void Config::ReadConfig() else if (option == "RHO") RHO = atof(text_line.c_str()); else - cout << "The option " + option + " is not recognized !" << endl; + std::cout << "The option " + option + " is not recognized !" << std::endl; } } InputFile.close(); if (CSD_SOLVER == "NATIVE") - cout << "The Native solver has been chosen" << endl; + std::cout << "The Native solver has been chosen" << std::endl; else - cout << "Cannot run the solver with other value than NATIVE for CSD_SOLVER option !" << endl; + std::cout << "Cannot run the solver with other value than NATIVE for CSD_SOLVER option !" << std::endl; if (UNSTEADY_SIMULATION == "YES") - cout << "Dynamic structure computation" << endl; + std::cout << "Dynamic structure computation" << std::endl; else - cout << "Static structure computation" << endl; + std::cout << "Static structure computation" << std::endl; if (STRUCT_TYPE == "SPRING_HOR" || STRUCT_TYPE == "SPRING_VER") - cout << "Structural model is a plunging spring" << endl; + std::cout << "Structural model is a plunging spring" << std::endl; else if (STRUCT_TYPE == "AIRFOIL") - cout << "Structural model is a pitching plunging airfoil" << endl; + std::cout << "Structural model is a pitching plunging airfoil" << std::endl; else - cout << "The specified structural model is not recognized or implemented yet !" << endl; + std::cout << "The specified structural model is not recognized or implemented yet !" << std::endl; } std::string Config::GetMeshFile() diff --git a/src/geometry.cpp b/src/geometry.cpp index 2b22e92..8876779 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -7,8 +7,6 @@ #include #include -using namespace std; - Point::Point() { Coord0 = new double[3]; @@ -95,7 +93,7 @@ double *Point::GetForce() const void Point::PrintCoord() const { - cout << Coord[0] << " ; " << Coord[1] << " ; " << Coord[2] << endl; + std::cout << Coord[0] << " ; " << Coord[1] << " ; " << Coord[2] << std::endl; } void Point::SetCoord0(double *newCoord) @@ -157,9 +155,9 @@ void Point::UpdateVel() Geometry::Geometry(Config *config) { - string meshFileName, textLine, tampon; - ifstream meshFile; - string::size_type position; + std::string meshFileName, textLine, tampon; + std::ifstream meshFile; + std::string::size_type position; double Coord[3]; double *TempCoord; unsigned long iMarker(0); @@ -179,32 +177,32 @@ Geometry::Geometry(Config *config) meshFileName = config->GetMeshFile(); /*--- Open the mesh file and check ---*/ - meshFile.open(meshFileName.c_str(), ios::in); + meshFile.open(meshFileName.c_str(), std::ios::in); if (meshFile.fail()) { - cout << "Unable to open the mesh file " << meshFileName << endl; + std::cout << "Unable to open the mesh file " << meshFileName << std::endl; exit(1); } - cout << "Mesh file " << meshFileName << " is open." << endl; - cout << "Constructing the mesh..." << endl; + std::cout << "Mesh file " << meshFileName << " is open." << std::endl; + std::cout << "Constructing the mesh..." << std::endl; while (getline(meshFile, textLine)) { position = textLine.find("NDIME=", 0); - if (position != string::npos) + if (position != std::string::npos) { textLine.erase(0, 6); nDim = atoi(textLine.c_str()); - cout << "Number of dimensions : " << nDim << endl; + std::cout << "Number of dimensions : " << nDim << std::endl; } position = textLine.find("NELEM=", 0); - if (position != string::npos) + if (position != std::string::npos) { textLine.erase(0, 6); nElem = atoi(textLine.c_str()); - cout << "Number of elements : " << nElem << endl; + std::cout << "Number of elements : " << nElem << std::endl; for (int iElem = 0; iElem < nElem; iElem++) { getline(meshFile, textLine); @@ -212,39 +210,39 @@ Geometry::Geometry(Config *config) } position = textLine.find("NPOIN=", 0); - if (position != string::npos) + if (position != std::string::npos) { textLine.erase(0, 6); nPoint = atoi(textLine.c_str()); - cout << "Number of points : " << nPoint << endl; + std::cout << "Number of points : " << nPoint << std::endl; node = new Point *[nPoint]; - // cout << "JE VAIS REMPLIR" << endl; + // std::cout << "JE VAIS REMPLIR" << std::endl; for (iPoint = 0; iPoint < nPoint; iPoint++) { getline(meshFile, textLine); - // if(iPoint == 1) cout << textLine << endl; + // if(iPoint == 1) std::cout << textLine << std::endl; node[iPoint] = new Point(); - istringstream point_line(textLine); + std::istringstream point_line(textLine); point_line >> Coord[0]; - // if(iPoint == 1) cout << Coord[0] << endl; + // if(iPoint == 1) std::cout << Coord[0] << std::endl; point_line >> Coord[1]; - // if(iPoint == 1) cout << Coord[1] << endl; + // if(iPoint == 1) std::cout << Coord[1] << std::endl; if (nDim == 3) point_line >> Coord[2]; node[iPoint]->SetCoord0(Coord); node[iPoint]->SetCoord(Coord); node[iPoint]->SetCoord_n(Coord); TempCoord = node[iPoint]->GetCoord(); - // cout << iPoint << endl; + // std::cout << iPoint << std::endl; } } position = textLine.find("NMARK=", 0); - if (position != string::npos) + if (position != std::string::npos) { textLine.erase(0, 6); nMarkers = atoi(textLine.c_str()); - cout << "Number of markers : " << nMarkers << endl; + std::cout << "Number of markers : " << nMarkers << std::endl; vertex = new unsigned long *[nMarkers]; nVertex = new unsigned long[nMarkers]; markersMoving = new bool[nMarkers]; @@ -252,13 +250,13 @@ Geometry::Geometry(Config *config) } position = textLine.find("MARKER_TAG=", 0); - if (position != string::npos) + if (position != std::string::npos) { textLine.erase(0, 12); - cout << "Reading elements for marker : " << textLine << endl; + std::cout << "Reading elements for marker : " << textLine << std::endl; if (textLine == config->GetMovingMarker()) { - cout << "Marker " << textLine << " is a moving marker." << endl; + std::cout << "Marker " << textLine << " is a moving marker." << std::endl; markersMoving[iMarker] = true; } else @@ -266,16 +264,16 @@ Geometry::Geometry(Config *config) } position = textLine.find("MARKER_ELEMS=", 0); - if (position != string::npos) + if (position != std::string::npos) { textLine.erase(0, 13); nElemMarker[iMarker] = atoi(textLine.c_str()); - cout << "Number of elements on the marker : " << nElemMarker[iMarker] << endl; - vector tempVertexMarker; + std::cout << "Number of elements on the marker : " << nElemMarker[iMarker] << std::endl; + std::vector tempVertexMarker; for (int iElem = 0; iElem < nElemMarker[iMarker]; iElem++) { getline(meshFile, textLine); - istringstream point_line(textLine); + std::istringstream point_line(textLine); point_line >> elemType; if (elemType == 3) { @@ -292,7 +290,7 @@ Geometry::Geometry(Config *config) } else { - cout << "Elem type " << elemType << " is not recognized !" << endl; + std::cout << "Elem type " << elemType << " is not recognized !" << std::endl; exit(1); } } @@ -306,7 +304,7 @@ Geometry::Geometry(Config *config) meshFile.close(); /*for (int iVertex = 0; iVertex < nVertex[0]; iVertex++){ - //cout << vertex[0][iVertex] << endl; + //cout << vertex[0][iVertex] << std::endl; iPoint = vertex[0][iVertex]; node[iPoint]->PrintCoord(); }*/ @@ -354,7 +352,7 @@ void Geometry::UpdateGeometry() } } -bool isInVec(vector const &inputVector, int dummyInt) +bool isInVec(std::vector const &inputVector, int dummyInt) { int i = 0; while (i < inputVector.size() && inputVector[i] != dummyInt) @@ -362,7 +360,7 @@ bool isInVec(vector const &inputVector, int dummyInt) return i < inputVector.size(); } -void vecCopy(vector const &sourceVector, unsigned long *destinationTab) +void vecCopy(std::vector const &sourceVector, unsigned long *destinationTab) { for (int i = 0; i < sourceVector.size(); i++) { diff --git a/src/integration.cpp b/src/integration.cpp index c3e3dbe..476eb07 100644 --- a/src/integration.cpp +++ b/src/integration.cpp @@ -7,8 +7,6 @@ #include #include -using namespace std; - Integration::Integration(Config *config, Structure *structure) { solver = NULL; @@ -88,35 +86,35 @@ void Integration::TemporalIteration(double &t0, double &tf, Structure *structure { if (structure->GetnDof() == 1) { - cout << fixed - << setw(10) << "Time" - << setw(15) << "Displacement" - << setw(15) << "Velocity" - << setw(15) << "Acceleration" << endl; - cout << fixed - << setw(10) << currentTime - << setw(15) << (solver->GetDisp())[0] - << setw(15) << (solver->GetVel())[0] - << setw(15) << (solver->GetAcc())[0] << endl; + std::cout << std::fixed + << std::setw(10) << "Time" + << std::setw(15) << "Displacement" + << std::setw(15) << "Velocity" + << std::setw(15) << "Acceleration" << std::endl; + std::cout << std::fixed + << std::setw(10) << currentTime + << std::setw(15) << (solver->GetDisp())[0] + << std::setw(15) << (solver->GetVel())[0] + << std::setw(15) << (solver->GetAcc())[0] << std::endl; } else if (structure->GetnDof() == 2) { - cout << fixed - << setw(10) << "Time" - << setw(15) << "Displacement1" - << setw(15) << "Displacement2" - << setw(15) << "Velocity1" - << setw(15) << "Velocity2" - << setw(15) << "Acceleration1" - << setw(15) << "Acceleration2" << endl; - cout << fixed - << setw(10) << currentTime - << setw(15) << (solver->GetDisp())[0] - << setw(15) << (solver->GetDisp())[1] - << setw(15) << (solver->GetVel())[0] - << setw(15) << (solver->GetVel())[1] - << setw(15) << (solver->GetAcc())[0] - << setw(15) << (solver->GetAcc())[1] << endl; + std::cout << std::fixed + << std::setw(10) << "Time" + << std::setw(15) << "Displacement1" + << std::setw(15) << "Displacement2" + << std::setw(15) << "Velocity1" + << std::setw(15) << "Velocity2" + << std::setw(15) << "Acceleration1" + << std::setw(15) << "Acceleration2" << std::endl; + std::cout << std::fixed + << std::setw(10) << currentTime + << std::setw(15) << (solver->GetDisp())[0] + << std::setw(15) << (solver->GetDisp())[1] + << std::setw(15) << (solver->GetVel())[0] + << std::setw(15) << (solver->GetVel())[1] + << std::setw(15) << (solver->GetAcc())[0] + << std::setw(15) << (solver->GetAcc())[1] << std::endl; } } } @@ -138,23 +136,23 @@ void Integration::StaticIteration(Structure *structure) { if (structure->GetnDof() == 1) { - cout << fixed - << setw(10) << "Time" - << setw(15) << "Displacement" << endl; - cout << fixed - << setw(10) << tf - << setw(15) << (solver->GetDisp())[0] << endl; + std::cout << std::fixed + << std::setw(10) << "Time" + << std::setw(15) << "Displacement" << std::endl; + std::cout << std::fixed + << std::setw(10) << tf + << std::setw(15) << (solver->GetDisp())[0] << std::endl; } else if (structure->GetnDof() == 2) { - cout << fixed - << setw(10) << "Time" - << setw(15) << "Displacement1" - << setw(15) << "Displacement2" << endl; - cout << fixed - << setw(10) << tf - << setw(15) << (solver->GetDisp())[0] - << setw(15) << (solver->GetDisp())[1] << endl; + std::cout << std::fixed + << std::setw(10) << "Time" + << std::setw(15) << "Displacement1" + << std::setw(15) << "Displacement2" << std::endl; + std::cout << std::fixed + << std::setw(10) << tf + << std::setw(15) << (solver->GetDisp())[0] + << std::setw(15) << (solver->GetDisp())[1] << std::endl; } } } diff --git a/src/output.cpp b/src/output.cpp index 268812e..c89a760 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -1,69 +1,135 @@ #include "output.h" #include -using namespace std; - -Output::Output() +Output::Output() { - } -Output::~Output() +Output::~Output() { - } /* -void Output::WriteHistory(Integration* solver, Structure* structure, ofstream* outputfile, const double & time){ - - if(structure->GetnDof() == 1){ - if(time == 0){ - cout << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << endl; - outputfile[0] << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << endl; +void Output::WriteHistory(Integration *solver, Structure *structure, ofstream *outputfile, const double &time) +{ + if (structure->GetnDof() == 1) + { + if (time == 0) + { + std::cout << "\"Time\"" + << "\t" + << "\"Displacement\"" + << "\t" + << "\"Velocity\"" + << "\t" + << "\"Acceleration\"" + << "\t" << std::endl; + outputfile[0] << "\"Time\"" + << "\t" + << "\"Displacement\"" + << "\t" + << "\"Velocity\"" + << "\t" + << "\"Acceleration\"" + << "\t" << std::endl; + } + std::cout << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << std::endl; + outputfile[0] << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << std::endl; } - cout << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << endl; - outputfile[0] << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << endl; - } - else if(structure->GetnDof() == 2){ - if(time == 0){ - cout << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << endl; - outputfile[0] << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << endl; + else if (structure->GetnDof() == 2) + { + if (time == 0) + { + std::cout << "\"Time\"" + << "\t" + << "\"Displacement 1\"" + << "\t" + << "\"Displacement 2\"" + << "\t" + << "\"Velocity 1\"" + << "\t" + << "\"Velocity 2\"" + << "\t" + << "\"Acceleration 1\"" + << "\t" + << "\"Acceleration 2\"" << std::endl; + outputfile[0] << "\"Time\"" + << "\t" + << "\"Displacement 1\"" + << "\t" + << "\"Displacement 2\"" + << "\t" + << "\"Velocity 1\"" + << "\t" + << "\"Velocity 2\"" + << "\t" + << "\"Acceleration 1\"" + << "\t" + << "\"Acceleration 2\"" << std::endl; + } + std::cout << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1] << std::endl; + outputfile[0] << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1] << std::endl; } - cout << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1] << endl; - outputfile[0] << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1] << endl; - } } -void Output::WriteRestart(Integration* solver, Structure* structure){ - ofstream RestartFile; - RestartFile.open("Nat_solution_restart.out", ios::out); +void Output::WriteRestart(Integration *solver, Structure *structure) +{ + ofstream RestartFile; + RestartFile.open("Nat_solution_restart.out", std::ios::out); - if(structure->GetnDof() == 1){ - RestartFile << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << "\"Acceleration variable\"" << endl; - RestartFile << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAccVar()))[0] << endl; - } - else if(structure->GetnDof() == 2){ - RestartFile << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << "\t" << "\"Acceleration variable 1\"" << "\t" << "\"Acceleration variable 2\"" << endl; - RestartFile << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1]<< "\t" << (*(solver->GetAccVar()))[0] << "\t" << (*(solver->GetAccVar()))[1] << endl; - } + if (structure->GetnDof() == 1) + { + RestartFile << "\"Displacement\"" + << "\t" + << "\"Velocity\"" + << "\t" + << "\"Acceleration\"" + << "\t" + << "\"Acceleration variable\"" << std::endl; + RestartFile << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAccVar()))[0] << std::endl; + } + else if (structure->GetnDof() == 2) + { + RestartFile << "\"Displacement 1\"" + << "\t" + << "\"Displacement 2\"" + << "\t" + << "\"Velocity 1\"" + << "\t" + << "\"Velocity 2\"" + << "\t" + << "\"Acceleration 1\"" + << "\t" + << "\"Acceleration 2\"" + << "\t" + << "\"Acceleration variable 1\"" + << "\t" + << "\"Acceleration variable 2\"" << std::endl; + RestartFile << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1] << "\t" << (*(solver->GetAccVar()))[0] << "\t" << (*(solver->GetAccVar()))[1] << std::endl; + } } -void Output::WriteStaticSolution(Config* config, Integration* solver, Structure* structure, ofstream* outputfile){ - if(structure->GetnDof() == 1){ - cout << "Static displacement is : " << (*(solver->GetDisp()))[0] << " [m]" << endl; - cout << "Writing displacement into a solution file" << endl; - if(config->GetStructType() == "SPRING_HOR"){ - outputfile[0] << -1.000 << "\t" << (*(solver->GetDisp()))[0] << "\t" << 0.000; +void Output::WriteStaticSolution(Config *config, Integration *solver, Structure *structure, ofstream *outputfile) +{ + if (structure->GetnDof() == 1) + { + std::cout << "Static displacement is : " << (*(solver->GetDisp()))[0] << " [m]" << std::endl; + std::cout << "Writing displacement into a solution file" << std::endl; + if (config->GetStructType() == "SPRING_HOR") + { + outputfile[0] << -1.000 << "\t" << (*(solver->GetDisp()))[0] << "\t" << 0.000; + } + else if (config->GetStructType() == "SPRING_VER") + { + outputfile[0] << -1.000 << "\t" << 0.000 << "\t" << (*(solver->GetDisp()))[0]; + } } - else if(config->GetStructType() == "SPRING_VER"){ - outputfile[0] << -1.000 << "\t" << 0.000 << "\t" << (*(solver->GetDisp()))[0]; + else if (structure->GetnDof() == 2) + { + std::cout << "Plunging displacement is :" << (*(solver->GetDisp()))[0] << " [m]" << std::endl; + std::cout << "Pitching rotation is :" << (*(solver->GetDisp()))[1] << " [rad]" << std::endl; + std::cout << "Writing displacement into a solution file" << std::endl; + outputfile[0] << -1.000 << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1]; } - } - else if(structure->GetnDof() == 2){ - cout << "Plunging displacement is :" << (*(solver->GetDisp()))[0] << " [m]" << endl; - cout << "Pitching rotation is :" << (*(solver->GetDisp()))[1] << " [rad]" << endl; - cout << "Writing displacement into a solution file" << endl; - outputfile[0] << -1.000 << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1]; - } } -*/ +*/ \ No newline at end of file diff --git a/src/solver.cpp b/src/solver.cpp index 36b61df..b3a3657 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -5,8 +5,6 @@ #include #include -using namespace std; - Solver::Solver(unsigned int nDof, bool bool_linear) { q.Initialize(nDof, 0.0); @@ -113,12 +111,12 @@ AlphaGenSolver::AlphaGenSolver(unsigned int nDof, double val_rho, alpha_f = rho / (rho + 1); gamma = 0.5 + alpha_f - alpha_m; beta = 0.25 * pow((gamma + 0.5), 2); - cout << "Integration with the alpha-generalized algorithm :" << endl; - cout << "rho : " << rho << endl; - cout << "alpha_m : " << alpha_m << endl; - cout << "alpha_f : " << alpha_f << endl; - cout << "gamma : " << gamma << endl; - cout << "beta : " << beta << endl; + std::cout << "Integration with the alpha-generalized algorithm :" << std::endl; + std::cout << "rho : " << rho << std::endl; + std::cout << "alpha_m : " << alpha_m << std::endl; + std::cout << "alpha_f : " << alpha_f << std::endl; + std::cout << "gamma : " << gamma << std::endl; + std::cout << "beta : " << beta << std::endl; } AlphaGenSolver::~AlphaGenSolver() @@ -324,13 +322,13 @@ void AlphaGenSolver::SetInitialState(Config *config, Structure *structure) if (config->GetRestartSol() == "YES") { - string InputFileName = config->GetRestartFile(); - string text_line; - string token, tempString; + std::string InputFileName = config->GetRestartFile(); + std::string text_line; + std::string token, tempString; size_t pos; - string delimiter = "\t"; - ifstream InputFile; - InputFile.open(InputFileName.c_str(), ios::in); + std::string delimiter = "\t"; + std::ifstream InputFile; + InputFile.open(InputFileName.c_str(), std::ios::in); double buffer[(4 * structure->GetnDof()) + 1]; int kk = 0; int jj; @@ -340,7 +338,7 @@ void AlphaGenSolver::SetInitialState(Config *config, Structure *structure) jj = 0; if (kk == 1) { - while ((pos = tempString.find(delimiter)) != string::npos) + while ((pos = tempString.find(delimiter)) != std::string::npos) { token = tempString.substr(0, pos); tempString.erase(0, pos + delimiter.length()); @@ -374,7 +372,7 @@ void AlphaGenSolver::SetInitialState(Config *config, Structure *structure) } else if (kk == 2) { - while ((pos = tempString.find(delimiter)) != string::npos) + while ((pos = tempString.find(delimiter)) != std::string::npos) { token = tempString.substr(0, pos); tempString.erase(0, pos + delimiter.length()); @@ -412,15 +410,15 @@ void AlphaGenSolver::SetInitialState(Config *config, Structure *structure) } else { - cout << "Setting basic initial conditions for alpha-Gen" << endl; + std::cout << "Setting basic initial conditions for alpha-Gen" << std::endl; q.Reset(); q_n.Reset(); - cout << "Read initial configuration" << endl; + std::cout << "Read initial configuration" << std::endl; q[0] = config->GetInitialDisp(); if (structure->GetnDof() == 2) q[1] = config->GetInitialAngle(); - cout << "Initial plunging displacement : " << q[0] << endl; - cout << "Initial pitching displacement : " << q[1] << endl; + std::cout << "Initial plunging displacement : " << q[0] << std::endl; + std::cout << "Initial pitching displacement : " << q[1] << std::endl; qdot.Reset(); qddot.Reset(); @@ -615,15 +613,15 @@ void RK4Solver::SetInitialState(Config *config, Structure *structure) } else { - cout << "Setting basic initial conditions for RK4" << endl; + std::cout << "Setting basic initial conditions for RK4" << std::endl; q.Reset(); q_n.Reset(); - cout << "Read initial configuration" << endl; + std::cout << "Read initial configuration" << std::endl; q[0] = config->GetInitialDisp(); if (structure->GetnDof() == 2) q[1] = config->GetInitialAngle(); - cout << "Initial plunging displacement : " << q[0] << endl; - cout << "Initial pitching displacement : " << q[1] << endl; + std::cout << "Initial plunging displacement : " << q[0] << std::endl; + std::cout << "Initial pitching displacement : " << q[1] << std::endl; qdot.Reset(); lastTime = 0.0; @@ -714,15 +712,15 @@ void StaticSolver::SetInitialState(Config *config, Structure *structure) } else { - cout << "Setting basic initial conditions for Static" << endl; + std::cout << "Setting basic initial conditions for Static" << std::endl; q.Reset(); q_n.Reset(); - cout << "Read initial configuration" << endl; + std::cout << "Read initial configuration" << std::endl; q[0] = config->GetInitialDisp(); if (_nDof == 2) q[1] = config->GetInitialAngle(); - cout << "Initial plunging displacement : " << q[0] << endl; - cout << "Initial pitching displacement : " << q[1] << endl; + std::cout << "Initial plunging displacement : " << q[0] << std::endl; + std::cout << "Initial pitching displacement : " << q[1] << std::endl; qdot.Reset(); qddot.Reset(); } @@ -736,7 +734,7 @@ void StaticSolver::SetInitialState(Config *config, Structure *structure) } else { - cerr << "Error in NativeSolid::StaticSolver: Number of degrees of freedom is out of range. nDof = " << _nDof << endl; + std::cerr << "Error in NativeSolid::StaticSolver: Number of degrees of freedom is out of range. nDof = " << _nDof << std::endl; throw(-1); } } diff --git a/src/structure.cpp b/src/structure.cpp index b0b2014..b97e11f 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -5,8 +5,6 @@ #include #include -using namespace std; - Structure::Structure(Config *config) { centerOfRotation[0] = 0.0; @@ -33,11 +31,11 @@ Structure::Structure(Config *config) S = 0; ICG = 0; If = 0; - cout << "Setting mass-spring-damper system" << endl; - cout << "Number of DOF : " << nDof << endl; - cout << "Plunging mass : " << m << " [kg]" << endl; - cout << "Plunging damping : " << Ch << " [Ns/m]" << endl; - cout << "Plunging stiffness : " << Kh << " [N/m]" << endl; + std::cout << "Setting mass-spring-damper system" << std::endl; + std::cout << "Number of DOF : " << nDof << std::endl; + std::cout << "Plunging mass : " << m << " [kg]" << std::endl; + std::cout << "Plunging damping : " << Ch << " [Ns/m]" << std::endl; + std::cout << "Plunging stiffness : " << Kh << " [N/m]" << std::endl; } else if (config->GetStructType() == "AIRFOIL") { @@ -56,18 +54,18 @@ Structure::Structure(Config *config) If = config->GetInertiaFlexural(); // S = m*(c/2.0-xf); // Ia = 1.0/3.0*m*(c*c-3*c*xf+3*xf*xf); - cout << "Setting pitching-plunging airfoil system" << endl; - cout << "Number of DOF : " << nDof << endl; - cout << "Airfoil mass : " << m << " [kg]" << endl; - cout << "Airfoil cord : " << c << " [m]" << endl; - cout << "Position of the flexural axis : " << xf << " [m]" << endl; - cout << "Inertia around the flexural axis : " << If << " [kg m²]" << endl; - cout << "Plunging damping : " << Ch << " [Ns/m]" << endl; - cout << "Plunging stiffness : " << Kh << " [N/m]" << endl; - cout << "Pitching damping : " << Ca << " [Ns]" << endl; - cout << "Pitching stiffness : " << Ka << " [N]" << endl; - cout << "Position of the center of gravity : " << xCG << " [m]" << endl; - cout << "Static unbalance : " << S << " [kg m]" << endl; + std::cout << "Setting pitching-plunging airfoil system" << std::endl; + std::cout << "Number of DOF : " << nDof << std::endl; + std::cout << "Airfoil mass : " << m << " [kg]" << std::endl; + std::cout << "Airfoil cord : " << c << " [m]" << std::endl; + std::cout << "Position of the flexural axis : " << xf << " [m]" << std::endl; + std::cout << "Inertia around the flexural axis : " << If << " [kg m²]" << std::endl; + std::cout << "Plunging damping : " << Ch << " [Ns/m]" << std::endl; + std::cout << "Plunging stiffness : " << Kh << " [N/m]" << std::endl; + std::cout << "Pitching damping : " << Ca << " [Ns]" << std::endl; + std::cout << "Pitching stiffness : " << Ka << " [N]" << std::endl; + std::cout << "Position of the center of gravity : " << xCG << " [m]" << std::endl; + std::cout << "Static unbalance : " << S << " [kg m]" << std::endl; centerOfRotation[0] = xf; centerOfRotation_n[0] = xf; @@ -75,7 +73,7 @@ Structure::Structure(Config *config) else { nDof = 0; - cerr << "Invalid structural type. Available choices are : SPRIN_HOR, SPRING_VER and AIRFOIL." << endl; + std::cerr << "Invalid structural type. Available choices are : SPRIN_HOR, SPRING_VER and AIRFOIL." << std::endl; throw(-1); } } From e223231971206e25e0eb54eda6a3b1bf79c22f99 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Thu, 3 Mar 2022 15:16:51 +0100 Subject: [PATCH 16/20] new file structure (same as other codes) --- CMakeLists.txt | 3 +- {_api => _src}/CMakeLists.txt | 6 ++- {_api => _src}/Native.i | 4 -- src/CMakeLists.txt | 32 +------------- src/MatVec.cpp | 2 +- {include => src}/MatVec.h | 0 {api => src}/NativeSolid_API.cpp | 76 ++++++++++++++++---------------- {api => src}/NativeSolid_API.h | 27 +++++------- {include => src}/config.h | 0 src/geometry.cpp | 13 +++--- {include => src}/geometry.h | 0 {include => src}/integration.h | 0 {include => src}/output.h | 0 src/solver.cpp | 11 +++-- {include => src}/solver.h | 0 {include => src}/structure.h | 0 tests/CMakeLists.txt | 7 +++ {src => tests}/testcvector.cpp | 0 18 files changed, 79 insertions(+), 102 deletions(-) rename {_api => _src}/CMakeLists.txt (71%) rename {_api => _src}/Native.i (73%) rename {include => src}/MatVec.h (100%) rename {api => src}/NativeSolid_API.cpp (93%) rename {api => src}/NativeSolid_API.h (86%) rename {include => src}/config.h (100%) rename {include => src}/geometry.h (100%) rename {include => src}/integration.h (100%) rename {include => src}/output.h (100%) rename {include => src}/solver.h (100%) rename {include => src}/structure.h (100%) create mode 100644 tests/CMakeLists.txt rename {src => tests}/testcvector.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8c2c46..a6631a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,5 +64,6 @@ ENABLE_TESTING() # -- Sub directories -- ADD_SUBDIRECTORY( src ) -ADD_SUBDIRECTORY( _api ) +ADD_SUBDIRECTORY( _src ) +ADD_SUBDIRECTORY( tests ) diff --git a/_api/CMakeLists.txt b/_src/CMakeLists.txt similarity index 71% rename from _api/CMakeLists.txt rename to _src/CMakeLists.txt index bda59bb..9d6c002 100644 --- a/_api/CMakeLists.txt +++ b/_src/CMakeLists.txt @@ -9,7 +9,7 @@ SET(CMAKE_SWIG_FLAGS "") SET_SOURCE_FILES_PROPERTIES(${ISRCS} PROPERTIES CPLUSPLUS ON) SET(SWINCFLAGS --I${PROJECT_SOURCE_DIR}/api +-I${PROJECT_SOURCE_DIR}/src ) SET_SOURCE_FILES_PROPERTIES(${ISRCS} PROPERTIES SWIG_FLAGS "${SWINCFLAGS}") @@ -22,4 +22,8 @@ ELSE() SOURCES ${ISRCS} ${SRCS}) ENDIF() +TARGET_INCLUDE_DIRECTORIES(_NativeSolid PRIVATE ${PROJECT_SOURCE_DIR}/_src + ${PROJECT_SOURCE_DIR}/src + ${PYTHON_INCLUDE_PATH}) + SWIG_LINK_LIBRARIES(NativeSolid Native ${PYTHON_LIBRARIES}) diff --git a/_api/Native.i b/_src/Native.i similarity index 73% rename from _api/Native.i rename to _src/Native.i index 2ea59d2..d8545da 100644 --- a/_api/Native.i +++ b/_src/Native.i @@ -12,11 +12,7 @@ threads="1" #include #include "NativeSolid_API.h" - %} -// ----------- MODULES UTILISES ------------ %include "std_string.i" - -// ----------- NATIVE CLASSES ---------------- %include "NativeSolid_API.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02544e7..5cef86c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,34 +1,6 @@ -# Compilation of the source code -# Generation of a shared librairy libNative.so - -ADD_LIBRARY(Native SHARED - ../include/config.h - ../include/geometry.h - ../include/integration.h - ../include/MatVec.h - ../include/structure.h - ../include/solver.h - config.cpp - geometry.cpp - integration.cpp - MatVec.cpp - output.cpp - structure.cpp - solver.cpp - ../api/NativeSolid_API.h - ../api/NativeSolid_API.cpp -) +FILE(GLOB SRCS *.cpp) +ADD_LIBRARY(Native SHARED ${SRCS}) TARGET_LINK_LIBRARIES(Native ${LAPACKE_LIBRARIES} ${CBLAS_LIBRARIES} ${BLAS_LIBRARIES}) - -ADD_EXECUTABLE(TestCVector ../include/MatVec.h MatVec.cpp testcvector.cpp) - -TARGET_LINK_LIBRARIES(TestCVector ${LAPACKE_LIBRARIES} - ${CBLAS_LIBRARIES} - ${BLAS_LIBRARIES}) - -ADD_TEST(NAME TestCVector COMMAND ${EXECUTABLE_OUTPUT_PATH}/TestCVector - WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) - diff --git a/src/MatVec.cpp b/src/MatVec.cpp index a130f03..479eb81 100644 --- a/src/MatVec.cpp +++ b/src/MatVec.cpp @@ -404,7 +404,7 @@ CMatrix ScalMatProd(const double &scal, const CMatrix &A) return copy; } -/* INDEPENDENT FUNCTIONS */ +// INDEPENDENT FUNCTIONS int SolveSys(const CMatrix &A, CVector &b) { const int N = A.GetnEq(); diff --git a/include/MatVec.h b/src/MatVec.h similarity index 100% rename from include/MatVec.h rename to src/MatVec.h diff --git a/api/NativeSolid_API.cpp b/src/NativeSolid_API.cpp similarity index 93% rename from api/NativeSolid_API.cpp rename to src/NativeSolid_API.cpp index fe6a12a..6e2e859 100644 --- a/api/NativeSolid_API.cpp +++ b/src/NativeSolid_API.cpp @@ -20,10 +20,10 @@ NativeSolidSolver::NativeSolidSolver(std::string str, bool FSIComp) : confFile(s { if (FSIComp) std::cout << std::endl - << "***************************** Setting NativeSolid for FSI simulation *****************************" << std::endl; + << "***************************** Setting NativeSolid for FSI simulation *****************************" << std::endl; else std::cout << std::endl - << "***************************** Setting NativeSolid for CSD simulation *****************************" << std::endl; + << "***************************** Setting NativeSolid for CSD simulation *****************************" << std::endl; } config = NULL; @@ -32,27 +32,27 @@ NativeSolidSolver::NativeSolidSolver(std::string str, bool FSIComp) : confFile(s structure = NULL; integrator = NULL; - /*--- Initialize the main containers ---*/ + //--- Initialize the main containers --- config = new Config(confFile); output = new Output(); - /*--- Read CSD configuration file ---*/ + //--- Read CSD configuration file --- std::cout << std::endl - << "\n----------------------- Reading Native configuration file ----------------------" << std::endl; + << "\n----------------------- Reading Native configuration file ----------------------" << std::endl; config->ReadConfig(); - /*--- Read a SU2 native mesh file ---*/ + //--- Read a SU2 native mesh file --- std::cout << std::endl - << "\n----------------------- Reading SU2 based mesh file ----------------------" << std::endl; + << "\n----------------------- Reading SU2 based mesh file ----------------------" << std::endl; geometry = new Geometry(config); - /*--- Initialize structural container and create the structural model ---*/ + //--- Initialize structural container and create the structural model --- std::cout << std::endl - << "\n----------------------- Creating the structural model ----------------------" << std::endl; + << "\n----------------------- Creating the structural model ----------------------" << std::endl; structure = new Structure(config); std::cout << std::endl - << "\n----------------------- Creating the FSI interface ----------------------" << std::endl; + << "\n----------------------- Creating the FSI interface ----------------------" << std::endl; double *Coord; unsigned long iMarker(0), iPoint; @@ -70,14 +70,14 @@ NativeSolidSolver::NativeSolidSolver(std::string str, bool FSIComp) : confFile(s std::cout << nSolidInterfaceVertex << " nodes on the moving interface have to be tracked." << std::endl; - /*--- Initialize the temporal integrator ---*/ + //--- Initialize the temporal integrator --- std::cout << std::endl - << "\n----------------------- Setting integration parameter ----------------------" << std::endl; + << "\n----------------------- Setting integration parameter ----------------------" << std::endl; integrator = new Integration(config, structure); integrator->SetInitialConditions(config, structure); std::cout << std::endl - << "\n----------------------- Setting FSI features ----------------------" << std::endl; + << "\n----------------------- Setting FSI features ----------------------" << std::endl; q_uM1.Initialize(structure->GetnDof()); q_uM1.Reset(); @@ -153,10 +153,10 @@ NativeSolidSolver::NativeSolidSolver(std::string str, bool FSIComp) : confFile(s { if (FSIComp) std::cout << std::endl - << "***************************** NativeSolid is set for FSI simulation *****************************" << std::endl; + << "***************************** NativeSolid is set for FSI simulation *****************************" << std::endl; else std::cout << std::endl - << "***************************** NativeSolid is set for CSD simulation *****************************" << std::endl; + << "***************************** NativeSolid is set for CSD simulation *****************************" << std::endl; } } @@ -176,7 +176,7 @@ void NativeSolidSolver::exit() { std::cout << "Solid history file is closed." << std::endl; std::cout << std::endl - << "***************************** Exit NativeSolid *****************************" << std::endl; + << "***************************** Exit NativeSolid *****************************" << std::endl; } if (config != NULL) @@ -365,12 +365,12 @@ void NativeSolidSolver::computeInterfacePosVel(bool initialize) unsigned long iPoint; double varCoordNorm2(0.0); - /*--- Get the current center of rotation (can vary at each iteration) ---*/ + //--- Get the current center of rotation (can vary at each iteration) --- Center[0] = structure->GetCenterOfRotation_x(); Center[1] = structure->GetCenterOfRotation_y(); Center[2] = structure->GetCenterOfRotation_z(); - /*--- Get the center of rotation from previous time step ---*/ + //--- Get the center of rotation from previous time step --- Center_n[0] = structure->GetCenterOfRotation_n_x(); Center_n[1] = structure->GetCenterOfRotation_n_y(); Center_n[2] = structure->GetCenterOfRotation_n_z(); @@ -421,8 +421,8 @@ void NativeSolidSolver::computeInterfacePosVel(bool initialize) sinPhi = sin(dPhi); sinPsi = sin(dPsi); - /*--- Compute the rotation matrix. The implicit - ordering is rotation about the x-axis, y-axis, then z-axis. ---*/ + //--- Compute the rotation matrix. The implicit + // ordering is rotation about the x-axis, y-axis, then z-axis. --- rotMatrix[0][0] = cosPhi * cosPsi; rotMatrix[1][0] = cosPhi * sinPsi; @@ -479,11 +479,11 @@ void NativeSolidSolver::computeInterfacePosVel(bool initialize) varCoordNorm2 += varCoord[0] * varCoord[0] + varCoord[1] * varCoord[1] + varCoord[2] * varCoord[2]; - /*--- Apply change of coordinates to the node on the moving interface ---*/ + //--- Apply change of coordinates to the node on the moving interface --- geometry->node[iPoint]->SetCoord(newCoord); geometry->node[iPoint]->SetVel(newVel); - /*--- At initialisation, propagate the initial position of the inteface in the past ---*/ + //--- At initialisation, propagate the initial position of the inteface in the past --- if (initialize) { geometry->node[iPoint]->SetCoord_n(newCoord); @@ -495,7 +495,7 @@ void NativeSolidSolver::computeInterfacePosVel(bool initialize) varCoordNorm = sqrt(varCoordNorm2); - /*--- Update the position of the center of rotation ---*/ + //--- Update the position of the center of rotation --- structure->SetCenterOfRotation_X(newCenter[0]); structure->SetCenterOfRotation_Y(newCenter[1]); structure->SetCenterOfRotation_Z(newCenter[2]); @@ -739,22 +739,22 @@ void NativeSolidSolver::updateSolution() } /* - * void NativeSolidSolver::updateGeometry(){ - - if(config->GetUnsteady() == "YES"){ - geometry->UpdateGeometry(); - structure->SetCenterOfRotation_n_X(structure->GetCenterOfRotation_x()); - structure->SetCenterOfRotation_n_Y(structure->GetCenterOfRotation_y()); - structure->SetCenterOfRotation_n_Z(structure->GetCenterOfRotation_z()); - } -}*/ - -/* -void NativeSolidSolver::displacementPredictor(){ - - mapRigidBodyMotion(true, false); +void NativeSolidSolver::updateGeometry() +{ + if (config->GetUnsteady() == "YES") + { + geometry->UpdateGeometry(); + structure->SetCenterOfRotation_n_X(structure->GetCenterOfRotation_x()); + structure->SetCenterOfRotation_n_Y(structure->GetCenterOfRotation_y()); + structure->SetCenterOfRotation_n_Z(structure->GetCenterOfRotation_z()); + } +} -}*/ +void NativeSolidSolver::displacementPredictor() +{ + mapRigidBodyMotion(true, false); +} +*/ unsigned short NativeSolidSolver::getFSIMarkerID() { diff --git a/api/NativeSolid_API.h b/src/NativeSolid_API.h similarity index 86% rename from api/NativeSolid_API.h rename to src/NativeSolid_API.h index 87746c0..a5cc27c 100644 --- a/api/NativeSolid_API.h +++ b/src/NativeSolid_API.h @@ -11,33 +11,30 @@ #include #include -class NativeSolidSolver{ - -protected: +class NativeSolidSolver +{ std::string confFile; - Config* config; - Geometry* geometry; - Structure* structure; - Integration* integrator; - Output* output; + Config *config; + Geometry *geometry; + Structure *structure; + Integration *integrator; + Output *output; std::ofstream historyFile; std::ofstream historyFile2; std::ofstream restartFile; - CVector q_uM1; //The displacement at the previous FSI iteration + CVector q_uM1; // The displacement at the previous FSI iteration double omega; unsigned long nSolidInterfaceVertex; double varCoordNorm; - public: - /* NEW generation */ NativeSolidSolver(std::string str, bool FSIComp); ~NativeSolidSolver(); void exit(); - //double getVarCoordNorm() const; + // double getVarCoordNorm() const; void preprocessIteration(unsigned long ExtIter); void timeIteration(double t0, double tf); - //void mapRigidBodyMotion(bool predicition, bool initialize); + // void mapRigidBodyMotion(bool predicition, bool initialize); void computeInterfacePosVel(bool initialize); void setInitialDisplacements(); void staticComputation(); @@ -45,8 +42,8 @@ class NativeSolidSolver{ void writeSolution(double time, int FSIter); void saveSolution(); void updateSolution(); - //void updateGeometry(); - //void displacementPredictor(); + // void updateGeometry(); + // void displacementPredictor(); unsigned short getFSIMarkerID(); unsigned long getNumberOfSolidInterfaceNodes(unsigned short iMarker); unsigned int getInterfaceNodeGlobalIndex(unsigned short iMarker, unsigned short iVertex); diff --git a/include/config.h b/src/config.h similarity index 100% rename from include/config.h rename to src/config.h diff --git a/src/geometry.cpp b/src/geometry.cpp index 8876779..8c4a2a7 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -176,7 +176,7 @@ Geometry::Geometry(Config *config) meshFileName = config->GetMeshFile(); - /*--- Open the mesh file and check ---*/ + //--- Open the mesh file and check --- meshFile.open(meshFileName.c_str(), std::ios::in); if (meshFile.fail()) { @@ -303,11 +303,12 @@ Geometry::Geometry(Config *config) meshFile.close(); - /*for (int iVertex = 0; iVertex < nVertex[0]; iVertex++){ - //cout << vertex[0][iVertex] << std::endl; - iPoint = vertex[0][iVertex]; - node[iPoint]->PrintCoord(); - }*/ + // for (int iVertex = 0; iVertex < nVertex[0]; iVertex++) + // { + // // cout << vertex[0][iVertex] << std::endl; + // iPoint = vertex[0][iVertex]; + // node[iPoint]->PrintCoord(); + // } } Geometry::~Geometry() diff --git a/include/geometry.h b/src/geometry.h similarity index 100% rename from include/geometry.h rename to src/geometry.h diff --git a/include/integration.h b/src/integration.h similarity index 100% rename from include/integration.h rename to src/integration.h diff --git a/include/output.h b/src/output.h similarity index 100% rename from include/output.h rename to src/output.h diff --git a/src/solver.cpp b/src/solver.cpp index b3a3657..6375004 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -98,11 +98,10 @@ void Solver::SetInitialState(Config *config, Structure *structure) { } -/*CLASS ALPHAGENSOLVER*/ +// CLASS ALPHAGENSOLVER AlphaGenSolver::AlphaGenSolver(unsigned int nDof, double val_rho, bool bool_linear) : Solver(nDof, bool_linear) { - a.Initialize(nDof, 0.0); a_n.Initialize(nDof, 0.0); @@ -142,7 +141,7 @@ void AlphaGenSolver::Iterate(double &t0, double &tf, Structure *structure) gammaPrime = gamma / (deltaT * beta); betaPrime = (1 - alpha_m) / (pow(deltaT, 2) * beta * (1 - alpha_f)); - /*--- Prediction phase ---*/ + //--- Prediction phase --- qddot.Reset(); a.Reset(); @@ -158,7 +157,7 @@ void AlphaGenSolver::Iterate(double &t0, double &tf, Structure *structure) qdot += ScalVecProd((1 - gamma) * deltaT, a_n); qdot += ScalVecProd(deltaT * gamma, a); - /*--- Tangent operator and corrector computation ---*/ + //--- Tangent operator and corrector computation --- CVector res(qddot.GetSize(), 0.0); CVector Deltaq(qddot.GetSize(), 0.0); CMatrix St(qddot.GetSize(), qddot.GetSize(), 0.0); @@ -459,7 +458,7 @@ void AlphaGenSolver::SetInitialState(Config *config, Structure *structure) } } -/*CLASS RK4 SOLVER*/ +// CLASS RK4 SOLVER RK4Solver::RK4Solver(unsigned nDof, bool bool_linear) : Solver(nDof, bool_linear) { size = nDof; @@ -692,7 +691,7 @@ CVector RK4Solver::SetState_n() return state; } -/*CLASS STATIC SOLVER*/ +// CLASS STATIC SOLVER StaticSolver::StaticSolver(unsigned nDof, bool bool_linear) : Solver(nDof, bool_linear) { _nDof = nDof; diff --git a/include/solver.h b/src/solver.h similarity index 100% rename from include/solver.h rename to src/solver.h diff --git a/include/structure.h b/src/structure.h similarity index 100% rename from include/structure.h rename to src/structure.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..44f648c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,7 @@ +ADD_EXECUTABLE(TestCVector testcvector.cpp) +TARGET_INCLUDE_DIRECTORIES(TestCVector PRIVATE ${PROJECT_SOURCE_DIR}/src) +TARGET_LINK_LIBRARIES(TestCVector Native) + +ADD_TEST(NAME TestCVector COMMAND ${EXECUTABLE_OUTPUT_PATH}/TestCVector + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) + \ No newline at end of file diff --git a/src/testcvector.cpp b/tests/testcvector.cpp similarity index 100% rename from src/testcvector.cpp rename to tests/testcvector.cpp From 4da44f3e9f31a5542f7b6398b9bf42fa279fe4d7 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Thu, 3 Mar 2022 15:45:12 +0100 Subject: [PATCH 17/20] new filenames --- README.md | 25 +++----------- _src/Native.i | 4 +-- src/{config.cpp => Config.cpp} | 2 +- src/{config.h => Config.h} | 0 src/{geometry.cpp => Geometry.cpp} | 4 +-- src/{geometry.h => Geometry.h} | 2 +- src/{integration.cpp => Integration.cpp} | 4 +-- src/{integration.h => Integration.h} | 6 ++-- src/MatVec.cpp | 5 ++- src/MatVec.h | 8 ++--- ...iveSolid_API.cpp => NativeSolidSolver.cpp} | 2 +- ...{NativeSolid_API.h => NativeSolidSolver.h} | 10 +++--- src/{output.cpp => Output.cpp} | 6 +--- src/Output.h | 20 +++++++++++ src/{solver.cpp => Solver.cpp} | 7 ++-- src/{solver.h => Solver.h} | 34 +++++++++++-------- src/{structure.cpp => Structure.cpp} | 6 +--- src/{structure.h => Structure.h} | 5 +-- src/output.h | 21 ------------ 19 files changed, 74 insertions(+), 97 deletions(-) rename src/{config.cpp => Config.cpp} (99%) rename src/{config.h => Config.h} (100%) rename src/{geometry.cpp => Geometry.cpp} (99%) rename src/{geometry.h => Geometry.h} (98%) rename src/{integration.cpp => Integration.cpp} (98%) rename src/{integration.h => Integration.h} (90%) rename src/{NativeSolid_API.cpp => NativeSolidSolver.cpp} (99%) rename src/{NativeSolid_API.h => NativeSolidSolver.h} (96%) rename src/{output.cpp => Output.cpp} (99%) create mode 100644 src/Output.h rename src/{solver.cpp => Solver.cpp} (99%) rename src/{solver.h => Solver.h} (83%) rename src/{structure.cpp => Structure.cpp} (98%) rename src/{structure.h => Structure.h} (96%) delete mode 100644 src/output.h diff --git a/README.md b/README.md index 0f83afd..eec554d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # NativeSolid / RBM -Native solid solver for FSI +Native solid solver for [CUPyDO](https://github.com/ulgltas/CUPyDO) ## Features Compute static or dynamic displacements for several 2D configurations. @@ -17,31 +17,16 @@ Compute static or dynamic displacements for several 2D configurations. * Static Computation - Stiffness term only -## Compilation (linux -gcc) - -Installation of NativeSolid code +## Build Required packages ``` -sudo apt-get install build-essential -sudo apt-get install cmake -sudo apt-get install liblapacke-dev -sudo apt-get install libopenblas-dev -``` -Optional packages (parallel build) -``` -sudo apt-get install openmpi-bin openmpi-common libopenmpi-dev +sudo apt install build-essential cmake libopenblas-dev liblapacke-dev libpython3-dev swig ``` -Compilation (you might need to set paths for headers and libraries in the FindCBLAS and FindLAPACKE files) + ``` mkdir build && cd build cmake .. make -j 4 ``` -Environment variables -``` -gedit /home/"username"/.bashrc -export NATIVE_RUN="INSTALL_PATH/NativeSolid/bin" -export PATH=$PATH:$NATIVE_RUN -export PYTHONPATH=$PYTHONPATH:$NATIVE_RUN -``` + diff --git a/_src/Native.i b/_src/Native.i index d8545da..bfcdd4a 100644 --- a/_src/Native.i +++ b/_src/Native.i @@ -10,9 +10,9 @@ threads="1" %{ #include -#include "NativeSolid_API.h" +#include "NativeSolidSolver.h" %} %include "std_string.i" -%include "NativeSolid_API.h" +%include "NativeSolidSolver.h" diff --git a/src/config.cpp b/src/Config.cpp similarity index 99% rename from src/config.cpp rename to src/Config.cpp index a955b27..a15395a 100644 --- a/src/config.cpp +++ b/src/Config.cpp @@ -1,4 +1,4 @@ -#include "config.h" +#include "Config.h" #include #include #include diff --git a/src/config.h b/src/Config.h similarity index 100% rename from src/config.h rename to src/Config.h diff --git a/src/geometry.cpp b/src/Geometry.cpp similarity index 99% rename from src/geometry.cpp rename to src/Geometry.cpp index 8c4a2a7..b8dbc9f 100644 --- a/src/geometry.cpp +++ b/src/Geometry.cpp @@ -1,5 +1,5 @@ -#include "geometry.h" -#include "config.h" +#include "Geometry.h" +#include "Config.h" #include #include #include diff --git a/src/geometry.h b/src/Geometry.h similarity index 98% rename from src/geometry.h rename to src/Geometry.h index 0702773..07d0f11 100644 --- a/src/geometry.h +++ b/src/Geometry.h @@ -1,6 +1,6 @@ #pragma once -#include "config.h" +#include "Config.h" #include class Point diff --git a/src/integration.cpp b/src/Integration.cpp similarity index 98% rename from src/integration.cpp rename to src/Integration.cpp index 476eb07..e4aebbd 100644 --- a/src/integration.cpp +++ b/src/Integration.cpp @@ -1,5 +1,5 @@ -#include "integration.h" -#include "solver.h" +#include "Integration.h" +#include "Solver.h" #include #include #include diff --git a/src/integration.h b/src/Integration.h similarity index 90% rename from src/integration.h rename to src/Integration.h index fdee320..7515d52 100644 --- a/src/integration.h +++ b/src/Integration.h @@ -1,8 +1,8 @@ #pragma once -#include "config.h" -#include "structure.h" -#include "solver.h" +#include "Config.h" +#include "Structure.h" +#include "Solver.h" #define PI 3.14159265 diff --git a/src/MatVec.cpp b/src/MatVec.cpp index 479eb81..adb6632 100644 --- a/src/MatVec.cpp +++ b/src/MatVec.cpp @@ -2,7 +2,7 @@ #include #include -CVector::CVector(void) : nElm(0) +CVector::CVector() : nElm(0) { vec_val = NULL; } @@ -211,7 +211,7 @@ void CVector::Reset() // --- Definition of the CMatrix class --- -CMatrix::CMatrix(void) : nEq(0), nVar(0) +CMatrix::CMatrix() : nEq(0), nVar(0) { } @@ -353,7 +353,6 @@ double CMatrix::DiagProduct() const prod *= GetElm(i, i); } } - return prod; } diff --git a/src/MatVec.h b/src/MatVec.h index 4c8adab..c86502b 100644 --- a/src/MatVec.h +++ b/src/MatVec.h @@ -1,7 +1,7 @@ #pragma once -#include "cblas.h" -#include "lapacke.h" +#include +#include #define ROW_MAJ 0 #define COL_MAJ 1 @@ -12,7 +12,7 @@ class CVector double *vec_val; public: - CVector(void); + CVector(); CVector(const unsigned long &size, const double &val = 0.0); CVector(const CVector &u); ~CVector(); @@ -39,7 +39,7 @@ class CMatrix CVector mat_val; public: - CMatrix(void); + CMatrix(); CMatrix(const unsigned long &val_nEq, const unsigned long &val_nVar, const double &val = 0.0); CMatrix(const CMatrix &A); ~CMatrix(); diff --git a/src/NativeSolid_API.cpp b/src/NativeSolidSolver.cpp similarity index 99% rename from src/NativeSolid_API.cpp rename to src/NativeSolidSolver.cpp index 6e2e859..ee17c2a 100644 --- a/src/NativeSolid_API.cpp +++ b/src/NativeSolidSolver.cpp @@ -1,4 +1,4 @@ -#include "NativeSolid_API.h" +#include "NativeSolidSolver.h" #include #include diff --git a/src/NativeSolid_API.h b/src/NativeSolidSolver.h similarity index 96% rename from src/NativeSolid_API.h rename to src/NativeSolidSolver.h index a5cc27c..a31e6a9 100644 --- a/src/NativeSolid_API.h +++ b/src/NativeSolidSolver.h @@ -1,11 +1,11 @@ #pragma once -#include "config.h" -#include "structure.h" -#include "integration.h" +#include "Config.h" +#include "Structure.h" +#include "Integration.h" #include "MatVec.h" -#include "geometry.h" -#include "output.h" +#include "Geometry.h" +#include "Output.h" #include #include #include diff --git a/src/output.cpp b/src/Output.cpp similarity index 99% rename from src/output.cpp rename to src/Output.cpp index c89a760..dacf515 100644 --- a/src/output.cpp +++ b/src/Output.cpp @@ -1,14 +1,10 @@ -#include "output.h" +#include "Output.h" #include Output::Output() { } -Output::~Output() -{ -} - /* void Output::WriteHistory(Integration *solver, Structure *structure, ofstream *outputfile, const double &time) { diff --git a/src/Output.h b/src/Output.h new file mode 100644 index 0000000..cce8f57 --- /dev/null +++ b/src/Output.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "MatVec.h" +#include "Config.h" +#include "Structure.h" +#include "Integration.h" + +class Output +{ +public: + Output(); + // void WriteHistory(Integration *solver, Structure *structure, + // std::ofstream *outputfile, const double &time); + // void WriteRestart(Integration *solver, Structure *structure); + // void WriteStaticSolution(Config *config, Integration *solver, + // Structure *structure, std::ofstream *outputfile); + // void WriteRestart(); +}; diff --git a/src/solver.cpp b/src/Solver.cpp similarity index 99% rename from src/solver.cpp rename to src/Solver.cpp index 6375004..9f1ba1d 100644 --- a/src/solver.cpp +++ b/src/Solver.cpp @@ -1,5 +1,5 @@ -#include "solver.h" -#include "structure.h" +#include "Solver.h" +#include "Structure.h" #include "MatVec.h" #include #include @@ -447,9 +447,6 @@ void AlphaGenSolver::SetInitialState(Config *config, Structure *structure) MM.SetElm(2, 1, (structure->Get_S()) * cos_a); MM.SetElm(2, 2, structure->Get_If()); } - else - { - } ComputeRHS(structure, RHS); SolveSys(MM, RHS); diff --git a/src/solver.h b/src/Solver.h similarity index 83% rename from src/solver.h rename to src/Solver.h index c9430c0..75b60d5 100644 --- a/src/solver.h +++ b/src/Solver.h @@ -1,8 +1,8 @@ #pragma once #include "MatVec.h" -#include "structure.h" -#include "config.h" +#include "Structure.h" +#include "Config.h" class Solver { @@ -49,16 +49,18 @@ class AlphaGenSolver : public Solver public: AlphaGenSolver(unsigned int nDof, double val_rho, bool bool_linear); - ~AlphaGenSolver(); - CVector &GetAccVar(); - CVector &GetAccVar_n(); - virtual void Iterate(double &t0, double &tf, Structure *structure); + virtual ~AlphaGenSolver() override; + virtual CVector &GetAccVar() override; + virtual CVector &GetAccVar_n() override; + virtual void Iterate(double &t0, double &tf, Structure *structure) override; + virtual void ResetSolution() override; + virtual void SaveToThePast() override; + virtual void SetInitialState(Config *config, Structure *structure) override; + +private: void ComputeRHS(Structure *structure, CVector &RHS); void ComputeResidual(Structure *structure, CVector &res); void ComputeTangentOperator(Structure *structure, CMatrix &St); - void ResetSolution(); - void SaveToThePast(); - virtual void SetInitialState(Config *config, Structure *structure); }; class RK4Solver : public Solver @@ -69,13 +71,15 @@ class RK4Solver : public Solver public: RK4Solver(unsigned nDof, bool bool_linear); - ~RK4Solver(); - virtual void Iterate(double &t0, double &tf, Structure *structure); + virtual ~RK4Solver() override; + virtual void Iterate(double &t0, double &tf, Structure *structure) override; + virtual void SetInitialState(Config *config, Structure *structure) override; + +private: void EvaluateStateDerivative(double tCurrent, CVector &state, CVector &stateDerivative, Structure *structure); void interpLoads(double &tCurrent, CVector &val_loads); - virtual void SetInitialState(Config *config, Structure *structure); CVector SetState(); CVector SetState_n(); }; @@ -87,8 +91,8 @@ class StaticSolver : public Solver public: StaticSolver(unsigned nDof, bool bool_linear); - ~StaticSolver(); + virtual ~StaticSolver() override; - virtual void Iterate(double &t0, double &tf, Structure *structure); - virtual void SetInitialState(Config *config, Structure *structure); + virtual void Iterate(double &t0, double &tf, Structure *structure) override; + virtual void SetInitialState(Config *config, Structure *structure) override; }; diff --git a/src/structure.cpp b/src/Structure.cpp similarity index 98% rename from src/structure.cpp rename to src/Structure.cpp index b97e11f..f5007a0 100644 --- a/src/structure.cpp +++ b/src/Structure.cpp @@ -1,4 +1,4 @@ -#include "structure.h" +#include "Structure.h" #include #include #include @@ -78,10 +78,6 @@ Structure::Structure(Config *config) } } -Structure::~Structure() -{ -} - void Structure::SetCenterOfRotation_X(double coord_x) { centerOfRotation[0] = coord_x; diff --git a/src/structure.h b/src/Structure.h similarity index 96% rename from src/structure.h rename to src/Structure.h index 4cc945c..234820d 100644 --- a/src/structure.h +++ b/src/Structure.h @@ -1,7 +1,7 @@ #pragma once #include "MatVec.h" -#include "config.h" +#include "Config.h" class Structure { @@ -23,7 +23,8 @@ class Structure public: Structure(Config *config); - virtual ~Structure(); + + // get/set methods void SetCenterOfRotation_X(double coord_x); void SetCenterOfRotation_Y(double coord_y); void SetCenterOfRotation_Z(double coord_z); diff --git a/src/output.h b/src/output.h deleted file mode 100644 index 72f1f77..0000000 --- a/src/output.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -#include "MatVec.h" -#include "config.h" -#include "structure.h" -#include "integration.h" - -class Output -{ -public: - Output(); - ~Output(); - void WriteHistory(Integration *solver, Structure *structure, - std::ofstream *outputfile, const double &time); - void WriteRestart(Integration *solver, Structure *structure); - void WriteStaticSolution(Config *config, Integration *solver, - Structure *structure, std::ofstream *outputfile); - void WriteRestart(); -}; From fef5689fbecccfe233efcf126aa8bdf17ffaef3b Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Thu, 3 Mar 2022 17:03:18 +0100 Subject: [PATCH 18/20] add ctest --- .github/workflows/build-test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 13207b2..fb4e6db 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -29,9 +29,9 @@ jobs: # Build your program with the given configuration run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - # - name: Test - # working-directory: ${{github.workspace}}/build - # # Execute tests defined by the CMake configuration. - # # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - # run: ctest -C ${{env.BUILD_TYPE}} + - name: Test + working-directory: ${{github.workspace}}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{env.BUILD_TYPE}} From e88b596192fe52c6277b568ecd18647549a8065c Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Wed, 9 Aug 2023 16:09:03 +0200 Subject: [PATCH 19/20] add explicit link to OpenMP for runs with DART in CUPyDO --- CMakeLists.txt | 8 ++++++++ src/CMakeLists.txt | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6631a7..9b7baa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,13 @@ set(CMAKE_MACOSX_RPATH ON) set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) +IF((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel")) + IF(NOT APPLE) + # required to find the correct OpenMP library when run in CUPyDO with a solver + # which uses MKL (e.g. DART) + SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed") + ENDIF() +ENDIF() # Type of build IF( NOT CMAKE_BUILD_TYPE ) @@ -29,6 +36,7 @@ SET(CMAKE_CXX_STANDARD_REQUIRED ON) # -- CBLAS/LAPACKE -- FIND_PACKAGE(LAPACKE REQUIRED) FIND_PACKAGE(CBLAS) +FIND_PACKAGE(OpenMP REQUIRED) # -- Python -- IF (CMAKE_VERSION VERSION_LESS 3.12.0) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5cef86c..5f83ec1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,10 @@ FILE(GLOB SRCS *.cpp) ADD_LIBRARY(Native SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(Native ${LAPACKE_LIBRARIES} +TARGET_LINK_LIBRARIES(Native PUBLIC ${LAPACKE_LIBRARIES} ${CBLAS_LIBRARIES} - ${BLAS_LIBRARIES}) + ${BLAS_LIBRARIES} + OpenMP::OpenMP_CXX) +# note: when the solver is used in CUPyDO, we must link explicitly +# to OpenMP so that CUPyDO is able to find OpenMP at runtime +# even if the fluid solver uses another threading library From ff11829cad058f32e843e5167baaa1155a3b3e49 Mon Sep 17 00:00:00 2001 From: Romain Boman Date: Fri, 5 Sep 2025 18:06:32 +0200 Subject: [PATCH 20/20] =?UTF-8?q?move=20repo=20to=20GitLab=20instance=20of?= =?UTF-8?q?=20ULi=C3=A8ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 11 - .editorconfig | 8 - .github/workflows/build-test.yml | 37 - .gitignore | 43 -- CMake/FindCBLAS.cmake | 24 - CMake/FindLAPACKE.cmake | 17 - CMake/ubuntu.cmake | 33 - CMakeLists.txt | 77 -- LICENSE | 505 -------------- RBMConf.cfg | 58 -- README.md | 31 +- _src/CMakeLists.txt | 29 - _src/Native.i | 18 - src/CMakeLists.txt | 10 - src/Config.cpp | 251 ------- src/Config.h | 49 -- src/Geometry.cpp | 370 ---------- src/Geometry.h | 54 -- src/Integration.cpp | 163 ----- src/Integration.h | 29 - src/MatVec.cpp | 633 ----------------- src/MatVec.h | 102 --- src/NativeSolidSolver.cpp | 1117 ------------------------------ src/NativeSolidSolver.h | 73 -- src/Output.cpp | 131 ---- src/Output.h | 20 - src/Solver.cpp | 746 -------------------- src/Solver.h | 98 --- src/Structure.cpp | 184 ----- src/Structure.h | 49 -- tests/CMakeLists.txt | 7 - tests/testcvector.cpp | 121 ---- 32 files changed, 1 insertion(+), 5097 deletions(-) delete mode 100644 .clang-format delete mode 100644 .editorconfig delete mode 100644 .github/workflows/build-test.yml delete mode 100644 .gitignore delete mode 100644 CMake/FindCBLAS.cmake delete mode 100644 CMake/FindLAPACKE.cmake delete mode 100644 CMake/ubuntu.cmake delete mode 100644 CMakeLists.txt delete mode 100644 LICENSE delete mode 100644 RBMConf.cfg delete mode 100644 _src/CMakeLists.txt delete mode 100644 _src/Native.i delete mode 100644 src/CMakeLists.txt delete mode 100644 src/Config.cpp delete mode 100644 src/Config.h delete mode 100644 src/Geometry.cpp delete mode 100644 src/Geometry.h delete mode 100644 src/Integration.cpp delete mode 100644 src/Integration.h delete mode 100644 src/MatVec.cpp delete mode 100644 src/MatVec.h delete mode 100644 src/NativeSolidSolver.cpp delete mode 100644 src/NativeSolidSolver.h delete mode 100644 src/Output.cpp delete mode 100644 src/Output.h delete mode 100644 src/Solver.cpp delete mode 100644 src/Solver.h delete mode 100644 src/Structure.cpp delete mode 100644 src/Structure.h delete mode 100644 tests/CMakeLists.txt delete mode 100644 tests/testcvector.cpp diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 60cf9d5..0000000 --- a/.clang-format +++ /dev/null @@ -1,11 +0,0 @@ ---- -# https://clang.llvm.org/docs/ClangFormatStyleOptions.html# -# the "Visual Studio" style is similar to: -BasedOnStyle: LLVM -UseTab: Never -IndentWidth: 4 -BreakBeforeBraces: Allman -AccessModifierOffset: -4 -SortIncludes: false -ColumnLimit: 0 -... diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index de6044b..0000000 --- a/.editorconfig +++ /dev/null @@ -1,8 +0,0 @@ -# EditorConfig is awesome: https://EditorConfig.org - -root = true - -[*] -charset = utf-8 -indent_style = space -indent_size = 4 diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml deleted file mode 100644 index fb4e6db..0000000 --- a/.github/workflows/build-test.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: build-test - -on: [ push ] - # push: - # branches: [ main ] - # pull_request: - # branches: [ main ] - -env: - BUILD_TYPE: Release - -jobs: - build: - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v2 - - - name: Update repositories - run: sudo apt update - - - name: Install dependencies - run: sudo apt install libopenblas-dev liblapacke-dev libpython3-dev swig - - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - - name: Test - working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} - diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 42dfaaa..0000000 --- a/.gitignore +++ /dev/null @@ -1,43 +0,0 @@ -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -#Backup files -*~ - -#Old files -*.old - -#Executables -bin/* - -#Build directory -build/* - -# Visual Studio Code files -.vscode/ diff --git a/CMake/FindCBLAS.cmake b/CMake/FindCBLAS.cmake deleted file mode 100644 index 8e336ab..0000000 --- a/CMake/FindCBLAS.cmake +++ /dev/null @@ -1,24 +0,0 @@ - -FIND_PATH(CBLAS_INCLUDE_DIR NAMES cblas.h HINTS ${CBLAS_INCLUDE_CUSTOM_PATHS} PATHS ${CBLAS_INCLUDE_SEARCH_PATHS}) -# on Ubuntu 20.04, -# - cblas.so has been merged into blas.so (libblas-dev or libopenblas-dev package) -# - libatlas-dev cannot be used because cblas.h does not contain an extern "C" section -FIND_LIBRARY(CBLAS_LIBRARIES NAMES cblas blas HINTS ${CBLAS_LIB_CUSTOM_PATHS} PATHS ${CBLAS_LIB_SEARCH_PATHS}) - -FIND_LIBRARY(BLAS_LIBRARIES NAMES blas HINTS ${BLAS_LIB_CUSTOM_PATHS} PATHS ${BLAS_LIB_SEARCH_PATHS}) - -SET(LOOKED_FOR - CBLAS_INCLUDE_DIR - CBLAS_LIBRARIES - BLAS_LIBRARIES -) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(CBLAS DEFAULT_MSG ${LOOKED_FOR}) - -IF(CBLAS_FOUND) - MESSAGE(STATUS "Found CBLAS & BLAS") - MESSAGE(STATUS CBLAS_INCLUDE_DIR=${CBLAS_INCLUDE_DIR}) - MESSAGE(STATUS CBLAS_LIBRARIES=${CBLAS_LIBRARIES}) - MESSAGE(STATUS BLAS_LIBRARIES=${BLAS_LIBRARIES}) -ENDIF(CBLAS_FOUND) diff --git a/CMake/FindLAPACKE.cmake b/CMake/FindLAPACKE.cmake deleted file mode 100644 index 5b8bf5b..0000000 --- a/CMake/FindLAPACKE.cmake +++ /dev/null @@ -1,17 +0,0 @@ - -FIND_PATH(LAPACKE_INCLUDE_DIR NAMES lapacke.h HINTS ${LAPACKE_INCLUDE_CUSTOM_PATHS} PATHS ${LAPACKE_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(LAPACKE_LIBRARIES NAMES lapacke HINTS ${LAPACKE_LIB_CUSTOM_PATHS} PATHS ${LAPACKE_LIB_SEARCH_PATHS}) - -SET(LOOKED_FOR - LAPACKE_INCLUDE_DIR - LAPACKE_LIBRARIES -) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LAPACKE DEFAULT_MSG ${LOOKED_FOR}) - -IF(LAPACKE_FOUND) - MESSAGE(STATUS "Found LAPACKE") - MESSAGE(STATUS LAPACKE_INCLUDE_DIR=${LAPACKE_INCLUDE_DIR}) - MESSAGE(STATUS LAPACKE_LIBRARIES=${LAPACKE_LIBRARIES}) -ENDIF(LAPACKE_FOUND) diff --git a/CMake/ubuntu.cmake b/CMake/ubuntu.cmake deleted file mode 100644 index 33ebc43..0000000 --- a/CMake/ubuntu.cmake +++ /dev/null @@ -1,33 +0,0 @@ - -SET(CBLAS_INCLUDE_SEARCH_PATHS - /usr/include - /usr/include/atlas - /usr/include/openblas - CACHE PATH "" -) - -SET(CBLAS_LIB_SEARCH_PATHS - /usr/lib - /usr/lib/atlas-base - /usr/lib/openblas-base - CACHE PATH "" -) - -SET(BLAS_LIB_SEARCH_PATHS - /usr/lib - /usr/lib/libblas - /usr/lib/atlas-base - /usr/lib/atlas-base/atlas - /usr/lib/openblas-base - CACHE PATH "" -) - -SET(LAPACKE_INCLUDE_SEARCH_PATHS - /usr/include - CACHE PATH "" -) - -SET(LAPACKE_LIB_SEARCH_PATHS - /usr/lib - CACHE PATH "" -) diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 9b7baa0..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,77 +0,0 @@ -# Main CMake file for NativeSolid project - -PROJECT(NativeSolid) -CMAKE_MINIMUM_REQUIRED(VERSION 3.1) - -SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin CACHE PATH - "Single output directory for building all libraries.") -SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin CACHE PATH - "Single output directory for building all executables.") -MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH) - -set(CMAKE_MACOSX_RPATH ON) -set(CMAKE_SKIP_BUILD_RPATH FALSE) -set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) - -IF((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel")) - IF(NOT APPLE) - # required to find the correct OpenMP library when run in CUPyDO with a solver - # which uses MKL (e.g. DART) - SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed") - ENDIF() -ENDIF() - -# Type of build -IF( NOT CMAKE_BUILD_TYPE ) - SET( CMAKE_BUILD_TYPE Release CACHE std::string "" FORCE ) -ENDIF() -MESSAGE(STATUS "Build type : ${CMAKE_BUILD_TYPE}") - -LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake") - -# -- C++11 -SET(CMAKE_CXX_STANDARD 11) -SET(CMAKE_CXX_STANDARD_REQUIRED ON) - -# -- CBLAS/LAPACKE -- -FIND_PACKAGE(LAPACKE REQUIRED) -FIND_PACKAGE(CBLAS) -FIND_PACKAGE(OpenMP REQUIRED) - -# -- Python -- -IF (CMAKE_VERSION VERSION_LESS 3.12.0) - FIND_PACKAGE(PythonInterp 3.6 REQUIRED) - FIND_PACKAGE(PythonLibs 3.6 REQUIRED) -ELSE() - find_package (Python3 COMPONENTS Interpreter Development) - # use Python3_ROOT_DIR if wrong python found (e.g. anaconda) - SET(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) - SET(PYTHON_LIBRARIES ${Python3_LIBRARIES}) - SET(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS}) - SET(PYTHONLIBS_VERSION_STRING ${Python3_VERSION}) -ENDIF() -MESSAGE(STATUS "PYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}") -MESSAGE(STATUS "PYTHON_LIBRARIES:FILEPATH=${PYTHON_LIBRARIES}") -MESSAGE(STATUS "PYTHON_INCLUDE_PATH:FILEPATH=${PYTHON_INCLUDE_PATH}") -MESSAGE(STATUS "PYTHON_FRAMEWORK_INCLUDES=${PYTHON_FRAMEWORK_INCLUDES}") -MESSAGE(STATUS "PYTHONLIBS_VERSION_STRING=${PYTHONLIBS_VERSION_STRING}") -MESSAGE(STATUS "Python_FRAMEWORKS=${Python_FRAMEWORKS}") - -# -- SWIG -- -FIND_PACKAGE(SWIG REQUIRED) -SET(CMAKE_SWIG_OUTDIR "${EXECUTABLE_OUTPUT_PATH}") - -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR}/api - ${LAPACKE_INCLUDE_DIR} - ${CBLAS_INCLUDE_DIR} - ${PYTHON_INCLUDE_PATH} -) - -ENABLE_TESTING() - -# -- Sub directories -- -ADD_SUBDIRECTORY( src ) -ADD_SUBDIRECTORY( _src ) -ADD_SUBDIRECTORY( tests ) - diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 5f2dd7f..0000000 --- a/LICENSE +++ /dev/null @@ -1,505 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -(This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.) - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - {description} - Copyright (C) {year} {fullname} - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random - Hacker. - - {signature of Ty Coon}, 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - diff --git a/RBMConf.cfg b/RBMConf.cfg deleted file mode 100644 index 4a12da3..0000000 --- a/RBMConf.cfg +++ /dev/null @@ -1,58 +0,0 @@ -% Unsteady (dynamic) simulation -UNSTEADY_SIMULATION = YES -% CSD solver (NATIVE or METAFOR) -CSD_SOLVER = NATIVE -% -MESH_FILE = 2D_FlatPlate_Rounded.su2 -% -MOVING_MARKER = plate -% -% If NATIVE -% Integration time step -DELTA_T = 0.001 -% Type of structural problem (SPRING_HOR or SPRING_VER or AIRFOIL) -STRUCT_TYPE = AIRFOIL -% Linearized equations of motion -LINEARIZE = YES -% Body mass -SPRING_MASS = 1.356 -%Inertia around CG -INERTIA_CG = 1000 -%Inertia around flexural axis -INERTIA_FLEXURAL = 2.07578e-4 -% Spring stiffness -SPRING_STIFFNESS = 2658.623 -% Spring damping -SPRING_DAMPING = 0.240172 -% -TORSIONAL_STIFFNESS = 0.663817 -% -TORSIONAL_DAMPING = 3.5216e-4 -% -CORD = 0.035 -%Position of the flexural axis -FLEXURAL_AXIS = -0.0028 -%Center of gravity -GRAVITY_CENTER = 0.0 -% -% INITIAL CONDITIONS -%Plunging -INITIAL_DISP = 0.0 -%Pitching -INITIAL_ANGLE = 0.7854 -% -% Restart solution from previous computations -RESTART_SOL = NO -% -DELTA_ITER_WRITE = 10 -% Restart solution file name -RESTART_FILE = restart_solid.dat -% Start time (usually 0) in seconds -START_TIME = 0 -% End time in seconds -STOP_TIME = 1.0 -% Integration algorithm (ALPHAGEN, RK4) -INTEGRATION_ALGO = ALPHAGEN -%INTEGRATION_ALGO = RK4 -% Integration parameter -RHO = 0.0 diff --git a/README.md b/README.md index eec554d..9584408 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,3 @@ # NativeSolid / RBM -Native solid solver for [CUPyDO](https://github.com/ulgltas/CUPyDO) - -## Features -Compute static or dynamic displacements for several 2D configurations. - -* Meshes - - .su2 format (can be built and exported from gmsh) -* Configuration - - Airfoil (pitch/plunge) - - Horizontal spring - - Vertical spring -* Dynamic computation - - AlphaGen time integration - - Runge-Kutta (order 4) time integration - - Mass/damping/stiffness/nonlinear terms -* Static Computation - - Stiffness term only - -## Build - -Required packages -``` -sudo apt install build-essential cmake libopenblas-dev liblapacke-dev libpython3-dev swig -``` - -``` -mkdir build && cd build -cmake .. -make -j 4 -``` +This repository has been moved to the [GitLab instance of the University of Liège](https://gitlab.uliege.be/am-dept/NativeSolid) diff --git a/_src/CMakeLists.txt b/_src/CMakeLists.txt deleted file mode 100644 index 9d6c002..0000000 --- a/_src/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# CMake input file of the SWIG wrapper around "Native.so" - -INCLUDE(${SWIG_USE_FILE}) - -FILE(GLOB SRCS *.h *.cpp *.inl *.swg) -FILE(GLOB ISRCS *.i) - -SET(CMAKE_SWIG_FLAGS "") -SET_SOURCE_FILES_PROPERTIES(${ISRCS} PROPERTIES CPLUSPLUS ON) - -SET(SWINCFLAGS --I${PROJECT_SOURCE_DIR}/src -) - -SET_SOURCE_FILES_PROPERTIES(${ISRCS} PROPERTIES SWIG_FLAGS "${SWINCFLAGS}") - -IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") - SWIG_ADD_MODULE(NativeSolid python ${ISRCS} ${SRCS}) -ELSE() - SWIG_ADD_LIBRARY(NativeSolid - LANGUAGE python - SOURCES ${ISRCS} ${SRCS}) -ENDIF() - -TARGET_INCLUDE_DIRECTORIES(_NativeSolid PRIVATE ${PROJECT_SOURCE_DIR}/_src - ${PROJECT_SOURCE_DIR}/src - ${PYTHON_INCLUDE_PATH}) - -SWIG_LINK_LIBRARIES(NativeSolid Native ${PYTHON_LIBRARIES}) diff --git a/_src/Native.i b/_src/Native.i deleted file mode 100644 index bfcdd4a..0000000 --- a/_src/Native.i +++ /dev/null @@ -1,18 +0,0 @@ -// SWIG input file of the 'NativeSolid' module - -%feature("autodoc","1"); - -%module(docstring= -"'NativeSolid' module", -directors="1", -threads="1" -) NativeSolid -%{ - -#include -#include "NativeSolidSolver.h" - -%} - -%include "std_string.i" -%include "NativeSolidSolver.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 5f83ec1..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -FILE(GLOB SRCS *.cpp) -ADD_LIBRARY(Native SHARED ${SRCS}) - -TARGET_LINK_LIBRARIES(Native PUBLIC ${LAPACKE_LIBRARIES} - ${CBLAS_LIBRARIES} - ${BLAS_LIBRARIES} - OpenMP::OpenMP_CXX) -# note: when the solver is used in CUPyDO, we must link explicitly -# to OpenMP so that CUPyDO is able to find OpenMP at runtime -# even if the fluid solver uses another threading library diff --git a/src/Config.cpp b/src/Config.cpp deleted file mode 100644 index a15395a..0000000 --- a/src/Config.cpp +++ /dev/null @@ -1,251 +0,0 @@ -#include "Config.h" -#include -#include -#include -#include -#include - -Config::Config(std::string filename) : ConfigFileName(filename) -{ -} - -Config::~Config() -{ -} - -Config *Config::GetAddress() -{ - return this; -} - -void Config::ReadConfig() -{ - std::string delimiter = "="; - size_t pos; - std::string text_line, option; - std::ifstream InputFile; - InputFile.open(ConfigFileName.c_str(), std::ios::in); - if (InputFile.fail()) - { - std::cerr << "Invalid configuration file name : " << ConfigFileName << std::endl; - throw(-1); - } - char caract; - while (getline(InputFile, text_line)) - { - caract = text_line[0]; - if (caract == '%') - { - } - else - { - pos = text_line.find(delimiter); - option = text_line.substr(0, pos); - text_line.erase(0, pos + delimiter.length()); - option.erase(remove(option.begin(), option.end(), ' '), option.end()); - text_line.erase(remove(text_line.begin(), text_line.end(), ' '), text_line.end()); - if (option == "CSD_SOLVER") - CSD_SOLVER = text_line; - else if (option == "MESH_FILE") - MESH_FILE = text_line; - else if (option == "UNSTEADY_SIMULATION") - UNSTEADY_SIMULATION = text_line; - else if (option == "STRUCT_TYPE") - STRUCT_TYPE = text_line; - else if (option == "LINEARIZE") - LINEARIZE = text_line; - else if (option == "INTEGRATION_ALGO") - INTEGRATION_ALGO = text_line; - else if (option == "RESTART_SOL") - RESTART_SOL = text_line; - else if (option == "RESTART_FILE") - RESTART_FILE = text_line; - else if (option == "MOVING_MARKER") - MOVING_MARKER = text_line; - else if (option == "SPRING_MASS") - SPRING_MASS = atof(text_line.c_str()); - else if (option == "INERTIA_CG") - INERTIA_CG = atof(text_line.c_str()); - else if (option == "INERTIA_FLEXURAL") - INERTIA_FLEXURAL = atof(text_line.c_str()); - else if (option == "SPRING_STIFFNESS") - SPRING_STIFFNESS = atof(text_line.c_str()); - else if (option == "SPRING_DAMPING") - SPRING_DAMPING = atof(text_line.c_str()); - else if (option == "TORSIONAL_STIFFNESS") - TORSIONAL_STIFFNESS = atof(text_line.c_str()); - else if (option == "TORSIONAL_DAMPING") - TORSIONAL_DAMPING = atof(text_line.c_str()); - else if (option == "CORD") - CORD = atof(text_line.c_str()); - else if (option == "FLEXURAL_AXIS") - FLEXURAL_AXIS = atof(text_line.c_str()); - else if (option == "GRAVITY_CENTER") - GRAVITY_CENTER = atof(text_line.c_str()); - else if (option == "INITIAL_DISP") - INITIAL_DISP = atof(text_line.c_str()); - else if (option == "INITIAL_ANGLE") - INITIAL_ANGLE = atof(text_line.c_str()); - else if (option == "START_TIME") - START_TIME = atof(text_line.c_str()); - else if (option == "DELTA_T") - DELTA_T = atof(text_line.c_str()); - else if (option == "DELTA_ITER_WRITE") - DELTAITERWRITE = atol(text_line.c_str()); - else if (option == "STOP_TIME") - STOP_TIME = atof(text_line.c_str()); - else if (option == "RHO") - RHO = atof(text_line.c_str()); - else - std::cout << "The option " + option + " is not recognized !" << std::endl; - } - } - InputFile.close(); - - if (CSD_SOLVER == "NATIVE") - std::cout << "The Native solver has been chosen" << std::endl; - else - std::cout << "Cannot run the solver with other value than NATIVE for CSD_SOLVER option !" << std::endl; - - if (UNSTEADY_SIMULATION == "YES") - std::cout << "Dynamic structure computation" << std::endl; - else - std::cout << "Static structure computation" << std::endl; - - if (STRUCT_TYPE == "SPRING_HOR" || STRUCT_TYPE == "SPRING_VER") - std::cout << "Structural model is a plunging spring" << std::endl; - else if (STRUCT_TYPE == "AIRFOIL") - std::cout << "Structural model is a pitching plunging airfoil" << std::endl; - else - std::cout << "The specified structural model is not recognized or implemented yet !" << std::endl; -} - -std::string Config::GetMeshFile() -{ - return MESH_FILE; -} - -std::string Config::GetUnsteady() -{ - return UNSTEADY_SIMULATION; -} - -std::string Config::GetCSDSolver() -{ - return CSD_SOLVER; -} - -std::string Config::GetStructType() -{ - return STRUCT_TYPE; -} - -std::string Config::GetLinearize() -{ - return LINEARIZE; -} - -std::string Config::GetIntegrationAlgo() -{ - return INTEGRATION_ALGO; -} - -std::string Config::GetRestartSol() -{ - return RESTART_SOL; -} - -std::string Config::GetRestartFile() -{ - return RESTART_FILE; -} - -std::string Config::GetMovingMarker() -{ - return MOVING_MARKER; -} - -double Config::GetStartTime() -{ - return START_TIME; -} - -double Config::GetDeltaT() -{ - return DELTA_T; -} - -unsigned long Config::GetDeltaIterWrite() -{ - return DELTAITERWRITE; -} - -double Config::GetStopTime() -{ - return STOP_TIME; -} - -double Config::GetSpringStiffness() -{ - return SPRING_STIFFNESS; -} - -double Config::GetSpringMass() -{ - return SPRING_MASS; -} - -double Config::GetInertiaCG() -{ - return INERTIA_CG; -} - -double Config::GetInertiaFlexural() -{ - return INERTIA_FLEXURAL; -} - -double Config::GetSpringDamping() -{ - return SPRING_DAMPING; -} - -double Config::GetTorsionalStiffness() -{ - return TORSIONAL_STIFFNESS; -} - -double Config::GetTorsionalDamping() -{ - return TORSIONAL_DAMPING; -} - -double Config::GetCord() -{ - return CORD; -} - -double Config::GetFlexuralAxis() -{ - return FLEXURAL_AXIS; -} - -double Config::GetGravityCenter() -{ - return GRAVITY_CENTER; -} - -double Config::GetInitialDisp() -{ - return INITIAL_DISP; -} - -double Config::GetInitialAngle() -{ - return INITIAL_ANGLE; -} - -double Config::GetRho() -{ - return RHO; -} diff --git a/src/Config.h b/src/Config.h deleted file mode 100644 index aee6c2b..0000000 --- a/src/Config.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -class Config -{ - std::string ConfigFileName; - std::string MESH_FILE, UNSTEADY_SIMULATION, CSD_SOLVER, - STRUCT_TYPE, LINEARIZE, INTEGRATION_ALGO, - RESTART_SOL, RESTART_FILE, MOVING_MARKER; - double SPRING_STIFFNESS, SPRING_MASS, INERTIA_CG, - INERTIA_FLEXURAL, SPRING_DAMPING, TORSIONAL_STIFFNESS, - TORSIONAL_DAMPING, CORD, FLEXURAL_AXIS, GRAVITY_CENTER, - INITIAL_DISP, INITIAL_ANGLE, START_TIME, - DELTA_T, STOP_TIME, RHO; - unsigned long DELTAITERWRITE; - -public: - Config(std::string filename); - virtual ~Config(); - virtual Config *GetAddress(); - virtual void ReadConfig(); - virtual std::string GetMeshFile(); - virtual std::string GetUnsteady(); - virtual std::string GetCSDSolver(); - virtual std::string GetStructType(); - virtual std::string GetLinearize(); - virtual std::string GetIntegrationAlgo(); - virtual std::string GetRestartSol(); - virtual std::string GetRestartFile(); - virtual std::string GetMovingMarker(); - virtual double GetSpringStiffness(); - virtual double GetSpringMass(); - virtual double GetInertiaCG(); - virtual double GetInertiaFlexural(); - virtual double GetSpringDamping(); - virtual double GetTorsionalStiffness(); - virtual double GetTorsionalDamping(); - virtual double GetCord(); - virtual double GetFlexuralAxis(); - virtual double GetGravityCenter(); - virtual double GetInitialDisp(); - virtual double GetInitialAngle(); - virtual double GetStartTime(); - virtual double GetDeltaT(); - virtual unsigned long GetDeltaIterWrite(); - virtual double GetStopTime(); - virtual double GetRho(); -}; diff --git a/src/Geometry.cpp b/src/Geometry.cpp deleted file mode 100644 index b8dbc9f..0000000 --- a/src/Geometry.cpp +++ /dev/null @@ -1,370 +0,0 @@ -#include "Geometry.h" -#include "Config.h" -#include -#include -#include -#include -#include -#include - -Point::Point() -{ - Coord0 = new double[3]; - Coord0[0] = 0.0; - Coord0[1] = 0.0; - Coord0[2] = 0.0; - - Coord = new double[3]; - Coord[0] = 0.0; - Coord[1] = 0.0; - Coord[2] = 0.0; - - Coord_n = new double[3]; - Coord_n[0] = 0.0; - Coord_n[1] = 0.0; - Coord_n[2] = 0.0; - - Vel = new double[3]; - Vel[0] = 0.0; - Vel[1] = 0.0; - Vel[2] = 0.0; - - Vel_n = new double[3]; - Vel_n[0] = 0.0; - Vel_n[1] = 0.0; - Vel_n[2] = 0.0; - - Force = new double[3]; - Force[0] = 0.0; - Force[1] = 0.0; - Force[2] = 0.0; -} - -Point::~Point() -{ - delete[] Coord0; - Coord0 = NULL; - - delete[] Coord; - Coord = NULL; - - delete[] Coord_n; - Coord_n = NULL; - - delete[] Vel; - Vel = NULL; - - delete[] Vel_n; - Vel_n = NULL; - - delete[] Force; - Force = NULL; -} - -double *Point::GetCoord0() const -{ - return Coord0; -} - -double *Point::GetCoord() const -{ - return Coord; -} - -double *Point::GetCoord_n() const -{ - return Coord_n; -} - -double *Point::GetVel() const -{ - return Vel; -} - -double *Point::GetVel_n() const -{ - return Vel_n; -} - -double *Point::GetForce() const -{ - return Force; -} - -void Point::PrintCoord() const -{ - std::cout << Coord[0] << " ; " << Coord[1] << " ; " << Coord[2] << std::endl; -} - -void Point::SetCoord0(double *newCoord) -{ - Coord0[0] = newCoord[0]; - Coord0[1] = newCoord[1]; - Coord0[2] = newCoord[2]; -} - -void Point::SetCoord(double *newCoord) -{ - Coord[0] = newCoord[0]; - Coord[1] = newCoord[1]; - Coord[2] = newCoord[2]; -} - -void Point::SetCoord_n(double *newCoord) -{ - Coord_n[0] = newCoord[0]; - Coord_n[1] = newCoord[1]; - Coord_n[2] = newCoord[2]; -} - -void Point::SetVel(double *newVel) -{ - Vel[0] = newVel[0]; - Vel[1] = newVel[1]; - Vel[2] = newVel[2]; -} - -void Point::SetVel_n(double *newVel_n) -{ - Vel_n[0] = newVel_n[0]; - Vel_n[1] = newVel_n[1]; - Vel_n[2] = newVel_n[2]; -} - -void Point::SetForce(double *newForce) -{ - Force[0] = newForce[0]; - Force[1] = newForce[1]; - Force[2] = newForce[2]; -} - -void Point::UpdateCoord() -{ - Coord_n[0] = Coord[0]; - Coord_n[1] = Coord[1]; - Coord_n[2] = Coord[2]; -} - -void Point::UpdateVel() -{ - Vel_n[0] = Vel[0]; - Vel_n[1] = Vel[1]; - Vel_n[2] = Vel[2]; -} - -Geometry::Geometry(Config *config) -{ - - std::string meshFileName, textLine, tampon; - std::ifstream meshFile; - std::string::size_type position; - double Coord[3]; - double *TempCoord; - unsigned long iMarker(0); - int elemType(0), dummyInt(0); - int iPoint; - - Coord[0] = 0.0; - Coord[1] = 0.0; - Coord[2] = 0.0; - - nDim = 0; - nElem = 0; - nPoint = 0; - nMarkers = 0; - // strcpy(cstr, config->GetMeshFile()); - - meshFileName = config->GetMeshFile(); - - //--- Open the mesh file and check --- - meshFile.open(meshFileName.c_str(), std::ios::in); - if (meshFile.fail()) - { - std::cout << "Unable to open the mesh file " << meshFileName << std::endl; - exit(1); - } - - std::cout << "Mesh file " << meshFileName << " is open." << std::endl; - std::cout << "Constructing the mesh..." << std::endl; - while (getline(meshFile, textLine)) - { - - position = textLine.find("NDIME=", 0); - if (position != std::string::npos) - { - textLine.erase(0, 6); - nDim = atoi(textLine.c_str()); - std::cout << "Number of dimensions : " << nDim << std::endl; - } - - position = textLine.find("NELEM=", 0); - if (position != std::string::npos) - { - textLine.erase(0, 6); - nElem = atoi(textLine.c_str()); - std::cout << "Number of elements : " << nElem << std::endl; - for (int iElem = 0; iElem < nElem; iElem++) - { - getline(meshFile, textLine); - } - } - - position = textLine.find("NPOIN=", 0); - if (position != std::string::npos) - { - textLine.erase(0, 6); - nPoint = atoi(textLine.c_str()); - std::cout << "Number of points : " << nPoint << std::endl; - node = new Point *[nPoint]; - // std::cout << "JE VAIS REMPLIR" << std::endl; - for (iPoint = 0; iPoint < nPoint; iPoint++) - { - getline(meshFile, textLine); - // if(iPoint == 1) std::cout << textLine << std::endl; - node[iPoint] = new Point(); - std::istringstream point_line(textLine); - point_line >> Coord[0]; - // if(iPoint == 1) std::cout << Coord[0] << std::endl; - point_line >> Coord[1]; - // if(iPoint == 1) std::cout << Coord[1] << std::endl; - if (nDim == 3) - point_line >> Coord[2]; - node[iPoint]->SetCoord0(Coord); - node[iPoint]->SetCoord(Coord); - node[iPoint]->SetCoord_n(Coord); - TempCoord = node[iPoint]->GetCoord(); - // std::cout << iPoint << std::endl; - } - } - - position = textLine.find("NMARK=", 0); - if (position != std::string::npos) - { - textLine.erase(0, 6); - nMarkers = atoi(textLine.c_str()); - std::cout << "Number of markers : " << nMarkers << std::endl; - vertex = new unsigned long *[nMarkers]; - nVertex = new unsigned long[nMarkers]; - markersMoving = new bool[nMarkers]; - nElemMarker = new unsigned long[nMarkers]; - } - - position = textLine.find("MARKER_TAG=", 0); - if (position != std::string::npos) - { - textLine.erase(0, 12); - std::cout << "Reading elements for marker : " << textLine << std::endl; - if (textLine == config->GetMovingMarker()) - { - std::cout << "Marker " << textLine << " is a moving marker." << std::endl; - markersMoving[iMarker] = true; - } - else - markersMoving[iMarker] = false; - } - - position = textLine.find("MARKER_ELEMS=", 0); - if (position != std::string::npos) - { - textLine.erase(0, 13); - nElemMarker[iMarker] = atoi(textLine.c_str()); - std::cout << "Number of elements on the marker : " << nElemMarker[iMarker] << std::endl; - std::vector tempVertexMarker; - for (int iElem = 0; iElem < nElemMarker[iMarker]; iElem++) - { - getline(meshFile, textLine); - std::istringstream point_line(textLine); - point_line >> elemType; - if (elemType == 3) - { - point_line >> dummyInt; - if (!isInVec(tempVertexMarker, dummyInt)) - { - tempVertexMarker.push_back(dummyInt); - } - point_line >> dummyInt; - if (!isInVec(tempVertexMarker, dummyInt)) - { - tempVertexMarker.push_back(dummyInt); - } - } - else - { - std::cout << "Elem type " << elemType << " is not recognized !" << std::endl; - exit(1); - } - } - nVertex[iMarker] = tempVertexMarker.size(); - vertex[iMarker] = new unsigned long[nVertex[iMarker]]; - vecCopy(tempVertexMarker, vertex[iMarker]); - iMarker++; - } - } - - meshFile.close(); - - // for (int iVertex = 0; iVertex < nVertex[0]; iVertex++) - // { - // // cout << vertex[0][iVertex] << std::endl; - // iPoint = vertex[0][iVertex]; - // node[iPoint]->PrintCoord(); - // } -} - -Geometry::~Geometry() -{ - - for (int iPoint = 0; iPoint < nPoint; iPoint++) - { - delete node[iPoint]; - } - - for (int iMarker = 0; iMarker < nMarkers; iMarker++) - { - delete[] vertex[iMarker]; - } - - delete[] vertex; - - delete[] node; - - delete[] nElemMarker; -} - -unsigned long Geometry::GetnMarkers() const -{ - return nMarkers; -} - -bool Geometry::GetMarkersMoving(unsigned long iMarker) const -{ - return markersMoving[iMarker]; -} - -void Geometry::UpdateGeometry() -{ - - unsigned long iPoint; - - for (iPoint = 0; iPoint < nPoint; iPoint++) - { - node[iPoint]->UpdateCoord(); - node[iPoint]->UpdateVel(); - } -} - -bool isInVec(std::vector const &inputVector, int dummyInt) -{ - int i = 0; - while (i < inputVector.size() && inputVector[i] != dummyInt) - i++; - return i < inputVector.size(); -} - -void vecCopy(std::vector const &sourceVector, unsigned long *destinationTab) -{ - for (int i = 0; i < sourceVector.size(); i++) - { - destinationTab[i] = sourceVector[i]; - } -} diff --git a/src/Geometry.h b/src/Geometry.h deleted file mode 100644 index 07d0f11..0000000 --- a/src/Geometry.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "Config.h" -#include - -class Point -{ - double *Coord0; - double *Coord; - double *Coord_n; - double *Vel; - double *Vel_n; - double *Force; - -public: - Point(); - ~Point(); - double *GetCoord0() const; - double *GetCoord() const; - double *GetCoord_n() const; - double *GetVel() const; - double *GetVel_n() const; - double *GetForce() const; - void PrintCoord() const; - void SetCoord0(double *newCoord); - void SetCoord(double *newCoord); - void SetCoord_n(double *newCoord); - void SetVel(double *newVel); - void SetVel_n(double *newVel_n); - void SetForce(double *newForce); - void UpdateCoord(); - void UpdateVel(); -}; - -class Geometry -{ - unsigned short nDim; - unsigned long nElem, nPoint, nMarkers; - unsigned long *nElemMarker; - -public: - Geometry(Config *config); - ~Geometry(); - unsigned long GetnMarkers() const; - bool GetMarkersMoving(unsigned long iMarker) const; - void UpdateGeometry(); - unsigned long **vertex; // vertex[iMarker][iPoint] - unsigned long *nVertex; // nVertex[iMarker] - bool *markersMoving; - Point **node; // node[iPoint] returns a pointeur to a Point object so e.g. node[iPoint]->PrintCoord(); -}; - -bool isInVec(std::vector const &inputVector, int dummyInt); -void vecCopy(std::vector const &sourceVector, unsigned long *destinationTab); diff --git a/src/Integration.cpp b/src/Integration.cpp deleted file mode 100644 index e4aebbd..0000000 --- a/src/Integration.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "Integration.h" -#include "Solver.h" -#include -#include -#include -#include -#include -#include - -Integration::Integration(Config *config, Structure *structure) -{ - solver = NULL; - bool linear; - - linear = (config->GetLinearize()) == "YES"; - - if (config->GetUnsteady() == "YES") - { - if (config->GetIntegrationAlgo() == "ALPHAGEN") - { - solver = new AlphaGenSolver(structure->GetnDof(), config->GetRho(), linear); - } - else if (config->GetIntegrationAlgo() == "RK4") - { - solver = new RK4Solver(structure->GetnDof(), linear); - } - } - else - solver = new StaticSolver(structure->GetnDof(), linear); -} - -Integration::~Integration() -{ - if (solver != NULL) - delete solver; -} - -Solver *Integration::GetSolver() -{ - - return solver; -} - -double Integration::GettotTime() -{ - return totTime; -} - -double Integration::GetdeltaT() -{ - return deltaT; -} - -void Integration::SetExtIter(unsigned long val_ExtIter) -{ - - ExtIter = val_ExtIter; -} - -unsigned long Integration::GetExtIter() -{ - - return ExtIter; -} - -void Integration::SetInitialConditions(Config *config, Structure *structure) -{ - ExtIter = 0; - solver->SetInitialState(config, structure); - structure->SetCenterOfRotation_Y((solver->GetDisp())[0]); -} - -void Integration::TemporalIteration(double &t0, double &tf, Structure *structure) -{ - int rank = 0; - -#ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#endif - - double currentTime(tf); - deltaT = tf - t0; - solver->Iterate(t0, tf, structure); - - if (rank == 0) - { - if (structure->GetnDof() == 1) - { - std::cout << std::fixed - << std::setw(10) << "Time" - << std::setw(15) << "Displacement" - << std::setw(15) << "Velocity" - << std::setw(15) << "Acceleration" << std::endl; - std::cout << std::fixed - << std::setw(10) << currentTime - << std::setw(15) << (solver->GetDisp())[0] - << std::setw(15) << (solver->GetVel())[0] - << std::setw(15) << (solver->GetAcc())[0] << std::endl; - } - else if (structure->GetnDof() == 2) - { - std::cout << std::fixed - << std::setw(10) << "Time" - << std::setw(15) << "Displacement1" - << std::setw(15) << "Displacement2" - << std::setw(15) << "Velocity1" - << std::setw(15) << "Velocity2" - << std::setw(15) << "Acceleration1" - << std::setw(15) << "Acceleration2" << std::endl; - std::cout << std::fixed - << std::setw(10) << currentTime - << std::setw(15) << (solver->GetDisp())[0] - << std::setw(15) << (solver->GetDisp())[1] - << std::setw(15) << (solver->GetVel())[0] - << std::setw(15) << (solver->GetVel())[1] - << std::setw(15) << (solver->GetAcc())[0] - << std::setw(15) << (solver->GetAcc())[1] << std::endl; - } - } -} - -void Integration::StaticIteration(Structure *structure) -{ - int rank = 0; - -#ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#endif - - double t0 = 0.; - double tf = 0.; - deltaT = 0.; - solver->Iterate(t0, tf, structure); - - if (rank == 0) - { - if (structure->GetnDof() == 1) - { - std::cout << std::fixed - << std::setw(10) << "Time" - << std::setw(15) << "Displacement" << std::endl; - std::cout << std::fixed - << std::setw(10) << tf - << std::setw(15) << (solver->GetDisp())[0] << std::endl; - } - else if (structure->GetnDof() == 2) - { - std::cout << std::fixed - << std::setw(10) << "Time" - << std::setw(15) << "Displacement1" - << std::setw(15) << "Displacement2" << std::endl; - std::cout << std::fixed - << std::setw(10) << tf - << std::setw(15) << (solver->GetDisp())[0] - << std::setw(15) << (solver->GetDisp())[1] << std::endl; - } - } -} - -void Integration::UpdateSolution() -{ - solver->SaveToThePast(); -} diff --git a/src/Integration.h b/src/Integration.h deleted file mode 100644 index 7515d52..0000000 --- a/src/Integration.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "Config.h" -#include "Structure.h" -#include "Solver.h" - -#define PI 3.14159265 - -class Integration -{ - double totTime; - double deltaT; - unsigned long ExtIter; - std::string algo; - Solver *solver; - -public: - Integration(Config *config, Structure *structure); - ~Integration(); - Solver *GetSolver(); - double GettotTime(); - double GetdeltaT(); - void SetExtIter(unsigned long val_ExtIter); - unsigned long GetExtIter(); - void SetInitialConditions(Config *config, Structure *structure); - void TemporalIteration(double &t0, double &tf, Structure *structure); - void StaticIteration(Structure *structure); - void UpdateSolution(); -}; diff --git a/src/MatVec.cpp b/src/MatVec.cpp deleted file mode 100644 index adb6632..0000000 --- a/src/MatVec.cpp +++ /dev/null @@ -1,633 +0,0 @@ -#include "MatVec.h" -#include -#include - -CVector::CVector() : nElm(0) -{ - vec_val = NULL; -} - -CVector::CVector(const unsigned long &size, const double &val) -{ - vec_val = NULL; - if (size <= 0) - { - nElm = 0; - std::cerr << "CVector:CVector(const unsigned long &, const double): " - << "invalid input : size = " << size << std::endl; - throw(-1); - } - else - { - nElm = size; - vec_val = new double[nElm]; - for (unsigned int i = 0; i < nElm; i++) - vec_val[i] = val; - } -} - -CVector::CVector(const CVector &u) -{ - nElm = u.nElm; - vec_val = NULL; - vec_val = new double[nElm]; - for (unsigned int i = 0; i < nElm; i++) - vec_val[i] = u.vec_val[i]; -} - -CVector::~CVector() -{ - if (vec_val != NULL) - delete[] vec_val; -} - -void CVector::Initialize(const unsigned long &size, const double &val) -{ - if (vec_val == NULL) - { - if (size <= 0) - { - nElm = 0; - std::cerr << "CVector::Initialize(const unsigned long &, const double &): " - << "invalid number of element" << nElm << std::endl; - throw(-1); - } - else - { - nElm = size; - vec_val = new double[nElm]; - for (unsigned int ii = 0; ii < nElm; ii++) - { - vec_val[ii] = val; - } - } - } - else - { - std::cerr << "CVector::Initialize(const unsigned long &, const double &): " - << "vector already initialize, resizing is not allowed." << std::endl; - throw(-1); - } -} - -unsigned long CVector::GetSize() const -{ - if (nElm <= 0) - { - std::cerr << "CVector::GetSize() const: " - << "invalid number of element" << nElm << std::endl; - throw(-1); - } - return nElm; -} - -double *CVector::GetVec() const -{ - return vec_val; -} - -void CVector::print() const -{ - std::cout << "**********" << std::endl; - for (unsigned int i = 0; i < nElm; i++) - std::cout << vec_val[i] << std::endl; - std::cout << "**********" << std::endl; -} - -void CVector::SetAllValues(const double &val) -{ - for (unsigned int ii = 0; ii < nElm; ii++) - vec_val[ii] = val; -} - -CVector &CVector::operator=(const CVector &u) -{ - if (this == &u) - return *this; - - if (nElm != u.nElm) - { - std::cerr << "Sizes do not match for operator = : size1 = " << nElm << " & size2 = " << u.nElm << std::endl; - throw(-1); - } - else - { - for (unsigned int i = 0; i < nElm; i++) - vec_val[i] = u.vec_val[i]; - } - - return *this; -} - -CVector &CVector::operator+=(const CVector &u) -{ - if (nElm != u.nElm) - { - std::cerr << "CVector::operator+=(const CVector &) const: " - << "sizes do not match" << std::endl; - throw(-1); - } - - for (unsigned int i = 0; i < nElm; i++) - vec_val[i] += u.vec_val[i]; - - return *this; -} - -CVector &CVector::operator-=(const CVector &u) -{ - if (nElm != u.nElm) - { - std::cerr << "CVector::operator-=const CVector &) const: " - << "sizes do not match" << std::endl; - throw(-1); - } - - for (unsigned int i = 0; i < nElm; i++) - vec_val[i] -= u.vec_val[i]; - - return *this; -} - -CVector &CVector::operator*=(const double &val) -{ - for (unsigned int i = 0; i < nElm; i++) - vec_val[i] *= val; - - return *this; -} - -CVector &CVector::operator/=(const double &val) -{ - for (unsigned int i = 0; i < nElm; i++) - vec_val[i] /= val; - - return *this; -} - -double &CVector::operator[](const unsigned long &i) const -{ - return vec_val[i]; -} - -double CVector::dotProd(const CVector &v) const -{ - if (nElm != v.nElm) - { - std::cerr << "CVector::dotProd(const CVector &, const CVector &): " - << "sizes do not math" << std::endl; - throw(-1); - } - - double dotProd(0.0); - for (unsigned int i = 0; i < nElm; i++) - dotProd += vec_val[i] * v.vec_val[i]; - - return dotProd; -} - -double CVector::norm() const -{ - double norm(0), tempVal(0); - tempVal = (*this).dotProd(*this); - - if (tempVal < 0) - { - std::cerr << "CVector::norm(): " - << "computed dot product is negative: " << tempVal << std::endl; - throw(-1); - } - - norm = sqrt(tempVal); - - return norm; -} - -void CVector::Reset() -{ - for (unsigned int i = 0; i < nElm; i++) - vec_val[i] = 0; -} - -// --- Definition of the CMatrix class --- - -CMatrix::CMatrix() : nEq(0), nVar(0) -{ -} - -CMatrix::CMatrix(const unsigned long &val_nEq, const unsigned long &val_nVar, - const double &val) -{ - nEq = val_nEq; - nVar = val_nVar; - unsigned long nElm = nEq * nVar; - - mat_val.Initialize(nElm, val); -} - -CMatrix::CMatrix(const CMatrix &A) -{ - nEq = A.nEq; - nVar = A.nVar; - unsigned long nElm = nEq * nVar; - - mat_val.Initialize(nElm, 0.0); - mat_val = A.mat_val; -} - -CMatrix::~CMatrix() -{ -} - -void CMatrix::Initialize(const unsigned long &val_nEq, const unsigned long &val_nVar, const double &val) -{ - nEq = val_nEq; - nVar = val_nVar; - unsigned long nElm = nEq * nVar; - mat_val.Initialize(nElm, val); -} - -void CMatrix::print() const -{ - mat_val.print(); -} - -CMatrix &CMatrix::operator=(const CMatrix &a) -{ - if (this == &a) - return *this; - - if (nEq != a.nEq || nVar != a.nVar) - { - std::cerr << "Sizes do not match for operator = : nEq1 = " << nEq - << " & nEq2 = " << a.nEq << " ; nVar1 = " << nVar - << " & nVar2 = " << a.nVar << std::endl; - throw(-1); - } - else - { - mat_val = a.mat_val; - } - return *this; -} - -CMatrix &CMatrix::operator+=(const CMatrix &a) -{ - if (nEq != a.nEq || nVar != a.nVar) - { - std::cerr << "CMatrix::operator+=(const CMatrix &): " - << "sizes do not match" << std::endl; - throw(-1); - } - else - { - mat_val += a.mat_val; - } - return *this; -} - -CMatrix &CMatrix::operator-=(const CMatrix &a) -{ - if (nEq != a.nEq || nVar != a.nVar) - { - std::cerr << "CMatrix::operator+=(const CMatrix &): " - << "sizes do not match" << std::endl; - throw(-1); - } - else - { - mat_val -= a.mat_val; - } - return *this; -} - -CMatrix &CMatrix::operator*=(const double &val) -{ - mat_val *= val; - return *this; -} - -CMatrix &CMatrix::operator/=(const double &val) -{ - mat_val /= val; - return *this; -} - -unsigned long CMatrix::GetnEq() const -{ - return nEq; -} - -unsigned long CMatrix::GetnVar() const -{ - return nVar; -} - -double *CMatrix::GetMat() const -{ - return mat_val.GetVec(); -} - -CVector CMatrix::GetCVec() const -{ - return mat_val; -} - -void CMatrix::SetElm(const int &i, const int &j, double val) -{ - mat_val[(j - 1) * nEq + (i - 1)] = val; -} - -double CMatrix::GetElm(const int &i, const int &j) const -{ - return mat_val[(j - 1) * nEq + (i - 1)]; -} - -double CMatrix::DiagProduct() const -{ - double prod(1); - if (nEq == nVar) - { - for (unsigned int i = 1; i <= nEq; i++) - { - prod *= GetElm(i, i); - } - } - return prod; -} - -double CMatrix::ComputeDet() const -{ - double Det(1); - int NbChange(0); - double PLU[nEq * nVar]; - int IPIV[nEq]; - int INFO(-1); - - *PLU = *(mat_val.GetVec()); - INFO = LAPACKE_dgetrf(LAPACK_COL_MAJOR, nEq, nVar, PLU, nEq, IPIV); - - for (int i = 0; i < nEq - 1; i++) - { - if (IPIV[i] != i + 1) - NbChange++; - } - return 0.0; -} - -void CMatrix::Reset() -{ - mat_val.Reset(); -} - -CVector MatVecProd(const CMatrix &A, const CVector &b) -{ - CVector x(A.GetnVar()); - cblas_dgemv(CblasColMajor, CblasNoTrans, A.GetnEq(), A.GetnVar(), - 1, A.GetMat(), A.GetnEq(), b.GetVec(), - 1, 0, x.GetVec(), 1); - return x; -} - -CVector ScalVecProd(const double &scal, const CVector &b) -{ - CVector x(b.GetSize()); - cblas_daxpy(b.GetSize(), scal, b.GetVec(), 1, x.GetVec(), 1); - return x; -} - -CMatrix ScalMatProd(const double &scal, const CMatrix &A) -{ - CMatrix copy(A); - copy *= scal; - return copy; -} - -// INDEPENDENT FUNCTIONS -int SolveSys(const CMatrix &A, CVector &b) -{ - const int N = A.GetnEq(); - const int LDA = A.GetnVar(); - CMatrix Mat(A); - int NRHS(1); - int *IPIV; - int LDB = b.GetSize(); - int INFO(-1); - - IPIV = new int[N]; - - INFO = LAPACKE_dgesv(LAPACK_COL_MAJOR, N, NRHS, Mat.GetMat(), - LDA, IPIV, b.GetVec(), LDB); - - return INFO; -} - -void MatrixToVec(int order, double **matrix, double *vecteur, int Nrow, int Ncol, int sizeVec) -{ - if (order == COL_MAJ) - { - for (int j = 0; j < sizeVec; j++) - vecteur[j] = matrix[j % Nrow][j / Nrow]; - } - else if (order == ROW_MAJ) - { - for (int j = 0; j < sizeVec; j++) - vecteur[j] = matrix[j / Ncol][j % Ncol]; - } - else - { - std::cerr << "Wrong storage order" << std::endl; - throw(-1); - } -} - -void VecToMatrix(int order, double **matrix, double *vecteur, - int Nrow, int Ncol, int sizeVec) -{ - if (order == COL_MAJ) - { - for (int i = 0; i < Nrow; i++) - for (int j = 0; j < Ncol; j++) - matrix[i][j] = vecteur[j * Nrow + i]; - } - else if (order == ROW_MAJ) - { - for (int i = 0; i < Nrow; i++) - for (int j = 0; j < Ncol; j++) - matrix[i][j] = vecteur[i * Ncol + j]; - } - else - { - std::cerr << "Wrong storage order" << std::endl; - throw(-1); - } -} - -// OPERATORS OVERLOADS -CVector operator+(CVector &vecA, CVector &vecB) -{ - CVector copy(vecA); - copy += vecB; - return copy; -} - -CVector operator+(const CVector &vecA, const CVector &vecB) -{ - CVector copy(vecA); - copy += vecB; - return copy; -} - -CVector operator+(CVector &vecA, const CVector &vecB) -{ - CVector copy(vecA); - copy += vecB; - return copy; -} - -CVector operator+(const CVector &vecA, CVector &vecB) -{ - CVector copy(vecA); - copy += vecB; - return copy; -} - -CVector operator-(CVector &vecA, CVector &vecB) -{ - CVector copy(vecA); - copy -= vecB; - return copy; -} - -CVector operator-(const CVector &vecA, CVector &vecB) -{ - CVector copy(vecA); - copy -= vecB; - return copy; -} - -CVector operator-(CVector &vecA, const CVector &vecB) -{ - CVector copy(vecA); - copy -= vecB; - return copy; -} - -CVector operator-(const CVector &vecA, const CVector &vecB) -{ - CVector copy(vecA); - copy -= vecB; - return copy; -} - -CVector operator*(CVector &vecA, double &val_mult) -{ - CVector copy(vecA); - copy *= val_mult; - return copy; -} - -CVector operator*(CVector &vecA, const double &val_mult) -{ - CVector copy(vecA); - copy *= val_mult; - return copy; -} - -CVector operator*(double &val_mult, CVector &vecA) -{ - CVector copy(vecA); - copy *= val_mult; - return copy; -} - -CVector operator*(const double &val_mult, CVector &vecA) -{ - CVector copy(vecA); - copy *= val_mult; - return copy; -} - -CVector operator*(const CVector &vecA, double &val_mult) -{ - CVector copy(vecA); - copy *= val_mult; - return copy; -} - -CVector operator*(const CVector &vecA, const double &val_mult) -{ - CVector copy(vecA); - copy *= val_mult; - return copy; -} - -CVector operator*(double &val_mult, const CVector &vecA) -{ - CVector copy(vecA); - copy *= val_mult; - return copy; -} - -CVector operator*(const double &val_mult, const CVector &vecA) -{ - CVector copy(vecA); - copy *= val_mult; - return copy; -} - -CVector operator/(CVector &vecA, double &val_mult) -{ - CVector copy(vecA); - copy /= val_mult; - return copy; -} - -CVector operator/(CVector &vecA, const double &val_mult) -{ - CVector copy(vecA); - copy /= val_mult; - return copy; -} - -CVector operator/(const CVector &vecA, double &val_mult) -{ - CVector copy(vecA); - copy /= val_mult; - return copy; -} - -CVector operator/(const CVector &vecA, const double &val_mult) -{ - CVector copy(vecA); - copy /= val_mult; - return copy; -} - -CMatrix operator+(CMatrix &matA, CMatrix &matB) -{ - CMatrix copy(matA); - copy += matB; - return copy; -} - -CMatrix operator-(CMatrix &matA, CMatrix &matB) -{ - CMatrix copy(matA); - copy -= matB; - return copy; -} - -CMatrix operator*(CMatrix matA, double &val) -{ - CMatrix copy(matA); - copy *= val; - return copy; -} - -CMatrix operator*(double &val, CMatrix matA) -{ - CMatrix copy(matA); - copy *= val; - return copy; -} diff --git a/src/MatVec.h b/src/MatVec.h deleted file mode 100644 index c86502b..0000000 --- a/src/MatVec.h +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once - -#include -#include - -#define ROW_MAJ 0 -#define COL_MAJ 1 - -class CVector -{ - unsigned long nElm; - double *vec_val; - -public: - CVector(); - CVector(const unsigned long &size, const double &val = 0.0); - CVector(const CVector &u); - ~CVector(); - unsigned long GetSize() const; - double *GetVec() const; - void print() const; - void Initialize(const unsigned long &size, const double &val = 0.0); - void SetAllValues(const double &val); - CVector &operator=(const CVector &u); - CVector &operator+=(const CVector &u); - CVector &operator-=(const CVector &u); - CVector &operator*=(const double &val); - CVector &operator/=(const double &val); - double &operator[](const unsigned long &i) const; - double norm() const; - double dotProd(const CVector &v) const; - void Reset(); -}; - -class CMatrix -{ - unsigned long nEq; - unsigned long nVar; - CVector mat_val; - -public: - CMatrix(); - CMatrix(const unsigned long &val_nEq, const unsigned long &val_nVar, const double &val = 0.0); - CMatrix(const CMatrix &A); - ~CMatrix(); - void Initialize(const unsigned long &val_nEq, const unsigned long &val_nVar, const double &val = 0.0); - void print() const; - CMatrix &operator=(const CMatrix &a); - CMatrix &operator+=(const CMatrix &a); - CMatrix &operator-=(const CMatrix &a); - CMatrix &operator*=(const double &val); - CMatrix &operator/=(const double &val); - unsigned long GetnEq() const; - unsigned long GetnVar() const; - double *GetMat() const; - CVector GetCVec() const; - void SetElm(const int &i, const int &j, double val); - double GetElm(const int &i, const int &j) const; - double DiagProduct() const; - double ComputeDet() const; - void Reset(); -}; - -CVector MatVecProd(const CMatrix &A, const CVector &b); -CVector ScalVecProd(const double &scal, const CVector &b); -CMatrix ScalMatProd(const double &scal, const CMatrix &A); -int SolveSys(const CMatrix &A, CVector &b); - -void MatrixToVec(int order, double **matrix, double *vecteur, int Nrow, int Ncol, int sizeVec); -void VecToMatrix(int order, double **matrix, double *vecteur, int Nrow, int Ncol, int sizeVec); - -// OPERATOR + -CVector operator+(CVector &vecA, CVector &vecB); -CVector operator+(const CVector &vecA, const CVector &vecB); -CVector operator+(CVector &vecA, const CVector &vecB); -CVector operator+(const CVector &vecA, CVector &vecB); -CMatrix operator+(const CMatrix &matA, const CMatrix &matB); - -// OPERATOR - -CVector operator-(CVector &vecA, CVector &vecB); -CVector operator-(const CVector &vecA, CVector &vecB); -CVector operator-(CVector &vecA, const CVector &vecB); -CVector operator-(const CVector &vecA, const CVector &vecB); -CMatrix operator-(const CMatrix &matA, const CMatrix &matB); - -// OPERATOR * -CVector operator*(CVector &vecA, double &val_mult); -CVector operator*(CVector &vecA, const double &val_mult); -CVector operator*(const CVector &vecA, double &val_mult); -CVector operator*(const CVector &vecA, const double &val_mult); -CVector operator*(double &val_mult, CVector &vecA); -CVector operator*(const double &val_mult, CVector &vecA); -CVector operator*(double &val_mult, const CVector &vecA); -CVector operator*(const double &val_mult, const CVector &vecA); -CMatrix operator*(CMatrix matA, double &val); -CMatrix operator*(double &val, CMatrix matA); - -// OPERATOR / -CVector operator/(CVector &vecA, double &val_mult); -CVector operator/(CVector &vecA, const double &val_mult); -CVector operator/(const CVector &vecA, double &val_mult); -CVector operator/(const CVector &vecA, const double &val_mult); diff --git a/src/NativeSolidSolver.cpp b/src/NativeSolidSolver.cpp deleted file mode 100644 index ee17c2a..0000000 --- a/src/NativeSolidSolver.cpp +++ /dev/null @@ -1,1117 +0,0 @@ -#include "NativeSolidSolver.h" -#include -#include - -const int MASTER_NODE = 0; - -NativeSolidSolver::NativeSolidSolver(std::string str, bool FSIComp) : confFile(str) -{ - int rank = MASTER_NODE; - - historyFile.open("NativeHistory.dat", std::ios::out); - historyFile2.open("NativeHistoryFSI.dat", std::ios::out); - - // --- MPI initialization, and buffer setting --- -#ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#endif - - if (rank == MASTER_NODE) - { - if (FSIComp) - std::cout << std::endl - << "***************************** Setting NativeSolid for FSI simulation *****************************" << std::endl; - else - std::cout << std::endl - << "***************************** Setting NativeSolid for CSD simulation *****************************" << std::endl; - } - - config = NULL; - output = NULL; - geometry = NULL; - structure = NULL; - integrator = NULL; - - //--- Initialize the main containers --- - config = new Config(confFile); - output = new Output(); - - //--- Read CSD configuration file --- - std::cout << std::endl - << "\n----------------------- Reading Native configuration file ----------------------" << std::endl; - config->ReadConfig(); - - //--- Read a SU2 native mesh file --- - std::cout << std::endl - << "\n----------------------- Reading SU2 based mesh file ----------------------" << std::endl; - geometry = new Geometry(config); - - //--- Initialize structural container and create the structural model --- - std::cout << std::endl - << "\n----------------------- Creating the structural model ----------------------" << std::endl; - structure = new Structure(config); - - std::cout << std::endl - << "\n----------------------- Creating the FSI interface ----------------------" << std::endl; - double *Coord; - unsigned long iMarker(0), iPoint; - - while (iMarker < geometry->GetnMarkers()) - { - if (geometry->GetMarkersMoving(iMarker)) - { - nSolidInterfaceVertex = geometry->nVertex[iMarker]; - break; - } - iMarker++; - } - - varCoordNorm = 0.0; - - std::cout << nSolidInterfaceVertex << " nodes on the moving interface have to be tracked." << std::endl; - - //--- Initialize the temporal integrator --- - std::cout << std::endl - << "\n----------------------- Setting integration parameter ----------------------" << std::endl; - integrator = new Integration(config, structure); - integrator->SetInitialConditions(config, structure); - - std::cout << std::endl - << "\n----------------------- Setting FSI features ----------------------" << std::endl; - q_uM1.Initialize(structure->GetnDof()); - q_uM1.Reset(); - - if (rank == MASTER_NODE) - { - if (structure->GetnDof() == 1) - { - if (config->GetUnsteady() == "YES") - { - historyFile << std::fixed - << std::setw(10) << "Delta_t" - << std::setw(10) << "FSI iter" - << std::setw(15) << "Displacement" - << std::setw(15) << "Velocity" - << std::setw(15) << "Acceleration" << std::endl; - historyFile2 << std::fixed - << std::setw(10) << "Time" - << std::setw(10) << "FSI iter" - << std::setw(15) << "Displacement" - << std::setw(15) << "Velocity" - << std::setw(15) << "Acceleration" << std::endl; - } - else - { - historyFile << std::fixed - << std::setw(10) << "Delta_t" - << std::setw(10) << "FSI iter" - << std::setw(15) << "Displacement" << std::endl; - historyFile2 << std::fixed - << std::setw(10) << "FSI iter" - << std::setw(15) << "Displacement" << std::endl; - } - } - else if (structure->GetnDof() == 2) - { - if (config->GetUnsteady() == "YES") - { - historyFile << std::fixed - << std::setw(10) << "Delta_t" - << std::setw(10) << "FSI iter" - << std::setw(15) << "Displacement 1" - << std::setw(15) << "Displacement 2" - << std::setw(15) << "Velocity 1" - << std::setw(15) << "Velocity 2" - << std::setw(15) << "Acceleration 1" - << std::setw(15) << "Acceleration 2" << std::endl; - historyFile2 << std::fixed - << std::setw(10) << "Time" - << std::setw(10) << "FSI iter" - << std::setw(15) << "Displacement 1" - << std::setw(15) << "Displacement 2" - << std::setw(15) << "Velocity 1" - << std::setw(15) << "Velocity 2" - << std::setw(15) << "Acceleration 1" - << std::setw(15) << "Acceleration 2" << std::endl; - } - else - { - historyFile << std::fixed - << std::setw(10) << "Delta_t" - << std::setw(10) << "FSI iter" - << std::setw(15) << "Displacement 1" - << std::setw(15) << "Displacement 2" << std::endl; - historyFile2 << std::fixed - << std::setw(10) << "FSI iter" - << std::setw(15) << "Displacement 1" - << std::setw(15) << "Displacement 2" << std::endl; - } - } - } - - if (rank == MASTER_NODE) - { - if (FSIComp) - std::cout << std::endl - << "***************************** NativeSolid is set for FSI simulation *****************************" << std::endl; - else - std::cout << std::endl - << "***************************** NativeSolid is set for CSD simulation *****************************" << std::endl; - } -} - -NativeSolidSolver::~NativeSolidSolver() {} - -void NativeSolidSolver::exit() -{ - - int rank = MASTER_NODE; - -#ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#endif - - historyFile.close(); - if (rank == MASTER_NODE) - { - std::cout << "Solid history file is closed." << std::endl; - std::cout << std::endl - << "***************************** Exit NativeSolid *****************************" << std::endl; - } - - if (config != NULL) - delete config; - if (geometry != NULL) - delete geometry; - if (structure != NULL) - delete structure; - if (integrator != NULL) - delete integrator; - if (output != NULL) - delete output; -} - -void NativeSolidSolver::preprocessIteration(unsigned long ExtIter) -{ - - integrator->SetExtIter(ExtIter); -} - -void NativeSolidSolver::timeIteration(double t0, double tf) -{ - - integrator->TemporalIteration(t0, tf, structure); - - // mapRigidBodyMotion(false, false); - computeInterfacePosVel(false); -} - -/* -void NativeSolidSolver::mapRigidBodyMotion(bool prediction, bool initialize){ - - double *Coord, *Coord_n, newCoord[3], Center[3], Center_n[3], newCenter[3], rotCoord[3], r[3]; - double varCoord[3] = {0.0, 0.0, 0.0}; - double rotMatrix[3][3] = {{0.0,0.0,0.0}, {0.0,0.0,0.0}, {0.0,0.0,0.0}}; - double dTheta, dPhi, dPsi; - double cosTheta, sinTheta, cosPhi, sinPhi, cosPsi, sinPsi; - unsigned short iMarker, iVertex, nDim(3); - unsigned long iPoint; - - double deltaT, q_n, qdot_n, qdot_nM1, q_nP1; - double alpha_n, alphadot_n, alphadot_nM1, alpha_nP1; - double alpha0, alpha1; - double disp, dAlpha; - double varCoordNorm2(0.0); - - //--- Get the current center of rotation (can vary at each iteration) --- - Center[0] = structure->GetCenterOfRotation_x(); - Center[1] = structure->GetCenterOfRotation_y(); - Center[2] = structure->GetCenterOfRotation_z(); - - //--- Get the center of rotation from previous time step --- - Center_n[0] = structure->GetCenterOfRotation_n_x(); - Center_n[1] = structure->GetCenterOfRotation_n_y(); - Center_n[2] = structure->GetCenterOfRotation_n_z(); - - if(!prediction){ - dTheta = 0.0; - dPhi = 0.0; - if (config->GetStructType() == "AIRFOIL"){ - dPsi = -( (*(integrator->GetDisp()))[1] - (*(integrator->GetDisp_n()))[1]); - newCenter[0] = Center[0]; - newCenter[1] = -(*(integrator->GetDisp()))[0]; - newCenter[2] = Center[2]; - disp = newCenter[1] - Center_n[1]; - } - else if(config->GetStructType() == "SPRING_HOR"){ - dPsi = 0.0; - newCenter[0] = (*(integrator->GetDisp()))[0]; - newCenter[1] = Center[1]; - newCenter[2] = Center[2]; - } - } - else{ - deltaT = config->GetDeltaT(); - alpha0 = 1.0; - alpha1 = 0.5; //Second order prediction - - q_n = (*(integrator->GetDisp()))[0]; - qdot_n = (*(integrator->GetVel()))[0]; - qdot_nM1 = (*(integrator->GetVel_n()))[0]; - q_nP1 = q_n + alpha0*deltaT*qdot_n + alpha1*deltaT*(qdot_n - qdot_nM1); - disp = q_nP1-q_n; - - if(structure->GetnDof() == 2){ - alpha_n = (*(integrator->GetDisp()))[1]; - alphadot_n = (*(integrator->GetVel()))[1]; - alphadot_nM1 = (*(integrator->GetVel_n()))[1]; - alpha_nP1 = alpha_n + alpha0*deltaT*alphadot_n + alpha1*deltaT*(alphadot_n - alphadot_nM1); - dAlpha = alpha_nP1-alpha_n; - } - dTheta = 0.0; - dPhi = 0.0; - if (config->GetStructType() == "AIRFOIL"){ - dPsi = -dAlpha; - newCenter[0] = Center[0]; - newCenter[1] = -q_nP1; - newCenter[2] = Center[2]; - } - else{ - dPsi = 0.0; - } - } - - cosTheta = cos(dTheta); cosPhi = cos(dPhi); cosPsi = cos(dPsi); - sinTheta = sin(dTheta); sinPhi = sin(dPhi); sinPsi = sin(dPsi); - - //--- Compute the rotation matrix. The implicit ordering is rotation about the x-axis, y-axis, then z-axis. --- - - rotMatrix[0][0] = cosPhi*cosPsi; - rotMatrix[1][0] = cosPhi*sinPsi; - rotMatrix[2][0] = -sinPhi; - - rotMatrix[0][1] = sinTheta*sinPhi*cosPsi - cosTheta*sinPsi; - rotMatrix[1][1] = sinTheta*sinPhi*sinPsi + cosTheta*cosPsi; - rotMatrix[2][1] = sinTheta*cosPhi; - - rotMatrix[0][2] = cosTheta*sinPhi*cosPsi + sinTheta*sinPsi; - rotMatrix[1][2] = cosTheta*sinPhi*sinPsi - sinTheta*cosPsi; - rotMatrix[2][2] = cosTheta*cosPhi; - - for(iMarker = 0; iMarker < geometry->GetnMarkers(); iMarker++){ - if (geometry->markersMoving[iMarker] == true){ - for(iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++){ - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - Coord_n = geometry->node[iPoint]->GetCoord_n(); - - if(config->GetUnsteady() == "YES"){ - for (int iDim=0; iDim < nDim; iDim++){ - r[iDim] = Coord_n[iDim] - Center_n[iDim]; - } - } - else{ - for (int iDim=0; iDim < nDim; iDim++){ - r[iDim] = Coord[iDim] - Center[iDim]; - } - } - - rotCoord[0] = rotMatrix[0][0]*r[0] - + rotMatrix[0][1]*r[1] - + rotMatrix[0][2]*r[2]; - - rotCoord[1] = rotMatrix[1][0]*r[0] - + rotMatrix[1][1]*r[1] - + rotMatrix[1][2]*r[2]; - - rotCoord[2] = rotMatrix[2][0]*r[0] - + rotMatrix[2][1]*r[1] - + rotMatrix[2][2]*r[2]; - - for(int iDim=0; iDim < nDim; iDim++){ - newCoord[iDim] = newCenter[iDim] + rotCoord[iDim]; - varCoord[iDim] = newCoord[iDim] - Coord[iDim]; - } - - varCoordNorm2 += varCoord[0]*varCoord[0] + varCoord[1]*varCoord[1] + varCoord[2]*varCoord[2]; - - //--- Apply change of coordinates to the node on the moving interface --- - geometry->node[iPoint]->SetCoord(newCoord); - - //--- At initialisation, propagate the initial position of the inteface in the past --- - if(initialize) geometry->node[iPoint]->SetCoord_n(newCoord); - } - } - } - - varCoordNorm = sqrt(varCoordNorm2); - - //--- Update the position of the center of rotation --- - structure->SetCenterOfRotation_X(newCenter[0]); - structure->SetCenterOfRotation_Y(newCenter[1]); - structure->SetCenterOfRotation_Z(newCenter[2]); -} -*/ - -void NativeSolidSolver::computeInterfacePosVel(bool initialize) -{ - double *Coord, *Coord_n, newCoord[3], newVel[3], Center[3], Center_n[3], newCenter[3], centerVel[3], rotCoord[3], r[3]; - double varCoord[3] = {0.0, 0.0, 0.0}; - double rotMatrix[3][3] = {{0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}}; - double dTheta, dPhi, dPsi; - double psidot; - double cosTheta, sinTheta, cosPhi, sinPhi, cosPsi, sinPsi; - unsigned short iMarker, iVertex, nDim(3); - unsigned long iPoint; - double varCoordNorm2(0.0); - - //--- Get the current center of rotation (can vary at each iteration) --- - Center[0] = structure->GetCenterOfRotation_x(); - Center[1] = structure->GetCenterOfRotation_y(); - Center[2] = structure->GetCenterOfRotation_z(); - - //--- Get the center of rotation from previous time step --- - Center_n[0] = structure->GetCenterOfRotation_n_x(); - Center_n[1] = structure->GetCenterOfRotation_n_y(); - Center_n[2] = structure->GetCenterOfRotation_n_z(); - - dTheta = 0.0; - dPhi = 0.0; - if (config->GetStructType() == "AIRFOIL") - { - dPsi = -((integrator->GetSolver()->GetDisp())[1] - (integrator->GetSolver()->GetDisp_n())[1]); - psidot = (integrator->GetSolver()->GetVel())[1]; - newCenter[0] = Center[0]; - newCenter[1] = -(integrator->GetSolver()->GetDisp())[0]; - newCenter[2] = Center[2]; - centerVel[0] = 0.0; - centerVel[1] = -(integrator->GetSolver()->GetVel())[0]; - centerVel[2] = 0.0; - } - else if (config->GetStructType() == "SPRING_HOR") - { - dPsi = 0.0; - psidot = 0.0; - newCenter[0] = (integrator->GetSolver()->GetDisp())[0]; - newCenter[1] = Center[1]; - newCenter[2] = Center[2]; - centerVel[0] = (integrator->GetSolver()->GetVel())[0]; - centerVel[1] = 0.0; - centerVel[2] = 0.0; - } - else if (config->GetStructType() == "SPRING_VER") - { - dPsi = 0.0; - psidot = 0.0; - newCenter[0] = Center[0]; - newCenter[1] = (integrator->GetSolver()->GetDisp())[0]; - newCenter[2] = Center[2]; - centerVel[0] = 0.0; - centerVel[1] = (integrator->GetSolver()->GetVel())[0]; - centerVel[2] = 0.0; - } - else - { - } - - cosTheta = cos(dTheta); - cosPhi = cos(dPhi); - cosPsi = cos(dPsi); - sinTheta = sin(dTheta); - sinPhi = sin(dPhi); - sinPsi = sin(dPsi); - - //--- Compute the rotation matrix. The implicit - // ordering is rotation about the x-axis, y-axis, then z-axis. --- - - rotMatrix[0][0] = cosPhi * cosPsi; - rotMatrix[1][0] = cosPhi * sinPsi; - rotMatrix[2][0] = -sinPhi; - - rotMatrix[0][1] = sinTheta * sinPhi * cosPsi - cosTheta * sinPsi; - rotMatrix[1][1] = sinTheta * sinPhi * sinPsi + cosTheta * cosPsi; - rotMatrix[2][1] = sinTheta * cosPhi; - - rotMatrix[0][2] = cosTheta * sinPhi * cosPsi + sinTheta * sinPsi; - rotMatrix[1][2] = cosTheta * sinPhi * sinPsi - sinTheta * cosPsi; - rotMatrix[2][2] = cosTheta * cosPhi; - - for (iMarker = 0; iMarker < geometry->GetnMarkers(); iMarker++) - { - if (geometry->markersMoving[iMarker] == true) - { - for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) - { - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - Coord_n = geometry->node[iPoint]->GetCoord_n(); - - if (config->GetUnsteady() == "YES") - { - for (int iDim = 0; iDim < nDim; iDim++) - { - r[iDim] = Coord_n[iDim] - Center_n[iDim]; - } - } - else - { - for (int iDim = 0; iDim < nDim; iDim++) - { - r[iDim] = Coord[iDim] - Center[iDim]; - } - } - - rotCoord[0] = rotMatrix[0][0] * r[0] + rotMatrix[0][1] * r[1] + rotMatrix[0][2] * r[2]; - - rotCoord[1] = rotMatrix[1][0] * r[0] + rotMatrix[1][1] * r[1] + rotMatrix[1][2] * r[2]; - - rotCoord[2] = rotMatrix[2][0] * r[0] + rotMatrix[2][1] * r[1] + rotMatrix[2][2] * r[2]; - - for (int iDim = 0; iDim < nDim; iDim++) - { - newCoord[iDim] = newCenter[iDim] + rotCoord[iDim]; - varCoord[iDim] = newCoord[iDim] - Coord[iDim]; - } - - newVel[0] = centerVel[0] + psidot * (newCoord[1] - newCenter[1]); - newVel[1] = centerVel[1] - psidot * (newCoord[0] - newCenter[0]); - newVel[2] = centerVel[2] + 0.0; - - varCoordNorm2 += varCoord[0] * varCoord[0] + varCoord[1] * varCoord[1] + varCoord[2] * varCoord[2]; - - //--- Apply change of coordinates to the node on the moving interface --- - geometry->node[iPoint]->SetCoord(newCoord); - geometry->node[iPoint]->SetVel(newVel); - - //--- At initialisation, propagate the initial position of the inteface in the past --- - if (initialize) - { - geometry->node[iPoint]->SetCoord_n(newCoord); - geometry->node[iPoint]->SetVel_n(newVel); - } - } - } - } - - varCoordNorm = sqrt(varCoordNorm2); - - //--- Update the position of the center of rotation --- - structure->SetCenterOfRotation_X(newCenter[0]); - structure->SetCenterOfRotation_Y(newCenter[1]); - structure->SetCenterOfRotation_Z(newCenter[2]); -} - -void NativeSolidSolver::setInitialDisplacements() -{ - // mapRigidBodyMotion(false, true); - computeInterfacePosVel(true); -} - -void NativeSolidSolver::staticComputation() -{ - - integrator->StaticIteration(structure); - - // mapRigidBodyMotion(false,false); - computeInterfacePosVel(false); -} - -void NativeSolidSolver::writeSolution(double currentTime, double lastTime, double currentFSIIter, unsigned long ExtIter, unsigned long NbExtIter) -{ - - int rank = MASTER_NODE; - double DeltaT; - std::string restartFileName; - unsigned long DeltaIter = config->GetDeltaIterWrite(); - - DeltaT = currentTime - lastTime; - -#ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#endif - - if (rank == MASTER_NODE) - { - if (structure->GetnDof() == 1) - { - if (config->GetUnsteady() == "YES") - { - // if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement\"" << "\t" << "\"Velocity\"" << "\t" << "\"Acceleration\"" << "\t" << "\"Acceleration variable\"" << std::endl; - historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << std::endl; - } - else - { - // if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement\"" << std::endl; - historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << std::endl; - } - } - else if (structure->GetnDof() == 2) - { - if (config->GetUnsteady() == "YES") - { - // if(currentTime == config->GetStartTime()) historyFile << "\"Time\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 2\"" << "\t" << "\"Velocity 1\"" << "\t" << "\"Velocity 2\"" << "\t" << "\"Acceleration 1\"" << "\t" << "\"Acceleration 2\"" << "\t" << "\"Acceleration variable 1\"" << "\t" << "\"Acceleration variable 2\"" << std::endl; - historyFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << std::endl; - } - else - { - // if(currentFSIIter == config->GetStartTime()) historyFile << "\"FSI Iteration\"" << "\t" << "\"Displacement 1\"" << "\t" << "\"Displacement 1\"" << std::endl; - historyFile << currentFSIIter << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << std::endl; - } - } - } - - if (config->GetUnsteady() == "YES") - { - if (ExtIter % DeltaIter == 0 || ExtIter == NbExtIter) - { - restartFileName = config->GetRestartFile(); - restartFile.open(restartFileName.c_str(), std::ios::out); - if (structure->GetnDof() == 1) - { - restartFile << "\"Time\"" - << "\t" - << "\"Displacement\"" - << "\t" - << "\"Velocity\"" - << "\t" - << "\"Acceleration\"" - << "\t" - << "\"Acceleration variable\"" << std::endl; - restartFile << currentTime - DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << std::endl; - restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << std::endl; - } - else if (structure->GetnDof() == 2) - { - restartFile << "\"Time\"" - << "\t" - << "\"Displacement 1\"" - << "\t" - << "\"Displacement 2\"" - << "\t" - << "\"Velocity 1\"" - << "\t" - << "\"Velocity 2\"" - << "\t" - << "\"Acceleration 1\"" - << "\t" - << "\"Acceleration 2\"" - << "\t" - << "\"Acceleration variable 1\"" - << "\t" - << "\"Acceleration variable 2\"" << std::endl; - restartFile << currentTime - DeltaT << "\t" << (integrator->GetSolver()->GetDisp_n())[0] << "\t" << (integrator->GetSolver()->GetDisp_n())[1] << "\t" << (integrator->GetSolver()->GetVel_n())[0] << "\t" << (integrator->GetSolver()->GetVel_n())[1] << "\t" << (integrator->GetSolver()->GetAcc_n())[0] << "\t" << (integrator->GetSolver()->GetAcc_n())[1] << "\t" << (integrator->GetSolver()->GetAccVar_n())[0] << "\t" << (integrator->GetSolver()->GetAccVar_n())[1] << std::endl; - restartFile << currentTime << "\t" << (integrator->GetSolver()->GetDisp())[0] << "\t" << (integrator->GetSolver()->GetDisp())[1] << "\t" << (integrator->GetSolver()->GetVel())[0] << "\t" << (integrator->GetSolver()->GetVel())[1] << "\t" << (integrator->GetSolver()->GetAcc())[0] << "\t" << (integrator->GetSolver()->GetAcc())[1] << "\t" << (integrator->GetSolver()->GetAccVar())[0] << "\t" << (integrator->GetSolver()->GetAccVar())[1] << std::endl; - } - restartFile.close(); - } - } -} - -void NativeSolidSolver::saveSolution() -{ - - int rank = MASTER_NODE; - double DeltaT; - // std::string restartFileName; - // unsigned long DeltaIter = config->GetDeltaIterWrite(); - unsigned long ExtIter = integrator->GetExtIter(); - - DeltaT = config->GetDeltaT(); - -#ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#endif - - if (rank == MASTER_NODE) - { - if (structure->GetnDof() == 1) - { - if (config->GetUnsteady() == "YES") - { - historyFile << std::fixed - << std::setw(10) << DeltaT - << std::setw(10) << ExtIter - << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] - << std::setw(15) << (integrator->GetSolver()->GetVel())[0] - << std::setw(15) << (integrator->GetSolver()->GetAcc())[0] << std::endl; - } - else - { - historyFile << std::fixed - << std::setw(10) << DeltaT - << std::setw(10) << ExtIter - << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] << std::endl; - } - } - else if (structure->GetnDof() == 2) - { - if (config->GetUnsteady() == "YES") - { - historyFile << std::fixed - << std::setw(10) << DeltaT - << std::setw(10) << ExtIter - << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] - << std::setw(15) << (integrator->GetSolver()->GetDisp())[1] - << std::setw(15) << (integrator->GetSolver()->GetVel())[0] - << std::setw(15) << (integrator->GetSolver()->GetVel())[1] - << std::setw(15) << (integrator->GetSolver()->GetAcc())[0] - << std::setw(15) << (integrator->GetSolver()->GetAcc())[1] << std::endl; - } - else - { - historyFile << std::fixed - << std::setw(10) << DeltaT - << std::setw(10) << ExtIter - << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] - << std::setw(15) << (integrator->GetSolver()->GetDisp())[1] << std::endl; - } - } - } -} - -void NativeSolidSolver::writeSolution(double time, int FSIter) -{ - - int rank = MASTER_NODE; - -#ifdef HAVE_MPI - MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#endif - - if (rank == MASTER_NODE) - { - if (structure->GetnDof() == 1) - { - if (config->GetUnsteady() == "YES") - { - historyFile2 << std::fixed - << std::setw(10) << time - << std::setw(10) << FSIter - << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] - << std::setw(15) << (integrator->GetSolver()->GetVel())[0] - << std::setw(15) << (integrator->GetSolver()->GetAcc())[0] << std::endl; - } - else - { - historyFile2 << std::fixed - << std::setw(10) << FSIter - << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] << std::endl; - } - } - else if (structure->GetnDof() == 2) - { - if (config->GetUnsteady() == "YES") - { - historyFile2 << std::fixed - << std::setw(10) << time - << std::setw(10) << FSIter - << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] - << std::setw(15) << (integrator->GetSolver()->GetDisp())[1] - << std::setw(15) << (integrator->GetSolver()->GetVel())[0] - << std::setw(15) << (integrator->GetSolver()->GetVel())[1] - << std::setw(15) << (integrator->GetSolver()->GetAcc())[0] - << std::setw(15) << (integrator->GetSolver()->GetAcc())[1] << std::endl; - } - else - { - historyFile2 << std::fixed - << std::setw(10) << FSIter - << std::setw(15) << (integrator->GetSolver()->GetDisp())[0] - << std::setw(15) << (integrator->GetSolver()->GetDisp())[1] << std::endl; - } - } - } -} - -void NativeSolidSolver::updateSolution() -{ - - if (config->GetUnsteady() == "YES") - { - integrator->UpdateSolution(); - geometry->UpdateGeometry(); - structure->SetCenterOfRotation_n_X(structure->GetCenterOfRotation_x()); - structure->SetCenterOfRotation_n_Y(structure->GetCenterOfRotation_y()); - structure->SetCenterOfRotation_n_Z(structure->GetCenterOfRotation_z()); - } - else - q_uM1 = (integrator->GetSolver()->GetDisp()); -} - -/* -void NativeSolidSolver::updateGeometry() -{ - if (config->GetUnsteady() == "YES") - { - geometry->UpdateGeometry(); - structure->SetCenterOfRotation_n_X(structure->GetCenterOfRotation_x()); - structure->SetCenterOfRotation_n_Y(structure->GetCenterOfRotation_y()); - structure->SetCenterOfRotation_n_Z(structure->GetCenterOfRotation_z()); - } -} - -void NativeSolidSolver::displacementPredictor() -{ - mapRigidBodyMotion(true, false); -} -*/ - -unsigned short NativeSolidSolver::getFSIMarkerID() -{ - - unsigned short iMarker(0), IDtoSend; - - while (iMarker < geometry->GetnMarkers()) - { - if (geometry->GetMarkersMoving(iMarker)) - { - IDtoSend = iMarker; - break; - } - iMarker++; - } - return IDtoSend; -} - -unsigned long NativeSolidSolver::getNumberOfSolidInterfaceNodes(unsigned short iMarker) -{ - return nSolidInterfaceVertex; -} - -unsigned int NativeSolidSolver::getInterfaceNodeGlobalIndex(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - - iPoint = geometry->vertex[iMarker][iVertex]; - - return iPoint; -} - -double NativeSolidSolver::getInterfaceNodePosX(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - - return Coord[0]; -} - -double NativeSolidSolver::getInterfaceNodePosY(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - - return Coord[1]; -} - -double NativeSolidSolver::getInterfaceNodePosZ(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - - return 0.0; // 3D is not really implemented in this solver... -} - -double NativeSolidSolver::getInterfaceNodePosX0(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord0(); - - return Coord[0]; -} - -double NativeSolidSolver::getInterfaceNodePosY0(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord0(); - - return Coord[1]; -} - -double NativeSolidSolver::getInterfaceNodePosZ0(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord0(); - - return 0.0; -} - -double NativeSolidSolver::getInterfaceNodeDispX(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord, *Coord0; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - Coord0 = geometry->node[iPoint]->GetCoord0(); - - return Coord[0] - Coord0[0]; -} - -double NativeSolidSolver::getInterfaceNodeDispY(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord, *Coord0; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - Coord0 = geometry->node[iPoint]->GetCoord0(); - return Coord[1] - Coord0[1]; -} - -double NativeSolidSolver::getInterfaceNodeDispZ(unsigned short iMarker, unsigned short iVertex) -{ - - unsigned long iPoint; - double *Coord, *Coord0; - - iPoint = geometry->vertex[iMarker][iVertex]; - Coord = geometry->node[iPoint]->GetCoord(); - Coord0 = geometry->node[iPoint]->GetCoord0(); - - return Coord[2] - Coord0[2]; -} - -double NativeSolidSolver::getInterfaceNodeVelX(unsigned short iMarker, unsigned short iVertex) -{ - unsigned long iPoint; - double *Vel; - - iPoint = geometry->vertex[iMarker][iVertex]; - Vel = geometry->node[iPoint]->GetVel(); - - return Vel[0]; -} - -double NativeSolidSolver::getInterfaceNodeVelY(unsigned short iMarker, unsigned short iVertex) -{ - unsigned long iPoint; - double *Vel; - - iPoint = geometry->vertex[iMarker][iVertex]; - Vel = geometry->node[iPoint]->GetVel(); - - return Vel[1]; -} - -double NativeSolidSolver::getInterfaceNodeVelZ(unsigned short iMarker, unsigned short iVertex) -{ - unsigned long iPoint; - double *Vel; - - iPoint = geometry->vertex[iMarker][iVertex]; - Vel = geometry->node[iPoint]->GetVel(); - - return Vel[2]; -} - -double NativeSolidSolver::getInterfaceNodeVelXNm1(unsigned short iMarker, unsigned short iVertex) -{ - unsigned long iPoint; - double *Vel_n; - - iPoint = geometry->vertex[iMarker][iVertex]; - Vel_n = geometry->node[iPoint]->GetVel_n(); - - return Vel_n[0]; -} - -double NativeSolidSolver::getInterfaceNodeVelYNm1(unsigned short iMarker, unsigned short iVertex) -{ - unsigned long iPoint; - double *Vel_n; - - iPoint = geometry->vertex[iMarker][iVertex]; - Vel_n = geometry->node[iPoint]->GetVel_n(); - - return Vel_n[1]; -} - -double NativeSolidSolver::getInterfaceNodeVelZNm1(unsigned short iMarker, unsigned short iVertex) -{ - unsigned long iPoint; - double *Vel_n; - - iPoint = geometry->vertex[iMarker][iVertex]; - Vel_n = geometry->node[iPoint]->GetVel_n(); - - return Vel_n[2]; -} - -double NativeSolidSolver::getRotationCenterPosX() -{ - - return structure->GetCenterOfRotation_x(); -} - -double NativeSolidSolver::getRotationCenterPosY() -{ - - return structure->GetCenterOfRotation_y(); -} - -double NativeSolidSolver::getRotationCenterPosZ() -{ - - return structure->GetCenterOfRotation_z(); -} - -void NativeSolidSolver::setGeneralisedForce() -{ - - unsigned short iVertex, iMarker; - unsigned long iPoint; - double ForceX(0.0), ForceY(0.0), ForceZ(0.0); - double *force; - - iMarker = getFSIMarkerID(); - - for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) - { - iPoint = geometry->vertex[iMarker][iVertex]; - force = geometry->node[iPoint]->GetForce(); - ForceX += force[0]; - ForceY += force[1]; - ForceZ += force[2]; - } - - if (config->GetStructType() == "SPRING_HOR") - { - (integrator->GetSolver()->GetLoads())[0] = ForceX; - } - else if (config->GetStructType() == "SPRING_VER") - { - (integrator->GetSolver()->GetLoads())[0] = ForceY; - } - else if (config->GetStructType() == "AIRFOIL") - { - (integrator->GetSolver()->GetLoads())[0] = -ForceY; - } - else - { - std::cerr << "Wrong structural type for applying global fluild loads !" << std::endl; - throw(-1); - } -} - -void NativeSolidSolver::setGeneralisedForce(double Fx, double Fy) -{ - - if (config->GetStructType() == "SPRING_HOR") - { - (integrator->GetSolver()->GetLoads())[0] = Fx; - } - else if (config->GetStructType() == "SPRING_VER") - { - (integrator->GetSolver()->GetLoads())[0] = Fy; - } - else if (config->GetStructType() == "AIRFOIL") - { - (integrator->GetSolver()->GetLoads())[0] = -Fy; - } - else - { - std::cerr << "Wrong structural type for applying global fluild loads !" << std::endl; - throw(-1); - } -} - -void NativeSolidSolver::setGeneralisedMoment() -{ - - unsigned short iVertex, iMarker; - unsigned long iPoint; - double Moment(0.0), CenterX, CenterY, CenterZ; - double *Force; - double *Coord; - - iMarker = getFSIMarkerID(); - - for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) - { - iPoint = geometry->vertex[iMarker][iVertex]; - Force = geometry->node[iPoint]->GetForce(); - Coord = geometry->node[iPoint]->GetCoord(); - CenterX = getRotationCenterPosX(); - CenterY = getRotationCenterPosY(); - Moment += (Force[1] * (Coord[0] - CenterX) - Force[0] * (Coord[1] - CenterY)); - } - - if (config->GetStructType() == "AIRFOIL") - { - (integrator->GetSolver()->GetLoads())[1] = -Moment; - } - else if (config->GetStructType() == "SPRING_VER") - { - } - else if (config->GetStructType() == "SPRING_HOR") - { - } - else - { - std::cerr << "Wrong structural type for applying global fluild loads !" << std::endl; - throw(-1); - } -} - -void NativeSolidSolver::setGeneralisedMoment(double M) -{ - - if (config->GetStructType() == "AIRFOIL") - { - (integrator->GetSolver()->GetLoads())[1] = -M; - } - else if (config->GetStructType() == "SPRING_VER") - { - } - else if (config->GetStructType() == "SPRING_HOR") - { - } - else - { - std::cerr << "Wrong structural type for applying global fluild loads !" << std::endl; - throw(-1); - } -} - -void NativeSolidSolver::applyload(unsigned short iVertex, double Fx, double Fy, double Fz) -{ - - unsigned short iMarker; - unsigned long iPoint; - double Force[3]; - - Force[0] = Fx; - Force[1] = Fy; - Force[2] = Fz; - - iMarker = getFSIMarkerID(); - iPoint = geometry->vertex[iMarker][iVertex]; - geometry->node[iPoint]->SetForce(Force); -} diff --git a/src/NativeSolidSolver.h b/src/NativeSolidSolver.h deleted file mode 100644 index a31e6a9..0000000 --- a/src/NativeSolidSolver.h +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include "Config.h" -#include "Structure.h" -#include "Integration.h" -#include "MatVec.h" -#include "Geometry.h" -#include "Output.h" -#include -#include -#include -#include - -class NativeSolidSolver -{ - std::string confFile; - Config *config; - Geometry *geometry; - Structure *structure; - Integration *integrator; - Output *output; - std::ofstream historyFile; - std::ofstream historyFile2; - std::ofstream restartFile; - CVector q_uM1; // The displacement at the previous FSI iteration - double omega; - unsigned long nSolidInterfaceVertex; - double varCoordNorm; - -public: - NativeSolidSolver(std::string str, bool FSIComp); - ~NativeSolidSolver(); - void exit(); - // double getVarCoordNorm() const; - void preprocessIteration(unsigned long ExtIter); - void timeIteration(double t0, double tf); - // void mapRigidBodyMotion(bool predicition, bool initialize); - void computeInterfacePosVel(bool initialize); - void setInitialDisplacements(); - void staticComputation(); - void writeSolution(double currentTime, double lastTime, double currentFSIIter, unsigned long ExtIter, unsigned long NbExtIter); - void writeSolution(double time, int FSIter); - void saveSolution(); - void updateSolution(); - // void updateGeometry(); - // void displacementPredictor(); - unsigned short getFSIMarkerID(); - unsigned long getNumberOfSolidInterfaceNodes(unsigned short iMarker); - unsigned int getInterfaceNodeGlobalIndex(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodePosX(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodePosY(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodePosZ(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodePosX0(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodePosY0(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodePosZ0(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeDispX(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeDispY(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeDispZ(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeVelX(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeVelY(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeVelZ(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeVelXNm1(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeVelYNm1(unsigned short iMarker, unsigned short iVertex); - double getInterfaceNodeVelZNm1(unsigned short iMarker, unsigned short iVertex); - double getRotationCenterPosX(); - double getRotationCenterPosY(); - double getRotationCenterPosZ(); - void setGeneralisedForce(); - void setGeneralisedForce(double Fx, double Fy); - void setGeneralisedMoment(); - void setGeneralisedMoment(double M); - void applyload(unsigned short iVertex, double Fx, double Fy, double Fz); -}; diff --git a/src/Output.cpp b/src/Output.cpp deleted file mode 100644 index dacf515..0000000 --- a/src/Output.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "Output.h" -#include - -Output::Output() -{ -} - -/* -void Output::WriteHistory(Integration *solver, Structure *structure, ofstream *outputfile, const double &time) -{ - if (structure->GetnDof() == 1) - { - if (time == 0) - { - std::cout << "\"Time\"" - << "\t" - << "\"Displacement\"" - << "\t" - << "\"Velocity\"" - << "\t" - << "\"Acceleration\"" - << "\t" << std::endl; - outputfile[0] << "\"Time\"" - << "\t" - << "\"Displacement\"" - << "\t" - << "\"Velocity\"" - << "\t" - << "\"Acceleration\"" - << "\t" << std::endl; - } - std::cout << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << std::endl; - outputfile[0] << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << std::endl; - } - else if (structure->GetnDof() == 2) - { - if (time == 0) - { - std::cout << "\"Time\"" - << "\t" - << "\"Displacement 1\"" - << "\t" - << "\"Displacement 2\"" - << "\t" - << "\"Velocity 1\"" - << "\t" - << "\"Velocity 2\"" - << "\t" - << "\"Acceleration 1\"" - << "\t" - << "\"Acceleration 2\"" << std::endl; - outputfile[0] << "\"Time\"" - << "\t" - << "\"Displacement 1\"" - << "\t" - << "\"Displacement 2\"" - << "\t" - << "\"Velocity 1\"" - << "\t" - << "\"Velocity 2\"" - << "\t" - << "\"Acceleration 1\"" - << "\t" - << "\"Acceleration 2\"" << std::endl; - } - std::cout << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1] << std::endl; - outputfile[0] << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1] << std::endl; - } -} - -void Output::WriteRestart(Integration *solver, Structure *structure) -{ - ofstream RestartFile; - RestartFile.open("Nat_solution_restart.out", std::ios::out); - - if (structure->GetnDof() == 1) - { - RestartFile << "\"Displacement\"" - << "\t" - << "\"Velocity\"" - << "\t" - << "\"Acceleration\"" - << "\t" - << "\"Acceleration variable\"" << std::endl; - RestartFile << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAccVar()))[0] << std::endl; - } - else if (structure->GetnDof() == 2) - { - RestartFile << "\"Displacement 1\"" - << "\t" - << "\"Displacement 2\"" - << "\t" - << "\"Velocity 1\"" - << "\t" - << "\"Velocity 2\"" - << "\t" - << "\"Acceleration 1\"" - << "\t" - << "\"Acceleration 2\"" - << "\t" - << "\"Acceleration variable 1\"" - << "\t" - << "\"Acceleration variable 2\"" << std::endl; - RestartFile << time << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1] << "\t" << (*(solver->GetVel()))[0] << "\t" << (*(solver->GetVel()))[1] << "\t" << (*(solver->GetAcc()))[0] << "\t" << (*(solver->GetAcc()))[1] << "\t" << (*(solver->GetAccVar()))[0] << "\t" << (*(solver->GetAccVar()))[1] << std::endl; - } -} - -void Output::WriteStaticSolution(Config *config, Integration *solver, Structure *structure, ofstream *outputfile) -{ - if (structure->GetnDof() == 1) - { - std::cout << "Static displacement is : " << (*(solver->GetDisp()))[0] << " [m]" << std::endl; - std::cout << "Writing displacement into a solution file" << std::endl; - if (config->GetStructType() == "SPRING_HOR") - { - outputfile[0] << -1.000 << "\t" << (*(solver->GetDisp()))[0] << "\t" << 0.000; - } - else if (config->GetStructType() == "SPRING_VER") - { - outputfile[0] << -1.000 << "\t" << 0.000 << "\t" << (*(solver->GetDisp()))[0]; - } - } - else if (structure->GetnDof() == 2) - { - std::cout << "Plunging displacement is :" << (*(solver->GetDisp()))[0] << " [m]" << std::endl; - std::cout << "Pitching rotation is :" << (*(solver->GetDisp()))[1] << " [rad]" << std::endl; - std::cout << "Writing displacement into a solution file" << std::endl; - outputfile[0] << -1.000 << "\t" << (*(solver->GetDisp()))[0] << "\t" << (*(solver->GetDisp()))[1]; - } -} -*/ \ No newline at end of file diff --git a/src/Output.h b/src/Output.h deleted file mode 100644 index cce8f57..0000000 --- a/src/Output.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -#include "MatVec.h" -#include "Config.h" -#include "Structure.h" -#include "Integration.h" - -class Output -{ -public: - Output(); - // void WriteHistory(Integration *solver, Structure *structure, - // std::ofstream *outputfile, const double &time); - // void WriteRestart(Integration *solver, Structure *structure); - // void WriteStaticSolution(Config *config, Integration *solver, - // Structure *structure, std::ofstream *outputfile); - // void WriteRestart(); -}; diff --git a/src/Solver.cpp b/src/Solver.cpp deleted file mode 100644 index 9f1ba1d..0000000 --- a/src/Solver.cpp +++ /dev/null @@ -1,746 +0,0 @@ -#include "Solver.h" -#include "Structure.h" -#include "MatVec.h" -#include -#include -#include - -Solver::Solver(unsigned int nDof, bool bool_linear) -{ - q.Initialize(nDof, 0.0); - qdot.Initialize(nDof, 0.0); - qddot.Initialize(nDof, 0.0); - q_n.Initialize(nDof, 0.0); - qdot_n.Initialize(nDof, 0.0); - qddot_n.Initialize(nDof, 0.0); - Loads.Initialize(nDof, 0.0); - Loads_n.Initialize(nDof, 0.0); - - ResetSolution(); - Loads.Reset(); - Loads_n.Reset(); - - linear = bool_linear; -} - -Solver::~Solver() -{ -} - -void Solver::Iterate(double &t0, double &tf, Structure *structure) -{ -} - -CVector &Solver::GetDisp() -{ - return q; -} - -CVector &Solver::GetVel() -{ - return qdot; -} - -CVector &Solver::GetAcc() -{ - return qddot; -} - -CVector &Solver::GetDisp_n() -{ - return q_n; -} - -CVector &Solver::GetVel_n() -{ - return qdot_n; -} - -CVector &Solver::GetAcc_n() -{ - return qddot_n; -} - -CVector &Solver::GetLoads() -{ - return Loads; -} - -CVector &Solver::GetAccVar() -{ - return a; -} - -CVector &Solver::GetAccVar_n() -{ - return a_n; -} - -void Solver::ResetSolution() -{ - q.Reset(); - qdot.Reset(); - qddot.Reset(); - q_n.Reset(); - qdot_n.Reset(); - qddot_n.Reset(); -} - -void Solver::SaveToThePast() -{ - q_n = q; - qdot_n = qdot; - qddot_n = qddot; - Loads_n = Loads; -} - -void Solver::SetInitialState(Config *config, Structure *structure) -{ -} - -// CLASS ALPHAGENSOLVER -AlphaGenSolver::AlphaGenSolver(unsigned int nDof, double val_rho, - bool bool_linear) : Solver(nDof, bool_linear) -{ - a.Initialize(nDof, 0.0); - a_n.Initialize(nDof, 0.0); - - rho = val_rho; - alpha_m = (2 * rho - 1) / (rho + 1); - alpha_f = rho / (rho + 1); - gamma = 0.5 + alpha_f - alpha_m; - beta = 0.25 * pow((gamma + 0.5), 2); - std::cout << "Integration with the alpha-generalized algorithm :" << std::endl; - std::cout << "rho : " << rho << std::endl; - std::cout << "alpha_m : " << alpha_m << std::endl; - std::cout << "alpha_f : " << alpha_f << std::endl; - std::cout << "gamma : " << gamma << std::endl; - std::cout << "beta : " << beta << std::endl; -} - -AlphaGenSolver::~AlphaGenSolver() -{ -} - -CVector &AlphaGenSolver::GetAccVar() -{ - return a; -} - -CVector &AlphaGenSolver::GetAccVar_n() -{ - return a_n; -} - -void AlphaGenSolver::Iterate(double &t0, double &tf, Structure *structure) -{ - - double deltaT(tf - t0), epsilon(1e-6); - int nMaxIter(1000), nIter(0); - - gammaPrime = gamma / (deltaT * beta); - betaPrime = (1 - alpha_m) / (pow(deltaT, 2) * beta * (1 - alpha_f)); - - //--- Prediction phase --- - qddot.Reset(); - a.Reset(); - - a += ScalVecProd(alpha_f / (1 - alpha_m), qddot_n); - a -= ScalVecProd(alpha_m / (1 - alpha_m), a_n); - - q = q_n; - q += ScalVecProd(deltaT, qdot_n); - q += ScalVecProd((0.5 - beta) * deltaT * deltaT, a_n); - q += ScalVecProd(deltaT * deltaT * beta, a); - - qdot = qdot_n; - qdot += ScalVecProd((1 - gamma) * deltaT, a_n); - qdot += ScalVecProd(deltaT * gamma, a); - - //--- Tangent operator and corrector computation --- - CVector res(qddot.GetSize(), 0.0); - CVector Deltaq(qddot.GetSize(), 0.0); - CMatrix St(qddot.GetSize(), qddot.GetSize(), 0.0); - ComputeResidual(structure, res); - while (res.norm() >= epsilon && nIter < nMaxIter) - { - St.Reset(); - ComputeTangentOperator(structure, St); - SolveSys(St, res); - //*res -= ScalVecProd(double(2),res); //=deltaq - Deltaq.Reset(); - Deltaq += ScalVecProd(-1, res); - q += Deltaq; - qdot += ScalVecProd(gammaPrime, Deltaq); - qddot += ScalVecProd(betaPrime, Deltaq); - res.Reset(); - ComputeResidual(structure, res); - nIter++; - } - a += ScalVecProd((1 - alpha_f) / (1 - alpha_m), qddot); -} - -void AlphaGenSolver::ComputeRHS(Structure *structure, CVector &RHS) -{ - - unsigned long size = q.GetSize(); - CMatrix CC(size, size, 0.0); - CMatrix KK(size, size, 0.0); - CVector NonLinTerm(size, 0.0); - - double cos_a; - - if (structure->GetnDof() == 1) - { - KK.SetElm(1, 1, structure->Get_Kh()); - CC.SetElm(1, 1, structure->Get_Ch()); - } - else if (structure->GetnDof() == 2) - { - if (linear) - { - cos_a = 1.0; - } - else - { - cos_a = cos(q[1]); - NonLinTerm[0] = (structure->Get_S()) * sin(q[1]) * pow(qdot[1], 2); - } - CC.SetElm(1, 1, structure->Get_Ch()); - CC.SetElm(2, 2, structure->Get_Ca()); - KK.SetElm(1, 1, structure->Get_Kh()); - KK.SetElm(2, 2, structure->Get_Ka()); - } - - RHS += Loads; - RHS -= MatVecProd(CC, qdot); - RHS -= MatVecProd(KK, q); - RHS += NonLinTerm; -} - -void AlphaGenSolver::ComputeResidual(Structure *structure, CVector &res) -{ - - res.Reset(); - - unsigned long size = q.GetSize(); - CMatrix MM(size, size, 0.0); - double cos_a; - - if (structure->GetnDof() == 1) - { - MM.SetElm(1, 1, structure->Get_m()); - } - else if (structure->GetnDof() == 2) - { - if (linear) - { - cos_a = 1.0; - } - else - { - cos_a = cos(q[1]); - } - MM.SetElm(1, 1, structure->Get_m()); - MM.SetElm(1, 2, (structure->Get_S()) * cos_a); - MM.SetElm(2, 1, (structure->Get_S()) * cos_a); - MM.SetElm(2, 2, structure->Get_If()); - } - - CVector RHS(size, 0.0); - ComputeRHS(structure, RHS); - - res = MatVecProd(MM, qddot) - RHS; -} - -void AlphaGenSolver::ComputeTangentOperator(Structure *structure, CMatrix &St) -{ - - St.Reset(); - - unsigned long size = q.GetSize(); - CMatrix MM(size, size, 0.0); - CMatrix Ct(size, size, 0.0); - CMatrix Kt(size, size, 0.0); - - if (structure->GetnDof() == 1) - { - MM.SetElm(1, 1, structure->Get_m()); - Kt.SetElm(1, 1, (structure->Get_Kh())); - Ct.SetElm(1, 1, (structure->Get_Ch())); - } - else if (structure->GetnDof() == 2) - { - if (linear) - { - MM.SetElm(1, 1, structure->Get_m()); - MM.SetElm(1, 2, (structure->Get_S())); - MM.SetElm(2, 1, (structure->Get_S())); - MM.SetElm(2, 2, structure->Get_If()); - Ct.SetElm(1, 1, (structure->Get_Ch())); - Ct.SetElm(2, 2, (structure->Get_Ca())); - Kt.SetElm(1, 1, (structure->Get_Kh())); - Kt.SetElm(2, 2, (structure->Get_Ka())); - } - else - { - MM.SetElm(1, 1, structure->Get_m()); - MM.SetElm(1, 2, (structure->Get_S()) * cos(q[1])); - MM.SetElm(2, 1, (structure->Get_S()) * cos(q[1])); - MM.SetElm(2, 2, structure->Get_If()); - Ct.SetElm(1, 1, -(structure->Get_Ch())); - Ct.SetElm(1, 2, (structure->Get_S()) * sin(q[1]) * 2 * qdot[1]); - Ct.SetElm(2, 2, -(structure->Get_Ca())); - Kt.SetElm(1, 1, -(structure->Get_Kh())); - Kt.SetElm(1, 2, (structure->Get_S()) * cos(q[1]) * pow(qdot[1], 2)); - Kt.SetElm(2, 2, -(structure->Get_Ka())); - } - } - - St += ScalMatProd(betaPrime, MM); - St += ScalMatProd(gammaPrime, Ct); - St += Kt; -} - -void AlphaGenSolver::ResetSolution() -{ - Solver::ResetSolution(); - a.Reset(); - a_n.Reset(); -} - -void AlphaGenSolver::SaveToThePast() -{ - - Solver::SaveToThePast(); - a_n = a; -} - -void AlphaGenSolver::SetInitialState(Config *config, Structure *structure) -{ - - if (config->GetRestartSol() == "YES") - { - std::string InputFileName = config->GetRestartFile(); - std::string text_line; - std::string token, tempString; - size_t pos; - std::string delimiter = "\t"; - std::ifstream InputFile; - InputFile.open(InputFileName.c_str(), std::ios::in); - double buffer[(4 * structure->GetnDof()) + 1]; - int kk = 0; - int jj; - while (getline(InputFile, text_line)) - { - tempString = text_line; - jj = 0; - if (kk == 1) - { - while ((pos = tempString.find(delimiter)) != std::string::npos) - { - token = tempString.substr(0, pos); - tempString.erase(0, pos + delimiter.length()); - buffer[jj] = atof(token.c_str()); - jj += 1; - } - buffer[jj] = atof(tempString.c_str()); - - if (structure->GetnDof() == 1) - { - q_n[0] = buffer[1]; - qdot_n[0] = buffer[2]; - qddot_n[0] = buffer[3]; - a_n[0] = buffer[4]; - } - else if (structure->GetnDof() == 2) - { - q_n[0] = buffer[1]; - q_n[1] = buffer[2]; - qdot_n[0] = buffer[3]; - qdot_n[1] = buffer[4]; - qddot_n[0] = buffer[5]; - qddot_n[1] = buffer[6]; - a_n[0] = buffer[7]; - a_n[1] = buffer[8]; - } - q_n.print(); - qdot_n.print(); - qddot_n.print(); - a_n.print(); - } - else if (kk == 2) - { - while ((pos = tempString.find(delimiter)) != std::string::npos) - { - token = tempString.substr(0, pos); - tempString.erase(0, pos + delimiter.length()); - buffer[jj] = atof(token.c_str()); - jj += 1; - } - buffer[jj] = atof(tempString.c_str()); - - if (structure->GetnDof() == 1) - { - q[0] = buffer[1]; - qdot[0] = buffer[2]; - qddot[0] = buffer[3]; - a[0] = buffer[4]; - } - else if (structure->GetnDof() == 2) - { - q[0] = buffer[1]; - q[1] = buffer[2]; - qdot[0] = buffer[3]; - qdot[1] = buffer[4]; - qddot[0] = buffer[5]; - qddot[1] = buffer[6]; - a[0] = buffer[7]; - a[1] = buffer[8]; - } - q.print(); - qdot.print(); - qddot.print(); - a.print(); - } - kk += 1; - } - InputFile.close(); - } - else - { - std::cout << "Setting basic initial conditions for alpha-Gen" << std::endl; - q.Reset(); - q_n.Reset(); - std::cout << "Read initial configuration" << std::endl; - q[0] = config->GetInitialDisp(); - if (structure->GetnDof() == 2) - q[1] = config->GetInitialAngle(); - std::cout << "Initial plunging displacement : " << q[0] << std::endl; - std::cout << "Initial pitching displacement : " << q[1] << std::endl; - - qdot.Reset(); - qddot.Reset(); - - unsigned long size = q.GetSize(); - CVector RHS(size, 0.0); - CMatrix MM(size, size, 0.0); - - double cos_a; - - if (structure->GetnDof() == 1) - { - MM.SetElm(1, 1, structure->Get_m()); - } - else if (structure->GetnDof() == 2) - { - if (linear) - { - cos_a = 1.0; - } - else - { - cos_a = cos(q[1]); - } - MM.SetElm(1, 1, structure->Get_m()); - MM.SetElm(1, 2, (structure->Get_S()) * cos_a); - MM.SetElm(2, 1, (structure->Get_S()) * cos_a); - MM.SetElm(2, 2, structure->Get_If()); - } - - ComputeRHS(structure, RHS); - SolveSys(MM, RHS); - qddot = RHS; - a = qddot; - } -} - -// CLASS RK4 SOLVER -RK4Solver::RK4Solver(unsigned nDof, bool bool_linear) : Solver(nDof, bool_linear) -{ - size = nDof; - lastTime = 0.0; - currentTime = 0.0; -} - -RK4Solver::~RK4Solver() {} - -void RK4Solver::Iterate(double &t0, double &tf, Structure *structure) -{ - - double h = tf - t0; - lastTime = t0; - currentTime = tf; - - CVector k1(2 * size); - CVector k2(2 * size); - CVector k3(2 * size); - CVector k4(2 * size); - - CVector state0(2 * size); - CVector statef(2 * size); - CVector statef_dot(2 * size); - state0 = SetState_n(); - - CVector TEMP(2 * size); - - EvaluateStateDerivative(lastTime, state0, k1, structure); - TEMP = state0 + (k1 * (h / 2.0)); - EvaluateStateDerivative(lastTime + h / 2.0, TEMP, k2, structure); - TEMP = state0 + (k2 * (h / 2.0)); - EvaluateStateDerivative(lastTime + h / 2.0, TEMP, k3, structure); - TEMP = state0 + (k3 * h); - EvaluateStateDerivative(lastTime + h, TEMP, k4, structure); - - statef = state0 + ((k1 + k2 * 2.0 + k3 * 2.0 + k4) * (h / 6.0)); - - EvaluateStateDerivative(lastTime + h, statef, statef_dot, structure); - - if (structure->GetnDof() == 1) - { - q[0] = statef[0]; - qdot[0] = statef[1]; - qddot[0] = statef_dot[1]; - } - else if (structure->GetnDof() == 2) - { - q[0] = statef[0]; - q[1] = statef[1]; - qdot[0] = statef[2]; - qdot[1] = statef[3]; - qddot[0] = statef_dot[2]; - qddot[1] = statef_dot[3]; - } -} - -void RK4Solver::EvaluateStateDerivative(double tCurrent, CVector &state, CVector &stateDerivative, Structure *structure) -{ - - CVector stateLoads(size, 0.0); - interpLoads(tCurrent, stateLoads); - - CMatrix MM(size, size, 0.0); - CMatrix CC(size, size, 0.0); - CMatrix KK(size, size, 0.0); - CVector NonLinTerm(size, 0.0); - CVector RHS(size, 0.0); - - CVector q_current(size, 0.0); - CVector qdot_current(size, 0.0); - CVector qddot_current(size, 0.0); - - if (structure->GetnDof() == 1) - { - MM.SetElm(1, 1, structure->Get_m()); - KK.SetElm(1, 1, structure->Get_Kh()); - CC.SetElm(1, 1, structure->Get_Ch()); - q_current[0] = state[0]; - qdot_current[0] = state[1]; - stateDerivative[0] = state[1]; - } - else if (structure->GetnDof() == 2) - { - double cos_a; - if (linear) - { - cos_a = 1.0; - } - else - { - cos_a = cos(state[1]); - NonLinTerm[0] = (structure->Get_S()) * sin(state[1]) * pow(state[3], 2); - } - MM.SetElm(1, 1, structure->Get_m()); - MM.SetElm(1, 2, (structure->Get_S()) * cos_a); - MM.SetElm(2, 1, (structure->Get_S()) * cos_a); - MM.SetElm(2, 2, structure->Get_If()); - CC.SetElm(1, 1, structure->Get_Ch()); - CC.SetElm(2, 2, structure->Get_Ca()); - KK.SetElm(1, 1, structure->Get_Kh()); - KK.SetElm(2, 2, structure->Get_Ka()); - q_current[0] = state[0]; - q_current[1] = state[1]; - qdot_current[0] = state[2]; - qdot_current[1] = state[3]; - stateDerivative[0] = state[2]; - stateDerivative[1] = state[3]; - } - - RHS += stateLoads; - RHS -= MatVecProd(CC, qdot_current); - RHS -= MatVecProd(KK, q_current); - RHS += NonLinTerm; - - SolveSys(MM, RHS); - qddot_current = RHS; - - if (structure->GetnDof() == 1) - { - stateDerivative[1] = qddot_current[0]; - } - else if (structure->GetnDof() == 2) - { - stateDerivative[2] = qddot_current[0]; - stateDerivative[3] = qddot_current[1]; - } -} - -void RK4Solver::interpLoads(double &tCurrent, CVector &val_loads) -{ - - if (lastTime != currentTime) - { - val_loads[0] = (Loads[0] - Loads_n[0]) / (currentTime - lastTime) * (tCurrent - lastTime) + Loads_n[0]; - if (size == 2) - val_loads[1] = (Loads[1] - Loads_n[1]) / (currentTime - lastTime) * (tCurrent - lastTime) + Loads_n[1]; - } - else - { - val_loads[0] = Loads[0]; - if (size == 2) - val_loads[1] = Loads[1]; - } -} - -void RK4Solver::SetInitialState(Config *config, Structure *structure) -{ - if (config->GetRestartSol() == "YES") - { - } - else - { - std::cout << "Setting basic initial conditions for RK4" << std::endl; - q.Reset(); - q_n.Reset(); - std::cout << "Read initial configuration" << std::endl; - q[0] = config->GetInitialDisp(); - if (structure->GetnDof() == 2) - q[1] = config->GetInitialAngle(); - std::cout << "Initial plunging displacement : " << q[0] << std::endl; - std::cout << "Initial pitching displacement : " << q[1] << std::endl; - qdot.Reset(); - - lastTime = 0.0; - currentTime = 0.0; - - qddot.Reset(); - CVector state(2 * size); - CVector state_dot(2 * size); - - state = SetState(); - EvaluateStateDerivative(0.0, state, state_dot, structure); - - if (structure->GetnDof() == 1) - { - qddot[0] = state_dot[1]; - } - else if (structure->GetnDof() == 2) - { - qddot[0] = state_dot[2]; - qddot[1] = state_dot[3]; - } - } -} - -CVector RK4Solver::SetState() -{ - CVector state(2 * size); - - if (size == 1) - { - state[0] = q[0]; - state[1] = qdot[0]; - } - else if (size == 2) - { - state[0] = q[0]; - state[1] = q[1]; - state[2] = qdot[0]; - state[3] = qdot[1]; - } - else - { - } - - return state; -} - -CVector RK4Solver::SetState_n() -{ - CVector state(2 * size); - - if (size == 1) - { - state[0] = q_n[0]; - state[1] = qdot_n[0]; - } - else if (size == 2) - { - state[0] = q_n[0]; - state[1] = q_n[1]; - state[2] = qdot_n[0]; - state[3] = qdot_n[1]; - } - else - { - } - - return state; -} - -// CLASS STATIC SOLVER -StaticSolver::StaticSolver(unsigned nDof, bool bool_linear) : Solver(nDof, bool_linear) -{ - _nDof = nDof; - KK.Initialize(_nDof, _nDof, 0.0); -} - -StaticSolver::~StaticSolver() -{ - std::cout << "NativeSolid::~StaticSolver()" << std::endl; -} - -void StaticSolver::SetInitialState(Config *config, Structure *structure) -{ - // Reset displacement, velocity and acceleration - if (config->GetRestartSol() == "YES") - { - } - else - { - std::cout << "Setting basic initial conditions for Static" << std::endl; - q.Reset(); - q_n.Reset(); - std::cout << "Read initial configuration" << std::endl; - q[0] = config->GetInitialDisp(); - if (_nDof == 2) - q[1] = config->GetInitialAngle(); - std::cout << "Initial plunging displacement : " << q[0] << std::endl; - std::cout << "Initial pitching displacement : " << q[1] << std::endl; - qdot.Reset(); - qddot.Reset(); - } - // Fill stiffness matrix - if (_nDof == 1) - KK.SetElm(1, 1, structure->Get_Kh()); - else if (_nDof == 2) - { - KK.SetElm(1, 1, structure->Get_Kh()); - KK.SetElm(2, 2, structure->Get_Ka()); - } - else - { - std::cerr << "Error in NativeSolid::StaticSolver: Number of degrees of freedom is out of range. nDof = " << _nDof << std::endl; - throw(-1); - } -} - -void StaticSolver::Iterate(double &t0, double &tf, Structure *structure) -{ - // Solve KK*q = Loads - q_n = q; // save previous state (used to compute rotation in NativeSolidSolver::computeInterfacePosVel) - CVector RHS(_nDof, 0.); - RHS += Loads; - SolveSys(KK, RHS); - q = RHS; -} diff --git a/src/Solver.h b/src/Solver.h deleted file mode 100644 index 75b60d5..0000000 --- a/src/Solver.h +++ /dev/null @@ -1,98 +0,0 @@ -#pragma once - -#include "MatVec.h" -#include "Structure.h" -#include "Config.h" - -class Solver -{ -protected: - CVector q; - CVector qdot; - CVector qddot; - CVector q_n; - CVector qdot_n; - CVector qddot_n; - CVector Loads; - CVector Loads_n; - CVector a; - CVector a_n; - bool linear; - -public: - Solver(unsigned int nDof, bool bool_linear); - virtual ~Solver(); - virtual void Iterate(double &t0, double &tf, Structure *structure); - virtual CVector &GetDisp(); - virtual CVector &GetVel(); - virtual CVector &GetAcc(); - virtual CVector &GetDisp_n(); - virtual CVector &GetVel_n(); - virtual CVector &GetAcc_n(); - virtual CVector &GetLoads(); - virtual CVector &GetAccVar(); - virtual CVector &GetAccVar_n(); - virtual void ResetSolution(); - virtual void SaveToThePast(); - virtual void SetInitialState(Config *config, Structure *structure); -}; - -class AlphaGenSolver : public Solver -{ - double beta; - double gamma; - double alpha_m; - double alpha_f; - double rho; - double gammaPrime; - double betaPrime; - -public: - AlphaGenSolver(unsigned int nDof, double val_rho, bool bool_linear); - virtual ~AlphaGenSolver() override; - virtual CVector &GetAccVar() override; - virtual CVector &GetAccVar_n() override; - virtual void Iterate(double &t0, double &tf, Structure *structure) override; - virtual void ResetSolution() override; - virtual void SaveToThePast() override; - virtual void SetInitialState(Config *config, Structure *structure) override; - -private: - void ComputeRHS(Structure *structure, CVector &RHS); - void ComputeResidual(Structure *structure, CVector &res); - void ComputeTangentOperator(Structure *structure, CMatrix &St); -}; - -class RK4Solver : public Solver -{ - unsigned int size; - double lastTime; - double currentTime; - -public: - RK4Solver(unsigned nDof, bool bool_linear); - virtual ~RK4Solver() override; - virtual void Iterate(double &t0, double &tf, Structure *structure) override; - virtual void SetInitialState(Config *config, Structure *structure) override; - -private: - void EvaluateStateDerivative(double tCurrent, CVector &state, - CVector &stateDerivative, - Structure *structure); - void interpLoads(double &tCurrent, CVector &val_loads); - CVector SetState(); - CVector SetState_n(); -}; - -class StaticSolver : public Solver -{ - unsigned int _nDof; - CMatrix KK; - -public: - StaticSolver(unsigned nDof, bool bool_linear); - virtual ~StaticSolver() override; - - virtual void Iterate(double &t0, double &tf, Structure *structure) override; - virtual void SetInitialState(Config *config, Structure *structure) override; -}; diff --git a/src/Structure.cpp b/src/Structure.cpp deleted file mode 100644 index f5007a0..0000000 --- a/src/Structure.cpp +++ /dev/null @@ -1,184 +0,0 @@ -#include "Structure.h" -#include -#include -#include -#include -#include - -Structure::Structure(Config *config) -{ - centerOfRotation[0] = 0.0; - centerOfRotation[1] = 0.0; - centerOfRotation[2] = 0.0; - - centerOfRotation_n[0] = 0.0; - centerOfRotation_n[1] = 0.0; - centerOfRotation_n[2] = 0.0; - - if (config->GetStructType() == "SPRING_HOR" || - config->GetStructType() == "SPRING_VER") - { - nDof = 1; - m = config->GetSpringMass(); - Kh = config->GetSpringStiffness(); - Ch = config->GetSpringDamping(); - Ka = 0; - Ca = 0; - xf = 0; - xCG = 0; - c = 0; - b = 0; - S = 0; - ICG = 0; - If = 0; - std::cout << "Setting mass-spring-damper system" << std::endl; - std::cout << "Number of DOF : " << nDof << std::endl; - std::cout << "Plunging mass : " << m << " [kg]" << std::endl; - std::cout << "Plunging damping : " << Ch << " [Ns/m]" << std::endl; - std::cout << "Plunging stiffness : " << Kh << " [N/m]" << std::endl; - } - else if (config->GetStructType() == "AIRFOIL") - { - nDof = 2; - m = config->GetSpringMass(); - Kh = config->GetSpringStiffness(); - Ch = config->GetSpringDamping(); - Ka = config->GetTorsionalStiffness(); - Ca = config->GetTorsionalDamping(); - xf = config->GetFlexuralAxis(); - xCG = config->GetGravityCenter(); - c = config->GetCord(); - b = c / 2.0; - S = m * (xCG - xf); - // If = ICG + m*pow((xCG-xf),2); - If = config->GetInertiaFlexural(); - // S = m*(c/2.0-xf); - // Ia = 1.0/3.0*m*(c*c-3*c*xf+3*xf*xf); - std::cout << "Setting pitching-plunging airfoil system" << std::endl; - std::cout << "Number of DOF : " << nDof << std::endl; - std::cout << "Airfoil mass : " << m << " [kg]" << std::endl; - std::cout << "Airfoil cord : " << c << " [m]" << std::endl; - std::cout << "Position of the flexural axis : " << xf << " [m]" << std::endl; - std::cout << "Inertia around the flexural axis : " << If << " [kg m²]" << std::endl; - std::cout << "Plunging damping : " << Ch << " [Ns/m]" << std::endl; - std::cout << "Plunging stiffness : " << Kh << " [N/m]" << std::endl; - std::cout << "Pitching damping : " << Ca << " [Ns]" << std::endl; - std::cout << "Pitching stiffness : " << Ka << " [N]" << std::endl; - std::cout << "Position of the center of gravity : " << xCG << " [m]" << std::endl; - std::cout << "Static unbalance : " << S << " [kg m]" << std::endl; - - centerOfRotation[0] = xf; - centerOfRotation_n[0] = xf; - } - else - { - nDof = 0; - std::cerr << "Invalid structural type. Available choices are : SPRIN_HOR, SPRING_VER and AIRFOIL." << std::endl; - throw(-1); - } -} - -void Structure::SetCenterOfRotation_X(double coord_x) -{ - centerOfRotation[0] = coord_x; -} - -void Structure::SetCenterOfRotation_Y(double coord_y) -{ - centerOfRotation[1] = coord_y; -} - -void Structure::SetCenterOfRotation_Z(double coord_z) -{ - centerOfRotation[2] = coord_z; -} - -double Structure::GetCenterOfRotation_x() const -{ - return centerOfRotation[0]; -} - -double Structure::GetCenterOfRotation_y() const -{ - return centerOfRotation[1]; -} - -double Structure::GetCenterOfRotation_z() const -{ - return centerOfRotation[2]; -} - -const double *Structure::GetCenterOfRotation() const -{ - return centerOfRotation; -} - -void Structure::SetCenterOfRotation_n_X(double coord_x) -{ - centerOfRotation_n[0] = coord_x; -} - -void Structure::SetCenterOfRotation_n_Y(double coord_y) -{ - centerOfRotation_n[1] = coord_y; -} - -void Structure::SetCenterOfRotation_n_Z(double coord_z) -{ - centerOfRotation_n[2] = coord_z; -} - -double Structure::GetCenterOfRotation_n_x() const -{ - return centerOfRotation_n[0]; -} - -double Structure::GetCenterOfRotation_n_y() const -{ - return centerOfRotation_n[1]; -} - -double Structure::GetCenterOfRotation_n_z() const -{ - return centerOfRotation_n[2]; -} - -unsigned int Structure::GetnDof() const -{ - return nDof; -} - -double Structure::Get_m() const -{ - return m; -} - -double Structure::Get_Kh() const -{ - return Kh; -} - -double Structure::Get_Ka() const -{ - return Ka; -} - -double Structure::Get_Ch() const -{ - return Ch; -} - -double Structure::Get_Ca() const -{ - return Ca; -} - -double Structure::Get_S() const -{ - return S; -} - -double Structure::Get_If() const -{ - return If; -} diff --git a/src/Structure.h b/src/Structure.h deleted file mode 100644 index 234820d..0000000 --- a/src/Structure.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "MatVec.h" -#include "Config.h" - -class Structure -{ - unsigned int nDof; - double m; - double Kh; - double Ka; - double Ch; - double Ca; - double c; - double b; - double xf; - double xCG; - double S; - double ICG; - double If; - double centerOfRotation[3]; - double centerOfRotation_n[3]; - -public: - Structure(Config *config); - - // get/set methods - void SetCenterOfRotation_X(double coord_x); - void SetCenterOfRotation_Y(double coord_y); - void SetCenterOfRotation_Z(double coord_z); - double GetCenterOfRotation_x() const; - double GetCenterOfRotation_y() const; - double GetCenterOfRotation_z() const; - const double *GetCenterOfRotation() const; - void SetCenterOfRotation_n_X(double coord_x); - void SetCenterOfRotation_n_Y(double coord_y); - void SetCenterOfRotation_n_Z(double coord_z); - double GetCenterOfRotation_n_x() const; - double GetCenterOfRotation_n_y() const; - double GetCenterOfRotation_n_z() const; - unsigned int GetnDof() const; - double Get_m() const; - double Get_Kh() const; - double Get_Ka() const; - double Get_Ch() const; - double Get_Ca() const; - double Get_S() const; - double Get_If() const; -}; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 44f648c..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -ADD_EXECUTABLE(TestCVector testcvector.cpp) -TARGET_INCLUDE_DIRECTORIES(TestCVector PRIVATE ${PROJECT_SOURCE_DIR}/src) -TARGET_LINK_LIBRARIES(TestCVector Native) - -ADD_TEST(NAME TestCVector COMMAND ${EXECUTABLE_OUTPUT_PATH}/TestCVector - WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) - \ No newline at end of file diff --git a/tests/testcvector.cpp b/tests/testcvector.cpp deleted file mode 100644 index 37531ee..0000000 --- a/tests/testcvector.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include "MatVec.h" - -int main(int argc, char **argv) -{ - // Test initialization - CVector myVec(5, 5.0); - - // Test copy - CVector myVec2(myVec); - - // Test initiate - std::cout << "initiate()" << std::endl; - CVector myVec4; - myVec4.Initialize(5, 7.0); - myVec4.print(); - - // Test getSize() - std::cout << "getSize()" << std::endl; - std::cout << myVec.GetSize() << std::endl; - std::cout << myVec2.GetSize() << std::endl; - - // Test dotProduct() - std::cout << "dot()" << std::endl; - CVector myVec3(5, 1.0); - double dotProduct(0.0), dotProduct2(0.0); - dotProduct = myVec.dotProd(myVec3); - dotProduct2 = myVec3.dotProd(myVec); - std::cout << dotProduct << std::endl; - std::cout << dotProduct2 << std::endl; - - // Test norm() - std::cout << "norm()" << std::endl; - std::cout << myVec.norm() << std::endl; - - // Test display() - std::cout << "display()" << std::endl; - myVec.print(); - - // Test reset(); - std::cout << "reset()" << std::endl; - myVec2.Reset(); - myVec2.print(); - - // Test operator[] as member - std::cout << "operator[]" << std::endl; - std::cout << myVec[3] << std::endl; - myVec[3] = 100.0; - myVec.print(); - - // Test operator = as member - std::cout << "operator=" << std::endl; - myVec2 = myVec; - myVec2.print(); - - // Test operator += as member - std::cout << "operator+=" << std::endl; - myVec.SetAllValues(2.0); - myVec2.SetAllValues(3.0); - myVec2 += myVec; - myVec2.print(); - - // Test operator -= as member - std::cout << "operator-=" << std::endl; - myVec2 -= myVec; - myVec2.print(); - - // Test operator *= as member - std::cout << "operator*=" << std::endl; - myVec.SetAllValues(2.0); - myVec *= 2.0; - myVec.print(); - - // Test operator /= as member - std::cout << "operator/=" << std::endl; - myVec /= 2.0; - myVec.print(); - - // Test addition - std::cout << "addition" << std::endl; - myVec.SetAllValues(2.0); - myVec2.SetAllValues(3.0); - CVector vecSum(5, 0.0); - vecSum = myVec + myVec2; - vecSum.print(); - - // Test multiplication - std::cout << "multiplication" << std::endl; - myVec.SetAllValues(2.0); - CVector vecMul(5, 0.0); - vecMul = myVec * 2.0; - vecMul = 3.0 * myVec; - vecMul.print(); - - // Test linear combination - std::cout << "linear combination" << std::endl; - myVec.SetAllValues(1.0); - myVec2.SetAllValues(1.0); - myVec3.SetAllValues(1.0); - myVec4 = myVec + (2.0 * myVec2 + 5.0 * myVec3) * 2.0; - myVec4.print(); - - std::cout << "Pointers..." << std::endl; - CVector *myVecPoint = NULL; - CVector *myVecPoint2 = NULL; - myVecPoint = new CVector(5, 10.0); - myVecPoint->print(); - std::cout << (*myVecPoint)[3] << std::endl; - myVecPoint2 = new CVector(*myVecPoint); - myVecPoint2->print(); - myVecPoint->Reset(); - *myVecPoint2 = *myVecPoint; - myVecPoint2->print(); - - if (myVecPoint != NULL) - delete myVecPoint; - if (myVecPoint2 != NULL) - delete myVecPoint2; - - return 0; -}