16 #include <Accelerate/Accelerate.h> 21 #include "boost/crc.hpp" 27 static LoggerPtr logger(Logger::getLogger(
"pz.mesh.sbfemelementgroup"));
28 static LoggerPtr loggerMT(Logger::getLogger(
"pz.mesh.sbfemelementgroupMT"));
39 std::map<int64_t,int64_t> locindex;
41 for (int64_t ic=0; ic<ncon ; ic++) {
50 for (int64_t el = 0; el<nel; el++) {
68 if (logger->isDebugEnabled()) {
73 std::stringstream sout;
75 sout <<
"Material id " << matid <<std::endl;
79 sout <<
"No associated geometry\n";
81 sout <<
"Connect indexes ";
86 sout <<
"Local indexes ";
91 E0Loc.
fMat.
Print(
"Matriz elementar E0",sout);
92 E1Loc.
fMat.
Print(
"Matriz elementar E1",sout);
93 E2Loc.
fMat.
Print(
"Matriz elementar E2",sout);
94 M0Loc.
fMat.
Print(
"Matriz elementar M0",sout);
100 boost::crc_32_type crc;
102 crc.process_bytes(&E0Loc.
fMat(0,0), n*n*
sizeof(STATE));
103 crc.process_bytes(&E1Loc.
fMat(0,0), n*n*
sizeof(STATE));
104 crc.process_bytes(&E2Loc.
fMat(0,0), n*n*
sizeof(STATE));
105 matEcrc[
Index()] = crc.checksum();
110 for (
int ic=0; ic<nelcon; ic++) {
113 int ibldest = locindex[icindex];
114 for (
int jc = 0; jc<nelcon; jc++) {
117 int jbldest = locindex[jcindex];
119 for (
int jdf=0; jdf<jblsize; jdf++) {
153 if (logger->isDebugEnabled()) {
154 std::stringstream sout;
188 int nwork = 4*n*n + 2*n;
192 dgetrf_(&n, &n, &E0Inv(0,0), &n, &pivot[0], &info);
195 sgetrf_(&n, &n, &E0Inv(0,0), &n, &pivot[0], &info);
201 dgetri_(&n, &E0Inv(0,0), &n, &pivot[0], &work[0], &nwork, &info);
204 sgetri_(&n, &E0Inv(0,0), &n, &pivot[0], &work[0], &nwork, &info);
218 cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, n, n, n, 1., &E0Inv(0,0), n, &E1.
fMat(0,0), n, 0., &globmat(0,0), 2*n);
219 #elif defined STATEfloat 220 cblas_sgemm(CblasColMajor, CblasNoTrans, CblasTrans, n, n, n, 1., &E0Inv(0,0), n, &E1.
fMat(0,0), n, 0., &globmat(0,0), 2*n);
222 std::cout <<
"SBFem does not execute for this configuration\n";
226 for (
int i=0; i<n; i++) {
227 for (
int j=0; j<n; j++) {
228 globmat(i,j+n) = -E0Inv(i,j);
232 cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1., &E1.
fMat(0,0), n, &globmat(0,0), 2*n, 0., &globmat(n,0), 2*n);
233 #elif defined STATEfloat 234 cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1., &E1.
fMat(0,0), n, &globmat(0,0), 2*n, 0., &globmat(n,0), 2*n);
236 std::cout <<
"SBFem does not execute for this configuration\n";
239 for (
int i=0; i<n; i++) {
240 for (
int j=0; j<n; j++) {
241 globmat(i+n,j) -= E2.
fMat(i,j);
246 cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, -1., &E1.
fMat(0,0), n, &E0Inv(0,0), n, 0., &globmat(n,n), 2*n);
247 #elif defined STATEfloat 248 cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, -1., &E1.
fMat(0,0), n, &E0Inv(0,0), n, 0., &globmat(n,n), 2*n);
250 std::cout <<
"SBFem does not execute for this configuration\n";
255 for (
int i=0; i<n; i++) {
256 globmat(i,i) -= (dim-2)*0.5;
257 globmat(i+n,i+n) += (dim-2)*0.5;
268 globmatkeep.SolveEigenProblem(eigenvalues, eigenVectors);
270 static pthread_mutex_t
mutex =PTHREAD_MUTEX_INITIALIZER;
271 pthread_mutex_lock(&mutex);
272 extern int gnumthreads;
273 std::stringstream sout;
274 sout <<
"eigval" << gnumthreads <<
".nb";
275 static int count = 0;
278 file.open(sout.str());
282 file.open(sout.str(),std::ios::app);
284 std::stringstream eigv;
285 eigv <<
"EigVec" <<
Index() <<
" = ";
291 pthread_mutex_unlock(&mutex);
299 for (
int i=0; i<2*n; i++) {
300 eigvalreal[i] = eigenvalues[i].real();
301 for (
int j=0; j<2*n; j++) {
302 eigvecreal(i,j) = eigenVectors(i,j).real();
313 for (
int i=0; i<2*n; i++) {
314 if (eigenvalues[i].real() < -1.e-6) {
315 double maxvaleigenvec = 0;
316 for (
int j=0; j<n; j++) {
317 QVectors(j,count) = eigenVectors(j+n,i);
318 eigvecsel(j,count) = eigenVectors(j,i);
319 eigvecsel(j+n,count) = eigenVectors(j+n,i);
320 fPhi(j,count) = eigenVectors(j,i);
321 double realvalabs =
fabs(
fPhi(j,count).real());
322 if (realvalabs > maxvaleigenvec) {
323 maxvaleigenvec = realvalabs;
326 eigvalsel[count] = eigenvalues[i];
327 eigvalmat(0,count) = eigenvalues[i];
328 for (
int j=0; j<n; j++) {
329 QVectors(j,count) /= maxvaleigenvec;
330 eigvecsel(j,count) /= maxvaleigenvec;
331 eigvecsel(j+n,count) /= maxvaleigenvec;
332 fPhi(j,count) /= maxvaleigenvec;
340 std::cout <<
"eigval = {" << eigvalsel <<
"};\n";
346 if (nstate != 2 && nstate != 1) {
349 if(count != n-nstate) {
354 std::set<int64_t> cornercon;
356 for (
int ic=0; ic<ncon; ic++) {
358 if (cornercon.find(conindex) != cornercon.end())
361 eigvecsel(eq,count) = 1;
364 fPhi(eq+1,count+1) = 1;
365 eigvecsel(eq+1,count+1) = 1;
371 if(dim==3 && count != n)
377 if(logger->isDebugEnabled())
379 std::stringstream sout;
380 sout <<
"eigenvalues " << eigvalsel << std::endl;
399 phicopy.Decompose_LU(pivot);
407 if (logger->isDebugEnabled())
409 std::stringstream sout;
421 std::ofstream out(
"EigenProblem.nb");
431 for (
int i=0; i<ekloc.Rows(); i++) {
432 for (
int j=0; j<ekloc.Cols(); j++) {
433 ek.
fMat(i,j) = ekloc(i,j).real();
434 ekimag(i,j) = ekloc(i,j).imag();
439 for (int64_t el = 0; el<nel; el++) {
450 pthread_mutex_lock(&
mutex);
452 boost::crc_32_type crc;
454 crc.process_bytes(&E0.
fMat(0,0), n*n*
sizeof(STATE));
455 crc.process_bytes(&E1.
fMat(0,0), n*n*
sizeof(STATE));
456 crc.process_bytes(&E2.
fMat(0,0), n*n*
sizeof(STATE));
457 matEcrc[
Index()] = crc.checksum();
461 boost::crc_32_type crc;
462 int64_t n = E0Inv.
Rows();
463 crc.process_bytes(&E0Inv(0,0), n*n*
sizeof(STATE));
464 matEInvcrc[
Index()] = crc.checksum();
468 boost::crc_32_type crc;
469 crc.process_bytes(&globmat(0,0), 4*n*n*
sizeof(STATE));
470 matglobcrc[
Index()] = crc.checksum();
473 boost::crc_32_type crc;
474 crc.process_bytes(&eigenVectors(0,0), n*n*
sizeof(std::complex<double>));
475 eigveccrc[
Index()] = crc.checksum();
478 boost::crc_32_type crc;
479 int n = ekloc.Rows();
480 crc.process_bytes(&ekloc(0,0), n*n*
sizeof(STATE));
481 stiffcrc[
Index()] = crc.checksum();
483 pthread_mutex_unlock(&
mutex);
488 if(logger->isDebugEnabled())
490 std::stringstream sout;
499 for (
int r=0; r<nr; r++) {
500 for (
int c=0; c<nr; c++) {
517 for (
int ic=0; ic<nc; ic++) {
521 int blsize = nshape*nstate;
524 for (
int seq=0; seq < blsize; seq++) {
525 for (
int c=0; c<uh_local.
Cols(); c++)
534 for (int64_t el = 0; el<nel; el++) {
557 for (
int i=0; i<nrow; i++) {
558 for(
int j=0; j<nrow; j++)
560 M0Loc(i, j) = M0.
fMat(i,j);
563 fPhi.
MultAdd(M0Loc, M0Loc, temp, alpha, beta, transpose);
566 for (
int i=0; i<nrow; i++) {
567 for (
int j=0; j<nrow; j++) {
576 for (
int i=0; i<nrow; i++) {
577 for(
int j=0; j<nrow; j++)
580 MassLocImag(i,j) = MassLoc(i,j).imag();
595 for (int64_t el = 0; el<nel; el++) {
612 std::set<int64_t> connects;
614 for (
int ic=0; ic<nc; ic++) {
620 for (
int ic=0; ic<nc; ic++) {
623 nc = connects.size();
626 std::set<int64_t>::iterator it = connects.begin();
627 for (
int ic = 0; it != connects.end(); it++,ic++) {
TPZFMatrix< std::complex< double > > fPhi
Matrix of eigenvectors which compose the stiffness matrix.
virtual void LoadSolution()
Loads the solution within the internal data structure of the element.
pthread_mutex_t mutex
Semaphore which controls multiple threads.
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
TPZFMatrix< std::complex< double > > fCoef
Multiplying coefficients of each eigenvector.
int Position(const int block_diagonal) const
Returns the position of first element block dependent on matrix diagonal.
Represents a set of shape functions associated with a computational element/side. Computational Eleme...
Implements a vector class which allows to use external storage provided by the user. Utility.
virtual int Decompose_LU(std::list< int64_t > &singular) override
LU Decomposition. Stores L and U matrices at the storage of the same matrix.
virtual int64_t ConnectIndex(int i) const override
Returns the index of the ith connectivity of the element.
int MaterialId() const
Returns the material index of the element.
TPZStack< TPZCompEl *, 5 > fElGroup
virtual int NConnects() const override
Returns the number of nodes of the element.
TPZStack< int64_t > fConnect
Vector of pointers to TPZConnect objects.
TPZManVector< int64_t, 27 > fConnectIndexes
TPZFNMatrix< 1000, STATE > fMat
Pointer to a blocked matrix object.
virtual void Identity()
Converts the matrix in an identity matrix.
void SetPhiEigVal(TPZFMatrix< std::complex< double > > &phi, TPZManVector< std::complex< double > > &eigval)
initialize the data structures of the eigenvectors and eigenvalues associated with this volume elemen...
EComputationMode fComputationMode
TPZManVector< std::complex< double > > fEigenvalues
Vector of eigenvalues of the SBFem analyis.
REAL fDelt
timestep coeficient
This class implements a simple vector storage scheme for a templated class T. Utility.
TPZFMatrix< std::complex< double > > fPhiInverse
Inverse of the eigenvector matrix (transfers eigenvector coeficients to side shape coeficients) ...
TPZBlock< STATE > fBlock
Block structure associated with fMat.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
void ComputeMatrices(TPZElementMatrix &E0, TPZElementMatrix &E1, TPZElementMatrix &E2, TPZElementMatrix &M0)
Computes the element stifness matrix and right hand side.
virtual void BuildCornerConnectList(std::set< int64_t > &connectindexes) const override
adds the connect indexes associated with base shape functions to the set
int Zero() override
Makes Zero all the elements.
int64_t size() const
Returns the number of elements of the vector.
TPZCompEl * Element(int64_t iel)
int64_t SequenceNumber() const
Returns the Sequence number of the connect object.
int NConnects()
Returns the number of nodes of TElementMatrix.
void ComputeMassMatrix(TPZElementMatrix &M0)
Compute the mass matrix based on the value of M0 and the eigenvectors.
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
#define DebugStop()
Returns a message to user put a breakpoint in.
virtual void LoadCoef(TPZFMatrix< std::complex< double > > &coef)
Loads the solution within the internal data structure of the element.
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
TPZCompMesh * Mesh() const
Return a pointer to the grid of the element.
void LoadEigenVector(int64_t eig)
Load the coeficients such that we visualize an eigenvector.
int Dimension() const
Returns the dimension of the simulation.
virtual void AddElement(TPZCompEl *cel)
add an element to the element group
unsigned int NShape() const
int64_t Rows() const
Returns number of rows.
const TPZBlock< STATE > & Block() const
Access the block structure of the solution vector.
static int Substitution(const TVar *ptr, int64_t rows, TPZFMatrix< TVar > *B)
int64_t Index() const
Returns element index of the mesh fELementVec list.
Contains declaration of TPZCompMesh class which is a repository for computational elements...
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
virtual TPZConnect & Connect(int i) const
Returns a pointer to the ith node.
unsigned char NState() const
Number of state variables associated with the connect.
virtual int64_t ConnectIndex(int i) const =0
Returns the index of the ith connectivity of the element.
This class associates an element matrix with the coeficients of its contribution in the global stiffn...
virtual int NConnects() const =0
Returns the number of nodes of the element.
REAL fMassDensity
multiplier to multiply the mass matrix
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
void ComputeKMatrices(TPZElementMatrix &E0, TPZElementMatrix &E1, TPZElementMatrix &E2, TPZElementMatrix &M0)
Compute the E0, E1 and E2 matrices.
int Size(const int block_diagonal) const
Returns block dimension.
virtual void CalcStiff(TPZElementMatrix &ek, TPZElementMatrix &ef)
Computes the element stifness matrix and right hand side.
virtual void Multiply(const TPZFMatrix< TVar > &A, TPZFMatrix< TVar > &res, int opt=0) const
It mutiplies itself by TPZMatrix<TVar>A putting the result in res.
void InitializeElementMatrix(TPZElementMatrix &ek, TPZElementMatrix &ef) const
Initialize the datastructure of ek and ef based on the connect information.
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha=1., const TVar beta=0., const int opt=0) const override
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
int64_t Cols() const
Returns number of cols.
virtual void Print(std::ostream &out) const
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
TPZFMatrix< STATE > fMassMatrix
Defines the interface of a computational element. Computational Element.
virtual void AddElement(TPZCompEl *cel)
add an element to the element group
TPZFMatrix< STATE > & Solution()
Access the solution vector.
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
TPZCompMesh * fMesh
Computational mesh to which the element belongs.