14#include <unordered_set>
19template<
class T,
int MatOrder>
22 m_solution.setZero(getAssembler()->numDofs(), 1);
23 m_iterationNumber = 0;
24 m_relNorm = std::numeric_limits<T>::infinity();
26 m_fileOutput = m_params.options().getSwitch(
"fileOutput");
27 m_dispOutput = !m_params.options().getSwitch(
"quiet");
37template<
class T,
int MatOrder>
40 m_solution.setZero(getAssembler()->numDofs(), 1);
44template<
class T,
int MatOrder>
47 std::string fileName = m_params.options().getString(
"outFile");
50 fileName = this->getName() +
"_output.txt";
52 m_outFile.open(fileName);
54 std::stringstream output;
55 output <<
"\n" << m_params.options() <<
"\n";
60template<
class T,
int MatOrder>
64#ifdef GISMO_WITH_PETSC
65 if (m_params.options().getSwitch(
"parallel"))
67 MPI_Barrier(PETSC_COMM_WORLD);
78template<
class T,
int MatOrder>
82#ifdef GISMO_WITH_PETSC
83 if (m_params.options().getSwitch(
"parallel"))
85 MPI_Barrier(PETSC_COMM_WORLD);
90 return m_clock.stop();
95template<
class T,
int MatOrder>
98 if (!getAssembler()->isInitialized())
100 real_t time0 = stopwatchStart();
101 getAssembler()->initialize();
102 real_t time1 = stopwatchStop();
104 m_initAssembT += time1 - time0;
107 m_linSolverPtr = createLinSolver<T, MatOrder>(m_params, getAssembler());
111template<
class T,
int MatOrder>
114 GISMO_ASSERT(getAssembler()->isInitialized(),
"Assembler must be initialized first, call initialize()");
116 for (
unsigned iter = 0; iter < numberOfIterations; iter++)
121template<
class T,
int MatOrder>
124 GISMO_ASSERT(getAssembler()->isInitialized(),
"Assembler must be initialized first, call initialize()");
126 m_relNorm = solutionChangeRelNorm();
128 while ((iter < minIterations) || ((m_relNorm > epsilon) && (iter < maxIterations)))
131 m_outStream <<
"Iteration number " << m_iterationNumber + 1 <<
"...";
135 m_relNorm = solutionChangeRelNorm();
138 m_outStream <<
" Solution change relative norm: " << m_relNorm;
146template<
class T,
int MatOrder>
149 real_t time0 = stopwatchStart();
150 getAssembler()->update(sol, updateSol);
151 real_t time1 = stopwatchStop();
153 m_assembT += time1 - time0;
157template<
class T,
int MatOrder>
162 if (m_iterationNumber)
163 relNorm = solutionChangeRelNorm(getAssembler()->getSolution(), m_solution);
165 relNorm = std::numeric_limits<T>::infinity();
171template<
class T,
int MatOrder>
175 T relNorm = solChangeVector.norm() / solNew.norm();
181template<
class T,
int MatOrder>
185 m_outStream <<
" [u, p] solution change relative norm: ";
187 for (
int i = 0; i < solOld.cols(); i++)
188 m_outStream << solutionChangeRelNorm(solOld.col(i), solNew.col(i)) <<
", ";
194template<
class T,
int MatOrder>
197 getAssembler()->markDofsAsEliminatedZeros(boundaryDofs, unk);
202template<
class T,
int MatOrder>
208 npts = m_params.options().getInt(
"jac.npts");
211 dist = m_params.options().getReal(
"jac.dist");
214 tol = m_params.options().getReal(
"jac.tol");
216 short_t dim = m_params.getPde().patches().domainDim();
217 size_t np = m_params.getPde().patches().nPatches();
219 npts = math::pow(math::abs(npts), dim-1);
220 dist = math::abs(dist);
221 tol = math::abs(tol);
223 for (
size_t p = 0; p < np; p++)
225 const gsGeometry<T>* patch = &m_params.getPde().patches().patch(p);
228 GISMO_ASSERT(parRange.rows() == dim,
"checkGeoJacobian: something went wrong, parRange.rows() != dim.");
230 std::unordered_set<gsVector<T>, gsVectorHash<T> > uniquePts;
233 for (
short_t i = 0; i < dim; i++)
238 reducedRange.topRows(i) = parRange.topRows(i);
241 reducedRange.bottomRows(dim - i - 1) = parRange.bottomRows(dim - i - 1);
244 reducedRange.col(0).array() += dist;
245 reducedRange.col(1).array() -= dist;
250 pts.topRows(i) = reducedPts.topRows(i);
253 pts.bottomRows(dim - i - 1) = reducedPts.bottomRows(dim - i - 1);
257 for(
int j = 0; j < pts.cols(); j++)
258 uniquePts.insert(pts.col(j));
262 for(
int j = 0; j < pts.cols(); j++)
263 uniquePts.insert(pts.col(j));
269 real_t jacDet = patch->jacobian(pt).determinant();
273 gsWarn <<
"Negative geometry jacobian!\n";
279 gsWarn <<
"Geometry jacobian close to zero!\n";
virtual void nextIteration()
Perform next iteration step.
Definition gsFlowSolverBase.h:110
virtual void initialize()
Initialize the solver.
Definition gsFlowSolverBase.hpp:96
T solutionChangeRelNorm() const
Compute and return the relative norm of the solution change.
Definition gsFlowSolverBase.hpp:158
virtual void writeSolChangeRelNorm(gsMatrix< T > solOld, gsMatrix< T > solNew)
Compute and display the relative norm of the solution change given the two successive solutions.
Definition gsFlowSolverBase.hpp:182
real_t stopwatchStart()
Start measuring time (decides whether to use gsStopwatch or MPI_Wtime)
Definition gsFlowSolverBase.hpp:61
virtual void markDofsAsEliminatedZeros(const std::vector< gsMatrix< index_t > > &boundaryDofs, const int unk)
Eliminate given DOFs as homogeneous Dirichlet boundary.
Definition gsFlowSolverBase.hpp:195
void solve(const int maxIterations, const T epsilon=1e-3, const int minIterations=1)
Solve the incompressible Navier-Stokes problem.
Definition gsFlowSolverBase.hpp:122
virtual void initMembers()
Initialize all members.
Definition gsFlowSolverBase.hpp:20
virtual void createOutputFile()
Create output file.
Definition gsFlowSolverBase.hpp:45
real_t stopwatchStop()
Stop measuring time (decides whether to use gsStopwatch or MPI_Wtime)
Definition gsFlowSolverBase.hpp:79
virtual void updateAssembler(const gsMatrix< T > &sol, bool updateSol=true)
Update the assembler with a given solution.
Definition gsFlowSolverBase.hpp:147
virtual void updateSizes()
Update sizes of members (when DOF numbers change, e.g. after markDofsAsEliminatedZeros()).
Definition gsFlowSolverBase.hpp:38
int checkGeoJacobian(int npts=-1, T dist=-1, T tol=-1)
Check values of jacobian near boundaries of all patches.
Definition gsFlowSolverBase.hpp:203
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
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 short_t
Definition gsConfig.h:35
#define gsWarn
Definition gsDebug.h:50
#define gsInfo
Definition gsDebug.h:43
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
The G+Smo namespace, containing all definitions for the library.
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 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