NeoPZ
TPZLagrangeMultiplier.cpp
Go to the documentation of this file.
1 //
2 // TPZLagrangeMultiplier.cpp
3 // PZ
4 //
5 // Created by Philippe Devloo on 5/2/14.
6 //
7 //
8 
10 #include "pzaxestools.h"
11 
12 
13 
16  return Hash("TPZLagrangeMultiplier") ^ TPZDiscontinuousGalerkin::ClassId() << 1;
17 }
18 
20 void TPZLagrangeMultiplier::Write(TPZStream &buf, int withclassid) const
21 {
22  TPZDiscontinuousGalerkin::Write(buf, withclassid);
23  buf.Write(&fNStateVariables);
24 }
25 
27 void TPZLagrangeMultiplier::Read(TPZStream &buf, void *context)
28 {
29  TPZDiscontinuousGalerkin::Read(buf, context);
30  buf.Read(&fNStateVariables);
31 
32 }
33 
34 //Contribution of skeletal elements.
36 {
37  int nmesh = datavec.size();
38  if (nmesh!=2) DebugStop();
39 
40  TPZFMatrix<REAL> &phiQ = datavec[0].phi;
41  TPZFMatrix<REAL> &phiP = datavec[1].phi;
42  int phrq = phiQ.Rows();
43  int phrp = phiP.Rows();
44 
45 //------- Block of matrix B ------
46  int iq, jp;
47  for(iq = 0; iq<phrq; iq++) {
48  for(jp=0; jp<phrp; jp++) {
49  ek(iq, phrq+jp) += fMultiplier*weight*phiQ(iq,0)*phiP(jp,0);
50  }
51  }
52 
53 
54 //------- Block of matrix B^T ------
55  int ip, jq;
56  for(ip=0; ip<phrp; ip++) {
57  for(jq=0; jq<phrq; jq++) {
58  ek(ip + phrq,jq) += fMultiplier*weight*phiP(ip,0)*phiQ(jq,0);
59  }
60  }
61 }
62 
74 {
75  TPZFMatrix<REAL> *phiLPtr = 0, *phiRPtr = 0;
76  for (int i=0; i<dataleft.size(); i++) {
77  if (dataleft[i].phi.Rows() != 0) {
78  phiLPtr = &dataleft[i].phi;
79  break;
80  }
81  }
82  for (int i=0; i<dataright.size(); i++) {
83  if (dataright[i].phi.Rows() != 0) {
84  phiRPtr = &dataright[i].phi;
85  break;
86  }
87  }
88 
89  if(!phiLPtr || !phiRPtr)
90  {
91  DebugStop();
92  }
93  TPZFMatrix<REAL> &phiL = *phiLPtr;
94  TPZFMatrix<REAL> &phiR = *phiRPtr;
95 
96 
97  int nrowl = phiL.Rows();
98  int nrowr = phiR.Rows();
99  static int count = 0;
100 
101  if((nrowl+nrowr)*fNStateVariables != ek.Rows() && count < 20)
102  {
103  std::cout<<"ek.Rows() "<< ek.Rows()<<
104  " nrowl " << nrowl <<
105  " nrowr " << nrowr << " may give wrong result " << std::endl;
106  count++;
107  }
108 
109  int secondblock = ek.Rows()-phiR.Rows()*fNStateVariables;
110  int il,jl,ir,jr;
111 
112  // 3) phi_I_left, phi_J_right
113  for(il=0; il<nrowl; il++) {
114  for(jr=0; jr<nrowr; jr++) {
115  for (int ist=0; ist<fNStateVariables; ist++) {
116  ek(fNStateVariables*il+ist,fNStateVariables*jr+ist+secondblock) += weight * fMultiplier * (phiL(il) * phiR(jr));
117  }
118  }
119  }
120 
121  // // 4) phi_I_right, phi_J_left
122  for(ir=0; ir<nrowr; ir++) {
123  for(jl=0; jl<nrowl; jl++) {
124  for (int ist=0; ist<fNStateVariables; ist++) {
125  ek(ir*fNStateVariables+ist+secondblock,jl*fNStateVariables+ist) += weight * fMultiplier * (phiR(ir) * phiL(jl));
126  }
127  }
128  }
129 
130 }
131 
132 
144 {
145 // TPZFMatrix<REAL> &dphiLdAxes = dataleft.dphix;
146 // TPZFMatrix<REAL> &dphiRdAxes = dataright.dphix;
147  TPZFMatrix<REAL> &phiL = dataleft.phi;
148  TPZFMatrix<REAL> &phiR = dataright.phi;
149 
150 // TPZFNMatrix<660> dphiL, dphiR;
151 // TPZAxesTools<REAL>::Axes2XYZ(dphiLdAxes, dphiL, dataleft.axes);
152 // TPZAxesTools<REAL>::Axes2XYZ(dphiRdAxes, dphiR, dataright.axes);
153 
154 
155  int nrowl = phiL.Rows();
156  int nrowr = phiR.Rows();
157 #ifdef PZDEBUG
158  if(phiL.Rows()*fNStateVariables+phiR.Rows()*fNStateVariables != ek.Rows())
159  {
160  DebugStop();
161  }
162 #endif
163  int secondblock = ek.Rows()-phiR.Rows()*fNStateVariables;
164  int il,jl,ir,jr;
165 
166  // 3) phi_I_left, phi_J_right
167  for(il=0; il<nrowl; il++) {
168  for(jr=0; jr<nrowr; jr++) {
169  for (int ist=0; ist<fNStateVariables; ist++) {
170  ek(fNStateVariables*il+ist,fNStateVariables*jr+ist+secondblock) += weight * fMultiplier * (phiL(il) * phiR(jr));
171  }
172  }
173  }
174 
175  // // 4) phi_I_right, phi_J_left
176  for(ir=0; ir<nrowr; ir++) {
177  for(jl=0; jl<nrowl; jl++) {
178  for (int ist=0; ist<fNStateVariables; ist++) {
179  ek(ir*fNStateVariables+ist+secondblock,jl*fNStateVariables+ist) += weight * fMultiplier * (phiR(ir) * phiL(jl));
180  }
181  }
182  }
183 
184 }
185 
196 {
197  DebugStop();
198 }
199 
200 
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 ClassId() const override
Unique identifier for serialization purposes.
Definition: pzdiscgal.cpp:110
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
Definition: pzdiscgal.cpp:118
virtual void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
TPZFNMatrix< 220, REAL > phi
vector of shapefunctions (format is dependent on the value of shapetype)
virtual void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
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
virtual int ClassId() const override
Unique identifier for serialization purposes.
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
int fNStateVariables
Number of state variables.
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
Contains declaration of the TPZAxesTools class which implements verifications over axes...
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
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...
virtual void Read(bool &val)
Definition: TPZStream.cpp:91