36 #include <boost/algorithm/string.hpp>
70 int expdim =
m_graph->GetMeshDimension();
78 ASSERTL0(
false,
"Last field is defined as pressure but this is not suitable for this solver, please remove this field as it is implicitly defined");
87 ASSERTL0(
m_fields.num_elements() > 2,
"Expect to have three at least three components of velocity variables");
103 Array<OneD, MultiRegions::ExpListSharedPtr> velocity(
m_velocity.num_elements());
104 for(i =0 ; i <
m_velocity.num_elements(); ++i)
110 m_locToGloMap = Array<OneD, CoupledLocalToGlobalC0ContMapSharedPtr> (nz);
112 if(
m_session->DefinesSolverInfo(
"SingleMode"))
115 ASSERTL0(nz <=2 ,
"For single mode calculation can only have nz <= 2");
117 if(
m_session->DefinesSolverInfo(
"BetaZero"))
136 for(i = 2; i < nz; ++i)
143 else if (expdim == 3)
146 ASSERTL0(
false,
"Setup mapping aray");
150 ASSERTL0(
false,
"Exp dimension not recognised");
175 m_mat = Array<OneD, CoupledSolverMatrices> (nz);
177 ASSERTL1(
m_npointsZ <=2,
"Only expected a maxmimum of two planes in single mode linear NS solver");
203 m_mat = Array<OneD, CoupledSolverMatrices> (nz);
208 for(n = 1; n < nz; ++n)
377 Array<OneD, unsigned int> bmap,imap;
379 Array<OneD,unsigned int> nsize_bndry (nel);
380 Array<OneD,unsigned int> nsize_bndry_p1(nel);
381 Array<OneD,unsigned int> nsize_int (nel);
382 Array<OneD,unsigned int> nsize_p (nel);
383 Array<OneD,unsigned int> nsize_p_m1 (nel);
404 for(n = 0; n < nel; ++n)
408 nsize_bndry_p1[n] = nsize_bndry[n]+nz_loc;
409 nsize_int [n] = (nvel*
m_fields[
m_velocity[0]]->GetExp(eid)->GetNcoeffs()*nz_loc - nsize_bndry[n]);
410 nsize_p[n] =
m_pressure->GetExp(eid)->GetNcoeffs()*nz_loc;
411 nsize_p_m1[n] = nsize_p[n]-nz_loc;
441 for(n = 0; n < nel; ++n)
444 nbndry = nsize_bndry[n];
446 k = nsize_bndry_p1[n];
448 Array<OneD, NekDouble> Ah_data = Ah->GetPtr();
451 Array<OneD, NekDouble> B_data = B->GetPtr();
453 Array<OneD, NekDouble> C_data = C->GetPtr();
455 Array<OneD, NekDouble> D_data = D->GetPtr();
461 locExp->GetBoundaryMap(bmap);
462 locExp->GetInteriorMap(imap);
466 locExp->DetShapeType(),
473 int nbmap = bmap.num_elements();
474 int nimap = imap.num_elements();
476 Array<OneD, NekDouble> coeffs(ncoeffs);
477 Array<OneD, NekDouble> phys (nphys);
478 int psize =
m_pressure->GetExp(eid)->GetNcoeffs();
479 int pqsize =
m_pressure->GetExp(eid)->GetTotPoints();
481 Array<OneD, NekDouble> deriv (pqsize);
482 Array<OneD, NekDouble> pcoeffs(psize);
484 if(AddAdvectionTerms ==
false)
490 CondMat = locExp->GetLocStaticCondMatrix(helmkey);
492 for(k = 0; k < nvel*nz_loc; ++k)
495 rows = SubBlock.GetRows();
496 cols = SubBlock.GetColumns();
497 for(i = 0; i < rows; ++i)
499 for(j = 0; j < cols; ++j)
501 (*Ah)(i+k*rows,j+k*cols) =
m_kinvis*SubBlock(i,j);
506 for(k = 0; k < nvel*nz_loc; ++k)
510 rows = SubBlock.GetRows();
511 cols = SubBlock.GetColumns();
512 for(i = 0; i < rows; ++i)
514 for(j = 0; j < cols; ++j)
516 (*B)(i+k*rows,j+k*cols) = SubBlock(i,j);
517 (*C)(i+k*rows,j+k*cols) =
m_kinvis*SubBlock1(j,i);
522 for(k = 0; k < nvel*nz_loc; ++k)
526 rows = SubBlock.GetRows();
527 cols = SubBlock.GetColumns();
528 for(i = 0; i < rows; ++i)
530 for(j = 0; j < cols; ++j)
532 (*D)(i+k*rows,j+k*cols) = inv_kinvis*SubBlock(i,j);
539 for(i = 0; i < bmap.num_elements(); ++i)
543 coeffs[bmap[i]] = 1.0;
547 for(j = 0; j < nvel; ++j)
549 if( (nz_loc == 2)&&(j == 2))
555 m_pressure->GetExp(eid)->IProductWRTBase(deriv,pcoeffs);
557 Blas::Dcopy(psize,&(pcoeffs)[0],1,
559 ((nz_loc*j+1)*bmap.num_elements()+i)*nsize_p[n],1);
562 Blas::Dcopy(psize,&(pcoeffs)[0],1,
564 ((nz_loc*j)*bmap.num_elements()+i)*nsize_p[n]+psize,1);
572 m_pressure->GetExp(eid)->IProductWRTBase(deriv,pcoeffs);
574 for(k = 0; k < nz_loc; ++k)
576 Blas::Dcopy(psize,&(pcoeffs)[0],1,
578 ((nz_loc*j+k)*bmap.num_elements()+i)*nsize_p[n]+ k*psize,1);
585 for(i = 0; i < imap.num_elements(); ++i)
589 coeffs[imap[i]] = 1.0;
593 for(j = 0; j < nvel; ++j)
595 if( (nz_loc == 2)&&(j == 2))
601 m_pressure->GetExp(eid)->IProductWRTBase(deriv,pcoeffs);
603 Blas::Dcopy(psize,&(pcoeffs)[0],1,
605 ((nz_loc*j+1)*imap.num_elements()+i)*nsize_p[n],1);
608 Blas::Dcopy(psize,&(pcoeffs)[0],1,
610 ((nz_loc*j)*imap.num_elements()+i)*nsize_p[n]+psize,1);
620 m_pressure->GetExp(eid)->IProductWRTBase(deriv,pcoeffs);
623 for(k = 0; k < nz_loc; ++k)
625 Blas::Dcopy(psize,&(pcoeffs)[0],1,
627 ((nz_loc*j+k)*imap.num_elements()+i)*nsize_p[n]+ k*psize,1);
641 ->GetLocMatrix(helmkey));
644 Array<OneD, const NekDouble> HelmMat_data = HelmMat.GetOwnedMatrix()->GetPtr();
645 NekDouble HelmMatScale = HelmMat.Scale();
646 int HelmMatRows = HelmMat.GetRows();
651 locExp->DetShapeType(),
654 ->GetLocMatrix(masskey);
657 Array<OneD, NekDouble> Advtmp;
658 Array<OneD, Array<OneD, NekDouble> > AdvDeriv(nvel*nvel);
660 Array<OneD, NekDouble> tmpphys =
m_fields[0]->UpdatePhys();
663 int npoints = locExp->GetTotPoints();
666 if(IsLinearNSEquation)
670 AdvDeriv[0] = Array<OneD, NekDouble>(nvel*nvel*npoints);
671 for(nv = 0; nv < nvel; ++nv)
673 for(nv1 = 0; nv1 < nvel; ++nv1)
675 if(cnt < nvel*nvel-1)
677 AdvDeriv[cnt+1] = AdvDeriv[cnt] + npoints;
694 for(i = 0; i < nbmap; ++i)
699 coeffs[bmap[i]] = 1.0;
700 locExp->BwdTrans(coeffs,phys);
702 for(k = 0; k < nvel*nz_loc; ++k)
704 for(j = 0; j < nbmap; ++j)
707 Ah_data[i+k*nbmap + (j+k*nbmap)*AhRows] +=
m_kinvis*HelmMatScale*HelmMat_data[bmap[i] + HelmMatRows*bmap[j]];
710 for(j = 0; j < nimap; ++j)
712 B_data[i+k*nbmap + (j+k*nimap)*nbndry] +=
m_kinvis*HelmMatScale*HelmMat_data[bmap[i]+HelmMatRows*imap[j]];
718 for(k = 0; k < nvel; ++k)
720 for(j = 0; j < nbmap; ++j)
722 Ah_data[i+2*k*nbmap + (j+(2*k+1)*nbmap)*AhRows] -= lambda_imag*(*MassMat)(bmap[i],bmap[j]);
725 for(j = 0; j < nbmap; ++j)
727 Ah_data[i+(2*k+1)*nbmap + (j+2*k*nbmap)*AhRows] += lambda_imag*(*MassMat)(bmap[i],bmap[j]);
730 for(j = 0; j < nimap; ++j)
732 B_data[i+2*k*nbmap + (j+(2*k+1)*nimap)*nbndry] -= lambda_imag*(*MassMat)(bmap[i],imap[j]);
735 for(j = 0; j < nimap; ++j)
737 B_data[i+(2*k+1)*nbmap + (j+2*k*nimap)*nbndry] += lambda_imag*(*MassMat)(bmap[i],imap[j]);
745 for(k = 0; k < nvel; ++k)
747 if((nz_loc == 2)&&(k == 2))
754 m_pressure->GetExp(eid)->IProductWRTBase(deriv,pcoeffs);
755 Blas::Dcopy(psize,&(pcoeffs)[0],1,
757 ((nz_loc*k+1)*bmap.num_elements()+i)*nsize_p[n],1);
761 Blas::Dcopy(psize,&(pcoeffs)[0],1,
763 ((nz_loc*k)*bmap.num_elements()+i)*nsize_p[n]+psize,1);
767 Advtmp = Advfield[k] + phys_offset,
768 1,deriv,1,tmpphys,1);
770 locExp->IProductWRTBase(tmpphys,coeffs);
774 for(nv = 0; nv < nvel; ++nv)
776 for(j = 0; j < nbmap; ++j)
778 Ah_data[j+2*nv*nbmap + (i+(2*nv+1)*nbmap)*AhRows] +=
782 for(j = 0; j < nimap; ++j)
784 C_data[i+(2*nv+1)*nbmap + (j+2*nv*nimap)*nbndry] +=
791 for(nv = 0; nv < nvel; ++nv)
793 for(j = 0; j < nbmap; ++j)
795 Ah_data[j+(2*nv+1)*nbmap + (i+2*nv*nbmap)*AhRows] +=
799 for(j = 0; j < nimap; ++j)
801 C_data[i+2*nv*nbmap + (j+(2*nv+1)*nimap)*nbndry] +=
812 Advtmp = Advfield[k] + phys_offset,
813 1,deriv,1,tmpphys,1);
814 locExp->IProductWRTBase(tmpphys,coeffs);
817 for(nv = 0; nv < nvel*nz_loc; ++nv)
819 for(j = 0; j < nbmap; ++j)
821 Ah_data[j+nv*nbmap + (i+nv*nbmap)*AhRows] +=
825 for(j = 0; j < nimap; ++j)
827 C_data[i+nv*nbmap + (j+nv*nimap)*nbndry] +=
833 m_pressure->GetExp(eid)->IProductWRTBase(deriv,pcoeffs);
834 for(j = 0; j < nz_loc; ++j)
836 Blas::Dcopy(psize,&(pcoeffs)[0],1,
838 ((nz_loc*k+j)*bmap.num_elements() + i)*nsize_p[n]+ j*psize,1);
843 if(IsLinearNSEquation)
845 for(nv = 0; nv < nvel; ++nv)
851 locExp->IProductWRTBase(tmpphys,coeffs);
853 for(
int n1 = 0; n1 < nz_loc; ++n1)
855 for(j = 0; j < nbmap; ++j)
857 Ah_data[j+(k*nz_loc+n1)*nbmap +
858 (i+(nv*nz_loc+n1)*nbmap)*AhRows] +=
862 for(j = 0; j < nimap; ++j)
864 C_data[i+(nv*nz_loc+n1)*nbmap +
865 (j+(k*nz_loc+n1)*nimap)*nbndry] +=
875 for(i = 0; i < nimap; ++i)
879 coeffs[imap[i]] = 1.0;
880 locExp->BwdTrans(coeffs,phys);
882 for(k = 0; k < nvel*nz_loc; ++k)
884 for(j = 0; j < nbmap; ++j)
886 C_data[j+k*nbmap + (i+k*nimap)*nbndry] +=
m_kinvis*HelmMatScale*HelmMat_data[imap[i]+HelmMatRows*bmap[j]];
889 for(j = 0; j < nimap; ++j)
891 D_data[i+k*nimap + (j+k*nimap)*nint] +=
m_kinvis*HelmMatScale*HelmMat_data[imap[i]+HelmMatRows*imap[j]];
897 for(k = 0; k < nvel; ++k)
899 for(j = 0; j < nbmap; ++j)
901 C_data[j+2*k*nbmap + (i+(2*k+1)*nimap)*nbndry] += lambda_imag*(*MassMat)(bmap[j],imap[i]);
904 for(j = 0; j < nbmap; ++j)
906 C_data[j+(2*k+1)*nbmap + (i+2*k*nimap)*nbndry] -= lambda_imag*(*MassMat)(bmap[j],imap[i]);
909 for(j = 0; j < nimap; ++j)
911 D_data[i+2*k*nimap + (j+(2*k+1)*nimap)*nint] -= lambda_imag*(*MassMat)(imap[i],imap[j]);
914 for(j = 0; j < nimap; ++j)
916 D_data[i+(2*k+1)*nimap + (j+2*k*nimap)*nint] += lambda_imag*(*MassMat)(imap[i],imap[j]);
922 for(k = 0; k < nvel; ++k)
924 if((nz_loc == 2)&&(k == 2))
930 m_pressure->GetExp(eid)->IProductWRTBase(deriv,pcoeffs);
931 Blas::Dcopy(psize,&(pcoeffs)[0],1,
933 ((nz_loc*k+1)*imap.num_elements()+i)*nsize_p[n],1);
936 Blas::Dcopy(psize,&(pcoeffs)[0],1,
938 ((nz_loc*k)*imap.num_elements()+i)*nsize_p[n]+psize,1);
942 Vmath::Vmul(npoints, Advtmp = Advfield[k] + phys_offset,1,deriv,1,tmpphys,1);
943 locExp->IProductWRTBase(tmpphys,coeffs);
946 for(nv = 0; nv < nvel; ++nv)
948 for(j = 0; j < nbmap; ++j)
950 B_data[j+2*nv*nbmap + (i+(2*nv+1)*nimap)*nbndry] +=
954 for(j = 0; j < nimap; ++j)
956 D_data[j+2*nv*nimap + (i+(2*nv+1)*nimap)*nint] +=
962 for(nv = 0; nv < nvel; ++nv)
964 for(j = 0; j < nbmap; ++j)
966 B_data[j+(2*nv+1)*nbmap + (i+2*nv*nimap)*nbndry] +=
970 for(j = 0; j < nimap; ++j)
972 D_data[j+(2*nv+1)*nimap + (i+2*nv*nimap)*nint] +=
986 Advtmp = Advfield[k] + phys_offset,
987 1,deriv,1,tmpphys,1);
988 locExp->IProductWRTBase(tmpphys,coeffs);
991 for(nv = 0; nv < nvel*nz_loc; ++nv)
993 for(j = 0; j < nbmap; ++j)
995 B_data[j+nv*nbmap + (i+nv*nimap)*nbndry] +=
999 for(j = 0; j < nimap; ++j)
1001 D_data[j+nv*nimap + (i+nv*nimap)*nint] +=
1006 m_pressure->GetExp(eid)->IProductWRTBase(deriv,pcoeffs);
1007 for(j = 0; j < nz_loc; ++j)
1009 Blas::Dcopy(psize,&(pcoeffs)[0],1,
1011 ((nz_loc*k+j)*imap.num_elements() + i)*nsize_p[n]+j*psize,1);
1016 if(IsLinearNSEquation)
1019 for(nv = 0; nv < nvel; ++nv)
1023 AdvDeriv[k*nvel+nv],
1025 locExp->IProductWRTBase(tmpphys,coeffs);
1027 for(n1 = 0; n1 < nz_loc; ++n1)
1029 for(j = 0; j < nbmap; ++j)
1031 B_data[j+(k*nz_loc+n1)*nbmap +
1032 (i+(nv*nz_loc+n1)*nimap)*nbndry] +=
1036 for(j = 0; j < nimap; ++j)
1038 D_data[j+(k*nz_loc+n1)*nimap +
1039 (i+(nv*nz_loc+n1)*nimap)*nint] +=
1056 Blas::Dgemm(
'N',
'T', B->GetRows(), C->GetRows(),
1057 B->GetColumns(), -1.0, B->GetRawPtr(),
1058 B->GetRows(), C->GetRawPtr(),
1060 Ah->GetRawPtr(), Ah->GetRows());
1073 DNekMat DintCinvDTint, BCinvDTint_m_DTbnd, DintCinvBTtilde_m_Dbnd;
1079 DintCinvDTint = (*Dint)*(*Cinv)*
Transpose(*Dint);
1083 DintCinvBTtilde_m_Dbnd = (*Dint)*(*Cinv)*
Transpose(*Btilde) - (*Dbnd);
1089 Array<OneD, NekDouble> Dh_data = Dh->GetPtr();
1093 for(n1 = 0; n1 < nz_loc; ++n1)
1095 for(i = 0; i < psize-1; ++i)
1097 for(n2 = 0; n2 < nz_loc; ++n2)
1099 for(j = 0; j < psize-1; ++j)
1103 Dh_data[(i+n1*(psize-1)) + (j+n2*(psize-1))*Dh->GetRows()] =
1104 -DintCinvDTint(i+1+n1*psize,j+1+n2*psize);
1110 for(n1 = 0; n1 < nz_loc; ++n1)
1112 for(i = 0; i < nsize_bndry_p1[n]-nz_loc; ++i)
1114 (*Ah)(i,nsize_bndry_p1[n]-nz_loc+n1) = BCinvDTint_m_DTbnd(i,n1*psize);
1115 (*Ah)(nsize_bndry_p1[n]-nz_loc+n1,i) = DintCinvBTtilde_m_Dbnd(n1*psize,i);
1119 for(n1 = 0; n1 < nz_loc; ++n1)
1121 for(n2 = 0; n2 < nz_loc; ++n2)
1123 (*Ah)(nsize_bndry_p1[n]-nz_loc+n1,nsize_bndry_p1[n]-nz_loc+n2) =
1124 -DintCinvDTint(n1*psize,n2*psize);
1128 for(n1 = 0; n1 < nz_loc; ++n1)
1130 for(j = 0; j < psize-1; ++j)
1132 for(i = 0; i < nsize_bndry_p1[n]-nz_loc; ++i)
1134 (*Bh)(i,j+n1*(psize-1)) = BCinvDTint_m_DTbnd(i,j+1+n1*psize);
1135 (*Ch)(j+n1*(psize-1),i) = DintCinvBTtilde_m_Dbnd(j+1+n1*psize,i);
1140 for(n1 = 0; n1 < nz_loc; ++n1)
1142 for(n2 = 0; n2 < nz_loc; ++n2)
1144 for(j = 0; j < psize-1; ++j)
1146 (*Bh)(nsize_bndry_p1[n]-nz_loc+n1,j+n2*(psize-1)) = -DintCinvDTint(n1*psize,j+1+n2*psize);
1147 (*Ch)(j+n2*(psize-1),nsize_bndry_p1[n]-nz_loc+n1) = -DintCinvDTint(j+1+n2*psize,n1*psize);
1154 (*Bh) = (*Bh)*(*Dh);
1156 Blas::Dgemm(
'N',
'N', Bh->GetRows(), Ch->GetColumns(), Bh->GetColumns(), -1.0,
1157 Bh->GetRawPtr(), Bh->GetRows(), Ch->GetRawPtr(), Ch->GetRows(),
1158 1.0, Ah->GetRawPtr(), Ah->GetRows());
1168 cout <<
"Matrix Setup Costs: " << timer.
TimePerTest(1) << endl;
1180 cout <<
"Multilevel condensation: " << timer.
TimePerTest(1) << endl;
1227 Array<OneD, Array<OneD, NekDouble> > AdvField(
m_velocity.num_elements());
1228 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1234 "Advection Velocity section must be defined in "
1237 std::vector<std::string> fieldStr;
1238 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1262 "Restart section must be defined in session file.");
1264 Array<OneD, Array<OneD, NekDouble> > Restart(
m_velocity.num_elements());
1265 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1269 std::vector<std::string> fieldStr;
1270 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1276 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1280 cout <<
"Saving the RESTART file for m_kinvis = "<<
m_kinvis <<
" (<=> Re = " << 1/
m_kinvis <<
")" <<endl;
1299 cout <<
"Saving the Stokes Flow for m_kinvis = "<<
m_kinvis <<
" (<=> Re = " << 1/
m_kinvis <<
")" <<endl;
1307 Array<OneD, Array<OneD, NekDouble> > AdvField(
m_velocity.num_elements());
1308 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1314 "Advection Velocity section must be defined in "
1317 std::vector<std::string> fieldStr;
1318 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1329 ASSERTL0(
false,
"Unknown or undefined equation type for CoupledLinearNS");
1334 Array<
OneD, Array<OneD, NekDouble> > &outarray,
1340 std::vector<SolverUtils::ForcingSharedPtr>::const_iterator x;
1343 (*x)->Apply(
m_fields, outarray, outarray, time);
1348 Array<
OneD, Array<OneD, NekDouble> > &outarray,
1356 Array <OneD, Array<OneD, NekDouble> > forcing(
m_velocity.num_elements());
1358 if(fabs(lambda_store - lambda) > 1e-10)
1360 cout <<
"Setting up Stokes matrix problem [.";
1363 cout <<
"]" << endl;
1364 lambda_store = lambda;
1370 for(i = 0; i <
m_velocity.num_elements(); ++i)
1379 for(i = 0; i <
m_velocity.num_elements(); ++i)
1388 int nfields =
m_fields.num_elements();
1389 for (
int k=0 ; k < nfields; ++k)
1400 int nfields =
m_fields.num_elements();
1401 for (
int k=0 ; k < nfields; ++k)
1429 Generaltimer.
Start();
1437 cout<<
"We execute INITIALLY SolveSteadyNavierStokes for m_kinvis = "<<
m_kinvis<<
" (<=> Re = "<<1/
m_kinvis<<
")"<<endl;
1444 cout<<
"We execute SolveSteadyNavierStokes for m_kinvis = "<<
m_kinvis<<
" (<=> Re = "<<1/
m_kinvis<<
")"<<endl;
1454 cout<<
"We execute SolveSteadyNavierStokes for m_kinvis = "<<
m_kinvis<<
" (<=> Re = "<<1/
m_kinvis<<
")"<<endl;
1462 Generaltimer.
Stop();
1463 cout<<
"\nThe total calculation time is : " << Generaltimer.
TimePerTest(1)/60 <<
" minute(s). \n\n";
1469 ASSERTL0(
false,
"Unknown or undefined equation type for CoupledLinearNS");
1477 const unsigned int ncmpt =
m_velocity.num_elements();
1478 Array<OneD, Array<OneD, NekDouble> > forcing_phys(ncmpt);
1479 Array<OneD, Array<OneD, NekDouble> > forcing (ncmpt);
1481 for(
int i = 0; i < ncmpt; ++i)
1483 forcing_phys[i] = Array<OneD, NekDouble> (
m_fields[
m_velocity[0]]->GetNpoints(), 0.0);
1487 std::vector<SolverUtils::ForcingSharedPtr>::const_iterator x;
1491 (*x)->Apply(
m_fields, forcing_phys, forcing_phys, time);
1493 for (
unsigned int i = 0; i < ncmpt; ++i)
1495 m_fields[i]->IProductWRTBase(forcing_phys[i], forcing[i]);
1500 m_fields[i]->HomogeneousFwdTrans(forcing[i], forcing[i]);
1513 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1516 m_ForcingTerm_Coeffs[i] = Array<OneD, NekDouble> (
m_fields[
m_velocity[i]]->GetNcoeffs(),0.0);
1519 if(
m_session->DefinesFunction(
"ForcingTerm"))
1521 std::vector<std::string> fieldStr;
1522 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1527 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1534 cout <<
"'ForcingTerm' section has not been defined in the input file => forcing=0" << endl;
1541 Newtontimer.
Start();
1543 Array<OneD, Array<OneD, NekDouble> > RHS_Coeffs(
m_velocity.num_elements());
1544 Array<OneD, Array<OneD, NekDouble> > RHS_Phys(
m_velocity.num_elements());
1545 Array<OneD, Array<OneD, NekDouble> > delta_velocity_Phys(
m_velocity.num_elements());
1546 Array<OneD, Array<OneD, NekDouble> >Velocity_Phys(
m_velocity.num_elements());
1547 Array<OneD, NekDouble > L2_norm(
m_velocity.num_elements(), 1.0);
1548 Array<OneD, NekDouble > Inf_norm(
m_velocity.num_elements(), 1.0);
1550 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1552 delta_velocity_Phys[i] = Array<OneD, NekDouble> (
m_fields[
m_velocity[i]]->GetTotPoints(),1.0);
1553 Velocity_Phys[i] = Array<OneD, NekDouble> (
m_fields[
m_velocity[i]]->GetTotPoints(),0.0);
1558 L2Norm(delta_velocity_Phys, L2_norm);
1561 while(max(L2_norm[0], L2_norm[1]) >
m_tol)
1566 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1572 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1594 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1600 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1602 Vmath::Vadd(Velocity_Phys[i].num_elements(),Velocity_Phys[i], 1, delta_velocity_Phys[i], 1,
1603 Velocity_Phys[i], 1);
1607 L2Norm(delta_velocity_Phys, L2_norm);
1609 if(max(Inf_norm[0], Inf_norm[1]) > 100)
1611 cout<<
"\nThe Newton method has failed at m_kinvis = "<<
m_kinvis<<
" (<=> Re = " << 1/
m_kinvis <<
")"<< endl;
1612 ASSERTL0(0,
"The Newton method has failed... \n");
1622 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1629 cout<<
"We have done "<<
m_counter-1 <<
" iteration(s) in " << Newtontimer.
TimePerTest(1)/60 <<
" minute(s). \n\n";
1635 Array<OneD, Array<OneD, NekDouble> > u_N(
m_velocity.num_elements());
1636 Array<OneD, Array<OneD, NekDouble> > tmp_RHS(
m_velocity.num_elements());
1637 Array<OneD, Array<OneD, NekDouble> > RHS(
m_velocity.num_elements());
1638 Array<OneD, Array<OneD, NekDouble> > u_star(
m_velocity.num_elements());
1640 cout <<
"We apply the continuation method: " <<endl;
1642 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1659 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1666 Vmath::Vadd(u_star[i].num_elements(), u_star[i], 1, u_N[i], 1, u_star[i], 1);
1676 Array<OneD, NekDouble> &outarray)
1678 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1681 for(
int j = 0; j < inarray[i].num_elements(); ++j)
1683 if(inarray[i][j] > outarray[i])
1685 outarray[i] = inarray[i][j];
1688 cout <<
"InfNorm["<<i<<
"] = "<< outarray[i] <<endl;
1693 Array<OneD, NekDouble> &outarray)
1695 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1698 for(
int j = 0; j < inarray[i].num_elements(); ++j)
1700 outarray[i] += inarray[i][j]*inarray[i][j];
1702 outarray[i]=sqrt(outarray[i]);
1703 cout <<
"L2Norm["<<i<<
"] = "<< outarray[i] <<endl;
1709 Array<
OneD, Array<OneD, NekDouble> > &outarray)
1711 Array<OneD, Array<OneD, NekDouble> > Eval_Adv(
m_velocity.num_elements());
1712 Array<OneD, Array<OneD, NekDouble> > tmp_DerVel(
m_velocity.num_elements());
1713 Array<OneD, Array<OneD, NekDouble> > AdvTerm(
m_velocity.num_elements());
1714 Array<OneD, Array<OneD, NekDouble> > ViscTerm(
m_velocity.num_elements());
1715 Array<OneD, Array<OneD, NekDouble> > Forc(
m_velocity.num_elements());
1717 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1720 tmp_DerVel[i] = Array<OneD, NekDouble> (
m_fields[
m_velocity[i]]->GetTotPoints(),0.0);
1734 for(
int i = 0; i <
m_velocity.num_elements(); ++i)
1740 Vmath::Vsub(outarray[i].num_elements(), outarray[i], 1, AdvTerm[i], 1, outarray[i], 1);
1741 Vmath::Vsub(outarray[i].num_elements(), outarray[i], 1, ViscTerm[i], 1, outarray[i], 1);
1743 Vmath::Vadd(outarray[i].num_elements(), outarray[i], 1, Forc[i], 1, outarray[i], 1);
1756 SpatialDomains::ExpansionMap::const_iterator expMapIter;
1759 for (expMapIter = VelExp.begin(); expMapIter != VelExp.end(); ++expMapIter)
1763 for(i = 0; i < expMapIter->second->m_basisKeyVector.size(); ++i)
1767 ASSERTL0(nummodes > 3,
"Velocity polynomial space not sufficiently high (>= 4)");
1770 BasisVec.push_back(newB);
1776 (*returnval)[expMapIter->first] = expansionElementShPtr;
1780 m_graph->SetExpansions(
"p",returnval);
1852 Array<OneD, MultiRegions::ExpListSharedPtr> vel_fields(
m_velocity.num_elements());
1853 Array<OneD, Array<OneD, NekDouble> > force(
m_velocity.num_elements());
1861 for(i = 0; i <
m_velocity.num_elements(); ++i)
1865 force[i] = forcing[i] + 2*n*ncoeffsplane;
1870 for(i = 0; i <
m_velocity.num_elements(); ++i)
1878 for(i = 0; i <
m_velocity.num_elements(); ++i)
1882 force[i] = forcing[i];
1890 int i,j,k,n,eid,cnt,cnt1;
1891 int nbnd,nint,offset;
1893 int nel = fields[0]->GetNumElmts();
1894 Array<OneD, unsigned int> bmap, imap;
1896 Array<OneD, NekDouble > f_bnd(
m_mat[mode].m_BCinv->GetRows());
1898 Array<OneD, NekDouble > f_int(
m_mat[mode].m_BCinv->GetColumns());
1902 int nplanecoeffs = fields[
m_velocity[0]]->GetNcoeffs();
1920 for(i = 0; i < fields.num_elements(); ++i)
1924 Vmath::Zero(2*pressure->GetNcoeffs(),pressure->UpdateCoeffs(),1);
1931 for(i = 0; i < nel; ++i)
1933 eid = fields[
m_velocity[0]]->GetOffset_Elmt_Id(i);
1934 fields[
m_velocity[0]]->GetExp(eid)->GetBoundaryMap(bmap);
1935 fields[
m_velocity[0]]->GetExp(eid)->GetInteriorMap(imap);
1936 nbnd = bmap.num_elements();
1937 nint = imap.num_elements();
1938 offset = fields[
m_velocity[0]]->GetCoeff_Offset(eid);
1940 for(j = 0; j < nvel; ++j)
1942 for(n = 0; n < nz_loc; ++n)
1944 for(k = 0; k < nbnd; ++k)
1946 f_bnd[cnt+k] = forcing[j][n*nplanecoeffs +
1949 for(k = 0; k < nint; ++k)
1951 f_int[cnt1+k] = forcing[j][n*nplanecoeffs +
1960 Array<OneD, NekDouble > f_p(
m_mat[mode].m_D_int->GetRows());
1965 F_bnd = F_bnd - (*
m_mat[mode].m_BCinv)*F_int;
1966 F_p_tmp = (*
m_mat[mode].m_Cinv)*F_int;
1967 F_p = (*
m_mat[mode].m_D_int) * F_p_tmp;
1970 Array<OneD, NekDouble > bnd (
m_locToGloMap[mode]->GetNumGlobalCoeffs(),0.0);
1971 Array<OneD, NekDouble > fh_bnd(
m_locToGloMap[mode]->GetNumGlobalCoeffs(),0.0);
1973 const Array<OneD,const int>& loctoglomap
1975 const Array<OneD,const NekDouble>& loctoglosign
1979 for(i = 0; i < nel; ++i)
1981 eid = fields[0]->GetOffset_Elmt_Id(i);
1982 nbnd = nz_loc*fields[0]->GetExp(eid)->NumBndryCoeffs();
1984 for(j = 0; j < nvel; ++j)
1986 for(k = 0; k < nbnd; ++k)
1988 fh_bnd[loctoglomap[offset+j*nbnd+k]] +=
1989 loctoglosign[offset+j*nbnd+k]*f_bnd[cnt+k];
1994 nint = pressure->GetExp(eid)->GetNcoeffs();
1995 offset += nvel*nbnd + nint*nz_loc;
1999 for(i = 0; i < nel; ++i)
2001 eid = fields[0]->GetOffset_Elmt_Id(i);
2002 nbnd = nz_loc*fields[0]->GetExp(eid)->NumBndryCoeffs();
2003 nint = pressure->GetExp(eid)->GetNcoeffs();
2005 for(n = 0; n < nz_loc; ++n)
2007 for(j = 0; j < nint; ++j)
2009 fh_bnd[loctoglomap[offset + nvel*nbnd + n*nint+j]] = f_p[cnt1+j];
2013 offset += nvel*nbnd + nz_loc*nint;
2017 const Array<OneD,const int>& bndmap
2024 for(k = 0; k < nvel; ++k)
2026 const Array<OneD, SpatialDomains::BoundaryConditionShPtr> bndConds = fields[k]->GetBndConditions();
2027 Array<OneD, const MultiRegions::ExpListSharedPtr> bndCondExp;
2030 bndCondExp =
m_fields[k]->GetPlane(2*mode)->GetBndCondExpansions();
2034 bndCondExp =
m_fields[k]->GetBndCondExpansions();
2037 for(i = 0; i < bndCondExp.num_elements(); ++i)
2039 const Array<OneD, const NekDouble > bndCondCoeffs = bndCondExp[i]->GetCoeffs();
2041 for(n = 0; n < nz_loc; ++n)
2043 if(bndConds[i]->GetBoundaryConditionType()
2046 for(j = 0; j < (bndCondExp[i])->
GetNcoeffs(); j++)
2052 bnd[bndmap[bndcnt++]] = 0;
2056 bnd[bndmap[bndcnt++]] = bndCondCoeffs[cnt++];
2062 for(j = 0; j < (bndCondExp[i])->
GetNcoeffs(); j++)
2064 fh_bnd[bndmap[bndcnt++]]
2065 += bndCondCoeffs[cnt++];
2076 int totpcoeffs = pressure->GetNcoeffs();
2077 Array<OneD, NekDouble> p_coeffs = pressure->UpdateCoeffs();
2078 for(i = 0; i < nel; ++i)
2080 eid = fields[0]->GetOffset_Elmt_Id(i);
2081 nbnd = nz_loc*fields[0]->GetExp(eid)->NumBndryCoeffs();
2082 nint = pressure->GetExp(eid)->GetNcoeffs();
2084 for(j = 0; j < nvel; ++j)
2086 for(k = 0; k < nbnd; ++k)
2088 f_bnd[cnt+k] = loctoglosign[offset+j*nbnd+k]*bnd[loctoglomap[offset + j*nbnd + k]];
2092 offset += nvel*nbnd + nint*nz_loc;
2095 pressure->SetPhysState(
false);
2097 offset = cnt = cnt1 = 0;
2098 for(i = 0; i < nel; ++i)
2100 eid = fields[0]->GetOffset_Elmt_Id(i);
2101 nint = pressure->GetExp(eid)->GetNcoeffs();
2102 nbnd = fields[0]->GetExp(eid)->NumBndryCoeffs();
2103 cnt1 = pressure->GetCoeff_Offset(eid);
2105 for(n = 0; n < nz_loc; ++n)
2107 for(j = 0; j < nint; ++j)
2109 p_coeffs[n*totpcoeffs + cnt1+j] =
2110 f_p[cnt+j] = bnd[loctoglomap[offset +
2111 (nvel*nz_loc)*nbnd +
2116 offset += (nvel*nbnd + nint)*nz_loc;
2123 F_int = (*
m_mat[mode].m_Cinv)*F_int;
2127 for(i = 0; i < nel; ++i)
2129 eid = fields[
m_velocity[0]]->GetOffset_Elmt_Id(i);
2130 fields[0]->GetExp(eid)->GetBoundaryMap(bmap);
2131 fields[0]->GetExp(eid)->GetInteriorMap(imap);
2132 nbnd = bmap.num_elements();
2133 nint = imap.num_elements();
2134 offset = fields[0]->GetCoeff_Offset(eid);
2136 for(j = 0; j < nvel; ++j)
2138 for(n = 0; n < nz_loc; ++n)
2140 for(k = 0; k < nbnd; ++k)
2142 fields[j]->SetCoeff(n*nplanecoeffs +
2147 for(k = 0; k < nint; ++k)
2149 fields[j]->SetCoeff(n*nplanecoeffs +
2159 for(j = 0; j < nvel; ++j)
2161 fields[j]->SetPhysState(
false);
2167 std::vector<Array<OneD, NekDouble> > fieldcoeffs(
m_fields.num_elements()+1);
2168 std::vector<std::string> variables(
m_fields.num_elements()+1);
2171 for(i = 0; i <
m_fields.num_elements(); ++i)
2173 fieldcoeffs[i] =
m_fields[i]->UpdateCoeffs();
2177 fieldcoeffs[i] = Array<OneD, NekDouble>(
m_fields[0]->GetNcoeffs());
2184 m_fields[0]->GetPlane(0)->FwdTrans_IterPerExp(
m_pressure->GetPlane(0)->GetPhys(),fieldcoeffs[i]);
2185 m_fields[0]->GetPlane(1)->FwdTrans_IterPerExp(
m_pressure->GetPlane(1)->GetPhys(),tmpfieldcoeffs);
2186 for(
int e=0; e<
m_fields[0]->GetNcoeffs()/2; e++)
2188 fieldcoeffs[i][e+
m_fields[0]->GetNcoeffs()/2] = tmpfieldcoeffs[e];
2205 return m_session->GetVariables().size();