Skip to content
Snippets Groups Projects

Update waves

Merged Boman Romain requested to merge adrien into master
2 files
+ 43
29
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 42
28
@@ -94,6 +94,8 @@ Solver::Solver(std::shared_ptr<Problem> _pbl) : pbl(_pbl)
iIC->apply(phi);
for(auto dBC : pbl->dBCs)
dBC->apply(phi);
// Find initial best upwind element
findUpwd();
}
Solver::~Solver()
{
@@ -121,6 +123,7 @@ bool Solver::run()
// Initialize solver loop
int itC = 0; // iteration counter
int avC = 0; // adaptive viscosity counter
bool rUpwd = true; // re-find best upwind element
// Compute initial residual
buildRes(rPhi);
@@ -151,8 +154,10 @@ bool Solver::run()
do
{
// Viscosity damping
if (relRes < avThrsh)
if (relRes < avThrsh && avC < 2) {
avC++;
rUpwd = true;
}
switch(avC) {
case 0 : { mCOv = 0.92;
muCv = 2.;
@@ -196,6 +201,11 @@ bool Solver::run()
{}
absRes = gmm::vect_norm2(rPhi);
relRes = absRes / resInit;
// Re-find best upwind element
if (rUpwd) {
findUpwd();
rUpwd = false;
}
// Compute aerodynamic coefficient on boundaries
Cl = 0.; Cd = 0.;
@@ -266,8 +276,7 @@ void Solver::buildJac(gmm::csr_matrix<double> &J)
// Current element
Element * e = p.first;
//Upwind element
size_t idx = findBestUpwd(p);
Element * eU = p.second[idx];
Element * eU = p.second[0];
// Merge nodes of current and upwind elements (and remove duplicate)
std::vector<Node *> nodeU;
@@ -405,8 +414,7 @@ void Solver::buildRes(std::vector<double> &R)
// Current element
Element * e = p.first;
// Upwind element
size_t idx = findBestUpwd(p);
Element * eU = p.second[idx];
Element * eU = p.second[0];
// Switching function and bias
double mach = fluid->mach.eval(*e, phi, 0);
@@ -549,31 +557,37 @@ void Solver::compute()
* @brief Find upwind element which is best aligned with current velocity vector
* @authors Adrien Crovato
*/
size_t Solver::findBestUpwd(std::pair<Element *, std::vector<Element *>> &p)
void Solver::findUpwd()
{
// Velocity
std::vector<double> gradPhi(pbl->nDim);
p.first->computeGrad(phi, gradPhi, 0);
Pt vel_;
for (size_t i = 0; i < gradPhi.size(); ++i)
vel_.x[i] = -gradPhi[i];
vel_.normalize();
// Best alignement strategy
// -> find (cgU-cgE) \dot vel_ closest to one
double SPbest = -1;
size_t idx = 0;
for (size_t i = 0; i < p.second.size(); ++i) {
Pt cgU = (p.second[i])->getVMem().getCg();
Pt cgE = (p.first)->getVMem().getCg();
double SP = (cgU - cgE).normalized() * vel_;
if (fabs(SP-1) < fabs(SPbest-1)) {
idx = i;
SPbest = SP;
tbb::parallel_do(pbl->medium->adjMap.begin(), pbl->medium->adjMap.end(), [&](std::pair<Element *, std::vector<Element *>> &p)
{
// Velocity
std::vector<double> gradPhi(pbl->nDim);
p.first->computeGrad(phi, gradPhi, 0);
Pt vel_;
for (size_t i = 0; i < gradPhi.size(); ++i)
vel_.x[i] = -gradPhi[i];
vel_.normalize();
// Best alignement strategy
// -> find (cgU-cgE) \dot vel_ closest to one
double SPbest = -1;
size_t idx = 0;
for (size_t i = 0; i < p.second.size(); ++i) {
Pt cgU = (p.second[i])->getVMem().getCg();
Pt cgE = (p.first)->getVMem().getCg();
double SP = (cgU - cgE).normalized() * vel_;
if (fabs(SP-1) < fabs(SPbest-1)) {
idx = i;
SPbest = SP;
}
else
continue;
}
else
continue;
}
return idx;
// Swap (best upwind element is moved at first emplacement)
Element * tmp = p.second[0];
p.second[0] = p.second[idx];
p.second[idx] = tmp;
});
}
/**
Loading