NeoPZ
pzmattest.cpp
Go to the documentation of this file.
1 
6 #include "pzmattest.h"
7 
8 #include "pzbndcond.h"
9 
10 #include "pzfmatrix.h"
11 #include "pzerror.h"
12 #include <math.h>
13 using namespace std;
14 
15 TPZMaterialTest::TPZMaterialTest(int nummat, STATE alfa, STATE x0) : TPZMaterial(nummat), fXf(1,1,0.) {
16 
17  fNumMat = nummat;
18 }
19 
21 }
22 
24  return 1;
25 }
26 
27 void TPZMaterialTest::Print(std::ostream &out) {
28  out << "name of material : " << Name() << "\n";
29  out << "properties : \n";
30  out << "Material id = " << fNumMat << endl;
31 }
32 
34  REAL weight,
36  TPZFMatrix<STATE> &ef) {
37  TPZFMatrix<REAL> &dphi = data.dphix;
38  TPZFMatrix<REAL> &phi = data.phi;
39  TPZManVector<REAL,3> &x = data.x;
40 
41  int phr = phi.Rows();
42 
43  if(fForcingFunction) { // phi(in, 0) : fun�o de forma associada ao n�in
45  fForcingFunction->Execute(x,res); // dphi(i,j) : derivada c/r a xi da fun�o de forma j
46  fXf(0,0) = res[0];
47  }
48  for( int in = 0; in < phr; in++ ) {
49  ef(in, 0) += weight * fXf(0,0) * phi(in, 0) ;
50  for( int jn = 0; jn < phr; jn++ ) {
51  ek(in,jn) += weight * (dphi(0,in) * dphi(0,jn) + dphi(1,in) * dphi(1,jn));
52  }
53  }
54 }
55 
57  REAL weight,
60  TPZBndCond &bc) {
61  TPZFMatrix<REAL> &phi = data.phi;
62 
63  if(bc.Material() != this) {
64  PZError << "TPZMat1dLin.apply_bc warning : this material didn't create the boundary condition!\n";
65  }
66 
67  if(bc.Type() < 0 && bc.Type() > 2){
68  PZError << "TPZMat1dLin.aplybc, unknown boundary condition type :" <<
69  bc.Type() << " boundary condition ignored\n";
70  }
71 
72 
73  int numdof = NStateVariables();
74  int numnod = ek.Rows()/numdof;
75  int r = numdof;
76 
77  int idf,jdf,in,jn;
78  switch(bc.Type()) {
79 
80  case 0:
81  for(in=0 ; in<numnod ; ++in){
82  for(idf = 0;idf<r;idf++) {
83  (ef)(in*r+idf,0) += gBigNumber*phi(in,0)*bc.Val2()(idf,0)*weight;
84  }
85  for(jn=0 ; jn<numnod ; ++jn) {
86  for(idf = 0;idf<r;idf++) {
87  ek(in*r+idf,jn*r+idf) += gBigNumber*phi(in,0)*phi(jn,0)*weight;
88  }
89  }
90  }
91  break;
92 
93  case 1:
94  for(in=0 ; in<numnod ; ++in){
95  for(idf = 0;idf<r;idf++) {
96  (ef)(in*r+idf,0) += phi(in,0)*bc.Val2()(idf,0)*weight;
97  }
98  }
99  break;
100 
101  case 2:
102  for(in=0 ; in<numnod ; ++in){
103  for(idf = 0;idf<r;idf++) {
104  (ef)(in*r+idf,0) += phi(in,0)*bc.Val2()(idf,0)*weight;
105  }
106  for(jn=0 ; jn<numnod ; ++jn) {
107  for(idf = 0;idf<r;idf++) {
108  for(jdf = 0;jdf<r;jdf++) {
109  ek(in*r+idf,jn*r+jdf) += bc.Val1()(idf,jdf)*phi(in,0)*phi(jn,0)*weight;
110  }
111  }
112  }
113  }//fim switch
114  }
115 }
116 
118 int TPZMaterialTest::VariableIndex(const std::string &name){
119  if(!strcmp("Displacement6",name.c_str())) return 0;
120  if(!strcmp("Solution",name.c_str())) return 1;
121  if(!strcmp("Derivate",name.c_str())) return 2;
122  if(!strcmp("POrder",name.c_str())) return 99;
123 
124  return TPZMaterial::VariableIndex(name);
125 }
126 
128 
129  if(var == 0 || var == 1 || var == 2) return 1;
131 }
132 
134 
135  if(var == 0 || var == 1) {
136  Solout[0] = Sol[0];//function
137  return;
138  }
139  if(var == 2) {
140  Solout[0] = DSol(0,0);//derivate
141  Solout[1] = DSol(1,0);//derivate
142  return;
143  }
144  TPZMaterial::Solution(Sol,DSol,axes,var,Solout);
145 }
146 
148  if(fabs(axes(2,0)) >= 1.e-6 || fabs(axes(2,1)) >= 1.e-6) {
149  cout << "TPZMaterialTest::Flux only serves for xy configuration\n";
150  axes.Print("axes");
151  }
152 }
153 
156  TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &values) {
157 
158  TPZVec<STATE> sol(1),dsol(2);
159  Solution(u,dudx,axes,1,sol);
160  Solution(u,dudx,axes,2,dsol);
161  for (int i = 0; i < 3; i++)
162  values[i] = 0.0;
163  //values[0] : norma energia do erro
164  values[0] = (dsol[0] - du_exact(0,0))*(dsol[0] - du_exact(0,0));
165  values[0] += (dsol[1] - du_exact(1,0))*(dsol[1] - du_exact(1,0));
166  //values[1] -> norma energia da solucao Uhp (aproximada)
167  values[1] = (dsol[0])*(dsol[0]);
168  values[1] += (dsol[1])*(dsol[1]);
169  //values[2] -> morma enaergia da solucao U (exata)
170  values[2] = (du_exact(0,0))*(du_exact(0,0));
171  values[2] += (du_exact(1,0))*(du_exact(1,0));
172 }
173 
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
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)
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: pzmattest.cpp:33
int Type()
Definition: pzbndcond.h:249
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
Defines PZError.
virtual void Print(std::ostream &out) override
Prints out the data associated with the material.
Definition: pzmattest.cpp:27
virtual int NStateVariables() const override
Returns the number of state variables associated with the material.
Definition: pzmattest.cpp:23
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
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 NSolutionVariables(int var) override
Returns the number of variables associated with the variable indexed by var.
Definition: pzmattest.cpp:127
Contains TPZMatrixclass which implements full matrix (using column major representation).
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
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: pzmattest.cpp:154
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual void Solution(TPZVec< STATE > &Sol, TPZFMatrix< STATE > &DSol, TPZFMatrix< REAL > &axes, int var, TPZVec< STATE > &Solout) override
Definition: pzmattest.cpp:133
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: pzmattest.cpp:56
string res
Definition: test.py:151
TPZFMatrix< STATE > & Val1()
Definition: pzbndcond.h:253
static REAL gBigNumber
Big number to penalization method, used for Dirichlet conditions.
Definition: TPZMaterial.h:83
virtual std::string Name() override
Returns the name of the material.
Definition: pzmattest.h:44
virtual ~TPZMaterialTest()
Definition: pzmattest.cpp:20
virtual void Flux(TPZVec< REAL > &x, TPZVec< STATE > &Sol, TPZFMatrix< STATE > &DSol, TPZFMatrix< REAL > &axes, TPZVec< STATE > &flux) override
Compute the value of the flux function to be used by ZZ error estimator.
Definition: pzmattest.cpp:147
static int idf[6]
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
TPZFMatrix< STATE > fXf
Definition: pzmattest.h:22
Contains the TPZMaterialTest class. Test.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: TPZMaterial.h:47
TPZMaterialTest(int nummat, STATE alfa, STATE x0)
Definition: pzmattest.cpp:15
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
def values
Definition: rdt.py:119
virtual int VariableIndex(const std::string &name) override
Definition: pzmattest.cpp:118
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
TPZMaterial * Material() const
Definition: pzbndcond.h:263