NeoPZ
pzmat1dlin.cpp
Go to the documentation of this file.
1 
6 #include "pzmat1dlin.h"
7 #include "TPZMaterial.h"
8 #include "pzconnect.h"
9 #include "pzbndcond.h"
10 #include "pzerror.h"
11 #include "pzvec.h"
12 
13 #include <math.h>
14 using namespace std;
15 
17  REAL weight,
18  TPZFMatrix<STATE> &ek,
19  TPZFMatrix<STATE> &ef) {
20  TPZFMatrix<REAL> &dphi = data.dphix;
21  TPZFMatrix<REAL> &phi = data.phi;
22  TPZManVector<REAL,3> &x = data.x;
23 
24  // this method adds the contribution of the material to the stiffness
25  // matrix and right hand side
26 
27  // check on the validity of the arguments
28 
29  if(phi.Cols() != 1 || dphi.Rows() != 1 || phi.Rows() != dphi.Cols())
30  {
31  PZError << "TPZMat1dLin.contr, inconsistent input data : phi.Cols() = "
32  << phi.Cols() << " dphi.Cols + " << dphi.Cols() <<
33  " phi.Rows = " << phi.Rows() << " dphi.Rows = " <<
34  dphi.Rows() << "\n";
35  StopError();
36  }
37 
38  if(fForcingFunction)
39  {
40  TPZManVector<STATE> xfloat(fXf.Rows());
41  fForcingFunction->Execute(x,xfloat);//fXf = xfloat
42  int i;
43  for(i=0; i<fXf.Rows(); i++) fXf(i,0) = xfloat[i];
44  }
45  int r = fXk.Rows();
46  int c = fXk.Cols();
47  TPZFMatrix<STATE> submat(r,c);
48  for(int in=0 ; in < phi.Rows() ; ++in)
49  {
50  STATE tmpef = (phi(in,0)*weight);
51  TPZFMatrix<STATE> tmpTPZFMatrix1 = fXf*tmpef;
52  ef.AddSub(in*r,0,tmpTPZFMatrix1);
53 
54  for(int jn=0 ; jn<phi.Rows() ; ++jn)
55  {
56  STATE temp = (phi(in,0)*phi(jn,0)*weight);
57  submat = fXb*temp;
58  STATE temp2 = (dphi(0,in)*dphi(0,jn)*weight);
59  submat += fXk*temp2;
60  STATE temp3 = (phi(in,0)*dphi(0,jn)*weight);
61  submat += fXc*temp3;
62  ek.AddSub(in*r,jn*c,submat);
63  }
64  }
65 }
66 
68  REAL weight,
71  TPZBndCond &bc){
72  TPZFMatrix<REAL> &phi = data.phi;
73 
74  // this method applies the boundary condition itype to ek and ef
75 
76  if(bc.Material() != this){
77  PZError << "TPZMat1dLin.apply_bc warning : this material didn't create the boundary condition!\n";
78  }
79 
80  if(bc.Type() < 0 && bc.Type() > 2){
81  PZError << "TPZMat1dLin.aplybc, unknown boundary condition type :" <<
82  bc.Type() << " boundary condition ignored\n";
83  }
84  int bcv1r,bcv1c,bcv2r,bcv2c;
85  int r = fXk.Rows();
86  int numnod = ek.Rows()/r;
87  bcv1r = bc.Val1().Rows();
88  bcv1c = bc.Val1().Cols();
89  bcv2r = bc.Val2().Rows();
90  bcv2c = bc.Val2().Cols();
91  if( bcv1r != r ||
92  bcv1c != r ||
93  bcv2r != r ||
94  bcv2c != 1 ) {
95  PZError << "TPZMat1dLin.aplybc, incompatible number of degrees of " <<
96  "freedom, \n"
97  " val1.Rows =" << bc.Val1().Rows() << " xk.Rows = " << fXk.Rows() << "\n"
98  " val2.Cols() = " << bc.Val2().Cols() << " val2.Rows() = " << bc.Val2().Rows() << "\n"
99  " val1.Cols() = " << bc.Val1().Cols() << "\n";
100  }
101 
102  int idf,jdf,in,jn;
103  switch(bc.Type()){
104 
105  case 0:
106  for(in=0 ; in<numnod ; ++in){
107  for(idf = 0;idf<r;idf++) {
108  (ef)(in*r+idf,0) += (STATE)gBigNumber*(STATE)phi(in,0)*bc.Val2()(idf,0)*(STATE)weight;
109  }
110  for(jn=0 ; jn<numnod ; ++jn) {
111  for(idf = 0;idf<r;idf++) {
112  ek(in*r+idf,jn*r+idf) += gBigNumber*phi(in,0)*phi(jn,0)*weight;
113  }
114  }
115  }
116  break;
117 
118  case 1:
119  for(in=0 ; in<numnod ; ++in){
120  for(idf = 0;idf<r;idf++) {
121  (ef)(in*r+idf,0) += (STATE)phi(in,0)*bc.Val2()(idf,0)*(STATE)weight;
122  }
123  }
124  break;
125 
126  case 2:
127  for(in=0 ; in<numnod ; ++in){
128  for(idf = 0;idf<r;idf++) {
129  (ef)(in*r+idf,0) += (STATE)phi(in,0)*bc.Val2()(idf,0)*(STATE)weight;
130  }
131  for(jn=0 ; jn<numnod ; ++jn) {
132  for(idf = 0;idf<r;idf++) {
133  for(jdf = 0;jdf<r;jdf++) {
134  ek(in*r+idf,jn*r+jdf) += bc.Val1()(idf,jdf)*(STATE)phi(in,0)*(STATE)phi(jn,0)*(STATE)weight;
135  }
136  }
137  }
138  }
139  break;
140  }
141 }
142 
143 void TPZMat1dLin::Print(std::ostream & out) {
144 
145  out << "Material type TPZMat1dLin -- number = " << Id() << "\n";
146  out << "Matrix xk -> "; fXk.Print("fXk",out);
147  out << "Matrix xc -> "; fXc.Print("fXc",out);
148  out << "Matrix xb -> "; fXb.Print("fXb",out);
149  out << "Matrix xf -> "; fXf.Print("fXf",out);
150 }
151 
153 
154  int row = NStateVariables();
155  for(int i=0; i<row; i++){
156  fl[i] = 0.;
157  for(int j=0; j<row; j++) {
158  fl[i] += -fXk(i,j)*dudx(0,j);
159  }
160  }
161 }
162 
164  TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &values) {
165 
166  TPZVec<STATE> udif(u);
167  int nelem= udif.NElements(),i;
168  for(i=0; i<nelem; i++) udif[i] -= u_exact[i];
169  TPZFMatrix<STATE> dudif(dudx);
170 
171  int r = NStateVariables();
172  TPZVec<STATE> flux_el( r );
173  short idf;
174  for(idf=0; idf<r; idf++) {
175  dudif(0,idf) -= du_exact(0,idf);
176  }
177 
178  values.Fill(0.);
179 
180  for (idf=0; idf<r; idf++) {
181  values[1] += fabs(udif[idf]*udif[idf]);
182  for (short jdf=0; jdf<r; jdf++) {
183  values[0] += fabs(dudif(0,idf)*fXk(idf,jdf)*dudif(0,jdf) + udif[idf]*fXb(idf,jdf)*udif[jdf]);
184  flux_el[idf] -= fXk(idf,jdf)*dudx(0,jdf);
185  }
186  }
187 
188  for (idf=0; idf<r; idf++) {
189  STATE dif = flux[idf]-flux_el[idf];
190  if(std::abs(fXk(idf,idf)) >= 1.e-10)
191  {
192  values[2] += fabs(dif*dif/sqrt(std::abs( fXk(idf,idf) )));
193  }
194  }
195 }
196 
197 
199  return Hash("TPZMat1dLin") ^ TPZMaterial::ClassId() << 1;
200 }
virtual int AddSub(const int64_t sRow, const int64_t sCol, const TPZFMatrix< TVar > &Source)
It adds Source matrix on current matrix from position (sRow, sCol)
Definition: pzmatrix.cpp:625
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
Definition: tfadfunc.h:140
TPZManVector< REAL, 3 > x
value of the coordinate at the integration point
clarg::argBool bc("-bc", "binary checkpoints", false)
void Print(std::ostream &out) override
Prints out the data associated with the material.
Definition: pzmat1dlin.cpp:143
void StopError()
Definition: pzlog.h:19
int Type()
Definition: pzbndcond.h:249
Templated vector implementation.
Defines PZError.
virtual void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
Computes contribution to the stiffness matrix and right hand side at the integration point of a bound...
Definition: pzmat1dlin.cpp:67
virtual void Flux(TPZVec< REAL > &x, TPZVec< STATE > &u, TPZFMatrix< STATE > &dudx, TPZFMatrix< REAL > &axes, TPZVec< STATE > &fl) override
Computes the value of the flux function to be used by ZZ error estimator.
Definition: pzmat1dlin.cpp:152
TinyFad< 8, T > abs(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:846
virtual void Errors(TPZVec< REAL > &x, TPZVec< STATE > &u, TPZFMatrix< STATE > &dudx, TPZFMatrix< REAL > &axes, TPZVec< STATE > &flux, 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...
Definition: pzmat1dlin.cpp:163
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)
TPZFNMatrix< 660, REAL > dphix
values of the derivative of the shape functions
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
Contains declaration of TPZConnect class which represents a set of shape functions associated with a ...
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
TPZFMatrix< STATE > & Val1()
Definition: pzbndcond.h:253
virtual int ClassId() const override
Define the class id associated with the class.
Definition: pzmat1dlin.cpp:198
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
int ClassId() const override
Unique identifier for serialization purposes.
virtual void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
Computes contribution to the stiffness matrix and right hand side at an integration point...
Definition: pzmat1dlin.cpp:16
static int idf[6]
Contains the TPZMat1dLin class which implements a one-dimensional linear problem. ...
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
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
def values
Definition: rdt.py:119
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
TPZMaterial * Material() const
Definition: pzbndcond.h:263