27 void gsDirichletValues(
32 if ( bc.
container(
"Dirichlet").empty() && bc.cornerValues().empty())
return;
40 case dirichlet::homogeneous :
41 case dirichlet::user :
44 case dirichlet::interpolation:
45 gsDirichletValuesByTPInterpolation(u,bc);
47 case dirichlet::l2Projection:
48 gsDirichletValuesByL2Projection(u,bc);
51 GISMO_ERROR(
"Something went wrong with Dirichlet values: "<< dir_values);
55 for (
typename gsBoundaryConditions<T>::const_citerator it = bc.
cornerBegin(); it != bc.
cornerEnd(); ++it )
57 if(it->unknown != u.id())
60 const int k = it->patch;
62 const int i = basis.functionAtCorner(it->corner);
63 const index_t com = it->component;
65 for (
index_t r = 0; r!=u.dim(); ++r)
67 if (com!=-1 && r!=com)
continue;
68 const int ii = mapper.
bindex( i , k, r );
69 fixedDofs.
at(ii) = it->value;
75 void gsDirichletValuesByTPInterpolation(
const expr::gsFeSpace<T> & u,
76 const gsBoundaryConditions<T> & bc)
78 const index_t parDim = u.source().domainDim();
80 std::vector< gsVector<T> > rr;
81 gsMatrix<index_t> boundary;
83 gsMatrix<T> fpts, tmp;
85 gsMatrix<T> & fixedDofs =
const_cast<expr::gsFeSpace<T>&
>(u).fixedPart();
86 fixedDofs.setZero(u.mapper().boundarySize(), 1 );
89 typedef gsBoundaryConditions<T> bcList;
90 for (
typename bcList::const_iterator it = bc.begin(
"Dirichlet");
91 it != bc.end(
"Dirichlet") ; ++it )
93 if( it->unknown()!=u.id() )
continue;
95 const index_t com = it->unkComponent();
97 const int k = it->patch();
101 boundary = basis.boundary(it->side());
104 const int dir = it->side().direction( );
105 const index_t param = (it->side().parameter() ? 1 : 0);
108 typename gsBasis<T>::uPtr h = basis.boundaryBasis(it->side());
111 for (
index_t r = 0; r!=u.dim(); ++r)
113 if (com!=-1 && r!=com)
continue;
116 if ( it->isHomogeneous() )
118 for (
index_t i=0; i!= boundary.size(); ++i)
120 const int ii = u.mapper().bindex( boundary.at(i) , k, r );
121 fixedDofs.at(ii) = 0;
128 rr.reserve( parDim );
130 for (
int i=0; i < parDim; ++i)
134 b[0] = ( basis.component(i).support() ) (0, param);
139 rr.push_back( basis.component(i).anchors().transpose() );
148 if ( it->parametric() )
149 fpts = it->function()->piece(it->patch()).eval( gsPointGrid<T>( rr ) );
152 const gsFunctionSet<T> & gmap = bc.geoMap();
153 fpts = it->function()->piece(it->patch()).eval( gmap.piece(it->patch()).eval( gsPointGrid<T>( rr ) ) );
157 typename gsGeometry<T>::uPtr geo = h->interpolateAtAnchors(fpts);
158 const gsMatrix<T> & dVals = geo->coefs();
161 for (
index_t l=0; l!= boundary.size(); ++l)
163 const int ii = u.mapper().bindex( boundary.at(l) , k, r );
164 fixedDofs.at(ii) = dVals.at(l);
171 template<
class T>
void
172 gsDirichletValuesInterpolationTP(
const expr::gsFeSpace<T> & u,
173 const boundary_condition<T> & bc,
174 gsMatrix<index_t> & boundary,
175 gsMatrix<T> & values)
177 const index_t parDim = u.source().domainDim();
179 const gsFunctionSet<T> & gmap = bc.geoMap();
180 std::vector< gsVector<T> > rr;
183 gsMatrix<T> fpts, tmp;
185 gsMatrix<T> & fixedDofs =
const_cast<expr::gsFeSpace<T>&
>(u).fixedPart();
187 if( bc.unknown()!=u.id() ) { boundary.clear(); values.clear();
return; }
189 const int k = bc.patch();
190 const gsBasis<T> & basis = u.source().basis(k);
193 boundary = basis.boundary(bc.side());
196 if ( bc.isHomogeneous() )
198 const index_t com = bc.unkComponent();
199 values.setZero(boundary.size(), (-1==com ? u.dim():1) );
204 int dir = bc.side().direction( );
205 index_t param = (bc.side().parameter() ? 1 : 0);
209 rr.reserve( parDim );
211 for (
int i=0; i < parDim; ++i)
215 b[0] = ( basis.component(i).support() ) (0, param);
220 rr.push_back( basis.component(i).anchors().transpose() );
229 if ( bc.parametric() )
230 fpts = bc.function()->eval( gsPointGrid<T>( rr ) );
233 const gsFunctionSet<T> & gmap = bc.geoMap();
234 fpts = bc.function()->eval( gmap.piece(bc.patch()).eval( gsPointGrid<T>( rr ) ) );
250 typename gsBasis<T>::uPtr h = basis.boundaryBasis(bc.side());
251 typename gsGeometry<T>::uPtr geo = h->interpolateAtAnchors(fpts);
252 values =
give( geo->coefs() );
257 void gsDirichletValuesByL2Projection(
const expr::gsFeSpace<T> & u,
258 const gsBoundaryConditions<T> & bc)
260 const gsFunctionSet<T> & gmap = bc.geoMap();
262 const gsDofMapper & mapper = u.mapper();
263 gsMatrix<T> & fixedDofs =
const_cast<expr::gsFeSpace<T>&
>(u).fixedPart();
267 gsSparseEntries<T> projMatEntries;
268 gsMatrix<T> globProjRhs;
269 globProjRhs.setZero(u.mapper().boundarySize(), 1 );
272 gsVector<T> quWeights;
273 gsMatrix<T> basisVals, rhsVals;
274 gsMatrix<index_t> globIdxAct, globBasisAct;
280 std::vector<index_t> eltBdryFcts;
285 typedef gsBoundaryConditions<T> bcList;
286 for (
typename bcList::const_iterator iter = bc.begin(
"Dirichlet");
287 iter != bc.end(
"Dirichlet"); ++iter)
289 const int unk = iter->unknown();
290 if(unk != u.id())
continue;
292 const index_t com = iter->unkComponent();
293 const int patchIdx = iter->patch();
294 const gsBasis<T> & basis = u.source().basis(patchIdx);
295 const gsFunction<T> & patch = gmap.function(patchIdx);
300 gsGaussRule<T> bdQuRule(basis, 1.0, 1, iter->side().direction());
303 typename gsBasis<T>::domainIter bdryIter = basis.makeDomainIterator(iter->side());
306 for (; bdryIter->good(); bdryIter->next())
308 bdQuRule.mapTo(bdryIter->lowerCorner(), bdryIter->upperCorner(),
309 md.points, quWeights);
311 patch.computeMap(md);
330 basis.active_into(md.points.col(0), globBasisAct);
334 basis.eval_into(md.points, basisVals);
336 for (
index_t r = 0; r!=u.dim(); ++r)
338 if (com!=-1 && r!=com)
continue;
340 mapper.localToGlobal(globBasisAct, patchIdx, globIdxAct,r);
349 eltBdryFcts.reserve(mapper.boundarySize());
350 for (
index_t i = 0; i < globIdxAct.rows(); i++)
352 if (mapper.is_boundary_index(globIdxAct.at(i)))
354 eltBdryFcts.push_back(i);
365 if ((com != -1) || (r == 0))
368 if (iter->isHomogeneous())
370 rhsVals.setZero((com==-1) ? u.dim() : 1, md.points.size());
374 if (iter->parametric())
376 iter->function()->piece(patchIdx).eval(md.points);
378 rhsVals = iter->function()->piece(patchIdx).eval(
379 gmap.piece(patchIdx).eval(md.points));
384 "If no component is specified for Dirichlet boundary, "
385 "target dimension must match field dimension.");
387 "If the component is specified for Dirichlet boundary, "
388 "then a scalar function is expected.");
391 for (
index_t k = 0; k < md.points.cols(); k++)
393 const T weight_k = quWeights[k] * md.measure(k);
396 for (
size_t i0 = 0; i0 < eltBdryFcts.size(); i0++)
400 const index_t i = eltBdryFcts[i0];
402 const index_t ii = mapper.global_to_bindex(globIdxAct.at(i));
404 for (
size_t j0 = 0; j0 < eltBdryFcts.size(); j0++)
406 const index_t j = eltBdryFcts[j0];
407 const index_t jj = mapper.global_to_bindex(globIdxAct.at(j));
413 projMatEntries.add(ii, jj, weight_k * basisVals(i, k) * basisVals(j, k));
416 globProjRhs.at(ii) += weight_k * basisVals(i, k) * rhsVals( (-1==com?r:0) ,k);
425 gsSparseMatrix<T> globProjMat(mapper.boundarySize(), mapper.boundarySize());
426 globProjMat.setFrom(projMatEntries);
427 globProjMat.makeCompressed();
433 typename gsSparseSolver<T>::CGDiagonal solver;
434 fixedDofs = solver.compute(globProjMat).solve(globProjRhs);
const_citerator cornerBegin() const
Definition: gsBoundaryConditions.h:561
index_t boundarySize() const
Returns the number of eliminated dofs.
Definition: gsDofMapper.h:457
S give(S &x)
Definition: gsMemory.h:266
#define index_t
Definition: gsConfig.h:32
Provides assembler and solver options.
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Maintains a mapping from patch-local dofs to global dof indices and allows the elimination of individ...
Definition: gsDofMapper.h:68
Provides the gsDofMapper class for re-indexing DoFs.
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition: gsMatrix.h:211
const gsBasis< T > & basis(const index_t k) const
Helper which casts and returns the k-th piece of this function set as a gsBasis.
Definition: gsFunctionSet.hpp:33
Definition: gsDirichletValues.h:23
const bcContainer & container(const std::string &label) const
Return a reference to boundary conditions of certain type.
Definition: gsBoundaryConditions.h:416
virtual const gsBasis & source() const
Definition: gsBasis.h:704
const_citerator cornerEnd() const
Definition: gsBoundaryConditions.h:566
The density of the measure pull back.
Definition: gsForwardDeclarations.h:76
index_t bindex(index_t i, index_t k=0, index_t c=0) const
Returns the boundary index of local dof i of patch k.
Definition: gsDofMapper.h:334
Enable optimizations based on the assumption that all evaluation points are in the same bezier domain...
Definition: gsForwardDeclarations.h:89
Class containing a set of boundary conditions.
Definition: gsBoundaryConditions.h:341
Provides functions to generate structured point data.
Provides gsBoundaryConditions class.
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78