NeoPZ
pzbndcond.cpp
Go to the documentation of this file.
1 
6 #include "pzbndcond.h"
7 #include "pzadmchunk.h"
8 #include "pzcmesh.h"
9 
10 #include "pzlog.h"
11 
12 #ifdef LOG4CXX
13 static LoggerPtr logger(Logger::getLogger("pz.material.bndcond"));
14 #endif
15 
17  return Hash("TPZBndCond::TPZ_BCDefine");
18 }
19 
20 void TPZBndCond::TPZ_BCDefine::Read(TPZStream& buf, void* context) {
21  fBCVal2.Read(buf, context);
22  fForcingFunction = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
23  fForcingFunctionExact = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
24  fTimeDependentForcingFunction = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
25  fTimedependentFunctionExact = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
26  fBCForcingFunction = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
27  fTimedependentBCForcingFunction = TPZAutoPointerDynamicCast<TPZFunction<STATE>>(TPZPersistenceManager::GetAutoPointer(&buf));
28 }
29 
30 void TPZBndCond::TPZ_BCDefine::Write(TPZStream& buf, int withclassid) const {
31  fBCVal2.Write(buf, withclassid);
38 }
39 
40 void TPZBndCond::Clone(std::map<int, TPZMaterial * > &matvec) {
41  int matid = Id();
42 
43  TPZMaterial * refmaterial = Material();
44  TPZMaterial * newrefmaterial = NULL;
45  int refmatid = 0;
46  if(refmaterial) {
47  refmaterial->Clone(matvec);
48  refmatid = refmaterial->Id();
49  newrefmaterial = matvec[refmatid];
50  }
51  std::map<int, TPZMaterial * >::iterator matit;
52  matit = matvec.find(matid);
53  if(matit == matvec.end())
54  {
55  TPZMaterial * newmat = (new TPZBndCond(*this, newrefmaterial));
56  matvec[matid] = newmat;
57  }
58 }
59 
61  TPZDiscontinuousGalerkin *mat = dynamic_cast<TPZDiscontinuousGalerkin *>(this->fMaterial);
62 
63  if(!mat) return;
64  if(fForcingFunction) {
66  fForcingFunction->Execute(x,result);
67  int i;
68  for(i=0; i<fBCVal2.Rows(); i++) {
69  fBCVal2(i,0) = result[i];
70  }
71  }
72 
73  if(leftu.NElements() == 0) {
74  mat->BCInterfaceJump(x, rightu, *this, jump);
75  return;
76  }
77 
78  if(rightu.NElements() == 0) {
79  mat->BCInterfaceJump(x, leftu, *this, jump);
80  return;
81  }
82 
83  PZError << __PRETTY_FUNCTION__ << " - Huge problem. Both leftu and rightu contain elements. Wich one is the actual element neighbour to the Dirichlet boundary ?" << std::endl;
84  DebugStop();
85 
86 }//InterfaceJump
87 
88 int TPZBndCond::ClassId() const{
89  return Hash("TPZBndCond") ^ TPZDiscontinuousGalerkin::ClassId() << 1;
90 }
91 
92 #ifndef BORLAND
93 template class TPZRestoreClass<TPZBndCond>;
94 #endif
95 
96 void TPZBndCond::Write(TPZStream &buf, int withclassid) const {
97  TPZDiscontinuousGalerkin::Write(buf, withclassid);
98  buf.Write(fBCs);
99  buf.Write(&fType);
100  fBCVal1.Write(buf, withclassid);
101  fBCVal2.Write(buf, withclassid);
103 }
104 
105 void TPZBndCond::Read(TPZStream &buf, void *context){
106  TPZDiscontinuousGalerkin::Read(buf, context);
107  buf.Read(fBCs);
108  buf.Read(&fType);
109  fBCVal1.Read(buf, context);
110  fBCVal2.Read(buf, context);
112  if (!fMaterial) {
113  std::cout << " reading a boundary condition without material object!!\n";
114 #ifdef LOG4CXX
115  LOGPZ_FATAL(logger, "reading a boundary condition without material object!!");
116 #endif
117  }
118 }
119 
121  REAL weight,
122  TPZVec<STATE> &nkL,
123  TPZVec<STATE> &nkR,
124  int &errorid){
125 
126  TPZDiscontinuousGalerkin *mat = dynamic_cast<TPZDiscontinuousGalerkin *>(this->fMaterial);
127  if(!mat) return;
128 
129  UpdateBCValues(data.x);
130 
131  if(dataleft.sol.NElements() < dataright.sol.NElements()){
132  // data.InvertLeftRightData();
133  for(int i=0; i<3; i++) data.normal[i] *= -1.;
134  mat->ContributeInterfaceBCErrors(data,dataright,weight,nkR,*this, errorid);
135  }
136  else {
137  mat->ContributeInterfaceBCErrors(data,dataleft,weight,nkL,*this, errorid);
138  }
139 
140 }
141 
143  this->fMaterial->ContributeBC(data, weight, ek, ef, *this);
144 }
145 
146 //----
148 
149  int nx = datavec[0].x.NElements();
150  if(nx==0){
151  UpdateBCValues(datavec[1].x);
152  }
153  else{
154  UpdateBCValues(datavec[0].x);
155  }
156 
157  this->fMaterial->ContributeBC(datavec,weight,ek,ef,*this);
158 }
159 //----
160 
162  UpdateBCValues(data.x);
163  this->fMaterial->ContributeBC(data,weight,ef,*this);
164 }
165 
167  DebugStop();//nothing to be done here
168 }
169 
171  DebugStop();//nothing to be done here
172 }
173 
176  if(!mat) DebugStop();
177  UpdateBCValues(data.x);
178 
179 
180  if(dataleft.phi.Rows() == 0){//it meanst right data has been filled
181  //left data should be filled instead of right data
182  // shouldn't we invert the normal vector?
183  for (int i=0; i<3; i++) data.normal[i] *= -1.;
184  mat->ContributeBCInterface(data,dataright,weight,ek,ef,*this);
185  }
186  else
187  {
188  mat->ContributeBCInterface(data,dataleft,weight,ek,ef,*this);
189  }
190 }//void
191 
193 
195  if(!mat) DebugStop();
196  UpdateBCValues(data.x);
197 
198  int nel = dataleft.size();
199  if(!nel) DebugStop();
200 
201  if(dataleft[0].phi.Rows() == 0){//it meanst right data has been filled
202  //left data should be filled instead of right data
203  // shouldn't we invert the normal vector?
204  for (int i=0; i<3; i++) data.normal[i] *= -1.;
205 
206  mat->ContributeBCInterface(data,dataright,weight,ek,ef,*this);
207  }
208  else
209  {
210  mat->ContributeBCInterface(data,dataleft,weight,ek,ef,*this);
211  }
212 
213 
214 }
215 
218  UpdateBCValues(data.x);
219  if(dataleft.phi.Rows() == 0){//it meanst right data has been filled
220  //left data should be filled instead of right data
221  for(int i=0; i<3; i++) data.normal[i] *= -1.;
222  mat->ContributeBCInterface(data,dataright,weight,ef,*this);
223  // data.InvertLeftRightData();
224  } else
225  {
226  mat->ContributeBCInterface(data,dataleft,weight,ef,*this);
227  }
228 }
229 
231  DebugStop();//nothing to be done here
232 }
233 
235  DebugStop();//nothing to be done here
236 }
237 
238 
240  if(fForcingFunction){
241  TPZManVector<STATE,3> result(fBCVal2.Rows(),0.);
243  // use gradu to update the Neumann boundary condition
244  fForcingFunction->Execute(x,result,gradu);
245 
246 #ifdef PZDEBUG
247  if (fBCVal2.Rows() != result.size()) {
248  DebugStop();
249  }
250 #endif
251  int i;
252  for(i=0; i<fBCVal2.Rows(); i++) {
253  fBCVal2(i,0) = result[i];
254  }
255  }
256 
257  if( this->fValFunction ){
258  TPZManVector<STATE> result(this->fBCVal2.Rows(),0.);
259  this->fValFunction(x, this->fBCVal1, result, this->fType );
260  int i;
261  for(i = 0; i < this->fBCVal2.Rows(); i++) {
262  this->fBCVal2(i,0) = result[i];
263  }
264  }//if
265 
266  int nbc = fBCs.size();
267  for (int ibc=0; ibc<nbc; ibc++) {
268  if (fBCs[ibc].fForcingFunction) {
269  TPZManVector<STATE> result(fBCVal2.Rows(),0.);
270  fBCs[ibc].fForcingFunction->Execute(x,result);
271  int i;
272  for(i=0; i<fBCVal2.Rows(); i++) {
273  fBCs[ibc].fBCVal2(i,0) = result[i];
274  }
275 
276  }
277  }
278 }
279 
280 
282 
283  PZError << "Error at " << __PRETTY_FUNCTION__ << " method is not implementedl!\n";
284  DebugStop();
285 }
286 
287 
289  if(!fMaterial)
290  {
291  PZError << "\nUnable to call TPZBndCond::fMaterial::FillDataRequirements - fMaterial pointer is null!\n";
292  return;
293  }
295  if(fLinearContext == false || fType == 50){
296  data.fNeedsSol = true;
297  }
298 }
299 
301  if(!fMaterial)
302  {
303  PZError << "\nUnable to call TPZBndCond::fMaterial::FillDataRequirements - fMaterial pointer is null!\n";
304  return;
305  }
307  int nref = datavec.size();
308 
309  if(fLinearContext == false){
310  for(int iref=0; iref<nref; iref++){
311  datavec[iref].fNeedsSol = true;
312  }
313  }
314 }
315 
317  data.fNeedsNormal = true;
318  int nref_left = datavec_left.size();
319  for(int iref = 0; iref<nref_left; iref++){
320  datavec_left[iref].SetAllRequirements(false);
321  datavec_left[iref].fNeedsSol = true;
322  datavec_left[iref].fNeedsNormal = true;
323  }
324  int nref_right = datavec_right.size();
325  for(int iref = 0; iref<nref_right; iref++){
326  datavec_right[iref].SetAllRequirements(false);
327  datavec_right[iref].fNeedsSol = true;
328  datavec_right[iref].fNeedsNormal = true;
329  }
330 }
void ContributeInterfaceErrors(TPZMaterialData &data, TPZMaterialData &dataleft, TPZMaterialData &dataright, REAL weight, TPZVec< STATE > &nkL, TPZVec< STATE > &nkR, int &errorid) override
Definition: pzbndcond.cpp:120
Defines the interface which material objects need to implement for discontinuous Galerkin formulation...
Definition: pzdiscgal.h:20
bool fLinearContext
Defines whether the equation context is linear solver or non linear.
Definition: TPZMaterial.h:70
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Performs function computation.
Definition: pzfunction.h:38
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzfmatrix.h:789
int ClassId() const override
Unique identifier for serialization purposes.
Definition: pzdiscgal.cpp:110
TPZManVector< REAL, 3 > normal
normal to the element at the integration point
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
TPZManVector< REAL, 3 > x
value of the coordinate at the integration point
TPZAutoPointer< TPZFunction< STATE > > fBCForcingFunction
Pointer to bc forcing function, it is a variable boundary condition at differential equation...
Definition: pzbndcond.h:54
clarg::argBool bc("-bc", "binary checkpoints", false)
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
Definition: pzdiscgal.cpp:118
TPZVec< TPZ_BCDefine > fBCs
Definition: pzbndcond.h:95
TPZAutoPointer< TPZFunction< STATE > > fTimeDependentForcingFunction
Pointer to time dependent forcing function, it is the right member at differential equation...
Definition: pzbndcond.h:48
virtual int ClassId() const override
Returns the unique identifier for reading/writing objects to streams.
Definition: pzbndcond.cpp:88
virtual void ContributeInterfaceBCErrors(TPZMaterialData &data, TPZMaterialData &dataleft, REAL weight, TPZVec< STATE > &nk, TPZBndCond &bc, int &errorid)
Definition: pzdiscgal.h:220
Declarates the TPZBlock<REAL>class which implements block matrices.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunctionExact
Pointer to exact solution function, needed to calculate exact error.
Definition: pzbndcond.h:45
static TPZSavable * GetInstance(const int64_t &objId)
TPZFNMatrix< 220, REAL > phi
vector of shapefunctions (format is dependent on the value of shapetype)
#define LOGPZ_FATAL(A, B)
Define log for fatal errors (cout)
Definition: pzlog.h:95
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
static TPZAutoPointer< TPZSavable > GetAutoPointer(const int64_t &objId)
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
TPZAutoPointer< TPZFunction< STATE > > fTimedependentFunctionExact
Pointer to time dependent exact solution function, needed to calculate exact error.
Definition: pzbndcond.h:51
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...
Definition: pzbndcond.cpp:142
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
virtual void ContributeInterface(TPZMaterialData &data, TPZMaterialData &dataleft, TPZMaterialData &dataright, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
It computes a contribution to stiffness matrix and load vector at one integration point...
Definition: pzbndcond.cpp:174
virtual void BCInterfaceJump(TPZVec< REAL > &x, TPZSolVec &leftu, TPZBndCond &bc, TPZSolVec &jump)
Computes interface jump from element to Dirichlet boundary condition. It has to reimplemented.
Definition: pzdiscgal.cpp:102
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzfmatrix.h:783
void UpdateBCValues(TPZManVector< REAL, 3 > &x)
Definition: pzbndcond.cpp:239
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...
Definition: pzbndcond.cpp:166
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
Definition: pzdiscgal.cpp:114
int ClassId() const override
Define the class id associated with the class.
Definition: pzbndcond.cpp:16
TPZFNMatrix< 9, STATE > fBCVal1
first value of boundary condition
Definition: pzbndcond.h:100
TPZBndCond()
Default constructor.
Definition: pzbndcond.h:124
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZAutoPointer< TPZFunction< STATE > > fTimedependentBCForcingFunction
Pointer to time dependent bc forcing function, it is a variable boundary condition at differential eq...
Definition: pzbndcond.h:57
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual void FillBoundaryConditionDataRequirement(int type, TPZMaterialData &data)
This method defines which parameters need to be initialized in order to compute the contribution of t...
Definition: TPZMaterial.h:120
virtual void ContributeBCInterface(TPZMaterialData &data, TPZMaterialData &dataleft, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
It computes a contribution to stiffness matrix and load vector at one BC integration point...
Definition: pzbndcond.cpp:230
virtual void InterfaceJump(TPZVec< REAL > &x, TPZSolVec &leftu, TPZSolVec &rightu, TPZSolVec &jump) override
Compute interface jumps.
Definition: pzbndcond.cpp:60
void(* fValFunction)(TPZVec< REAL > &loc, TPZFMatrix< STATE > &Val1, TPZVec< STATE > &Val2, int &BCType)
Function to allow fBCVal1 to be variable.
Definition: pzbndcond.h:107
TPZMaterial * fMaterial
pointer to material which created bc
Definition: pzbndcond.h:104
virtual void ContributeBCInterface(TPZMaterialData &data, TPZMaterialData &dataleft, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc)=0
It computes a contribution to stiffness matrix and load vector at one BC integration point...
virtual void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc)=0
It computes a contribution to the stiffness matrix and load vector at one BC integration point...
virtual void FillDataRequirementsInterface(TPZMaterialData &data, TPZVec< TPZMaterialData > &datavec_left, TPZVec< TPZMaterialData > &datavec_right) override
This method defines which parameters need to be initialized in order to compute the contribution of i...
Definition: pzbndcond.cpp:316
int fType
boundary condition type
Definition: pzbndcond.h:98
virtual void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
Definition: pzbndcond.cpp:96
Contains declaration of TPZCompMesh class which is a repository for computational elements...
virtual void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
Definition: pzbndcond.cpp:105
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: pzbndcond.h:42
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzbndcond.cpp:30
TPZFNMatrix< 6, STATE > fBCVal2
second value of boundary condition
Definition: pzbndcond.h:39
virtual void FillDataRequirements(TPZMaterialData &data) override
Calls the aggregate material correspondent function.
Definition: pzbndcond.cpp:288
int Dimension() const override
Returns the integrable dimension of the material.
Definition: pzbndcond.h:240
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzbndcond.cpp:20
virtual void Clone(std::map< int, TPZMaterial * > &matvec) override
Creates a copy of the material object and put it in the vector which is passed on.
Definition: pzbndcond.cpp:40
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.
int Id() const
Definition: TPZMaterial.h:170
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
TPZSolVec sol
vector of the solutions at the integration point
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
TPZMaterial * Material() const
Definition: pzbndcond.h:263
virtual void Read(bool &val)
Definition: TPZStream.cpp:91