1 /*
2 XLiFE++ is an extended library of finite elements written in C++
3     Copyright (C) 2014  Lun�ville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13     You should have received a copy of the GNU General Public License
14     along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 /*!
18   \file HMatrix.cpp
19   \author E. Lun�ville
20   \since 20 dec 2017
21   \date 20 mar 2017
22 
23   \brief Implementation of xlifepp::HMatrixIM class members
24 */
25 
26 #include "HMatrix.hpp"
27 
28 namespace xlifepp
29 {
30 //===============================================================================
31 //member functions of HMatrixIM class
32 //===============================================================================
33 //constructors with IntegrationMethod
HMatrixIM(ClusteringMethod clm,number_t minRow,number_t minCol,HMApproximationMethod hmap,number_t maxr,IntegrationMethod & im)34 HMatrixIM::HMatrixIM(ClusteringMethod clm, number_t minRow, number_t minCol, HMApproximationMethod hmap, number_t maxr, IntegrationMethod& im)
35   : rowCluster_(0), colCluster_(0), clusterMethod(clm), hmAppMethod(hmap), minRowSize(minRow), minColSize(minCol), maxRank(maxr),
36     epsRank(0.), intgMethod(im.clone())
37 {
38   imType = _HMatrixIM;
39   deletePointers_ = true;
40 }
41 
HMatrixIM(ClusteringMethod clm,number_t minRow,number_t minCol,HMApproximationMethod hmap,real_t epsr,IntegrationMethod & im)42 HMatrixIM::HMatrixIM(ClusteringMethod clm, number_t minRow, number_t minCol, HMApproximationMethod hmap, real_t epsr, IntegrationMethod& im)
43   : rowCluster_(0), colCluster_(0), clusterMethod(clm), hmAppMethod(hmap), minRowSize(minRow), minColSize(minCol), maxRank(0),
44     epsRank(epsr), intgMethod(im.clone())
45 {
46   imType = _HMatrixIM;
47   deletePointers_ = true;
48 }
49 
HMatrixIM(HMApproximationMethod hmap,number_t maxr,IntegrationMethod & im,ClusterTree<FeDof> & rowC,ClusterTree<FeDof> & colC)50 HMatrixIM::HMatrixIM(HMApproximationMethod hmap,  number_t maxr, IntegrationMethod& im, ClusterTree<FeDof>& rowC, ClusterTree<FeDof>& colC)
51   : rowCluster_(&rowC), colCluster_(&colC), hmAppMethod(hmap), maxRank(maxr), epsRank(0.), intgMethod(im.clone())
52 {
53   imType = _HMatrixIM;
54   clusterMethod=rowC.method_;
55   minRowSize=rowC.maxInBox_;
56   minColSize=colC.maxInBox_;
57   deletePointers_ = false;
58 }
59 
HMatrixIM(HMApproximationMethod hmap,int maxr,IntegrationMethod & im,ClusterTree<FeDof> & rowC,ClusterTree<FeDof> & colC)60 HMatrixIM::HMatrixIM(HMApproximationMethod hmap,  int maxr, IntegrationMethod& im, ClusterTree<FeDof>& rowC, ClusterTree<FeDof>& colC)
61   : rowCluster_(&rowC), colCluster_(&colC), hmAppMethod(hmap), maxRank(maxr), epsRank(0.), intgMethod(im.clone())
62 {
63   imType = _HMatrixIM;
64   clusterMethod=rowC.method_;
65   minRowSize=rowC.maxInBox_;
66   minColSize=colC.maxInBox_;
67   deletePointers_ = false;
68 }
69 
HMatrixIM(HMApproximationMethod hmap,real_t epsr,IntegrationMethod & im,ClusterTree<FeDof> & rowC,ClusterTree<FeDof> & colC)70 HMatrixIM::HMatrixIM(HMApproximationMethod hmap,  real_t epsr, IntegrationMethod& im, ClusterTree<FeDof>& rowC, ClusterTree<FeDof>& colC)
71   : rowCluster_(&rowC), colCluster_(&colC), hmAppMethod(hmap), maxRank(0), epsRank(epsr), intgMethod(im.clone())
72 {
73   imType = _HMatrixIM;
74   clusterMethod=rowC.method_;
75   minRowSize=rowC.maxInBox_;
76   minColSize=colC.maxInBox_;
77   deletePointers_ = false;
78 }
79 
80 //constructors with IntegrationMethods
HMatrixIM(ClusteringMethod clm,number_t minRow,number_t minCol,HMApproximationMethod hmap,number_t maxr,IntegrationMethods & ims)81 HMatrixIM::HMatrixIM(ClusteringMethod clm, number_t minRow, number_t minCol, HMApproximationMethod hmap, number_t maxr, IntegrationMethods& ims)
82   : rowCluster_(0), colCluster_(0), clusterMethod(clm), hmAppMethod(hmap), minRowSize(minRow), minColSize(minCol), maxRank(maxr),
83     epsRank(0.), intgMethod(0), intgMethods(ims)
84 {
85   imType = _HMatrixIM;
86   deletePointers_ = true;
87 }
88 
HMatrixIM(ClusteringMethod clm,number_t minRow,number_t minCol,HMApproximationMethod hmap,real_t epsr,IntegrationMethods & ims)89 HMatrixIM::HMatrixIM(ClusteringMethod clm, number_t minRow, number_t minCol, HMApproximationMethod hmap, real_t epsr, IntegrationMethods& ims)
90   : rowCluster_(0), colCluster_(0), clusterMethod(clm), hmAppMethod(hmap), minRowSize(minRow), minColSize(minCol), maxRank(0),
91     epsRank(epsr),  intgMethod(0), intgMethods(ims)
92 {
93   imType = _HMatrixIM;
94   deletePointers_ = true;
95 }
96 
HMatrixIM(HMApproximationMethod hmap,number_t maxr,IntegrationMethods & ims,ClusterTree<FeDof> & rowC,ClusterTree<FeDof> & colC)97 HMatrixIM::HMatrixIM(HMApproximationMethod hmap,  number_t maxr, IntegrationMethods& ims, ClusterTree<FeDof>& rowC, ClusterTree<FeDof>& colC)
98   : rowCluster_(&rowC), colCluster_(&colC), hmAppMethod(hmap), maxRank(maxr), epsRank(0.),  intgMethod(0), intgMethods(ims)
99 {
100   imType = _HMatrixIM;
101   clusterMethod=rowC.method_;
102   minRowSize=rowC.maxInBox_;
103   minColSize=colC.maxInBox_;
104   deletePointers_ = false;
105 }
106 
HMatrixIM(HMApproximationMethod hmap,int maxr,IntegrationMethods & ims,ClusterTree<FeDof> & rowC,ClusterTree<FeDof> & colC)107 HMatrixIM::HMatrixIM(HMApproximationMethod hmap, int maxr, IntegrationMethods& ims, ClusterTree<FeDof>& rowC, ClusterTree<FeDof>& colC)
108   : rowCluster_(&rowC), colCluster_(&colC), hmAppMethod(hmap), maxRank(maxr), epsRank(0.),  intgMethod(0), intgMethods(ims)
109 {
110   imType = _HMatrixIM;
111   clusterMethod=rowC.method_;
112   minRowSize=rowC.maxInBox_;
113   minColSize=colC.maxInBox_;
114   deletePointers_ = false;
115 }
116 
HMatrixIM(HMApproximationMethod hmap,real_t epsr,IntegrationMethods & ims,ClusterTree<FeDof> & rowC,ClusterTree<FeDof> & colC)117 HMatrixIM::HMatrixIM(HMApproximationMethod hmap,  real_t epsr, IntegrationMethods& ims, ClusterTree<FeDof>& rowC, ClusterTree<FeDof>& colC)
118   : rowCluster_(&rowC), colCluster_(&colC), hmAppMethod(hmap), maxRank(0), epsRank(epsr), intgMethod(0), intgMethods(ims)
119 {
120   imType = _HMatrixIM;
121   clusterMethod=rowC.method_;
122   minRowSize=rowC.maxInBox_;
123   minColSize=colC.maxInBox_;
124   deletePointers_ = false;
125 }
126 
127 //destructor
~HMatrixIM()128 HMatrixIM::~HMatrixIM()
129 {
130   if(deletePointers_) clear();
131 }
132 
clear()133 void HMatrixIM::clear()
134 {
135   if(rowCluster_ != 0) delete rowCluster_;
136   if(colCluster_ != rowCluster_ && colCluster_ != 0) delete colCluster_;
137   rowCluster_ = 0;  colCluster_ = 0;
138   if(intgMethod==0) delete intgMethod;
139 }
140 
141 //print stuff
print(std::ostream & out) const142 void HMatrixIM::print(std::ostream& out) const
143 {
144   out<<"HMatrix method : "<<words("cluster method",clusterMethod)<<" row leaf size = "<<minRowSize<<" "<<" col leaf size = "<<minColSize<<" ";
145   if(rowCluster_==0 && colCluster_==0) out<<" cluster not allocated";
146   else out<<" cluster allocated";
147   out<<eol<<"                "<<" compression method : "<<words("HMAtrix approximation", hmAppMethod)<< " epsRank="<<epsRank<<" maxRank="<<maxRank;
148   out<<eol<<"                "<<" integration method : ";
149   if(intgMethod!=0) out<<*intgMethod;
150   else out<<intgMethods;
151   out<<eol;
152 }
153 
154 }
155