NeoPZ
TPZBndCondWithMem_impl.h
Go to the documentation of this file.
1 //
2 // TPZBndCondWithMem_impl.h
3 // pz
4 //
5 // Created by Omar DurĂ¡n on 6/12/19.
6 //
7 
8 #include "TPZBndCondWithMem.h"
9 
10 template <class TMEM>
11 void TPZBndCondWithMem<TMEM>::Print(std::ostream &out)
12 {
13  out << this->Name();
14  TPZBndCond::Print(out);
15 }
16 
17 template <class TMEM>
18 TMEM & TPZBndCondWithMem<TMEM>::MemItem(const int i) const{
19  return fMemory.get()->operator [](i);
20 }
21 
22 template <class TMEM>
24  return Hash("TPZBndCondWithMem") ^ TPZBndCond::ClassId() << 1 ^ TMEM().ClassId() << 2;
25 }
26 
27 template <class TMEM>
28 void TPZBndCondWithMem<TMEM>::Write(TPZStream &buf, int withclassid) const{
29  TPZBndCond::Write(buf, withclassid);
30  int updatemem = fUpdateMem;
31  buf.Write(&updatemem);
32  fDefaultMem.Write(buf, 0);
33  TPZPersistenceManager::WritePointer(fMemory.get(), &buf);
34 }
35 
36 template <class TMEM>
37 void TPZBndCondWithMem<TMEM>::Read(TPZStream &buf, void *context){
38  TPZBndCond::Read(buf, context);
39  int updatemem;
40  buf.Read(&updatemem);
41  if (updatemem) {
42  fUpdateMem = true;
43  } else {
44  fUpdateMem = false;
45  }
46  fDefaultMem.Read(buf, 0);
47  fMemory = std::dynamic_pointer_cast<TPZAdmChunkVector<TMEM> >(TPZPersistenceManager::GetSharedPointer(&buf));
48 }
49 
50 template <class TMEM>
51 std::shared_ptr<TPZAdmChunkVector<TMEM>> & TPZBndCondWithMem<TMEM>::GetMemory(){
52  return fMemory;
53 }
54 
55 template <class TMEM>
57  fMemory = memory;
58 }
59 
60 template <class TMEM>
62  int index = fMemory->AllocateNewElement();
63  if (sourceIndex < 0) {
64  this->ResetMemItem(index);
65  } else {
66  this->MemItem(index) = this->MemItem(sourceIndex);
67  }
68  return index;
69 }
70 
71 template <class TMEM>
73  fMemory->SetFree(index);
74 }
75 
76 template <class TMEM>
78  fDefaultMem = defaultMem;
79 }
80 
81 template <class TMEM>
83  fUpdateMem = update;
84 }
85 
86 template <class TMEM>
88  TPZBndCond::Contribute(data, weight, ek, ef);
89 }
90 
91 template <class TMEM>
93  TPZFMatrix<STATE> ek_fake(ef.Rows(),ef.Rows());
94  this->Contribute(data, weight, ek_fake, ef);
95 }
96 
97 template <class TMEM>
99  TPZBndCond::Contribute(datavec, weight, ek, ef);
100 }
101 
102 template <class TMEM>
104  TPZFMatrix<STATE> ek_fake(ef.Rows(),ef.Rows());
105  this->Contribute(datavec, weight, ek_fake, ef);
106 }
107 
108 #define IMPLEMENTTPZBNDCONDWITHMEM(TMEM) \
109 \
110 template class \
111 TPZRestoreClass< TPZBndCondWithMem<TMEM> >;
int ClassId() const override
Unique identifier for serialization purposes.
virtual int ClassId() const override
Returns the unique identifier for reading/writing objects to streams.
Definition: pzbndcond.cpp:88
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
Implements a chunk vector with free store administration. Utility.
Definition: TPZStream.h:39
virtual void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
Contribute methods.
virtual void SetUpdateMem(bool update=1)
void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
virtual int PushMemItem(int sourceIndex=-1) override
Pushes a new entry in the context of materials with memory, returning its index at the internal stora...
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
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
std::shared_ptr< TPZAdmChunkVector< TMEM > > & GetMemory()
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
static std::shared_ptr< TPZSavable > GetSharedPointer(const int64_t &objId)
virtual void Print(std::ostream &out) override
Prints out the data associated with the material.
void Print(std::ostream &out=std::cout) override
Prints out the data associated with the material.
Definition: pzbndcond.h:284
virtual void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
Definition: pzbndcond.cpp:96
virtual void FreeMemItem(int index) override
Frees an entry in the material with memory internal history storage.
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
void SetMemory(std::shared_ptr< TPZAdmChunkVector< TMEM >> &memory)
virtual void SetDefaultMem(TMEM &defaultMem)
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
virtual TMEM & MemItem(const int i) const
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
virtual void Read(bool &val)
Definition: TPZStream.cpp:91