// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: #ifndef ANISOTROPIC_HH #define ANISOTROPIC_HH #include #include #include #include #include #include #include typedef Dune::OwnerOverlapCopyAttributeSet GridAttributes; typedef GridAttributes::AttributeSet GridFlag; typedef Dune::ParallelLocalIndex LocalIndex; template void setupPattern(int N, M& mat, Dune::ParallelIndexSet& indices, int overlapStart, int overlapEnd, int start, int end); template void fillValues(int N, M& mat, int overlapStart, int overlapEnd, int start, int end); template void setupPattern(int N, M& mat, Dune::ParallelIndexSet& indices, int overlapStart, int overlapEnd, int start, int end) { int n = overlapEnd - overlapStart; typename M::CreateIterator iter = mat.createbegin(); indices.beginResize(); for(int j=0; j < N; j++) for(int i=overlapStart; i < overlapEnd; i++, ++iter) { GridFlag flag = GridAttributes::owner; if((i 0) || (i>= end && i < N-1)) flag=GridAttributes::copy; if(i= end-1) { int global = j*N+i; indices.add(global, LocalIndex(iter.index(), flag, true)); } iter.insert(iter.index()); // i direction if(i > overlapStart ) // We have a left neighbour iter.insert(iter.index()-1); if(i < overlapEnd-1) // We have a right neighbour iter.insert(iter.index()+1); // j direction // Overlap is a dirichlet border, discard neighbours if(flag != GridAttributes::copy) { if(j>0) // lower neighbour iter.insert(iter.index()-n); if(j void fillValues([[maybe_unused]] int N, M& mat, int overlapStart, int overlapEnd, int start, int end, T eps) { typedef typename M::block_type Block; Block dval(0), bone(0), bmone(0), beps(0); auto setDiagonal = [](auto&& scalarOrMatrix, const auto& value) { auto&& matrix = Dune::Impl::asMatrix(scalarOrMatrix); for (auto rowIt = matrix.begin(); rowIt != matrix.end(); ++rowIt) (*rowIt)[rowIt.index()] = value; }; using real_type = typename Dune::FieldTraits::real_type; setDiagonal(dval, static_cast(2.0)+static_cast(2.0)*eps); setDiagonal(bone, static_cast(1.0)); setDiagonal(bmone, static_cast(-1.0)); setDiagonal(beps, -eps); int n = overlapEnd-overlapStart; typedef typename M::ColIterator ColIterator; typedef typename M::RowIterator RowIterator; for (RowIterator i = mat.begin(); i != mat.end(); ++i) { // calculate coordinate int y = i.index() / n; int x = overlapStart + i.index() - y * n; ColIterator endi = (*i).end(); if(x= end) { // || x==0 || x==N-1 || y==0 || y==N-1){ // overlap node is dirichlet border ColIterator j = (*i).begin(); for(; j.index() < i.index(); ++j) *j=0; *j = bone; for(++j; j != endi; ++j) *j=0; }else{ for(ColIterator j = (*i).begin(); j != endi; ++j) if(j.index() == i.index()) *j=dval; else if(j.index()+1==i.index() || j.index()-1==i.index()) *j=beps; else *j=bmone; } } } template void setBoundary(V& lhs, V& rhs, const G& n, Dune::ParallelIndexSet& indices) { typedef typename Dune::ParallelIndexSet::const_iterator Iter; for(Iter i=indices.begin(); i != indices.end(); ++i) { G x = i->global()/n; G y = i->global()%n; if(x==0 || y ==0 || x==n-1 || y==n-1) { //double h = 1.0 / ((double) (n-1)); lhs[i->local()]=rhs[i->local()]=0; //((double)x)*((double)y)*h*h; } } } template void setBoundary(V& lhs, V& rhs, const G& N) { for(int j=0; j < N; ++j) for(int i=0; i < N; i++) if(i==0 || j ==0 || i==N-1 || j==N-1) lhs[j*N+i]=rhs[j*N+i]=0; } /** * \tparam M A matrix type */ template Dune::BCRSMatrix setupAnisotropic2d(int N, Dune::ParallelIndexSet& indices, const Dune::Communication& p, int *nout, typename Dune::BCRSMatrix::field_type eps=1.0) { int procs=p.size(), rank=p.rank(); using BCRSMat = Dune::BCRSMatrix; // calculate size of local matrix in the distributed direction int start, end, overlapStart, overlapEnd; int n = N/procs; // number of unknowns per process int bigger = N%procs; // number of process with n+1 unknowns // Compute owner region if(rank0) overlapStart = start - 1; else overlapStart = start; if(end