Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
SplineSegmentBase.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8
9#ifndef model_SplineSegmentBase_H_
10#define model_SplineSegmentBase_H_
11
12#include <math.h>
13#include <Eigen/Dense>
14
15
16namespace model
17{
18
19 /************************************************************************/
20 /* SplineSegmentBase, general case **************************************/
21 /************************************************************************/
22 template <short unsigned int dim, short unsigned int corder>
24
25
26 /************************************************************************/
27 /* SplineSegmentBase, template specialization corder=0 ******************/
28 /************************************************************************/
29 template <short unsigned int dim>
30 struct SplineSegmentBase<dim,0>
31 {
32
33
34 static constexpr int corder = 0;
35 static constexpr int Ncoeff= 2*(corder+1);
36 typedef Eigen::Matrix<double,Ncoeff,1> VectorNcoeff;
37 typedef Eigen::Matrix<double, 1, Ncoeff> RowNcoeff;
38 typedef Eigen::Matrix<double, 1, Ncoeff-1> RowNcoeffu;
39 typedef Eigen::Matrix<double, 1, Ncoeff-2> RowNcoeffuu;
40 typedef Eigen::Matrix<double, Ncoeff, Ncoeff> MatrixNcoeff;
41 typedef Eigen::Matrix<double, Ncoeff, dim> MatrixNcoeffDim;
42 typedef Eigen::Matrix<double,dim,1> VectorDim;
43 typedef Eigen::Matrix<double,dim,dim> MatrixDim;
44
45 typedef std::map<size_t,
46 /* */ std::pair<VectorNcoeff,VectorDim>,
47 /* */ std::less<size_t>
48 /* */ > H2PmapType;
49
50 /**********************************************************************/
51 static RowNcoeff powers(const double& uin)
52 {
53 return (RowNcoeff()<<1.0, uin).finished();
54 }
55
56 /**********************************************************************/
57 static RowNcoeffu powersDiff1(const double& )
58 {
59 return (RowNcoeffu()<<1.0).finished();
60 }
61
62 /**********************************************************************/
63 static RowNcoeffuu powersDiff2(const double& )
64 {
65 return RowNcoeffuu::Zero();
66 }
67
68 /**********************************************************************/
69 static MatrixNcoeff sfCoeffs(const double&)
70 {
73 /* P0 P1 */
74 return (MatrixNcoeff()<< 1.0, 0.0, // u^0
75 /* */ -1.0, 1.0).finished(); // u^1;
76 }
77
78 /**********************************************************************/
79 static RowNcoeff sf(const double& uin,const double& g)
80 {/*\param[in] uin parameter value in [0,1]
81 *\returns The row vector of shape function at uin
82 */
83 return powers(uin)*sfCoeffs(g);
84 }
85
86 /******************************************************************************/
87 static RowNcoeff sfDiff1(const double& uin,const double& g)
88 {
89 return powersDiff1(uin)*sfCoeffs(g).template block<Ncoeff-1,Ncoeff>(1,0);
90 }
91
92 /******************************************************************************/
93 static RowNcoeff sfDiff2(const double& uin,const double& g)
94 {
95 return powersDiff2(uin)*sfCoeffs(g).template block<Ncoeff-2,Ncoeff>(2,0);
96 }
97
98
99 /**********************************************************************/
100 template<typename LinkType>
101 static MatrixNcoeffDim hermiteDofs(const LinkType& link)
102 {
105 return (MatrixNcoeffDim()<< link.sourceP.transpose(),
106 /* */ link. sinkP.transpose()).finished();
107 }
108
109 /**********************************************************************/
110 template<typename LinkType>
111 static VectorDim sourceT(const LinkType&)
112 {
113 return VectorDim::Zero();
114 }
115
116 /**********************************************************************/
117 template<typename LinkType>
118 static VectorDim sinkT(const LinkType&)
119 {
120 return VectorDim::Zero();
121 }
122
123// /**********************************************************************/
124// template<typename LinkType>
125// static H2PmapType hermite2posMap(const LinkType& link) // move to CatmullRom?
126// {
127//
128// // std::cout<<link.source->sID<<"->"<<link.sink->sID<<std::endl;
129//
130// // std::map<size_t,VectorDim> posMap;
131// // std::map<size_t,std::pair<double,double>> temp;
132//
133// H2PmapType temp;
134// temp.emplace(link.source->snID(),std::make_pair((VectorNcoeff()<<1.0,0.0).finished(),link.sourceP));
135// temp.emplace(link. sink->snID(),std::make_pair((VectorNcoeff()<<0.0,1.0).finished(),link. sinkP));
136//
137//
138//
139// return temp;
140// }
141
142 /**********************************************************************/
143 template<typename LinkType>
144 static Eigen::Matrix<double,dim,Ncoeff> hermiteCoefficients(const LinkType& link)
145 {
146 Eigen::Matrix<double,dim,Ncoeff> HrCf;
147 HrCf.col(0)= link.source->get_P();
148 HrCf.col(1)= link.sink->get_P();
149 return HrCf;
150 }
151
152 // MatrixNcoeffDim get_qH() const {
153 // return (MatrixNcoeffDim()<< link.source->get_P().transpose(),
154 // /* */ link. sink->get_P().transpose()).finished();
155 // }
156
157
158
159 // //////////////////////////////////////////////////////////////
160 // //BezierCoefficients: Bezier coefficients (uniform parametrization)
161 // Eigen::Matrix<double,dim+1,Ncoeff> BezierCoefficients() const {
162 // Eigen::Matrix<double,dim+1,Ncoeff> BzCf;
163 // double w =1.0;
164 // BzCf.col(0)<< link.source->get_P(), w;
165 // BzCf.col(2)<< link.sink ->get_P(), w;
166 // return BzCf;
167 // }
168
169
170 };
171
172
173
174 /**************************************************************************/
175 /* SplineSegmentBase, template specialization corder=1 ******************/
176 /**************************************************************************/
177 template <short unsigned int dim>
178 struct SplineSegmentBase<dim,1>
179 {
180
181 static constexpr int corder = 1;
182 static constexpr int Ncoeff= 2*(corder+1);
183 typedef Eigen::Matrix<double, 1, Ncoeff> RowNcoeff;
184 typedef Eigen::Matrix<double, 1, Ncoeff-1> RowNcoeffu;
185 typedef Eigen::Matrix<double, 1, Ncoeff-2> RowNcoeffuu;
186 typedef Eigen::Matrix<double, Ncoeff, Ncoeff> MatrixNcoeff;
187 typedef Eigen::Matrix<double, Ncoeff, dim> MatrixNcoeffDim;
188 typedef Eigen::Matrix<double,Ncoeff,1> VectorNcoeff;
189 typedef Eigen::Matrix<double,dim,1> VectorDim;
190 typedef Eigen::Matrix<double,dim,dim> MatrixDim;
191
192 typedef std::map<size_t,
193 /* */ std::pair<VectorNcoeff,VectorDim>,
194 /* */ std::less<size_t>> H2PmapType;
195
196 /**********************************************************************/
197 static RowNcoeff powers(const double & uin)
198 {
199 return (RowNcoeff()<<1.0, uin, std::pow(uin,2), std::pow(uin,3)).finished();
200 }
201
202 static RowNcoeffu powersDiff1(const double & uin)
203 {
204 return (RowNcoeffu()<<1.0, 2.0*uin, 3.0*std::pow(uin,2)).finished();
205 }
206
207 static RowNcoeffuu powersDiff2(const double & uin)
208 {
209 return (RowNcoeffuu()<<2.0, 6.0*uin).finished();
210 }
211
212 /**********************************************************************/
213 static MatrixNcoeff sfCoeffs(const double& g)
214 {
217 /* P0 T0 P1 T1 */
218 return (MatrixNcoeff()<< 1.0, 0.0, 0.0, 0.0, // u^0
219 /* */ 0.0, g, 0.0, 0.0, // u^1
220 /* */ -3.0, -2.0*g, 3.0, -g, // u^2
221 /* */ 2.0, g, -2.0, g).finished(); // u^3;
222 }
223
224 /******************************************************************************/
225 static RowNcoeff sf(const double& uin,const double& g)
226 {
227 return powers(uin)*sfCoeffs(g);
228 }
229
230 /******************************************************************************/
231 static RowNcoeff sfDiff1(const double& uin,const double& g)
232 {
233 return powersDiff1(uin)*sfCoeffs(g).template block<Ncoeff-1,Ncoeff>(1,0);
234 }
235
236 /******************************************************************************/
237 static RowNcoeff sfDiff2(const double& uin,const double& g)
238 {
239 return powersDiff2(uin)*sfCoeffs(g).template block<Ncoeff-2,Ncoeff>(2,0);
240 }
241
242 /**********************************************************************/
243 template<typename LinkType>
244 static MatrixNcoeffDim hermiteDofs(const LinkType& link)
245 {
251 return (MatrixNcoeffDim()<< link.source->get_P().transpose(),
252 /* */ sourceT(link).transpose(),
253 /* */ link. sink->get_P().transpose(),
254 /* */ sinkT(link).transpose()).finished();
255 }
256
257
258
259 /**********************************************************************/
260 template<typename LinkType>
261 static VectorDim sourceT(const LinkType& link)
262 {
263 VectorDim temp=VectorDim::Zero();
264 for(const auto& loopLink : link.loopLinks())
265 {
266 if(link.source->sID==loopLink->source()->sID && link.sink->sID==loopLink->sink()->sID)
267 {
268 temp+=link.source->tangents().at(loopLink->loop()->sID);
269 }
270 else if(link.source->sID==loopLink->sink()->sID && link.sink->sID==loopLink->source()->sID)
271 {
272 temp-=link.source->tangents().at(loopLink->loop()->sID);
273 }
274 else
275 {
276 assert(0);
277 }
278 }
279
280 return link.loopLinks().size()==0? temp : temp/link.loopLinks().size();
281 }
282
283 /**********************************************************************/
284 template<typename LinkType>
285 static VectorDim sinkT(const LinkType& link)
286 {
287 VectorDim temp=VectorDim::Zero();
288 for(const auto& loopLink : link.loopLinks())
289 {
290 if(link.source->sID==loopLink->source()->sID && link.sink->sID==loopLink->sink()->sID)
291 {
292 temp+=link.sink->tangents().at(loopLink->loop()->sID);
293 }
294 else if(link.source->sID==loopLink->sink()->sID && link.sink->sID==loopLink->source()->sID)
295 {
296 temp-=link.sink->tangents().at(loopLink->loop()->sID);
297 }
298 else
299 {
300 assert(0);
301 }
302 }
303
304 return link.loopLinks().size()==0? temp : temp/link.loopLinks().size();
305 }
306
307
308
309
310 /**********************************************************************/
311 template<typename LinkType>
312 static std::pair<Eigen::Matrix<double,Ncoeff,Eigen::Dynamic>,Eigen::Matrix<double,Eigen::Dynamic,dim>> hermite2posMatrix(const LinkType& link)
313 {
315
316 Eigen::Matrix<double,Ncoeff,Eigen::Dynamic> m(Ncoeff,temp.size());
317 Eigen::Matrix<double,Eigen::Dynamic,dim> n(temp.size(),dim);
318
319 size_t k=0;
320 for (const auto& ele : temp)
321 {
322 m.col(k)=ele.second.first;
323 n.row(k)=ele.second.second.transpose();
324 k++;
325 }
326
327 return std::make_pair(m,n);
328 }
329
330 /**********************************************************************/
331 template<typename LinkType>
332 static H2PmapType hermite2posMap(const LinkType& link) // move to CatmullRom?
333 {
334
335 // std::cout<<link.source->sID<<"->"<<link.sink->sID<<std::endl;
336
337 // std::map<size_t,VectorDim> posMap;
338 // std::map<size_t,std::pair<double,double>> temp;
339
341
342 const std::map<size_t,std::map<size_t,std::pair<double,VectorDim>>> sourceMapMap=link.source->loopTangentCoeffs();
343 const std::map<size_t,std::map<size_t,std::pair<double,VectorDim>>> sinkMapMap=link. sink->loopTangentCoeffs();
344
345
346 for(const auto& loopLink : link.loopLinks())
347 {
348
349 temp.emplace(link.source->snID(),std::make_pair((VectorNcoeff()<<1.0,0.0,0.0,0.0).finished(),link.source->get_P()));
350 temp.emplace(link. sink->snID(),std::make_pair((VectorNcoeff()<<0.0,0.0,1.0,0.0).finished(),link. sink->get_P()));
351
352 const auto& sourceMap=sourceMapMap.at(loopLink->loop()->sID);
353 const auto& sinkMap= sinkMapMap.at(loopLink->loop()->sID);
354
355 for(const auto& pair : sourceMap)
356 {
357 // initialize if not existent
358 const auto mapIter=temp.find(pair.first);
359 if(mapIter==temp.end())
360 {
361 temp.emplace(pair.first,std::make_pair(VectorNcoeff::Zero(),pair.second.second));
362 }
363
364 if(link.source->sID==loopLink->source()->sID && link.sink->sID==loopLink->sink()->sID)
365 {
366 temp[pair.first].first(1)+=pair.second.first/link.loopLinks().size();
367 }
368 else if(link.source->sID==loopLink->sink()->sID && link.sink->sID==loopLink->source()->sID)
369 {
370 temp[pair.first].first(1)-=pair.second.first/link.loopLinks().size();
371 }
372 else
373 {
374 assert(0);
375 }
376 }
377
378 for(const auto& pair : sinkMap)
379 {
380
381 // initialize if not existent
382 const auto mapIter=temp.find(pair.first);
383 if(mapIter==temp.end())
384 {
385 temp.emplace(pair.first,std::make_pair(VectorNcoeff::Zero(),pair.second.second));
386 }
387
388 if(link.source->sID==loopLink->source()->sID && link.sink->sID==loopLink->sink()->sID)
389 {
390 temp[pair.first].first(3)+=pair.second.first/link.loopLinks().size();
391 }
392 else if(link.source->sID==loopLink->sink()->sID && link.sink->sID==loopLink->source()->sID)
393 {
394 temp[pair.first].first(3)-=pair.second.first/link.loopLinks().size();
395 }
396 else
397 {
398 assert(0);
399 }
400 }
401
402 }
403
404 return temp;
405 }
406
407 //
408 // /**********************************************************************/
409 // Eigen::Matrix<double,dim+1,Ncoeff> BezierCoefficients() const {
410 // /*!\returns The [dim x 4] matrix of Bezier coefficients of this spline segment
411 // * [P0 P0+T0/3 P1-T1/3 P1]
412 // */
413 // Eigen::Matrix<double,dim+1,Ncoeff> BzCf;
414 // double w =1.0;
415 // BzCf.col(0)<< link.source->get_P(), w;
416 // BzCf.col(1)<< link.source->get_P()+sourceT()/3.0*chordParametricLength(), w;
417 // BzCf.col(2)<< link.sink ->get_P()- sinkT()/3.0*chordParametricLength(), w;
418 // BzCf.col(3)<< link.sink ->get_P(), w;
419 // return BzCf;
420 // }
421 //
422 // /**********************************************************************/
423 // Eigen::Matrix<double,dim,Ncoeff> hermiteCoefficients() const
424 // {
425 // Eigen::Matrix<double,dim,Ncoeff> HrCf;
426 // HrCf.col(0)= link.source->get_P();
427 // HrCf.col(1)= sourceT()*chordParametricLength();
428 // HrCf.col(2)= link.sink->get_P();
429 // HrCf.col(3)= sinkT()*chordParametricLength();
430 // return HrCf;
431 // }
432 //
433 // /************************************************************************/
434 // Eigen::Matrix<double,dim,Ncoeff> polynomialCoeff() const
435 // {/*!\returns The matrix of coefficients of the polynomial associated to this
436 // * SplineSegmentBase. If C=polynomialCoeff() then the polynomial is:
437 // * P(u)=C.col(0)+u*C.col(1)+u^2*C.col(2)+...
438 // */
439 // return Coeff2Hermite<pOrder>::template h2c<dim>(hermiteCoefficients());
440 // }
441
442 };
443
444
445
446
447
448
449 // /************************************************************************/
450 // /* SplineSegmentBase, template specialization corder=2 ******************/
451 // /************************************************************************/
452 // template <typename Derived, short unsigned int dim>
453 // class SplineSegmentBase<Derived,dim,2> : public NetworkLink<Derived>,
454 // /* */ public ParametricCurve<Derived,dim> {
455 //
456 //
457 // enum {corder=2};
458 //#include<model/Geometry/Splines/SplineEnums.h>
459 //
460 //
461 //
462 // ////////////////////////////////////////////////////////////////
463 // //! Returns the length of the chord vector to the power alpha
464 // double chordParametricLength() const
465 // {
466 // return std::pow(chordLength(),alpha);;
467 // }
468 //
469 // public:
470 //
471 // static double alpha;
472 //
473 //
474 // RowNcoeff powers(const double & uin){
475 // return (RowNcoeff()<<1.0, uin, std::pow(uin,2), std::pow(uin,3), std::pow(uin,4), std::pow(uin,5)).finished();
476 // }
477 //
478 //
479 // RowNcoeffu powersu(const double & uin){
480 // return (RowNcoeffu()<<1.0, 2.0*uin, 3.0*std::pow(uin,2), 4.0*std::pow(uin,3), 5.0*std::pow(uin,4)).finished();
481 // }
482 //
483 //
484 // RowNcoeffuu powersuu(const double & uin){
485 // return (RowNcoeffuu()<<2.0, 6.0*uin, 12.0*std::pow(uin,2), 20.0*std::pow(uin,3)).finished();
486 // }
487 //
488 //
489 // //////////////////////////////////////////////////////////////
490 // //get_SFCH
491 // MatrixNcoeff get_SFCH() const {
492 // //! !!!!!!!! FINISH HERE !!!!!!!! //
493 // assert(0);
494 // return MatrixNcoeff::Zero();
495 // }
496 //
497 // MatrixNcoeffDim get_qH() const {
498 // return (MatrixNcoeffDim()<< link.source->get_P().transpose(),
499 // /* */ sourceT().transpose(),
500 // /* */ link.source->get_K().transpose(),
501 // /* */ link. sink->get_P().transpose(),
502 // /* */ sinkT().transpose(),
503 // /* */ link. sink->get_K().transpose()).finished();
504 // }
505 //
506 //#include "SplineSegmentBase_common.h"
507 //
508 // };
509 //
510 // //static data
511 // template <typename Derived, short unsigned int dim>
512 // double SplineSegmentBase<Derived,dim,2>::alpha=0.5;
514 //
515 //
516 // //////////////////////////////////////////////////////////////s
517 //} // namespace model
518}
519#endif
520
static VectorDim sinkT(const LinkType &)
Eigen::Matrix< double, Ncoeff, 1 > VectorNcoeff
Eigen::Matrix< double, Ncoeff, Ncoeff > MatrixNcoeff
static RowNcoeffuu powersDiff2(const double &)
Eigen::Matrix< double, 1, Ncoeff > RowNcoeff
Eigen::Matrix< double, 1, Ncoeff-2 > RowNcoeffuu
static MatrixNcoeff sfCoeffs(const double &)
std::map< size_t, std::pair< VectorNcoeff, VectorDim >, std::less< size_t > > H2PmapType
static VectorDim sourceT(const LinkType &)
static Eigen::Matrix< double, dim, Ncoeff > hermiteCoefficients(const LinkType &link)
static RowNcoeff sfDiff2(const double &uin, const double &g)
static RowNcoeffu powersDiff1(const double &)
static RowNcoeff sfDiff1(const double &uin, const double &g)
Eigen::Matrix< double, Ncoeff, dim > MatrixNcoeffDim
static MatrixNcoeffDim hermiteDofs(const LinkType &link)
static RowNcoeff powers(const double &uin)
Eigen::Matrix< double, dim, 1 > VectorDim
Eigen::Matrix< double, 1, Ncoeff-1 > RowNcoeffu
static RowNcoeff sf(const double &uin, const double &g)
Eigen::Matrix< double, dim, dim > MatrixDim
static RowNcoeff sfDiff2(const double &uin, const double &g)
Eigen::Matrix< double, Ncoeff, dim > MatrixNcoeffDim
static RowNcoeff sf(const double &uin, const double &g)
static std::pair< Eigen::Matrix< double, Ncoeff, Eigen::Dynamic >, Eigen::Matrix< double, Eigen::Dynamic, dim > > hermite2posMatrix(const LinkType &link)
std::map< size_t, std::pair< VectorNcoeff, VectorDim >, std::less< size_t > > H2PmapType
Eigen::Matrix< double, 1, Ncoeff-1 > RowNcoeffu
Eigen::Matrix< double, dim, dim > MatrixDim
Eigen::Matrix< double, 1, Ncoeff > RowNcoeff
static H2PmapType hermite2posMap(const LinkType &link)
static RowNcoeffu powersDiff1(const double &uin)
Eigen::Matrix< double, 1, Ncoeff-2 > RowNcoeffuu
static MatrixNcoeffDim hermiteDofs(const LinkType &link)
static MatrixNcoeff sfCoeffs(const double &g)
Eigen::Matrix< double, Ncoeff, Ncoeff > MatrixNcoeff
static RowNcoeff powers(const double &uin)
static RowNcoeff sfDiff1(const double &uin, const double &g)
Eigen::Matrix< double, dim, 1 > VectorDim
static RowNcoeffuu powersDiff2(const double &uin)
Eigen::Matrix< double, Ncoeff, 1 > VectorNcoeff
static VectorDim sinkT(const LinkType &link)
static VectorDim sourceT(const LinkType &link)
int k
vertex temp
void t struct mesh * m