21 void increment(
const index_t ** ptr){++(*ptr);}
23 template <
class T,
typename matrixT>
24 void getNonZeroInnerOfMatrix ( matrixT
const &mat,
typename gsWeightMapper<T>::IndexContainer
const & outer,
typename gsWeightMapper<T>::IndexContainer & inner)
26 const index_t numSource=outer.size();
27 std::vector<const index_t*> nzIndices(numSource);
28 std::vector<const index_t*> end(numSource);
29 std::vector<const index_t**> nzMin;
30 nzMin.reserve(numSource);
32 inner.reserve(10*numSource);
35 for (
index_t i=0; i<numSource;++i)
37 nzIndices[i]=mat.innerIndexPtr()+mat.outerIndexPtr()[outer[i]];
38 end[i]=mat.innerIndexPtr()+mat.outerIndexPtr()[outer[i]+1];
47 for(
index_t i=0; i<numSource;++i)
49 if(nzIndices[i]<end[i])
51 if (*nzIndices[i]<curMin)
55 nzMin.push_back(&nzIndices[i]);
57 else if (*nzIndices[i]==curMin)
59 nzMin.push_back(&nzIndices[i]);
65 inner.push_back(curMin);
66 std::for_each(nzMin.begin(),nzMin.end(),increment);
73 void gsWeightMapper<T>::mapToTargetCoefs(gsMatrix<weightType>
const & sourceCoefs,gsMatrix<weightType> & targetCoefs)
const
85 GISMO_ASSERT(sourceCoefs.rows()==m_matrix.rows(),
"Wrong coefficient size!");
87 if(!m_optimizationMatrix)
88 optimize(gsWeightMapper<T>::optTargetToSource);
90 typename gsSparseSolver<T>::QR solver;
91 solver.compute(*m_optimizationMatrix);
93 GISMO_ERROR(
"Could not compute the solver SparseQR");
94 targetCoefs=solver.solve(sourceCoefs);
96 GISMO_ERROR(
"Could not solve the QR system for the specific b");
100 void gsWeightMapper<T>::sourceToTarget(indexType source, IndexContainer & target, WeightContainer & weights)
const
105 for(InIterMat it = InIterMat(m_matrix,source);it;++it)
107 target.push_back(it.col());
108 weights.push_back(it.value());
113 void gsWeightMapper<T>::targetToSource(indexType target,IndexContainer & indizes,WeightContainer & weights)
const
118 for(indexType i=0;i<m_matrix.rows();i++)
120 const weightType w = m_matrix.coeff(i,target);
123 indizes.push_back(i);
124 weights.push_back(w);
130 void gsWeightMapper<T>::fastSourceToTarget(IndexContainer
const & source,IndexContainer & target)
const
132 GISMO_ASSERT(m_matrix.isCompressed(),
"optimize() must be called on the mapper with fastSourceToTarget flag before using this function.");
133 getNonZeroInnerOfMatrix<T>(m_matrix,source,target);
137 void gsWeightMapper<T>::fastTargetToSource(
const IndexContainer &target, IndexContainer &source)
const
139 GISMO_ASSERT(m_optimizationMatrix,
"optimize() must be called on the mapper with fastTargetToSource flag before using this function.");
140 getNonZeroInnerOfMatrix<T>(*m_optimizationMatrix,target,source);
145 void gsWeightMapper<T>::getLocalMap (IndexContainer
const & source, IndexContainer
const & target, gsMatrix<T> &map)
const
147 GISMO_ASSERT(m_matrix.isCompressed(),
"optimize() must be called on the mapper with fastSourceToTarget flag before using this function.");
149 const index_t numRow=source.size();
150 const index_t numCol=target.size();
152 map.resize(numRow,numCol);
157 Iterator coef = fastSourceToTarget(source[r]);
159 while (c<numCol && coef)
161 if (target[c]< coef.index())
167 if (target[c]== coef.index())
169 map(r,c)=coef.weight();
183 void gsWeightMapper<T>::getLocalMap (IndexContainer
const & source, gsMatrix<T> &map)
const
185 GISMO_ASSERT(m_matrix.isCompressed(),
"optimize() must be called on the mapper with fastSourceToTarget flag before using this function.");
187 const index_t numRow=source.size();
188 const index_t numCol=getNrOfTargets();
190 map.resize(numRow,numCol);
195 Iterator coef = fastSourceToTarget(source[r]);
197 while (c<numCol && coef)
205 if (c== coef.index())
207 map(r,c)=coef.weight();
#define index_t
Definition: gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Provides declaration of gsWeightMapper class.
#define GISMO_ERROR(message)
Definition: gsDebug.h:118