21#ifdef GISMO_WITH_PARDISO
25inline void pardisoSetup(
typename gsSparseSolver<T>::PardisoLU& solver)
27 solver.setParam(7, 15);
28 solver.setParam(9, 13);
29 solver.setParam(12, 0);
34inline void startAnimationFile(std::ofstream& file)
36 file <<
"<?xml version=\"1.0\"?>\n";
37 file <<
"<VTKFile type=\"Collection\" version=\"0.1\">";
38 file <<
"<Collection>\n";
42inline void endAnimationFile(std::ofstream& file)
44 file <<
"</Collection>\n";
45 file <<
"</VTKFile>\n";
55inline void gsWriteOutput(std::ofstream& file,
const std::string output,
bool fileOutput,
bool dispInTerminal)
70inline void gsWriteOutputLine(std::ofstream& file,
const std::string line,
bool fileOutput,
bool dispInTerminal)
87 std::map<T, bool> map;
88 std::vector<T> vecTmp;
90 for (
index_t j = 0; j < mat.cols(); j++)
92 for (
index_t i = 0; i < mat.rows(); i++)
94 if(map.count(mat(i,j)) == 0)
97 vecTmp.push_back(mat(i,j));
103 for (
size_t i = 0; i < vecTmp.size(); i++)
115template<
class T,
int MatOrder>
119 nnzPerOuter.setZero();
121 for (
index_t outer = 0; outer < mat.outerSize(); outer++)
123 ++nnzPerOuter[outer];
136template<
class T,
int MatOrder>
139 GISMO_ENSURE(mat.nonZeros() != 0,
"diagInvMatrix_into(): The matrix is empty!");
141 int varDofs = mat.rows();
143 diagInv.resize(repeat*varDofs, repeat*varDofs);
153 for (
int j = 0; j < varDofs; j++)
154 lumped.insert(j, j) = math::abs(mat.at(j, j));
156 for (
int j = 0; j < varDofs; j++)
163 lumped.coeffRef(i, i) += math::abs(it.value());
170 for (
int i = 0; i < varDofs; i++)
172 T tmp = 1 / matPtr->coeff(i, i);
174 for (
int s = 0; s < repeat; s++)
175 diagInv.coeffRef(i + s * varDofs, i + s * varDofs) = tmp;
193 int n = kv.
size() - deg - 1;
196 for (
int i = 0; i < n; i++)
197 for (
int j = 0; j < n; j++)
198 coef.row(i + j*n) << llx + (i*a) / (deg*(numSep + 1)), lly + (j*b) / (deg*(numSep + 1));
219 int n = kv.
size() - deg - 1;
222 for (
int i = 0; i < n; i++)
223 for (
int j = 0; j < n; j++)
224 for (
int k = 0; k < n; k++)
225 coef.row(i + j*n + k*n*n) << llx + (i*a) / (deg*(numSep + 1)), lly + (j*b) / (deg*(numSep + 1)), llz + (k*c) / (deg*(numSep + 1));
246 for (
int j = 0; j < np; j++)
247 for (
int i = 0; i < np; i++)
248 mp.addPatch(
BSplineRectangle(deg, i*aPatch, j*bPatch, aPatch, bPatch, numSep));
250 mp.computeTopology();
267 mp.addPatch(
BSplineBlock(deg, 0.0, 0.0, 0.0, a, b, c, numSep));
268 mp.computeTopology();
293 mp.addInterface(0, boundary::north, 1, boundary::south);
294 mp.addInterface(1, boundary::west, 2, boundary::east);
297 mp.addInterface(0, boundary::south, 1, boundary::north);
299 mp.addAutoBoundaries();
322 mp.addPatch(BSplineBlock<T>(deg, 0.0, 0.0, 0.0, a, h, c));
323 mp.addPatch(BSplineBlock<T>(deg, 0.0, h, 0.0, a, b - h, c));
324 mp.addPatch(BSplineBlock<T>(deg, -a_in, h, 0.0, a_in, b - h, c));
326 mp.addInterface(0, boundary::north, 1, boundary::south);
327 mp.addInterface(2, boundary::east, 1, boundary::west);
331 mp.addInterface(0, boundary::front, (
size_t)0, boundary::back);
332 mp.addInterface(1, boundary::front, 1, boundary::back);
333 mp.addInterface(2, boundary::front, 2, boundary::back);
336 mp.addAutoBoundaries();
352 for (
size_t i = 0; i < bndIn.size(); i++)
355 for (
size_t i = 0; i < bndWall.size(); i++)
372 for (
int i = 1; i <= np; i++)
375 bndWall.push_back(std::make_pair(np*np - i, boundary::north));
378 for (
int i = 0; i < np; i++)
381 bndWall.push_back(std::make_pair(i, boundary::south));
384 for (
int i = 0; i < np; i++)
388 bndWall.push_back(std::make_pair(i * np, boundary::west));
389 bndWall.push_back(std::make_pair((i + 1)*np - 1, boundary::east));
411 bndWall.push_back(std::make_pair(0, boundary::north));
412 bndWall.push_back(std::make_pair(0, boundary::south));
413 bndWall.push_back(std::make_pair(0, boundary::west));
414 bndWall.push_back(std::make_pair(0, boundary::east));
415 bndWall.push_back(std::make_pair(0, boundary::front));
416 bndWall.push_back(std::make_pair(0, boundary::back));
454void defineBCs_step2D(
gsBoundaryConditions<T>& bcInfo, std::vector<std::pair<int, boxSide> >& bndIn, std::vector<std::pair<int, boxSide> >& bndOut, std::vector<std::pair<int, boxSide> >& bndWall,
bool periodic =
false, std::string inVel =
"default")
456 if (inVel ==
"default")
457 inVel =
"(-4*(y-1.5)^2 + 1)";
465 bndIn.push_back(std::make_pair(2, boundary::west));
466 bndWall.push_back(std::make_pair(0, boundary::west));
467 bndWall.push_back(std::make_pair(0, boundary::south));
468 bndWall.push_back(std::make_pair(1, boundary::north));
469 bndWall.push_back(std::make_pair(2, boundary::south));
470 bndWall.push_back(std::make_pair(2, boundary::north));
471 bndOut.push_back(std::make_pair(0, boundary::east));
472 bndOut.push_back(std::make_pair(1, boundary::east));
476 bndIn.push_back(std::make_pair(2, boundary::west));
477 bndWall.push_back(std::make_pair(0, boundary::west));
478 bndWall.push_back(std::make_pair(2, boundary::south));
479 bndWall.push_back(std::make_pair(2, boundary::north));
480 bndOut.push_back(std::make_pair(0, boundary::east));
481 bndOut.push_back(std::make_pair(1, boundary::east));
484 addBCs(bcInfo, bndIn, bndWall, Uin, Uwall);
497void defineBCs_step3D(
gsBoundaryConditions<T>& bcInfo, std::vector<std::pair<int, boxSide> >& bndIn, std::vector<std::pair<int, boxSide> >& bndOut, std::vector<std::pair<int, boxSide> >& bndWall,
bool periodic =
false, std::string inVel =
"default")
503 if (inVel ==
"default")
504 inVel =
"(-4*(y-1.5)^2 + 1)*(-(z-1)^2 + 1)";
509 bndIn.push_back(std::make_pair(2, boundary::west));
510 bndWall.push_back(std::make_pair(0, boundary::west));
511 bndWall.push_back(std::make_pair(0, boundary::south));
512 bndWall.push_back(std::make_pair(0, boundary::front));
513 bndWall.push_back(std::make_pair(0, boundary::back));
514 bndWall.push_back(std::make_pair(1, boundary::north));
515 bndWall.push_back(std::make_pair(1, boundary::front));
516 bndWall.push_back(std::make_pair(1, boundary::back));
517 bndWall.push_back(std::make_pair(2, boundary::south));
518 bndWall.push_back(std::make_pair(2, boundary::north));
519 bndWall.push_back(std::make_pair(2, boundary::front));
520 bndWall.push_back(std::make_pair(2, boundary::back));
521 bndOut.push_back(std::make_pair(0, boundary::east));
522 bndOut.push_back(std::make_pair(1, boundary::east));
526 if (inVel ==
"default")
527 inVel =
"(-4*(y-1.5)^2 + 1)";
532 bndIn.push_back(std::make_pair(2, boundary::west));
533 bndWall.push_back(std::make_pair(0, boundary::west));
534 bndWall.push_back(std::make_pair(0, boundary::south));
535 bndWall.push_back(std::make_pair(1, boundary::north));
536 bndWall.push_back(std::make_pair(2, boundary::south));
537 bndWall.push_back(std::make_pair(2, boundary::north));
538 bndOut.push_back(std::make_pair(0, boundary::east));
539 bndOut.push_back(std::make_pair(1, boundary::east));
542 addBCs(bcInfo, bndIn, bndWall, Uin, Uwall);
556void defineBCs_step(
gsBoundaryConditions<T>& bcInfo, std::vector<std::pair<int, boxSide> >& bndIn, std::vector<std::pair<int, boxSide> >& bndOut, std::vector<std::pair<int, boxSide> >& bndWall,
int dim,
bool periodic =
false, std::string inVel =
"default")
588 bndIn.push_back(std::make_pair(0, boundary::west));
589 bndWall.push_back(std::make_pair(1, boundary::north));
590 bndWall.push_back(std::make_pair(1, boundary::south));
591 bndOut.push_back(std::make_pair(2, boundary::east));
593 addBCs(bcInfo, bndIn, bndWall, Uin, Uwall);
604template<
int d,
class T>
610 for (
int i = 0; i < numRefine; i++)
613 T knot = patchBasis->knot(dir, patchBasis->
degree(dir) + 1);
615 basis.refine(patch, box);
627template<
int d,
class T>
633 for (
int i = 0; i < numRefine; i++)
636 int sizeKnots = patchBasis->knots(dir).size() - 1;
637 T lastKnot = patchBasis->knot(dir, sizeKnots);
638 T knot = patchBasis->knot(dir, sizeKnots - (patchBasis->
degree(dir) + 1));
640 box(dir, 1) = lastKnot;
641 basis.refine(patch, box);
660 int npDir = math::sqrt(basis.nPieces());
661 int npRef = std::log2(npDir);
662 int sepRef = std::log2(numSep + 1);
664 for (
int i = 0; i < numRefine - npRef - sepRef; ++i)
665 basis.uniformRefine();
667 if (numRefineLocal && npDir == 1)
669 for (
int dir = 0; dir < dim; dir++)
671 refineFirstKnotSpan<2, T>(basis, numRefineLocal, 0, dir);
672 refineLastKnotSpan<2, T>(basis, numRefineLocal, 0, dir);
680 for (
int i = 0; i < numRefine; ++i)
681 basis.uniformRefine();
683 for (
int dir = 0; dir < dim; dir++)
685 refineFirstKnotSpan<3, T>(basis, numRefineLocal, 0, dir);
686 refineLastKnotSpan<3, T>(basis, numRefineLocal, 0, dir);
704template<
int d,
class T>
708 refineFirstKnotSpan<d, T>(basis, numRefineWalls, 0, 1);
709 refineLastKnotSpan<d, T>(basis, numRefineWalls, 1, 1);
710 refineLastKnotSpan<d, T>(basis, numRefineWalls, 2, 1);
713 refineFirstKnotSpan<d, T>(basis, numRefineCorner, 0, 0);
714 refineFirstKnotSpan<d, T>(basis, numRefineCorner, 1, 0);
715 refineLastKnotSpan<d, T>(basis, numRefineCorner, 2, 0);
716 refineLastKnotSpan<d, T>(basis, numRefineCorner, 0, 1);
717 refineFirstKnotSpan<d, T>(basis, numRefineCorner, 1, 1);
718 refineFirstKnotSpan<d, T>(basis, numRefineCorner, 2, 1);
735void refineBasis_step(
gsMultiBasis<T>& basis,
int numRefine,
int numRefineWalls,
int numRefineCorner,
int numRefineU, real_t addRefPart,
int dim, real_t a, real_t b, real_t c = 0.0)
737 for (
int i = 0; i < numRefine; ++i)
738 basis.uniformRefine();
742 int uRefine = math::floor(std::log2(a / b)) + 1 + numRefineU;
745 for (
int i = 0; i < uRefine; i++)
746 for (
int p = 0; p < 2; p++)
747 basis.refine(p, box);
751 int wRefine = math::floor(std::log2(c / b)) + 1;
754 for (
int i = 0; i < wRefine; i++)
755 for (
int p = 0; p < 3; p++)
756 basis.refine(p, box);
760 box(0,1) = addRefPart;
761 for (
int p = 0; p < 2; p++)
762 basis.refine(p, box);
767 refineLocal_step<2, T>(basis, numRefineWalls, numRefineCorner);
770 refineLocal_step<3, T>(basis, numRefineWalls, numRefineCorner);
788 for (
int i = 0; i < numRefine; ++i)
789 basis.uniformRefine();
793 for (
int p = 0; p < basis.nPieces(); p++)
795 refineFirstKnotSpan<2, T>(basis, numRefineBlade, p, 1);
796 refineLastKnotSpan<2, T>(basis, numRefineBlade, p, 1);
802 refineLastKnotSpan<2, T>(basis, numRefineLead, 0, 0);
803 refineFirstKnotSpan<2, T>(basis, numRefineLead, 1, 0);
809void plotQuantityFromSolution(std::string quantity,
const gsField<T>& solField, std::string
const & fn,
unsigned npts)
812 std::string fileName;
814 for (
unsigned int p = 0; p < solField.
patches().nPatches(); p++)
822 const int parDim = patch->domainDim();
823 const int tarDim = patch->targetDim();
828 np = uniformSampleCount(a, b, npts);
832 geoVals = patch->eval(pts);
836 np.conservativeResize(3);
837 np.bottomRows(3 - parDim).setOnes();
841 geoVals.conservativeResize(3, geoVals.cols());
842 geoVals.bottomRows(3 - tarDim).setZero();
846 if (quantity ==
"divergence")
847 solField.
function(p).div_into(pts, quantityVals);
849 GISMO_ERROR(
"Function plotQuantityFromSolution for " + quantity +
" not implemented.");
852 gsWriteParaviewTPgrid(geoVals, quantityVals, np.template cast<index_t>(), fileName);
854 pwCollection.addPart(fileName +
".vts");
866 std::size_t operator()(
const gsVector<T>& vec)
const
868 std::size_t seed = vec.size();
869 for (
int i = 0; i < vec.size(); i++)
870 seed ^= std::hash<T>()(vec(i)) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
877inline index_t mapTensorID(index_t i, index_t j, index_t k,
size_t size1,
size_t size2)
879 index_t result = (k*size1*size2)+(j*size1)+i;
Class containing a set of boundary conditions.
Definition gsBoundaryConditions.h:342
void addCondition(int p, boxSide s, condition_type::type t, gsFunctionSet< T > *f, short_t unknown=0, bool parametric=false, int comp=-1)
Adds another boundary condition.
Definition gsBoundaryConditions.h:650
A scalar of vector field defined on a m_parametric geometry.
Definition gsField.h:55
const gsFunction< T > & function(int i=0) const
Returns the gsFunction of patch i.
Definition gsField.h:231
const gsMultiPatch< T > & patches() const
Returns gsMultiPatch containing the geometric information on the domain.
Definition gsField.h:210
Class defining a multivariate (real or vector) function given by a string mathematical expression.
Definition gsFunctionExpr.h:52
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
Class for representing a knot vector.
Definition gsKnotVector.h:80
size_t size() const
Number of knots (including repetitions).
Definition gsKnotVector.h:242
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Holds a set of patch-wise bases and their topology information.
Definition gsMultiBasis.h:37
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
This class is used to create a Paraview .pvd (collection) file.
Definition gsParaviewCollection.h:77
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition gsSparseMatrix.h:139
A tensor product B-spline basis.
Definition gsTensorBSplineBasis.h:37
A tensor product of d B-spline functions, with arbitrary target dimension.
Definition gsTensorBSpline.h:45
short_t degree(short_t i) const
Returns the degree of the basis wrt variable i.
Definition gsTensorBasis.h:465
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
Main header to be included by clients using the G+Smo library.
std::string to_string(const C &value)
Converts value to string, assuming "operator<<" defined on C.
Definition gsUtils.h:56
gsMatrix< T > gsPointGrid(gsVector< T > const &a, gsVector< T > const &b, gsVector< unsigned > const &np)
Construct a Cartesian grid of uniform points in a hypercube, using np[i] points in direction i.
Definition gsPointGrid.hpp:82
#define index_t
Definition gsConfig.h:32
#define GISMO_ERROR(message)
Definition gsDebug.h:118
#define GISMO_ENSURE(cond, message)
Definition gsDebug.h:102
#define gsInfo
Definition gsDebug.h:43
The G+Smo namespace, containing all definitions for the library.
gsMultiPatch< T > BSplineStep2D(int deg, const T a, const T b, const T a_in, T h=0, bool periodic=false)
Returns a B-spline multipatch domain for 2D problems of flow over a backward facing step.
Definition gsFlowUtils.h:282
gsTensorBSpline< 2, T > BSplineRectangle(int deg, const T llx, const T lly, const T a, const T b, int numSep=0)
Returns a B-spline parametrization of a rectangle of a given degree in both directions.
Definition gsFlowUtils.h:189
void defineBCs_profile2D(gsBoundaryConditions< T > &bcInfo, std::vector< std::pair< int, boxSide > > &bndIn, std::vector< std::pair< int, boxSide > > &bndOut, std::vector< std::pair< int, boxSide > > &bndWall, T inVelX, T inVelY)
Define boundary conditions for the 2D blade profile problem.
Definition gsFlowUtils.h:583
void defineBCs_cavity(gsBoundaryConditions< T > &bcInfo, std::vector< std::pair< int, boxSide > > &bndWall, int dim, const int np=1, std::string lidVel="1")
Define boundary conditions for the lid-driven cavity problem.
Definition gsFlowUtils.h:428
gsMultiPatch< T > BSplineStep3D(int deg, const T a, const T b, const T c, const T a_in, T h=0, bool periodic=false)
Returns a B-spline multipatch domain for 3D problems of flow over a backward facing step.
Definition gsFlowUtils.h:315
void defineBCs_step2D(gsBoundaryConditions< T > &bcInfo, std::vector< std::pair< int, boxSide > > &bndIn, std::vector< std::pair< int, boxSide > > &bndOut, std::vector< std::pair< int, boxSide > > &bndWall, bool periodic=false, std::string inVel="default")
Define boundary conditions for the 2D backward-facing step problem.
Definition gsFlowUtils.h:454
void addBCs(gsBoundaryConditions< T > &bcInfo, std::vector< std::pair< int, boxSide > > &bndIn, std::vector< std::pair< int, boxSide > > &bndWall, gsFunctionExpr< T > Uin, gsFunctionExpr< T > Uwall)
Define boundary conditions for the corresponding boundary parts.
Definition gsFlowUtils.h:350
void refineLocal_step(gsMultiBasis< T > &basis, int numRefineWalls, int numRefineCorner)
Refine basis for the backward-facing step problem near walls.
Definition gsFlowUtils.h:705
void refineBasis_step(gsMultiBasis< T > &basis, int numRefine, int numRefineWalls, int numRefineCorner, int numRefineU, real_t addRefPart, int dim, real_t a, real_t b, real_t c=0.0)
Refine basis for the backward-facing step problem.
Definition gsFlowUtils.h:735
void refineBasis_cavity(gsMultiBasis< T > &basis, int numRefine, int numRefineLocal, int dim, int numSep=0)
Refine basis for the 2D lid-driven cavity problem.
Definition gsFlowUtils.h:654
gsMatrix< T > createVectorOfUniqueIndices(const gsMatrix< T > &mat)
Creates a one-column matrix (vector) of unique values from the input matrix (useful for creating a un...
Definition gsFlowUtils.h:85
gsMultiPatch< T > BSplineCavity2D(int deg, const T a, const T b, const int np=1, int numSep=0)
Returns a B-spline multipatch domain for 2D problems of flow in a cavity.
Definition gsFlowUtils.h:239
void gsWriteOutputLine(std::ofstream &file, const std::string line, bool fileOutput, bool dispInTerminal)
Writes an output line into the given file and optionally also into terminal.
Definition gsFlowUtils.h:70
void defineBCs_cavity2D(gsBoundaryConditions< T > &bcInfo, const int np, std::vector< std::pair< int, boxSide > > &bndWall, std::string lidVel="1")
Define boundary conditions for the 2D lid-driven cavity problem.
Definition gsFlowUtils.h:367
gsTensorBSpline< 3, T > BSplineBlock(int deg, const T llx, const T lly, const T llz, const T a, const T b, const T c, int numSep=0)
Returns a B-spline parametrization of a 3D block of a given degree in all directions.
Definition gsFlowUtils.h:215
gsMultiPatch< T > BSplineCavity3D(int deg, const T a, const T b, const T c, int numSep=0)
Returns a B-spline multipatch domain for 3D problems of flow in a cavity.
Definition gsFlowUtils.h:264
void defineBCs_cavity3D(gsBoundaryConditions< T > &bcInfo, std::vector< std::pair< int, boxSide > > &bndWall, std::string lidVel="1")
Define boundary conditions for the 3D lid-driven cavity problem.
Definition gsFlowUtils.h:400
void refineFirstKnotSpan(gsMultiBasis< T > &basis, int numRefine, int patch, int dir)
Refine basis near wall (the first knot span).
Definition gsFlowUtils.h:605
gsVector< index_t > getNnzVectorPerOuter(const gsSparseMatrix< T, MatOrder > &mat)
Get a vector of nonzero entries per outer index (row or column depending on the matrix storage order)...
Definition gsFlowUtils.h:116
void diagInvMatrix_into(const gsSparseMatrix< T, MatOrder > &mat, gsSparseMatrix< T, MatOrder > &diagInv, int repeat, bool lumping=false)
Fill a diagonal approximation of an inverse matrix.
Definition gsFlowUtils.h:137
void refineBasis_profile2D(gsMultiBasis< T > &basis, int numRefine, int numRefineBlade, int numRefineLead)
Refine basis for the 2D profile problem.
Definition gsFlowUtils.h:786
void gsWriteOutput(std::ofstream &file, const std::string output, bool fileOutput, bool dispInTerminal)
Writes an output into the given file and optionally also into terminal.
Definition gsFlowUtils.h:55
void defineBCs_step3D(gsBoundaryConditions< T > &bcInfo, std::vector< std::pair< int, boxSide > > &bndIn, std::vector< std::pair< int, boxSide > > &bndOut, std::vector< std::pair< int, boxSide > > &bndWall, bool periodic=false, std::string inVel="default")
Define boundary conditions for the 3D backward-facing step problem.
Definition gsFlowUtils.h:497
void refineLastKnotSpan(gsMultiBasis< T > &basis, int numRefine, int patch, int dir)
Refine basis near wall (the last knot span).
Definition gsFlowUtils.h:628
void defineBCs_step(gsBoundaryConditions< T > &bcInfo, std::vector< std::pair< int, boxSide > > &bndIn, std::vector< std::pair< int, boxSide > > &bndOut, std::vector< std::pair< int, boxSide > > &bndWall, int dim, bool periodic=false, std::string inVel="default")
Define boundary conditions for the backward-facing step problem.
Definition gsFlowUtils.h:556
@ dirichlet
Dirichlet type.
Definition gsBoundaryConditions.h:31