NeoPZ
pzl2projection.cpp
Go to the documentation of this file.
1 
6 #include "pzl2projection.h"
7 #include "pzbndcond.h"
8 #include "tpzintpoints.h"
9 
10 TPZL2Projection::TPZL2Projection(int id, int dim, int nstate, TPZVec<STATE> &sol,
11  int IntegrationOrder) :
13 TPZDiscontinuousGalerkin(id) , fScale(1.)
14 {
15  this->fDim = dim;
16  this->fNStateVars = nstate;
17  this->fSol = sol;
18  this->fIntegrationOrder = IntegrationOrder;
19  this->SetIsReferred(false);
20 }
21 
24 {
25  this->fDim = cp.fDim;
26  this->fNStateVars = cp.fNStateVars;
27  this->fSol = cp.fSol;
29  this->SetIsReferred(cp.fIsReferred);
30 }
31 
33 {
34 }
35 
37  this->fIsReferred = val;
38 }
39 
41  return new TPZL2Projection(*this);
42 }
43 
45 
47  if(shapetype==data.EVecShape){
48  ContributeVecShape(data,weight,ek, ef);
49  return;
50  }
51 
52  TPZManVector<STATE> solloc(fSol);
53  if (this->HasForcingFunction()){
55  this->fForcingFunction->Execute(data.x, solloc);
56  }
57  int numbersol = data.sol.size();
58  if (numbersol != 1) {
59  DebugStop();
60  }
61 
62  const int nvars = this->fNStateVars;
63  if (this->fIsReferred){
64  solloc.Resize(nvars);
65  if (data.sol[0].NElements() < 2*nvars){//it means the referred element does not exist or it is an interface element. In that case, I ASSUME the referred solution is ZERO
66  solloc.Fill(0.);
67  }//if
68  else{
69  for(int i = 0; i < nvars; i++){
70  solloc[i] = data.sol[0][i+nvars];
71  }//for
72  }//else
73  }//if
74 
75  const int nshape = data.phi.Rows();
76  for(int i = 0; i < nshape; i++){
77  for(int j = 0; j < nshape; j++){
78  for(int ivi = 0; ivi < nvars; ivi++){
79  const int posI = nvars*i+ivi;
80  const int posJ = nvars*j+ivi;
81  ek(posI, posJ) += weight*fScale*data.phi(i,0)*data.phi(j,0);
82  }//ivi
83  }//for j
84  for(int ivi = 0; ivi < nvars; ivi++){
85  const int posI = nvars*i+ivi;
86  ef(posI,0) += (STATE)weight*(STATE)fScale*(STATE)data.phi(i,0)*solloc[ivi];
87  }//ivi
88  }//for i
89 }
90 
92 {
93  TPZManVector<STATE> solloc(fSol);
94  if (this->HasForcingFunction()){
96  this->fForcingFunction->Execute(data.x, solloc);
97  }
98 
99  int numbersol = data.sol.size();
100  if (numbersol != 1) {
101  DebugStop();
102  }
103 
104  const int nvariables = this->fNStateVars;
105  const int vecFuncSize = data.phi.Rows();
106  const int nshape = data.phi.Cols();
107  if(nvariables != vecFuncSize)
108  {
109  //Nao implementado neste material ainda
110  DebugStop();
111  }
112 
113  if (this->fIsReferred){
114  //Nao implementado neste material ainda
115  DebugStop();
116  }//if
117 
118  for(int i = 0; i < nshape; i++){
119  for(int j = 0; j < nshape; j++){
120  for(int ivi = 0; ivi < nvariables; ivi++){
121  ek(i,j) += weight*fScale*data.phi(ivi,i)*data.phi(ivi,j);
122  }//ivi
123  }//for j
124  for(int ivi = 0; ivi < nvariables; ivi++){
125  ef(i,0) += (STATE)weight*(STATE)fScale*(STATE)data.phi(ivi,i)*solloc[ivi];
126  }//ivi
127  }//for i
128 }
129 
131 
132  const int nvars = this->fNStateVars;
133  TPZFMatrix<REAL> &phi = data.phi;
134  const int phr = phi.Rows();
135  int in, jn, iv;
136 
137  switch (bc.Type()){
138 
139  // Dirichlet condition
140  case 0 : {
141  for(iv = 0; iv < nvars; iv++){
142  for(in = 0 ; in < phr; in++) {
143  ef(nvars*in+iv,0) += (STATE)TPZMaterial::gBigNumber * bc.Val2()(iv,0) * (STATE)phi(in,0) * (STATE)weight;
144  for (jn = 0 ; jn < phr; jn++) {
145  ek(nvars*in+iv,nvars*jn+iv) += TPZMaterial::gBigNumber * phi(in,0) * phi(jn,0) * weight;
146  }//jn
147  }//in
148  }//iv
149  break;
150  }
151 
152  // Neumann condition
153  case 1 : {
154  for(iv = 0; iv < nvars; iv++){
155  for(in = 0 ; in < phr; in++) {
156  ef(nvars*in+iv,0) += bc.Val2()(iv,0) * (STATE)fScale * (STATE)phi(in,0) * (STATE)weight;
157  }//in
158  }//iv
159  break;
160  }
161 
162  default:{
163  std::cout << __PRETTY_FUNCTION__ << " at line " << __LINE__ << " not implemented\n";
164  }
165  }//switch
166 
167 }
168 
169 int TPZL2Projection::VariableIndex(const std::string &name){
170  if(!strcmp("Solution",name.c_str())) return ESolution;
171  if(!strcmp("Derivative",name.c_str())) return EDerivative;
172  return TPZMaterial::VariableIndex(name);
173 }
174 
176  const int nvars = this->NStateVariables();
177  if(var == ESolution) return nvars;
178  if (var == EDerivative) {
179  return fDim;
180  }
181 
183 }
184 
186  TPZFMatrix<REAL> &axes, int var, TPZVec<STATE> &Solout){
187  if (var == ESolution){
188  Solout.Resize(Sol.size());
189  for (int i=0; i<Sol.size(); i++) {
190  Solout[i] = Sol[i];
191  }
192  return;
193  }
194  if (var == EDerivative) {
195  Solout.Resize(fDim);
196  for (int i=0; i<fDim; i++) {
197  Solout[i] = DSol(i,0);
198  }
199  return;
200  }
201  TPZMaterial::Solution(Sol , DSol, axes, var, Solout);
202 }
203 
208 int TPZL2Projection::IntegrationRuleOrder(int elPMaxOrder) const
209 {
210  if (this->fIntegrationOrder == -1) {
212  }
213  else
214  {
215  int order = (fIntegrationOrder > (2*elPMaxOrder) ) ? fIntegrationOrder : 2*elPMaxOrder;
216  return order;
217  }
218 }
219 
220 #include "pzaxestools.h"
221 
223  TPZFMatrix<STATE> &dudx, TPZFMatrix<REAL> &axes, TPZVec<STATE> &/*flux*/,
224  TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &values) {
225 
226  values.Resize(NEvalErrors());
227  values.Fill(0.0);
228  TPZFNMatrix<3,STATE> gradu(3,1);
229  TPZAxesTools<STATE>::Axes2XYZ(dudx,gradu,axes);
230 
231  TPZManVector<STATE> sol(1),dsol(3,0.);
232  int id;
233  //values[0] : erro em norma H1 <=> norma Energia
234  //values[1] : eror em norma L2
235  //values[2] : erro em semi norma H1
236  STATE diff = (u[0] - u_exact[0]);
237 #ifdef STATE_COMPLEX
238  values[1] = std::real(diff*std::conj(diff));
239  //values[2] : erro em semi norma H1
240  values[2] = 0.;
241  for(id=0; id<fDim; id++) {
242  diff = (gradu(id) - du_exact(id,0));
243  values[2] += std::real(diff*std::conj(diff));
244  }
245 #else
246  values[1] = diff*diff;
247 
248  values[2] = 0.;
249 
250  for(id=0; id<fDim; id++) {
251  diff = (gradu(id) - du_exact(id,0));
252  values[2] += diff*diff;
253  }
254 #endif
255  values[0] = values[1]+values[2];
256 }
257 
259  return Hash("TPZL2Projection") ^ TPZDiscontinuousGalerkin::ClassId() << 1;
260 }
Defines the interface which material objects need to implement for discontinuous Galerkin formulation...
Definition: pzdiscgal.h:20
virtual void Solution(TPZMaterialData &data, int var, TPZVec< STATE > &Solout)
Returns the solution associated with the var index based on the finite element approximation.
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Performs function computation.
Definition: pzfunction.h:38
int fDim
Problem dimension.
TPZL2Projection(int id, int dim, int nstate, TPZVec< STATE > &sol, int IntegrationOrder=-1)
Class constructor.
virtual void ContributeVecShape(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef)
int ClassId() const override
Unique identifier for serialization purposes.
Definition: pzdiscgal.cpp:110
TPZManVector< REAL, 3 > x
value of the coordinate at the integration point
virtual int VariableIndex(const std::string &name) override
It returns the variable index associated with the name.
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
virtual void Errors(TPZVec< REAL > &x, TPZVec< STATE > &u, TPZFMatrix< STATE > &dudx, TPZFMatrix< REAL > &axes, TPZVec< STATE > &, TPZVec< STATE > &u_exact, TPZFMatrix< STATE > &du_exact, TPZVec< REAL > &values) override
Computes the error due to the difference between the interpolated flux and the flux computed based o...
clarg::argBool bc("-bc", "binary checkpoints", false)
virtual void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
It computes a contribution to the stiffness matrix and load vector at one integration point...
int fIntegrationOrder
Order for setting the integration rule.
static void Axes2XYZ(const TPZFMatrix< TVar > &dudaxes, TPZFMatrix< TVar > &dudx, const TPZFMatrix< REAL > &axesv, bool colMajor=true)
Makes the basis transformation from axes basis to euclidian basis.
Definition: pzaxestools.h:61
int Type()
Definition: pzbndcond.h:249
virtual void Solution(TPZVec< STATE > &Sol, TPZFMatrix< STATE > &DSol, TPZFMatrix< REAL > &axes, int var, TPZVec< STATE > &Solout) override
It returns the solution associated with the var index based on the finite element approximation...
REAL fScale
Scale factor applied to the stiffness matrix and right hand side.
int fNStateVars
Number of state variables.
virtual TPZMaterial * NewMaterial() override
To create another material of the same type.
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
void SetIsReferred(bool val)
Define if material is referred or not.
MShapeFunctionType fShapeType
Contains the TPZL2Projection class which implements an L2 projection to constant solution values...
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
TPZFMatrix< STATE > & Val2(int loadcase=0)
Definition: pzbndcond.h:255
TPZFNMatrix< 220, REAL > phi
vector of shapefunctions (format is dependent on the value of shapetype)
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
virtual int ClassId() const override
Unique identifier for serialization purposes.
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
virtual int IntegrationRuleOrder(int elPMaxOrder) const
Gets the order of the integration rule necessary to integrate an element with polinomial order p...
virtual int NEvalErrors()
Returns the number of norm errors. Default is 3: energy, L2 and H1.
Definition: TPZMaterial.h:524
virtual int NSolutionVariables(int var) override
Returns the number of variables associated with the variable indexed by var.
virtual int IntegrationRuleOrder(int elPMaxOrder) const override
Get the order of the integration rule necessary to integrate an element with polinomial order p...
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
virtual int NStateVariables() const override
Returns number of state variables.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
It computes a contribution to the stiffness matrix and load vector at one BC integration point...
virtual int NFunctions() const
number of values returned by this function
Definition: pzfunction.h:71
virtual int HasForcingFunction()
Directive that gives true if the material has a forcing function.
Definition: TPZMaterial.h:472
static REAL gBigNumber
Big number to penalization method, used for Dirichlet conditions.
Definition: TPZMaterial.h:83
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
TPZVec< STATE > fSol
Constant solution vector.
~TPZL2Projection()
Default destructor.
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
bool fIsReferred
Argument defining this material is a referred material.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: TPZMaterial.h:47
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
Contains declaration of the TPZAxesTools class which implements verifications over axes...
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
Contains the TPZIntPoints class which defines integration rules.
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
def values
Definition: rdt.py:119
TPZSolVec sol
vector of the solutions at the integration point
Implements an L2 projection to constant solution values.