8#ifndef INCLUDE_STRESSTUPLE_H_
9#define INCLUDE_STRESSTUPLE_H_
12template<std::size_t I=0,
typename ...TStress>
13inline typename std::enable_if<I ==
sizeof...(TStress),
void>::type
21 const int& i_gridPoint,
23 std::tuple<TStress&...> t)
25 if (
sizeof...(TStress)!=0)
28template<std::size_t I=0,
StressType stressType,
typename ...BF>
29inline typename std::enable_if<I <
sizeof...(BF),
void>::type
37 const int& i_gridPoint,
41 if (I == i_stress && stressType ==
Cauchy)
43 assert(rab.squaredNorm()>
epsilon);
44 std::get<I>(t).field[i_gridPoint]= std::get<I>(t).field[i_gridPoint] +
45 std::get<I>(t).method.bondFunction(ra,rb)*fij*rab.transpose()*rab/rab.norm();
47 else if (I == i_stress && stressType ==
Piola)
49 assert(rab.squaredNorm()>
epsilon);
50 std::get<I>(t).field[i_gridPoint]= std::get<I>(t).field[i_gridPoint] +
51 std::get<I>(t).method.bondFunction(rA,rB)*fij*rAB.transpose()*rab/rab.norm();
54 recursiveBuildStress<I+1>(fij,ra,rA,rb,rB,rab,rAB,i_gridPoint,i_stress,t);
58template<std::size_t I=0,
typename ...TStress>
59inline typename std::enable_if<I ==
sizeof...(TStress),
void>::type
60recursiveNullifyStress(std::tuple<TStress&...> t)
63template<std::size_t I=0,
StressType stressType,
typename ...BF>
64inline typename std::enable_if<I <
sizeof...(BF),
void>::type
67 std::fill(std::get<I>(t).field.begin(), std::get<I>(t).field.end(),Matrix3d::Zero() );
68 recursiveNullifyStress<I+1>(t);
76template<std::size_t I=0,
typename ...TStress>
77inline typename std::enable_if<I ==
sizeof...(TStress)-1,
double>::type
80 return std::get<I>(t).method.getAveragingDomainSize();
82template<std::size_t I=0,
typename ...TStress>
83inline typename std::enable_if<I <
sizeof...(TStress)-1,
double>::type
86 return std::max(std::get<I>(t).method.getAveragingDomainSize(),averagingDomainSize_max<I+1>(t));
93std::map<Grid<Reference>*,
double> map;
96template<std::size_t I=0,
StressType stressType,
97 typename TGrid=
typename std::conditional<stressType == Piola,Grid<Reference>,
Grid<Current>>::type,
99inline typename std::enable_if<I ==
sizeof...(BF), std::map<TGrid*,double>>::type
102 std::map<TGrid*,double> map;
105template<std::size_t I=0,
StressType stressType,
106 typename TGrid=
typename std::conditional<stressType == Piola,Grid<Reference>,
Grid<Current>>::type,
108inline typename std::enable_if<I <
sizeof...(BF), std::map<TGrid*,double>>::type
111 std::map<TGrid*,double> map;
112 const std::map<TGrid*,double>& rmap= recursiveGridMaxAveragingDomainSizeMap<I+1>(t);
113 map[std::get<I>(t).pgrid]= std::get<I>(t).method.getAveragingDomainSize();
116 for (
const auto& pair : rmap)
117 if (std::get<I>(t).pgrid == pair.first)
119 map[pair.first]= std::max(map.at(std::get<I>(t).pgrid),pair.second);
123 auto result= map.insert(pair);
124 assert(result.second==
true);
133 std::vector<std::pair<Grid<Current>*,
double>> emptyVectorPair;
134 return emptyVectorPair;
138 std::vector<std::pair<Grid<Reference>*,
double>> emptyVectorPair;
139 return emptyVectorPair;
141template<std::size_t I=0,
StressType stressType,
142 typename TGrid=
typename std::conditional<stressType == Piola,Grid<Reference>,
Grid<Current>>::type,
144inline typename std::enable_if<I ==
sizeof...(BF)-1, std::vector<std::pair<TGrid*,double>>>::type
147 std::vector<std::pair<TGrid*,double>>
vectorPair;
148 vectorPair.push_back({std::get<I>(t).pgrid,std::get<I>(t).method.getAveragingDomainSize()});
151template<std::size_t I=0,
StressType stressType,
152 typename TGrid=
typename std::conditional<stressType == Piola,Grid<Reference>,
Grid<Current>>::type,
154inline typename std::enable_if< I <
sizeof...(BF)-1, std::vector<std::pair<TGrid*,double>> >::type
157 std::vector<std::pair<TGrid*,double>>
vectorPair;
158 vectorPair.push_back({std::get<I>(t).pgrid,std::get<I>(t).method.getAveragingDomainSize()});
159 std::vector<std::pair<TGrid*,double>>
next= getTGridDomainSizePairs<I+1>(t);
170template<std::size_t I=0,
typename ...TStress>
171inline typename std::enable_if<I ==
sizeof...(TStress)-1, std::vector<GridBase*>>::type
178template<std::size_t I=0,
typename ...TStress>
179inline typename std::enable_if<I <
sizeof...(TStress)-1, std::vector<GridBase*>>::type
185 std::vector<GridBase*>
next= getBaseGridList<I+1>(t);
192template<std::size_t I=0,
typename ...TStress>
193inline typename std::enable_if<I ==
sizeof...(TStress),
void>::type
196template<std::size_t I=0,
typename ...TStress>
197inline typename std::enable_if<I <
sizeof...(TStress),
void>::type
201 std::tuple<TStress&...> t)
203 BoxPoints boxPoints(origin,step, std::get<I>(t).pgrid->coordinates);
204 std::cout <<
"Folding grid points in grid: " << std::get<I>(t).pgrid <<
" if necessary...."<<
"\n";
206 std::cout << std::endl;
207 recursiveFold<I+1>(origin,step,pbc,t);
211template<std::size_t I=0,
typename ...TStress>
212inline typename std::enable_if<I ==
sizeof...(TStress),
void>::type
216template<std::size_t I=0,
typename ...TStress>
217inline typename std::enable_if<I <
sizeof...(TStress),
void>::type
220 std::cout <<
"Writing stress and grid of " << std::get<I>(t).name << std::endl;
221 std::get<I>(t).write();
222 std::get<I>(t).pgrid->write(std::get<I>(t).name);
double averagingDomainSize_max(const std::tuple<> t)
std::enable_if< I< sizeof...(BF) -1, std::vector< std::pair< TGrid *, double > > >::type getTGridDomainSizePairs(const std::tuple< Stress< BF, stressType > &... > t){ std::vector< std::pair< TGrid *, double > > vectorPair;vectorPair.push_back({std::get< I >(t).pgrid, std::get< I >(t).method.getAveragingDomainSize()});std::vector< std::pair< TGrid *, double > next
std::enable_if< I==sizeof...(TStress), void >::type recursiveFold(const Vector3d &origin, const Vector3d &step, const Vector3i &pbc, const std::tuple< TStress &... > t)
std::enable_if< I==sizeof...(TStress), void >::type recursiveBuildStress(const double &fij, const Vector3d &ra, const Vector3d &rA, const Vector3d &rb, const Vector3d &rB, const Vector3d &rab, const Vector3d &rAB, const int &i_gridPoint, const int &i_stress, std::tuple< TStress &... > t)
std::enable_if< I< sizeof...(BF), std::map< TGrid *, double > >::type recursiveGridMaxAveragingDomainSizeMap(const std::tuple< Stress< BF, stressType > &... > t){ std::map< TGrid *, double > map;const std::map< TGrid *, double > &rmap=recursiveGridMaxAveragingDomainSizeMap< I+1 >(t);map[std::get< I >(t).pgrid]=std::get< I >(t).method.getAveragingDomainSize();for(const auto &pair :rmap) if(std::get< I >(t).pgrid==pair.first) { map[pair.first]=std::max(map.at(std::get< I >(t).pgrid), pair.second);} else { auto result=map.insert(pair);assert(result.second==true);} return map;}inline std::vector< std::pair< Grid< Current > *, double > getTGridDomainSizePairs(const std::tuple<> &emptyTuple)
std::vector< GridBase * > getBaseGridList(const std::tuple<> t)
recursiveWriteStressAndGrid< I+1 >(t)
std::enable_if< I==sizeof...(TStress), void >::type recursiveWriteStressAndGrid(std::tuple< TStress &... > t)
std::enable_if< I< sizeof...(TStress) -1, double >::type averagingDomainSize_max(const std::tuple< TStress &... > t){ return std::max(std::get< I >(t).method.getAveragingDomainSize(), averagingDomainSize_max< I+1 >(t));}std::map< Grid< Reference > double recursiveGridMaxAveragingDomainSizeMap(const std::tuple<> &t)
Eigen::Matrix< double, 1, DIM, Eigen::RowMajor > Vector3d
Eigen::Matrix< int, 1, DIM, Eigen::RowMajor > Vector3i