19 this->fTimeStep = TimeStep;
20 this->fSimulationTime = 0.;
21 this->SetConvergence(0, 0.);
22 this->SetNewtonConvergence(0, 0.);
23 this->SetInitialSolutionAsZero();
24 this->SetSaveFrequency(0,0);
27 TPZBlackOilAnalysis::~TPZBlackOilAnalysis(){
34 if ( (InitialSol.
Rows() != nrows) || (InitialSol.
Cols() != ncols) ){
35 PZError <<
"ERROR! " << __PRETTY_FUNCTION__ <<
" at line " << __LINE__ << std::endl;
43 void TPZBlackOilAnalysis::SetInitialSolutionAsZero(){
49 void TPZBlackOilAnalysis::AssembleResidual(){
50 this->SetCurrentState();
53 this->
fRhs += fLastState;
56 void TPZBlackOilAnalysis::Run(std::ostream &out,
bool linesearch){
58 ofstream File(
"Pocos.txt");
59 File <<
"t(mes)\tPi(Pa)\tPp(Pa)\tQwiSC(m3/day)\tQoiSC(m3/day)\tQwpSC(m3/day)\tQopSC(m3/day)\t\tQwiFundo(m3/day)\tQoiFundo(m3/day)\tQwpFundo(m3/day)\tQopFundo(m3/day)\n";
61 this->fSimulationTime = 0.;
64 double nextDeltaT = this->fTimeStep;
65 this->SetAllMaterialsDeltaT();
66 const double TotalTime = fTimeStep*fNIter;
70 for(; this->fSimulationTime < TotalTime; ){
72 this->fTimeStep = nextDeltaT;
73 this->SetAllMaterialsDeltaT();
78 fLastState = this->
fRhs;
82 this->SetCurrentState();
83 REAL
error = this->fNewtonTol * 2. + 1.;
85 while(error > this->fNewtonTol && iter < this->fNewtonMaxIter){
89 this->
fRhs += fLastState;
97 this->LineSearch(prevsol,
fSolution, nextSol, LineSearchTol, niter);
105 REAL norm =
Norm(prevsol);
106 out <<
"Iteracao n : " << (iter+1) <<
" : norma da solucao |Delta(Un)|: " << norm << endl;
114 if((iter % 20) == 0){
119 this->TimeStep() *= fator;
120 nextDeltaT = this->TimeStep();
121 cout <<
"\nMultiplicando passo de tempo por " << fator <<
"\n";
122 this->SetAllMaterialsDeltaT();
123 this->SetLastState();
125 fLastState = this->
fRhs;
126 this->SetCurrentState();
127 this->fNIter = fCurrentStep + ((int)((1./fator) * (fNIter - fCurrentStep) + 0.5));
133 nextDeltaT = fTimeStep * 5./((double)(iter));
141 this->fSimulationTime += this->TimeStep();
143 if (this->fSaveFrequency){
144 if (!(this->fCurrentStep % fSaveFrequency)){
146 double VazaoAguaIsc, VazaoAguaPsc, VazaoOleoIsc, VazaoOleoPsc;
147 double VazaoAguaIFundo, VazaoAguaPFundo, VazaoOleoIFundo, VazaoOleoPFundo;
148 Vazao(*
this,-1,VazaoAguaIsc,VazaoOleoIsc,VazaoAguaIFundo,VazaoOleoIFundo);
149 Vazao(*
this,-2,VazaoAguaPsc,VazaoOleoPsc,VazaoAguaPFundo,VazaoOleoPFundo);
150 File << this->fSimulationTime/2629743.8 <<
"\t" << PressaoMedia(*
this,-1) <<
"\t" << PressaoMedia(*
this,-2) <<
"\t" 151 << VazaoAguaIsc <<
"\t" 152 << VazaoOleoIsc <<
"\t" 153 << VazaoAguaPsc <<
"\t" 154 << VazaoOleoPsc <<
"\t" <<
"\t" 155 << VazaoAguaIFundo <<
"\t" 156 << VazaoOleoIFundo <<
"\t" 157 << VazaoAguaPFundo <<
"\t" 158 << VazaoOleoPFundo <<
"\n";
164 REAL steadynorm =
Norm(prevsol);
165 std::cout <<
"*********** Steady state error at iteration " << this->fCurrentStep <<
", " << this->fSimulationTime/2629743.8 <<
" meses " <<
" = " << steadynorm <<
"\n\n";
166 if (!fForceAllSteps){
167 if (steadynorm < this->fSteadyTol){
168 std::cout <<
"Steady state solution achieved\n\n";
169 this->fNIter = this->fCurrentStep;
180 void TPZBlackOilAnalysis::SetLastState(){
182 std::map<int, TPZMaterial * >::iterator matit;
185 if(!matit->second)
continue;
186 TPZBlackOil2P3D * blackoilmat =
dynamic_cast< TPZBlackOil2P3D *
>(matit->second);
188 blackoilmat->SetLastState();
194 void TPZBlackOilAnalysis::SetCurrentState(){
196 std::map<int, TPZMaterial * >::iterator matit;
199 if(!matit->second)
continue;
200 TPZBlackOil2P3D * blackoilmat =
dynamic_cast< TPZBlackOil2P3D *
>(matit->second);
202 blackoilmat->SetCurrentState();
207 void TPZBlackOilAnalysis::SetAllMaterialsDeltaT(){
209 std::map<int, TPZMaterial * >::iterator matit;
212 if(!matit->second)
continue;
213 TPZBlackOil2P3D * blackoilmat =
dynamic_cast< TPZBlackOil2P3D *
>(matit->second);
215 blackoilmat->SetTimeStep(this->TimeStep());
221 void TPZBlackOilAnalysis::PostProcess(
int resolution,
int dimension){
222 REAL T = this->fSimulationTime;
228 void TPZBlackOilAnalysis::PostProcess(
TPZVec<REAL> &loc, std::ostream &out){
229 REAL T = this->fSimulationTime;
230 out <<
"\nSOLUTION #" << this->fCurrentStep <<
" AT TIME = " << T << std::endl;
232 out <<
"\n***************************************\n" << std::endl;
235 void TPZBlackOilAnalysis::Assemble(){
237 cout <<
"TPZBlackOilAnalysis::Assemble lacking definition for Assemble fCompMesh "<< (
void *)
fCompMesh 239 << __FILE__ <<
" line " << __LINE__ << endl;
255 void TPZBlackOilAnalysis::SetConvergence(
int niter, REAL eps,
bool ForceAllSteps){
256 this->fNIter = niter;
257 this->fSteadyTol = eps;
258 this->fForceAllSteps = ForceAllSteps;
261 void TPZBlackOilAnalysis::SetSaveFrequency(
int SaveFrequency,
int resolution){
262 this->fSaveFrequency = SaveFrequency;
263 this->fDXResolution = resolution;
266 void TPZBlackOilAnalysis::SetNewtonConvergence(
int niter, REAL eps){
267 this->fNewtonMaxIter = niter;
268 this->fNewtonTol = eps;
271 REAL & TPZBlackOilAnalysis::TimeStep(){
272 return this->fTimeStep;
275 void TPZBlackOilAnalysis::Solve(){
278 double minP = 0, maxP = 0, minS = 0, maxS = 0, p, S;
279 for(
int i = 0; i < n/2; i++){
282 if(p > maxP) maxP = p;
283 if(p < minP) minP = p;
284 if(S > maxS) maxS = S;
285 if(S < minS) minS = S;
288 double ScaleP =
fabs(minP+maxP)/2.;
289 double ScaleS =
fabs(minS+maxS)/2.;
290 for(
int j = 0; j < n/2; j++){
291 for(
int i = 0; i < n; i++){
292 this->
Solver().
Matrix()->operator()(i,2*j) *= 1./ScaleP;
293 this->
Solver().
Matrix()->operator()(i,2*j+1) *= 1./ScaleS;
298 double minP = 0, maxP = 0, minS = 0, maxS = 0, p, S;
299 for(
int i = 0; i < n/2; i++){
302 if(p > maxP) maxP = p;
303 if(p < minP) minP = p;
304 if(S > maxS) maxS = S;
305 if(S < minS) minS = S;
311 for(
int i = 0; i < n/2; i++){
319 double TPZBlackOilAnalysis::PressaoMedia(TPZBlackOilAnalysis &an,
int matid){
320 an.LoadSolution(an.Solution());
328 for(
int iel = 0; iel < nel; iel++){
337 press += sol[0] * locVol;
340 double result = press/AccVol;
345 void TPZBlackOilAnalysis::Vazao(TPZBlackOilAnalysis &an,
int matid,
double & VazaoAguaSC,
double & VazaoOleoSC,
double & VazaoAguaFundo,
double & VazaoOleoFundo){
347 an.LoadSolution(an.Solution());
359 for(
int iel = 0; iel < nel; iel++){
370 TPZBlackOil2P3D::BFadREAL po(sol[0],0);
371 TPZBlackOil2P3D::BFadREAL Bo;
374 TPZBlackOil2P3D * bo =
dynamic_cast<TPZBlackOil2P3D *
> (bc->
Material());
377 VazaoOleoSC += ef.fMat(0,0)*86400.;
378 VazaoAguaSC += ef.fMat(1,0)*86400.;
380 VazaoOleoFundo += ef.fMat(0,0)*Bo.val()*86400.;
381 VazaoAguaFundo += ef.fMat(1,0)*bo->Bw()*86400.;
int64_t NElements() const
Number of computational elements allocated.
TPZMatrixSolver< STATE > * fSolver
Type of solver to be applied.
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
REAL Volume()
Return the volume of the element.
virtual void Solve()
Invert the stiffness matrix.
TPZFMatrix< STATE > fSolution
Solution vector.
clarg::argBool bc("-bc", "binary checkpoints", false)
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > matrix) override
Updates the values of the current matrix based on the values of the matrix.
int64_t NEquations()
This computes the number of equations associated with non-restrained nodes.
clarg::argInt dimension("-d", "Matrices dimension M x M", 1000)
virtual int Zero()
Zeroes the matrix.
TPZCompMesh * fCompMesh
Computational mesh.
virtual void Assemble()
Assemble the stiffness matrix and load vector.
TPZCompMesh * Mesh() const
Returns the pointer to the computational mesh.
virtual void CalcStiff(TPZElementMatrix &ek, TPZElementMatrix &ef) override
CalcStiff computes the element stiffness matrix and right hand side.
virtual int NSides() const =0
Returns the number of connectivities of the element.
Contains the TPZStructMatrixOR class which responsible for a interface among Matrix and Finite Elemen...
TPZMatrixSolver< STATE > & Solver()
Get the solver matrix.
Contains the TPZFStructMatrix class which implements Full Structural Matrices.
virtual void CenterPoint(int side, TPZVec< REAL > &masscent) const =0
It returns the coordinates from the center of the side of the element in the element coordinate space...
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
virtual TPZMaterial * Material() const
Identify the material object associated with the element.
int Zero() override
Makes Zero all the elements.
Contains the TPZSpStructMatrix class which implements sparse structural matrices. ...
virtual void LoadSolution()
Load the solution into the computable grid.
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
Contains declaration of TPZInterfaceElement class which computes the contribution over an interface b...
This class defines the boundary condition for TPZMaterial objects.
int64_t Rows() const
Returns number of rows.
Contains TPZSequenceSolver class which defines sequence solvers.
virtual void PostProcess(int resolution)
Draw solution over mesh for all dimensions.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
std::map< int,TPZMaterial *> & MaterialVec()
Returns a reference to the material pointers vector.
Computes the contribution over an interface between two discontinuous elements. Computational Element...
This class associates an element matrix with the coeficients of its contribution in the global stiffn...
TPZAutoPointer< TPZStructMatrix > fStructMatrix
Structural matrix.
virtual void AssembleResidual()
Assemble the load vector.
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
TPZCompEl * LeftElement() const
Returns the left element from the element interface.
Implements computational mesh. Computational Mesh.
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
TPZAutoPointer< TPZMatrix< TVar > > Matrix() const
Returns a pointer to TPZMatrix<>
virtual void Solution(TPZVec< REAL > &qsi, int var, TPZVec< STATE > &sol)
Calculates the solution - sol - for the variable var at point qsi, where qsi is expressed in terms of...
int64_t Cols() const
Returns number of cols.
Derived class from TPZAnalysis implements non linear analysis (Newton's method). Analysis.
Contains the TPZBlackOil2P3D class which implements a 3D two-phase (oil-water) black-oil flow...
TPZFMatrix< STATE > & Rhs()
Returns the load vector.
TPZFMatrix< STATE > fRhs
Load vector.
Contains the implementation of the CheckConvergence function.
Defines the interface of a computational element. Computational Element.
Contains TPZBlackOilAnalysis class derived from TPZNonLinearAnalysis class.
TPZFMatrix< STATE > & Solution()
Access the solution vector.
REAL fTime
Time variable which is used in dx output.
#define PZError
Defines the output device to error messages and the DebugStop() function.
TPZMaterial * Material() const