G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsL2Projection.hpp
Go to the documentation of this file.
1
18#include <gsCore/gsBoundary.h>
19
20namespace gismo {
21
22template<typename T>
23T gsL2Projection<T>::_project( const gsMultiBasis<T> & integrationBasis,
24 const gsFunctionSet<T> & projectionBasis,
25 const gsFunctionSet<T> & geometryMap,
26 const gsFunctionSet<T> & sourceFunction,
27 gsMatrix<T> & coefs,
28 const gsOptionList & options)
29{
30 // Clear the result
31 coefs.clear();
32
33 // Create an assembler
34 gsExprAssembler<T> A(1,1);
35
36 // Set the integration elements
37 A.setIntegrationElements(integrationBasis);
38
39 // Assign the space
40 space u = A.getSpace(projectionBasis,sourceFunction.targetDim());
41
42 // Assign the source function
43 auto f = A.getCoeff(sourceFunction);
44
45 // Assign the geometry map
46 typename gsExprAssembler<T>::geometryMap G = A.getMap(geometryMap);
47
48 // Set up the space
49 u.setup(options.askInt("Continuity",-1));
50
51 // Initialize the system
52 A.initSystem();
53
54 // Assemble the system
55 A.assemble(u*u.tr() * meas(G),u * f * meas(G));
56
57 // Solve the system
58 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<T>::get( options.askString("LinearSolver","SimplicialLDLT") );
59 solver->compute(A.matrix());
60 coefs = solver->solve(A.rhs());
61
62 if (options.askSwitch("ComputeError",true))
63 {
64 // Extract the solution and compute the error
65 solution sol = A.getSolution(u, coefs);
67 return ev.integral((sol-f).sqNorm() * meas(G));
68 }
69 else
70 return -1;
71}
72
73template<typename T>
75 const gsGeometry<T> & geometry,
76 gsMatrix<T> & result)
77{
78 result.clear();
79
80 gsMultiBasis<T> mb(basis);
82 mp.addPatch(geometry);
83
84 gsExprAssembler<T> A(1,1);
86 space u = A.getSpace(mb,mp.targetDim());
87 auto f = A.getCoeff(mp);
88 geometryMap G = A.getMap(mp);
89
90 u.setup(-1);
91 A.initSystem();
92
93 // assemble system
94 A.assemble(u*u.tr() * meas(G),u * f * meas(G));
95
96 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<T>::get( "SimplicialLDLT" );
97 solver->compute(A.matrix());
98 result = solver->solve(A.rhs());
99
100 solution sol = A.getSolution(u, result);
101 gsExprEvaluator<> ev(A);
102 return ev.integral((sol-f).sqNorm() * meas(G));
103}
104
105
106template<typename T>
108 const gsFunctionSet<T> & geometry,
109 gsMultiPatch<T> & result)
110{
111 result.clear();
112
113 gsExprAssembler<T> A(1,1);
114 gsMatrix<T> solVector;
115
116 A.setIntegrationElements(basis);
117 space u = A.getSpace(basis,geometry.targetDim());
118 solution sol = A.getSolution(u, solVector);
119 auto f = A.getCoeff(geometry);
120 geometryMap G = A.getMap(geometry);
121
122 u.setup(0);
123 A.initSystem();
124
125 // assemble system
126 A.assemble(u*u.tr() * meas(G),u * f * meas(G));
127
128 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<real_t>::get( "SimplicialLDLT" );
129 solver->compute(A.matrix());
130 solVector = solver->solve(A.rhs());
131
132 gsExprEvaluator<> ev(A);
133 sol.extract(result);
134 result.computeTopology();
135 result.closeGaps();
136
137 return ev.integral((sol-f).sqNorm() * meas(G));
138}
139
140template<typename T>
142 const gsFunctionSet<T> & geometry,
143 gsMatrix<T> & result)
144{
145 gsExprAssembler<T> A(1,1);
146 A.setIntegrationElements(basis);
147 space u = A.getSpace(basis,geometry.targetDim());
148 auto f = A.getCoeff(geometry);
149 geometryMap G = A.getMap(geometry);
150
151 u.setup(-1);
152 A.initSystem();
153
154 // assemble system
155 A.assemble(u*u.tr() * meas(G),u * f * meas(G));
156
157 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<T>::get( "SimplicialLDLT" );
158 solver->compute(A.matrix());
159 result = solver->solve(A.rhs());
160
161 solution sol = A.getSolution(u, result);
162 gsExprEvaluator<> ev(A);
163 return ev.integral((sol-f).sqNorm() * meas(G));
164}
165
166template<typename T>
168 const gsMappedBasis<2,T> & basis,
169 const gsFunctionSet<T> & geometry,
170 gsMatrix<T> & result)
171{
172 gsExprAssembler<T> A(1,1);
173
174 A.setIntegrationElements(intbasis);
175 space u = A.getSpace(basis,geometry.targetDim());
176 auto f = A.getCoeff(geometry);
177 geometryMap G = A.getMap(geometry);
178
179 u.setup(-1);
180 A.initSystem();
181
182 // assemble system
183 A.assemble(u*u.tr()*meas(G),u * f*meas(G));
184
185 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<real_t>::get( "SimplicialLDLT" );
186 solver->compute(A.matrix());
187 result = solver->solve(A.rhs());
188
189 solution sol = A.getSolution(u, result);
190 gsExprEvaluator<> ev(A);
191 return ev.integral((sol-f).sqNorm() * meas(G));
192}
193
194template<typename T>
196 const gsFunctionSet<T> & source,
197 const gsMultiPatch<T> & geometry,
198 gsMultiPatch<T> & result)
199{
200 result.clear();
201
202 gsExprAssembler<T> A(1,1);
203 gsMatrix<T> solVector;
204
205 A.setIntegrationElements(basis);
206 space u = A.getSpace(basis,source.targetDim());
207 auto f = A.getCoeff(source);
208 solution sol = A.getSolution(u, solVector);
209 geometryMap G = A.getMap(geometry);
210
211 u.setup(-1);
212 A.initSystem();
213
214 // assemble system
215 A.assemble(u*u.tr() * meas(G),u * f * meas(G));
216
217 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<real_t>::get( "SimplicialLDLT" );
218 solver->compute(A.matrix());
219 solVector = solver->solve(A.rhs());
220
221 sol.extract(result);
222 result.computeTopology();
223 result.closeGaps();
224 gsExprEvaluator<> ev(A);
225 return ev.integral((sol-f).sqNorm() * meas(G));
226}
227
228template<typename T>
230 const gsFunctionSet<T> & source,
231 const gsMultiPatch<T> & geometry,
232 gsMatrix<T> & result)
233{
234 gsExprAssembler<T> A(1,1);
235
236 A.setIntegrationElements(basis);
237 space u = A.getSpace(basis,source.targetDim());
238 auto f = A.getCoeff(source);
239 solution sol = A.getSolution(u, result);
240 geometryMap G = A.getMap(geometry);
241
242 u.setup(-1);
243 A.initSystem();
244
245 // assemble system
246 A.assemble(u*u.tr() * meas(G),u * f * meas(G));
247
248 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<real_t>::get( "SimplicialLDLT" );
249 solver->compute(A.matrix());
250 result = solver->solve(A.rhs());
251 gsExprEvaluator<> ev(A);
252 return ev.integral((sol-f).sqNorm() * meas(G));
253}
254
255
256template<typename T>
258 const gsMappedBasis<2,T>& basis,
259 const gsFunctionSet<T> & source,
260 const gsMultiPatch<T> & geometry,
261 gsMatrix<T> & result)
262{
263 gsExprAssembler<T> A(1,1);
264
265 A.setIntegrationElements(intbasis);
266 space u = A.getSpace(basis,source.targetDim());
267 auto f = A.getCoeff(source);
268 geometryMap G = A.getMap(geometry);
269
270 u.setup(-1);
271 A.initSystem();
272
273 // assemble system
274 A.assemble(u*u.tr()*meas(G),u * f *meas(G));
275
276 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<real_t>::get( "SimplicialLDLT" );
277 solver->compute(A.matrix());
278 result = solver->solve(A.rhs());
279
280 solution sol = A.getSolution(u, result);
281 gsExprEvaluator<> ev(A);
282 return ev.integral((sol-f).sqNorm() * meas(G));
283}
284
285template<typename T>
287 const gsMultiPatch<T> & geometry,
288 gsMultiPatch<T> & result)
289{
290 result.clear();
291
292 gsExprAssembler<T> A(1,1);
293 gsMatrix<T> solVector;
294
295 A.setIntegrationElements(basis);
296 space u = A.getSpace(basis,geometry.geoDim());
297 solution sol = A.getSolution(u, solVector);
298 geometryMap G = A.getMap(geometry);
299
300 std::vector<gsMultiPatch<T>> coords(geometry.geoDim());
301 for (index_t p=0; p!=geometry.geoDim(); p++)
302 coords[p] = geometry.coord(p);
303
305 bc.setGeoMap(geometry);
306 for (index_t p=0; p!=geometry.geoDim(); p++)
307 for (typename gsMultiPatch<T>::const_biterator bit = geometry.bBegin(); bit != geometry.bEnd(); ++bit)
308 bc.addCondition(*bit, condition_type::dirichlet,static_cast<gsFunctionSet<T>*>(&coords[p]), 0, true, p);
309
310 u.setup(bc, dirichlet::l2Projection, 0);
311
312 A.initSystem();
313
314 // assemble system
315 A.assemble(u*u.tr()*meas(G),u * G*meas(G));
316
317 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<real_t>::get( "SimplicialLDLT" );
318 solver->compute(A.matrix());
319 solVector = solver->solve(A.rhs());
320
321 sol.extract(result);
322 result.computeTopology();
323 result.closeGaps();
324 gsExprEvaluator<> ev(A);
325 return ev.integral((sol-G).sqNorm() * meas(G));
326}
327
328
329template<typename T>
331 const gsMultiPatch<T> & geometry,
332 gsMultiPatch<T> & result,
333 T penalty)
334{
335 result.clear();
336
337 gsExprAssembler<T> A(1,1);
338 gsMatrix<T> solVector;
339
340 A.setIntegrationElements(basis);
341 space u = A.getSpace(basis,geometry.geoDim());
342 solution sol = A.getSolution(u, solVector);
343 geometryMap G = A.getMap(geometry);
344 auto Gvar = A.getCoeff(geometry,G);
345 element el = A.getElement();
346
347 std::vector<gsMultiPatch<T>> coords(geometry.geoDim());
348 for (index_t p=0; p!=geometry.geoDim(); p++)
349 coords[p] = geometry.coord(p);
350
352 bc.setGeoMap(geometry);
353 for (index_t p=0; p!=geometry.geoDim(); p++)
354 for (typename gsMultiPatch<T>::const_biterator bit = geometry.bBegin(); bit != geometry.bEnd(); ++bit)
355 bc.addCondition(*bit, condition_type::dirichlet,static_cast<gsFunctionSet<T>*>(&coords[p]), 0, true, p);
356
357
358 u.setup(bc, dirichlet::l2Projection, -1);
359
360
361 std::vector<boundaryInterface> iFace;
362 for (typename gsMultiPatch<T>::const_iiterator iit = geometry.iBegin(); iit != geometry.iEnd(); ++iit)
363 iFace.push_back(*iit);
364
365 A.initSystem();
366
367 // assemble system
368 A.assemble(u*u.tr()*meas(G),u * Gvar*meas(G));
369 A.assembleBdr(
370 bc.get("Weak Dirichlet"),
371 -(penalty / el.area(G) * u * u.tr()) * tv(G).norm()
372 );
373
374 A.assembleIfc(iFace,
375 penalty / el.area(G) * u.left() * u.left().tr() * tv(G).norm()
376 ,
377 - penalty / el.area(G) * u.right()* u.left() .tr() * tv(G).norm()
378 ,
379 - penalty / el.area(G) * u.left() * u.right().tr() * tv(G).norm()
380 ,
381 penalty / el.area(G) * u.right()* u.right().tr() * tv(G).norm()
382 );
383
384 typename gsSparseSolver<T>::uPtr solver = gsSparseSolver<real_t>::get( "SimplicialLDLT" );
385 solver->compute(A.matrix());
386 solVector = solver->solve(A.rhs());
387
388 sol.extract(result);
389 result.computeTopology();
390 result.closeGaps();
391 gsExprEvaluator<> ev(A);
392 return ev.integral((Gvar-G).sqNorm() * meas(G));
393}
394
395
396
397} // gismo
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
Class containing a set of boundary conditions.
Definition gsBoundaryConditions.h:342
void addCondition(int p, boxSide s, condition_type::type t, gsFunctionSet< T > *f, short_t unknown=0, bool parametric=false, int comp=-1)
Adds another boundary condition.
Definition gsBoundaryConditions.h:650
bcRefList get(const std::string &label, const short_t unk=0, int comp=-1) const
Definition gsBoundaryConditions.h:420
void setGeoMap(const gsFunctionSet< T > &gm)
Set the geometry map to evaluate boundary conditions.
Definition gsBoundaryConditions.h:916
const_iiterator iEnd() const
Definition gsBoxTopology.h:124
const_biterator bBegin() const
Definition gsBoxTopology.h:139
const_biterator bEnd() const
Definition gsBoxTopology.h:144
const_iiterator iBegin() const
Definition gsBoxTopology.h:119
Definition gsExprAssembler.h:33
void setIntegrationElements(const gsMultiBasis< T > &mesh)
Sets the domain of integration.
Definition gsExprAssembler.h:161
void assembleBdr(const bcRefList &BCs, expr &... args)
Adds the expressions args to the system matrix/rhs The arguments are considered as integrals over the...
Definition gsExprAssembler.h:1167
gsExprHelper< T >::geometryMap geometryMap
Geometry map type.
Definition gsExprAssembler.h:65
space getSpace(const gsFunctionSet< T > &mp, index_t dim=1, index_t id=0)
Definition gsExprAssembler.h:191
const gsMatrix< T > & rhs() const
Returns the right-hand side vector(s)
Definition gsExprAssembler.h:154
solution getSolution(const expr::gsFeSpace< T > &s, gsMatrix< T > &cf) const
Registers a representation of a solution variable from space s, based on the vector cf.
Definition gsExprAssembler.h:299
geometryMap getMap(const gsFunctionSet< T > &g)
Registers g as an isogeometric geometry map and return a handle to it.
Definition gsExprAssembler.h:186
void initSystem(const index_t numRhs=1)
Initializes the sparse system (sparse matrix and rhs)
Definition gsExprAssembler.h:315
variable getCoeff(const gsFunctionSet< T > &func)
Definition gsExprAssembler.h:285
void assemble(const expr &... args)
Adds the expressions args to the system matrix/rhs The arguments are considered as integrals over the...
Definition gsExprAssembler.h:1077
const gsSparseMatrix< T > & matrix() const
Returns the left-hand global matrix.
Definition gsExprAssembler.h:127
Generic evaluator of isogeometric expressions.
Definition gsExprEvaluator.h:39
T integral(const expr::_expr< E > &expr)
Calculates the integral of the expression expr on the whole integration domain.
Definition gsExprEvaluator.h:154
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition gsFunctionSet.h:219
virtual short_t targetDim() const
Dimension of the target space.
Definition gsFunctionSet.h:595
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Holds a set of patch-wise bases and their topology information.
Definition gsMultiBasis.h:37
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
bool computeTopology(T tol=1e-4, bool cornersOnly=false, bool tjunctions=false)
Attempt to compute interfaces and boundaries automatically.
Definition gsMultiPatch.hpp:377
short_t geoDim() const
Dimension of the geometry (must match for all patches).
Definition gsMultiPatch.hpp:150
void clear()
Clear (delete) all patches.
Definition gsMultiPatch.h:388
void closeGaps(T tol=1e-4)
Attempt to close gaps between the interfaces. Assumes that the topology is computed,...
Definition gsMultiPatch.hpp:577
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
bool askSwitch(const std::string &label, const bool &value=false) const
Reads value for option label from options.
Definition gsOptionList.cpp:128
index_t askInt(const std::string &label, const index_t &value=0) const
Reads value for option label from options.
Definition gsOptionList.cpp:117
std::string askString(const std::string &label, const std::string &value="") const
Reads value for option label from options.
Definition gsOptionList.cpp:106
Abstract class for solvers. The solver interface is base on 3 methods: -compute set the system matrix...
Definition gsSparseSolver.h:67
Provides gsBoundaryConditions class.
Provides structs and classes related to interfaces and boundaries.
#define index_t
Definition gsConfig.h:32
Generic expressions matrix assembly.
Generic expressions evaluator.
abstract interfaces for solvers and wrapper around Eigen solvers
The G+Smo namespace, containing all definitions for the library.
@ dirichlet
Dirichlet type.
Definition gsBoundaryConditions.h:31
static GISMO_DEPRECATED T projectFunction(const gsMultiBasis< T > &basis, const gsFunctionSet< T > &source, const gsMultiPatch< T > &geometry, gsMatrix< T > &result)
Projects a function on a basis.
Definition gsL2Projection.hpp:229
static T _project(const gsMultiBasis< T > &integrationBasis, const gsFunctionSet< T > &projectionBasis, const gsFunctionSet< T > &geometryMap, const gsFunctionSet< T > &sourceFunction, gsMatrix< T > &coefs, const gsOptionList &options)
Projects a source function onto a projection basis using a geometry map.
Definition gsL2Projection.hpp:23
static GISMO_DEPRECATED T projectGeometry(const gsBasis< T > &basis, const gsGeometry< T > &geometry, gsMatrix< T > &result)
Projects a source geometry onto basis and returns it in result.
Definition gsL2Projection.hpp:74
static GISMO_DEPRECATED T projectGeometryBoundaries(const gsMultiBasis< T > &basis, const gsMultiPatch< T > &geometry, gsMultiPatch< T > &result)
Projects a source geometry onto basis and returns it in result. Fixes the boundaries.
Definition gsL2Projection.hpp:286
static GISMO_DEPRECATED T projectGeometryPenalty(const gsMultiBasis< T > &basis, const gsMultiPatch< T > &geometry, gsMultiPatch< T > &result, T penalty=1e3)
Projects a source geometry onto basis and returns it in result. Penalizes interfaces and boundaries.
Definition gsL2Projection.hpp:330