23#include "dune/istl/bcrsmatrix.hh"
73 template <
int m=1,
class Index=
size_t>
89 std::vector<Index>
const& subdomainSize,
107 template <
class Scalar=
double>
127 std::vector<Interfaces> ifs;
129 std::vector<Index> subdomainSize;
131 std::vector<std::vector<std::vector<int>>> cifs;
132 std::array<int,3> ifCount;
177 template <
int m,
class Scalar_=double,
class CoarseScalar=Scalar_,
178 class Transfer=SpaceTransfer<m,Scalar_> >
226 template <
int cComponents>
231 template <
class Interface>
250 trans.getInterfaceAveragingWeights(s,rho);
260 trans.setInterfaceAveragingWeights(s,rho);
323 trans.getInterfaceResidualUpdate(s,dres);
333 trans.setInterfaceResidualUpdate(s,dres);
418 trans.preProlongate(du);
427 trans.getInterfaceValues(s,values);
437 trans.setInterfaceValues(s,values);
501 return activeSubdomains_sub;
506 activeSubdomains_sub.resize(activeSubdomains_.size());
508 for (
int i = 0; i < activeSubdomains_.size(); ++i)
510 activeSubdomains_sub[i] = activeSubdomains_[i];
545 bool activeId =
true;
547 std::vector<int> interiorDofs;
548 std::vector<int> interfaceDofs;
549 std::vector<bool> activeSubdomains_sub;
551 Vector rawCorrection, residual, restrictedResidual;
553 std::vector<int> globalIndex_notActive;
557std::vector<int> cIndices;
564 void solveDirichlet(
Vector& x,
Vector const& rhs)
const;
574 template <
class Subdomain>
610 return subdomains->size();
613 std::vector<DynamicMatrix<Dune::FieldMatrix<Scalar,1,1>>>
getS()
const;
625 return activeSubdomains;
630 std::cout <<
"activeIds.size() = " << activeIds.size() <<std::endl;
631 activeSubdomains.resize(
size());
632 for (
int i = 0; i < activeIds.size(); ++i)
634 activeSubdomains[activeIds[i]] =
true;
647 return std::array<int,6>{exchangeCount,transfers,initTraffic,restrictionTraffic,
648 prolongationTraffic,coarseGridTraffic};
652 std::vector<Subdom>* subdomains;
653 std::vector<std::pair<int,int>> neighbors;
654 std::vector<bool> activeSubdomains;
658 int exchangeCount = 0;
661 int restrictionTraffic = 0;
662 int prolongationTraffic = 0;
663 int coarseGridTraffic = 0;
760 template <
class Domain>
781 , constraints(domain->size())
782 , localConstraintsSize(domain->size())
783 , sOffsets(constr.size()+1)
788 for (
int k=0; k<constr.size(); ++k)
790 auto const& [s,m] = constr[k];
793 assert(0<=i && i<domain->size());
794 constraints[i].push_back(k);
795 localConstraintsSize[i] += m;
799 std::partial_sum(begin(sOffsets),end(sOffsets),begin(sOffsets));
803 int const ns = sOffsets.back();
807 for (
auto const& ss: constraints)
811 sOffsets[sCol],sOffsets[sCol+1]);
817 using SortedIdx = std::vector<std::pair<int,int>>;
819 auto localSchurComplements = domain->getS();
820 for (
int i=0; i<domain->size(); ++i)
824 for (
int k: constraints[i])
825 for (
int l=sOffsets[k]; l<sOffsets[k+1]; ++l)
826 rows.push_back({l,localIndex++});
827 assert(std::is_sorted(rows.begin(),rows.end(),
FirstLess()));
829 lm.
back() = localSchurComplements[i];
846 int const ns = sOffsets.back();
855 timer.
start(
"get Schur rhs");
858 timer.
stop(
"get Schur rhs");
861 std::vector<int> d(ns,1);
862 for (
int i=0; i<domain->size(); ++i)
864 if(not domain->getActiveSubdomains()[i])
866 for (
auto const k: constraints[i])
868 int const off = sOffsets[k];
869 int const nsk = sOffsets[k+1]-off;
870 for (
int l=0; l<nsk; ++l)
876 for (
int i=0; i<ns; ++i)
879 timer.
start(
"solve Schur system");
882 timer.
stop(
"solve Schur system");
885 for (
int i=0; i<ns; ++i)
889 timer.
start(
"set corrections");
890 std::vector<Vector> dcs(domain->size());
891 for (
int i=0; i<domain->size(); ++i)
893 if(domain->getActiveSubdomains()[i])
895 Vector si(localConstraintsSize[i]);
897 for (
auto const k: constraints[i])
899 int const off = sOffsets[k];
900 int const nsk = sOffsets[k+1]-off;
901 for (
int l=0; l<nsk; ++l)
902 si[pos++] = s[l+off];
907 domain->setCorrections(dcs);
908 timer.
stop(
"set corrections");
914 void getRightHandSide(Vector& f)
const
917 auto floc = domain->getSchurResiduals();
919 for (
int i=0; i<domain->size(); ++i)
921 if(domain->getActiveSubdomains()[i])
924 for (
auto const k: constraints[i])
926 int const off = sOffsets[k];
927 int const nsk = sOffsets[k+1]-off;
928 for (
int l=0; l<nsk; ++l)
929 f[l+off] += floc[i][pos++];
937 std::vector<std::vector<int>> constraints;
938 std::vector<int> localConstraintsSize;
939 std::vector<int> sOffsets;
940 DirectSolver<Vector,Vector> Sinv;
1070 template <
class Subdomain>
1095 std::vector<int> & activeIds,
1096 bool cg_solver=
false,
1097 bool BDDC_verbose=
false);
1107 (*subdomains)[i].update_rhs(Fs[i]);
1132 std::vector<Subdomain>* subdomains;
1136 std::vector<XVector>
const Fs;
1138 double sigma_pre = 0;
1139 double BDDC_verbose =
false;
Balanced Domain Decomposition with Constraints preconditioner.
BDDCSolver(std::vector< Subdomain > &subdomains, CoarseConstraints const &constraints, std::vector< int > &activeIds, bool cg_solver=false, bool BDDC_verbose=false)
Constructor.
typename Subdom::Vector Vector
double solve()
Performs a gradient step.
void update_rhs(std::vector< XVector > &Fs)
update rhs for each subdomain
std::array< int, 6 > traffic() const
Reports the amount of data exchanged between subdomains.
typename Subdom::Scalar Scalar
A class for computing and providing BDDC coarse space constraints (interface averages).
CoarseConstraints coarseConstraints() const
Provides information about subdomains sharing coarse constraints.
std::array< int, 3 > interfaceCount() const
Reports on number of corners, edges, and faces.
NumaBCRSMatrix< Dune::FieldMatrix< Scalar, m, m > > coarseConstraint(int id) const
Creates the subdomain-local constraints defining the coarse space.
static constexpr int components
InterfaceAverages(std::vector< std::vector< LocalDof > > const &sharedDofs, std::vector< Index > const &subdomainSize, int types=CORNER|FACE)
Constructor.
Interfaces const & interfaces(int id) const
For the given subdomain, tells with which neighboring domain which dofs are shared.
A class for solving a block-diagonal-structured KKT system.
void solve()
solves the system.
KKTSolver(Domain &domain_, CoarseConstraints const &constr)
Constructor.
std::tuple< int, int, int > Constraint
typename Domain::Scalar Scalar
A class that orchestrates the exchange of data between BDDC subdomains.
void updateSolution(Scalar alpha)
std::array< int, 6 > traffic() const
Reports the amount of data exchanged between subdomains.
std::vector< Vector > getSchurResiduals()
std::vector< bool > getActiveSubdomains()
typename Subdom::XVector XVector
void restrict()
Performs restriction in BDDC.
Dune::FieldVector< double, 2 > prolongate()
Performs prolongation in BDDC.
std::vector< DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > > > getS() const
Dune::FieldVector< double, 1 > updateSearchDirectionNorm()
void updateSearchDirection(double beta)
void set_solver_type(bool cg_solver)
void setActiveSubdomains(std::vector< int > &activeIds)
SharedMemoryDomain(std::vector< Subdom > &subdomains)
typename Subdom::Vector Vector
typename Subdom::Scalar Scalar
void setCorrections(std::vector< Vector > const &dcs)
int size() const
Reports the number of subdomains.
A class representing small KKT systems on a single subdomain.
void setCorrection(Vector const &c)
Computes the correction vector .
Subdomain(int id, AMatrix const &A, Interfaces const &interfaces, NumaBCRSMatrix< Dune::FieldMatrix< Scalar, cComponents, components > > const &C)
Constructor.
Dune::FieldVector< double, 1 > updateSearchDirectionNorm()
std::vector< int > neighbors() const
Reports a list of its neighbor subdomains.
XVector getSolution() const
Provides the current solution vector .
void updateSolution(Scalar alpha)
Updates the solution approximation.
void preRestrict()
First step of the restriction: Dirichlet solve.
void setInterfaceAveragingWeights(int s, XVector const &rho)
Accumulates interface weights of adjacent subdomains.
void getRawCorrection(XVector &dx) const
void setActiveId(bool active)
Dune::BlockVector< Dune::FieldVector< Scalar, 1 > > Vector
void getCorrection(XVector &dx) const
Provides the current correction vector .
Vector const & getRestrictedResidual() const
Dune::FieldVector< double, 2 > prolongate()
Perform averaging on the shared interfaces, projecting the solution to the subspace of functions cont...
Subdomain(int id, AMatrix const &A, Interface const &ifs)
void getS(SMatrix &S) const
Compute .
static const int components
Number of (vectorial) components of .
void getResidual(XVector &rr) const
void set_solver_type(bool cg_solver)
Set solver type.
void preProlongate()
Prepares the exchange of interface values.
void setInterfaceResidualUpdate(int s, TransmissionType const &dres)
Sets interface residual of the correction from neighboring subdomains.
std::vector< bool > getActiveSubdomains()
Scalar_ Scalar
The scalar field type used in coefficients.
void getInterfaceAveragingWeights(int s, XVector &rho) const
Reports own interface averaging weights.
void getSolution(XVector &x) const
Provides the current solution vector .
Dune::BlockVector< XEntry > XVector
void update_rhs(XVector const &f)
update rhs for the current subdomain
void imposeDC_inActiveInterface(Vector &Aq, Vector &q)
void imposeDCq(Vector &q)
void getSchurResidual(Vector &lambda) const
Provides the Schur residual.
void updateSearchDirection(double beta)
Update search direction q for cg solver.
void getInterfaceResidualUpdate(int s, TransmissionType &dres) const
Gets interface residual that shall be shared with neighboring subdomain.
void updateIteration(int cg_itr)
typename Transfer::TransmissionType TransmissionType
A container type used for exchanging coefficients between subdomains.
void setActiveSubdomains_sub(std::vector< bool > &activeSubdomains_)
void restrict()
Performs the restriction of the residual vector.
void getInterfaceValues(int s, TransmissionType &values) const
Gets boundary values that shall be shared with neighboring subdomain.
void setInterfaceValues(int s, TransmissionType const &values)
Sets boundary values of the correction from neighboring subdomains.
A structure for holding a sequence of several local matrices to be filled sequentially and to be scat...
void scatter()
Scatters the local matrices into the global one and removes them from the local container.
value_type & back()
A reference to the last pushed local matrix.
void push_back(SortedRowIdx const &ridx, SortedColIdx const &cidx)
Appends another (zero-initialized) local matrix.
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
A NUMA-aware creator for matrix sparsity patterns.
void addDenseBlock(Index fromRow, Index toRow, Index fromCol, Index toCol)
Enters a contiguous dense block into the sparsity pattern.
Supports gathering and reporting execution times information for nested program parts.
static Timings & instance()
Returns a reference to a single default instance.
void stop(std::string const &name)
Stops the timing of given section.
struct Times const * start(std::string const &name)
Starts or continues the timing of given section.
@ UMFPACK
UMFPack from SuiteSparse, using 32 bit integer indices.
InterfaceType
Discrimination of different interface types.
std::vector< std::pair< int, std::vector< int > > > Interfaces
A data structure describing the interfaces of a subdomain.
void parallelFor(Func const &f, int maxTasks=std::numeric_limits< int >::max())
A parallel for loop that executes the given functor in parallel on different CPUs.
std::vector< std::pair< std::vector< int >, int > > CoarseConstraints
A data structure describing coarse constraints.
A pair of subdomain id and local dof index denotes a subdomain-local reference to a global dof.
A comparator functor that supports sorting std::pair by their first component.