42 if( index < 0 || index >= fMeshes.NElements() )
43 PZError <<
"TPZNonLinMultGridAnalysis::IMesh mesh index out of range\n";
44 return fMeshes[index];
49 cmesh->
SetName(
"* * * MALHA INICIAL * * *");
72 cout <<
"TPZNonLinMultGridAnalysis::AppendMesh can only be called after solving the coarse mesh\n";
81 cout <<
"TPZNonLinMultGridAnalysis cannot delete the root mesh, sorry\n";
93 int levelnumbertogroup){
106 if(levelnumbertorefine < 1)
return coarcmesh;
109 cout <<
"TPZMGAnalysis::UniformlyRefineMesh mesh with null reference, cancelled method\n";
112 cout <<
"\nTPZNonLinMultGridAnalysis::UniformlyRefineMesh uniforme division of coarcmesh," 113 <<
" levels to be fine = " << levelnumbertorefine << endl;
120 std::map<int, TPZMaterial * >::iterator
m;
127 int64_t el,nelem = elementvec.
NElements();
128 for(el=0; el<nelem; el++) {
132 PZError <<
"TPZNonLinMultGridAnalysis::UniformlyRefineMesh mesh error," 142 cout <<
"TPZMGAnalysis::UniformlyRefineMesh encountered an element without" 143 <<
" geometric reference\n";
148 int lev = 0,k,nsons,i;
151 while(lev < levelnumbertorefine){
155 for(i=0;i<nsubs;i++){
156 copy[i]->Divide(sub1);
158 for(k=0;k<nsons;k++) sub.
Push(sub1[k]);
165 for(isub=0; isub<
nsub; isub++) {
167 if(setdegree > 0 && setdegree != degree) disc->
SetDegree(degree);
193 if(!mat)
PZError <<
"TPZNonLinMultGridAnalysis::ResetReference null material\n";
194 if(mat->
Id() < 0)
continue;
198 PZError <<
"TPZNonLinMultGridAnalysis::ResetReference not agglomerate element\n";
201 PZError <<
"TPZNonLinMultGridAnalysis::ResetReference null fine mesh\n";
205 if(!size)
PZError <<
"main::ResetReference error1\n";
210 if(!ref)
PZError <<
"main::ResetReference error2\n";
218 if(!ref0)
PZError <<
"main::ResetReference error2\n";
237 if(!mat)
PZError <<
"TPZNonLinMultGridAnalysis::SetReference null material\n";
238 if(mat->
Id() < 0)
continue;
241 PZError <<
"TPZNonLinMultGridAnalysis::SetReference not agglomerate element\n";
250 for(k=0;k<indsize;k++){
253 PZError <<
"TPZNonLinMultGridAnalysis::SetReference null sub-element\n";
263 clock_t end = clock();
264 cout << title << endl;
265 clock_t segundos = ((end - start)/CLOCKS_PER_SEC);
266 cout << segundos <<
" segundos" << endl;
267 cout << segundos/60.0 <<
" minutos" << endl << endl;
294 if(numiter <= 1) numiter = 2;
297 cout <<
"PZAnalysis::SmoothingSolutionTest beginning of the iterative process iterac� = " << iter << endl;
301 cout <<
"TPZNonLinMultGridAnalysis::SmoothingSolution iteration = " << ++iter << endl;
307 while(iter < numiter && normsol < tol) {
314 cout <<
"TPZNonLinMultGridAnalysis::SmoothingSolution iteracao = " << ++iter << endl;
318 cout <<
"\nTPZNonLinMultGridAnalysis::SmoothingSolution the iterative process stopped" 319 <<
" due the great norm of the solution, norm solution = " << normsol << endl;
322 rhs = an.
Rhs() - rhsim1;
327 TPZAnalysis &an,
int marcha,
const std::string &dxout) {
329 cout <<
"PZAnalysis::SmoothingSolution NENHUMA RESOLU�O EFETUADA\n";
339 cout <<
"PZAnalysis::SmoothingSolutionTest beginning of the iterative process\n";
344 cout <<
"TPZNonLinMultGridAnalysis::SmoothingSolution iteration = " << ++iter << endl;
349 while(iter < numiter && normsol < tol) {
355 cout <<
"TPZNonLinMultGridAnalysis::SmoothingSolution iteracao = " << ++iter << endl;
359 cout <<
"\nTPZNonLinMultGridAnalysis::SmoothingSolution the iterative process stopped" 360 <<
" due the great norm of the solution, norm solution = " << normsol << endl;
366 TPZAnalysis &an,
int marcha,
const std::string &dxout) {
369 scalar[0] =
"pressure";
373 std::set<int> matids;
377 matids.insert(mat->
Id());
390 cout <<
"TPZNonLinMultGridAnalysis::SmoothingSolution iteration = " << ++iter
391 <<
" general time 0\n";
393 CoutTime(
fBegin,
"TPZNonLinMultGridAnalysis:: Fim system solution first iteration");
396 REAL time = (REAL)iter;
402 while(iter < numiter && normsol < tol) {
408 CoutTime(
fBegin,
"TPZNonLinMultGridAnalysis:: Fim system solution actual iteration");
409 CoutTime(
fInit,
"TPZNonLinMultGridAnalysis:: accumulated time");
412 cout <<
"TPZNonLinMultGridAnalysis::SmoothingSolution iteracao = " << ++iter << endl;
414 if( REAL(iter) / REAL(marcha) == draw || marcha == 1){
420 cout <<
"\nTPZNonLinMultGridAnalysis::SmoothingSolution the iterative process stopped" 421 <<
" due the great norm of the solution, norm solution = " << normsol << endl;
424 CoutTime(
fInit,
"TPZNonLinMultGridAnalysis::SmoothingSolution general time of iterative process");
427 ofstream out(
"SmoothingSolution2_ANALYSIS.out");
428 an.
Print(
"\n\n* * * SOLUCAO PELO ANALYSIS: ltima solu�o * * *\n\n",out);
437 ofstream out(
"CalcResidual_STIFF.out");
438 stiff->Print(
"\n\n\t\t\t* * * MATRIZ DE RIGIDEZ * * *\n\n",out);
439 int dim = stiff->Dim(),i,j;
444 if( !strcmp(decompose.c_str() ,
"LDLt") ) {
448 for(j=i+1;j<dim;j++){
449 sum += stiff->GetVal(i,j) * sol(j,0);
451 tsup(i,0) = sol(i,0) + sum;
454 for(i=0;i<dim;i++) diag(i,0) = stiff->GetVal(i,i) * tsup(i,0);
459 sum += stiff->GetVal(i,j) * diag(j,0);
461 res(i,0) = sum + diag(i,0);
465 ofstream out(
"MATRIZES_DECOMPOSI�O.out");
466 sol.
Print(
"\n* * * sol * * *\n",out);
467 tsup.Print(
"\n* * * tsup * * *\n",out);
468 diag.Print(
"\n* * * diag * * *\n",out);
469 tinf.
Print(
"\n* * * tinf * * *\n",out);
471 res.
Print(
"\n* * * res * * *\n",out);
472 stiff->Print(
"\n* * * stiff * * *\n",out);
478 cout <<
"TPZNonLinMultGridAnalysis::CalcResidual Calculation of the residue for this" 479 <<
" decomposition is not implemented, implements now!\n";
488 ofstream out(
"CalcResidual_STIFF.out");
489 stiff->Print(
"\n\n\t\t\t* * * MATRIZ DE RIGIDEZ * * *\n\n",out);
490 int dim = stiff->Dim(),i,j;
494 if( !strcmp(decompose.c_str() ,
"LDLt") ){
498 for(j=i+1;j<dim;j++){
499 sum += stiff->GetVal(i,j);
501 tsup(i,0) = sol(i,0) + sum;
504 for(i=0;i<dim;i++) diag(i,0) = stiff->GetVal(i,i) * tsup(i,0);
509 sum += stiff->GetVal(i,j) * diag(i,0);
511 tinf(i,0) = sum + diag(i,0);
515 for(i=0;i<dim;i++)
res(i,0) = anres.
GetVal(i,0) - tinf(i,0);
516 sol.
Print(
"\n* * * sol * * *\n",cout);
517 anres.
Print(
"\n* * * anres * * *\n",cout);
518 tinf.
Print(
"\n* * * tinf * * *\n",cout);
519 res.
Print(
"\n* * * residuo * * *\n",cout);
521 cout <<
"TPZNonLinMultGridAnalysis::CalcResidual Calculation of the residue for this" 522 <<
" decomposition is not implemented, implements now!\n";
538 cout <<
"TPZNonLinMultGridAnalysis::OneGridAlgorithm Name of the out dx OneGridAlgorithm.dx\n";
539 int levelnumbertorefine = 1;
540 cout <<
"TPZNonLinMultGridAnalysis:: nmero de n�eis a dividir: ";
541 cin >> levelnumbertorefine;
548 finemesh->
SetName(
"\n\t\t\t* * * MALHA COMPUTACIONAL FINA * * *\n\n");
561 cout <<
"\nTPZNonLinMultGridAnalysis::OneGridAlgorithm Numero de iteracoes ? :\n";
563 cout <<
"\nTPZNonLinMultGridAnalysis::OneGridAlgorithm Marcha ? :\n";
566 std::string solout(
"OneGridAlgorithm.vtk");
579 ifstream INd(
"DADOS.in");
584 int levelnumbertorefine = 1;
585 cout <<
"TPZNonLinMultGridAnalysis:: nmero de n�eis a dividir: ";
586 INd >> levelnumbertorefine;
591 finemesh->
SetName(
"\n\t\t\t* * * MALHA COMPUTACIONAL FINA * * *\n\n");
593 int levelnumbertogroup = levelnumbertorefine - 1;
594 cout <<
"TPZNonLinMultGridAnalysis:: nmero do n�el a ser agrupado: ";
595 INd >> levelnumbertogroup;
597 aggmesh->
SetName(
"\n\t\t\t* * * MALHA COMPUTACIONAL AGLOMERADA * * *\n\n");
600 aggmesh->
Reference()->
SetName(
"\n\t\t\t* * * MALHA GEOM�RICA REFINADA * * *\n\n");
605 finemesh->
Print(out);
634 int preiter,positer,premarcha,posmarcha;
639 cout <<
"\nNumero de iteracoes pre-suavisamento? :\n";
642 cout <<
"main:: Parametro marcha : \n";
645 cout <<
"\nNumero de iteracoes p�-suavisamento? :\n";
649 posmarcha = premarcha;
650 fMeshes[2]->Reference()->ResetReference();
658 REAL normsolfine = 0.0,normsolcoar = 1.e10,erro;
659 REAL errsol =
fabs(normsolcoar - normsolfine);
661 int64_t coarneq =
fMeshes[1]->NEquations();
662 int64_t fineneq =
fMeshes[2]->NEquations();
664 TPZFMatrix<STATE> coarsesol(coarneq,1,0.),projfineres(coarneq,1),rhs(coarneq,1),frhsk;
666 int mgmaxiter = 100,mgiter = 0;
668 scalar[0] =
"pressure";
674 std::set<int> matids;
675 matids.insert(finemat->
Id());
687 matids.insert(coarsemat->
Id());
693 REAL sol_tol = 1.e15;
694 REAL time,skm1 = 1.0;
695 cout <<
"TwoGridAlgorithm entre sk-1 : ";
697 REAL skm1inv = 1.0/skm1;
698 int draw = 0,residuo;
699 cout <<
"TwoGridAlgorithm nmero m�imo de itera�es : ";
701 cout <<
"TwoGridAlgorithm res�uo [1:Lk-1(u0k-1)] ou res�uo [2:fk-1] ? : ";
704 cout <<
"PZAnalysis::SmoothingSolutionTest beginning of the iterative process, time = 0\n";
706 while( errsol > gridtol && mgiter < mgmaxiter){
708 cout <<
"\nTwoGridAlgorithm: iterac� nmero = " << mgiter <<
"\n\n";
711 finesolkeep = finesol;
716 if( REAL(mgiter) / REAL(premarcha) == draw || premarcha == 1 || (mgiter+1) == mgmaxiter){
719 erro =
Norm(finesol - finesolkeep);
720 cout <<
"TwoGridAlgorithm: ||finesol(i) - finesol(i-1)|| = " << erro << endl;
726 fMeshes[1]->ProjectSolution(projfinesol);
727 fMeshes[1]->LoadSolution(projfinesol);
742 rhs = rhs + projfineres;
743 coarsean.
Rhs() = rhs;
745 }
else if(residuo == 2){
751 coarsean.
Rhs() = coarres;
754 coarsesolkeep = coarsesol;
758 finesol0 = finesol + finesol0;
759 fMeshes[2]->LoadSolution(finesol0);
761 if( REAL(mgiter) / REAL(posmarcha) == draw || posmarcha == 1 || (mgiter+1) == mgmaxiter){
765 erro =
Norm(coarsesol - coarsesolkeep);
766 cout <<
"||coarsesol(i) - coarsesol(i-1)|| = " << erro << endl;
770 CoutTime(
fInit,
"TPZNonLinMultGridAnalysis::SmoothingSolution general time of iterative process");
int64_t NElements() const
Number of computational elements allocated.
void IndexesDiscSubEls(TPZStack< int64_t > &elvec)
Returns a vector of all indexes of the discontinuous elements in cluster.
TPZGeoMesh * Reference() const
Returns a pointer to the geometrical mesh associated.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
void AdjustBoundaryElements()
Will refine the elements associated with a boundary condition till there are no elements constrained ...
virtual void SetFileName(const std::string &filename)
Sets the name of the output file.
void SetName(const std::string &nm)
Set the mesh name.
clock_t fBegin
Times by iteration and accumulated time.
TPZNonLinMultGridAnalysis(TPZCompMesh *cmesh)
Creates an object multigrid analysis giving a computational mesh.
virtual void Solve()
Invert the stiffness matrix.
virtual MElementType Type()
Return the type of the element.
void SetStructuralMatrix(TPZAutoPointer< TPZStructMatrix > strmatrix)
Set structural matrix as auto pointer for analysis.
void Print(const std::string &name, std::ostream &out)
Print connect and solution information.
virtual TPZSolver< TVar > * Clone() const override
Clones the current object returning a pointer of type TPZSolver.
void SetTimeStep(REAL timeStep)
Sets the time step used for time integration.
static TPZAgglomerateMesh * CreateAgglomerateMesh(TPZCompMesh *finemesh, TPZVec< int64_t > &accumlist, int64_t numaggl)
TPZFMatrix< STATE > fSolution
Solution vector.
Contains TPZNonLinMultGridAnalysis class which implements multigrid analysis to non linear problems...
Implements the interface of the graphmesh to the OpenDX graphics package. Post processing.
clarg::argInt nsub("-nsub", "number of substructs", 4)
TPZStack< TPZFMatrix< STATE > * > fSolutions
Contains the meshes solutions.
Contains the TPZVTKGraphMesh class which implements the graphical mesh to VTK environment.
Contains declaration of TPZCompEl class which defines the interface of a computational element...
Templated vector implementation.
Defines step solvers class. Solver.
void(* fFunction)(TPZMaterial *mat, TPZCompMesh *cmesh)
void SetSolver(TPZMatrixSolver< STATE > &solver)
Set solver matrix.
void TwoGridAlgorithm(std::ostream &out, int nummat)
TPZCompMesh * fCompMesh
Computational mesh.
To export a graphical mesh to VTK environment. Post processing.
TPZCompMesh * Mesh() const
Returns the pointer to the computational mesh.
void degree(int root, int adj_num, int adj_row[], int adj[], int mask[], int deg[], int *iccsze, int ls[], int node_num)
virtual int Dimension() const =0
Returns the integrable dimension of the material.
Declarates the TPZBlock<REAL>class which implements block matrices.
Defines enum MElementType and contains the implementation of MElementType_NNodes(...) functions.
void SetDeltaTime(TPZCompMesh *CompMesh, TPZMaterial *mat)
int64_t NElements() const
Access method to query the number of elements of the vector.
Implements a chunk vector with free store administration. Utility.
Contains the TPZStructMatrixOR class which responsible for a interface among Matrix and Finite Elemen...
virtual void Divide(TPZVec< TPZGeoEl *> &pv)
Divides the element and puts the resulting elements in the vector.
TPZMatrixSolver< STATE > & Solver()
Get the solver matrix.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Contains the TPZTransfer class which implements a rectangular sparse block matrix.
void LoadReferences()
Map this grid in the geometric grid.
TPZCompMesh * PopMesh()
Pop the last mesh of the meshes vector.
Implements SkyLine Structural Matrices. Structural Matrix.
TPZFMatrix< STATE > & Solution()
Returns the solution matrix.
This abstract class defines the behaviour which each derived class needs to implement.
TPZStack< TPZMatrixSolver< STATE > * > fPrecondition
Contains the preconditioner of the solution method.
void SetResolution(int res)
Sets resolution.
REAL TimeStep()
Returns the value of the time step.
Computational mesh with additional data for CFD problems. Computational Mesh.
TPZAutoPointer< TPZStructMatrix > StructMatrix()
Returns a reference to the structural matrix.
virtual TPZMaterial * Material() const
Identify the material object associated with the element.
TPZCompEl * CreateCompEl(TPZGeoEl *gel, int64_t &index)
Create a computational element based on the geometric element.
int Zero() override
Makes Zero all the elements.
REAL MaxVelocityOfMesh()
According to each material settings, it returns the greatest velocity in the mesh.
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
Implements the sequence of actions to perform a finite element analysis. Analysis.
void Push(const T object)
Pushes a copy of the object on the stack.
void CoutTime(clock_t &start, const char *title)
virtual void DrawSolution(TPZBlock< REAL > &Sol)
Draw solution as dx file.
virtual void LoadSolution()
Load the solution into the computable grid.
virtual void Print(std::ostream &out=std::cout) const
Print the information of the grid to an ostream.
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
void CalcResidual(TPZMatrix< STATE > &sol, TPZAnalysis &an, const std::string &decompose, TPZFMatrix< STATE > &res)
TPZStack< TPZMatrixSolver< STATE > * > fSolvers
Contains the solution method applied to the mesh.
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
#define DebugStop()
Returns a message to user put a breakpoint in.
Contains the TPZSkylineStructMatrix class which implements SkyLine Structural Matrices.
void TransferResidual(const TPZFMatrix< TVar > &fine, TPZFMatrix< TVar > &coarse)
Will transfer the residual, taking into acount there may be more than one TVar variable.
int Dimension() const
Returns the dimension of the simulation.
void OneGridAlgorithm(std::ostream &out, int nummat)
TPZMaterial * FindMaterial(int id)
Find the material with identity id.
TPZCompEl * Reference() const
Return a pointer to the element referenced by the geometric element.
void ResetReference(TPZCompMesh *aggcmesh)
TPZStack< TPZCompMesh *> fMeshes
Contains the computational meshes of one cycle: V, W, F, etc.
TPZCompMesh * IMesh(int64_t index)
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
Contains declaration of TPZCompelDisc class which implements a computational element for discontinuou...
void AppendMesh(TPZCompMesh *mesh)
Append a mesh to the meshes vector.
Contains declaration of TPZCompMesh class which is a repository for computational elements...
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
virtual void DrawMesh(int numcases)
Draw mesh as dx file.
void SetDimModel(int dim)
Set de dimension of the domain of the problem.
virtual void Run(std::ostream &out=std::cout)
Calls the appropriate sequence of methods to build a solution or a time stepping sequence.
std::map< int,TPZMaterial *> & MaterialVec()
Returns a reference to the material pointers vector.
static TPZCompMesh * AgglomerateMesh(TPZCompMesh *finemesh, int levelnumbertogroup)
It generates a new mesh based on the agglomeration of elements of the fine mesh.
void TransferSolution(const TPZFMatrix< TVar > &coarsesol, TPZFMatrix< TVar > &finesol)
Will transfer the solution, taking into acount there may be more than one TVar variable.
virtual void SetFileName(const std::string &filename)
Sets the filename to output of graph.
virtual void DrawSolution(int step, REAL time)
Draw solution depending on the resolution.
Implements the interface for conservation laws, keeping track of the timestep as well.
~TPZNonLinMultGridAnalysis()
Destructor.
void SmoothingSolution2(REAL tol, int numiter, TPZMaterial *mat, TPZAnalysis &an, int marcha, const std::string &dxout)
virtual void DrawMesh(int numcases)
Draw the graphical mesh.
T Pop()
Retrieve an object from the stack.
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Free store vector implementation in chunks.
This class implements a geometric mesh for the pz environment. Geometry.
This class implements a stack object. Utility.
void SetForcingFunction(TPZAutoPointer< TPZFunction< STATE > > fp)
Sets a procedure as source function for the material.
Contains declaration of TPZFlowCompMesh class which is a computational mesh with additional data for ...
Implements computational mesh. Computational Mesh.
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
void SmoothingSolution(REAL tol, int numiter, TPZMaterial *mat, TPZAnalysis &an, int marcha=0, const std::string &dxout="plotfile.dx")
Contains TPZSolver class which defines a abstract class of solvers which will be used by matrix class...
TPZAutoPointer< TPZMatrix< TVar > > Matrix() const
Returns a pointer to TPZMatrix<>
virtual void Clone(std::map< int, TPZMaterial * > &matvec)
Creates a copy of the material object and put it in the vector which is passed on.
void SetReference(TPZCompMesh *aggcmesh)
void SetReference(TPZCompEl *elp)
Make the current element reference to the computational element.
Contains TPZStepSolver class which defines step solvers class.
virtual void SetDegree(int degree)
Assigns the degree of the element.
virtual void Print(std::ostream &out) const
virtual int Degree() const
Returns the degree of interpolation of the element.
Contains declaration of TPZAgglomerateMesh which implements a mesh that contains agglomerated element...
int64_t NElements() const
Returns the number of elements of the vector.
Contains the TPZConservationLaw class which implements the interface for conservation laws...
TPZFMatrix< STATE > & Rhs()
Returns the load vector.
void SetDirect(const DecomposeType decomp)
Contains the TPZDXGraphMesh class which implements the interface of the graphmesh to the OpenDX graph...
This class implements a discontinuous element (for use with discontinuous Galerkin). Computational Element.
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")
Implements rectangular matrix which extends a solution vector of the coarse mesh to a solution vector...
static TPZCompMesh * UniformlyRefineMesh(TPZCompMesh *coarcmesh, int levelnumbertorefine, int setdegree)
It creates a new established computational mesh in the refinement uniform of a fixed number of levels...
void ResetReference()
Resets all load references in elements and nodes.
TPZCompMesh * MotherMesh()
Returns father mesh.
Defines the interface of a computational element. Computational Element.
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
static void ListOfGroupings(TPZCompMesh *finemesh, TPZVec< int64_t > &accumlist, int nivel, int64_t &numaggl, int dim)
void SetName(const std::string &nm)
#define PZError
Defines the output device to error messages and the DebugStop() function.
Implements an agglomerated discontinuous element. Computational Element.
virtual void Print(std::ostream &out=std::cout) const
Prints mesh data.
This class implements a reference counter mechanism to administer a dynamically allocated object...