21#ifndef _libint2_src_lib_libint_shell_h_
22#define _libint2_src_lib_libint_shell_h_
24#include <libint2/util/cxxstd.h>
25#if LIBINT2_CPLUSPLUS_STD < 2011
26#error "libint2/shell.h requires C++11 support"
30#include <libint2/config.h>
31#include <libint2/util/small_vector.h>
45static constexpr std::array<int64_t, 21> fac = {{1LL,
65 2432902008176640000LL}};
72static constexpr std::array<long double, 171> fac_ld = {
94 5.109094217170944e19l,
95 1.12400072777760768e21l,
96 2.585201673888497664e22l,
97 6.2044840173323943936e23l,
98 1.5511210043330985984e25l,
99 4.03291461126605635584e26l,
100 1.0888869450418352160768e28l,
101 3.04888344611713860501504e29l,
102 8.841761993739701954543616e30l,
103 2.6525285981219105863630848e32l,
104 8.22283865417792281772556288e33l,
105 2.6313083693369353016721801216e35l,
106 8.68331761881188649551819440128e36l,
107 2.9523279903960414084761860964352e38l,
108 1.03331479663861449296666513375232e40l,
109 3.719933267899012174679994481508352e41l,
110 1.37637530912263450463159795815809024e43l,
111 5.23022617466601111760007224100074291e44l,
112 2.03978820811974433586402817399028974e46l,
113 8.15915283247897734345611269596115894e47l,
114 3.34525266131638071081700620534407517e49l,
115 1.40500611775287989854314260624451157e51l,
116 6.04152630633738356373551320685139975e52l,
117 2.65827157478844876804362581101461589e54l,
118 1.19622220865480194561963161495657715e56l,
119 5.50262215981208894985030542880025489e57l,
120 2.5862324151116818064296435515361198e59l,
121 1.2413915592536072670862289047373375e61l,
122 6.08281864034267560872252163321295377e62l,
123 3.04140932017133780436126081660647688e64l,
124 1.55111875328738228022424301646930321e66l,
125 8.0658175170943878571660636856403767e67l,
126 4.27488328406002556429801375338939965e69l,
127 2.30843697339241380472092742683027581e71l,
128 1.2696403353658275925965100847566517e73l,
129 7.1099858780486345185404564746372495e74l,
130 4.05269195048772167556806019054323221e76l,
131 2.35056133128287857182947491051507468e78l,
132 1.38683118545689835737939019720389406e80l,
133 8.32098711274139014427634118322336438e81l,
134 5.07580213877224798800856812176625227e83l,
135 3.14699732603879375256531223549507641e85l,
136 1.98260831540444006411614670836189814e87l,
137 1.26886932185884164103433389335161481e89l,
138 8.24765059208247066672317030678549625e90l,
139 5.44344939077443064003729240247842753e92l,
140 3.64711109181886852882498590966054644e94l,
141 2.48003554243683059960099041856917158e96l,
142 1.71122452428141311372468338881272839e98l,
143 1.19785716699698917960727837216890987e100l,
144 8.5047858856786231752116764423992601e101l,
145 6.12344583768860868615240703852746727e103l,
146 4.47011546151268434089125713812505111e105l,
147 3.30788544151938641225953028221253782e107l,
148 2.48091408113953980919464771165940337e109l,
149 1.88549470166605025498793226086114656e111l,
150 1.45183092028285869634070784086308285e113l,
151 1.13242811782062978314575211587320462e115l,
152 8.94618213078297528685144171539831652e116l,
153 7.15694570462638022948115337231865322e118l,
154 5.79712602074736798587973423157810911e120l,
155 4.75364333701284174842138206989404947e122l,
156 3.94552396972065865118974711801206106e124l,
157 3.31424013456535326699938757913013129e126l,
158 2.81710411438055027694947944226061159e128l,
159 2.42270953836727323817655232034412597e130l,
160 2.1077572983795277172136005186993896e132l,
161 1.85482642257398439114796845645546284e134l,
162 1.65079551609084610812169192624536193e136l,
163 1.48571596448176149730952273362082574e138l,
164 1.35200152767840296255166568759495142e140l,
165 1.24384140546413072554753243258735531e142l,
166 1.15677250708164157475920516230624044e144l,
167 1.08736615665674308027365285256786601e146l,
168 1.03299784882390592625997020993947271e148l,
169 9.91677934870949689209571401541893801e149l,
170 9.61927596824821198533284259495636987e151l,
171 9.42689044888324774562618574305724247e153l,
172 9.33262154439441526816992388562667005e155l,
173 9.33262154439441526816992388562667005e157l,
174 9.42594775983835942085162312448293675e159l,
175 9.61446671503512660926865558697259548e161l,
176 9.90290071648618040754671525458177335e163l,
177 1.02990167451456276238485838647650443e166l,
178 1.08139675824029090050410130580032965e168l,
179 1.14628056373470835453434738414834943e170l,
180 1.22652020319613793935175170103873389e172l,
181 1.3246418194518289744998918371218326e174l,
182 1.44385958320249358220488210246279753e176l,
183 1.58824554152274294042537031270907729e178l,
184 1.76295255109024466387216104710707579e180l,
185 1.97450685722107402353682037275992488e182l,
186 2.23119274865981364659660702121871512e184l,
187 2.54355973347218755712013200418933523e186l,
188 2.92509369349301569068815180481773552e188l,
189 3.3931086844518982011982560935885732e190l,
190 3.96993716080872089540195962949863065e192l,
191 4.68452584975429065657431236280838416e194l,
192 5.57458576120760588132343171174197716e196l,
193 6.68950291344912705758811805409037259e198l,
194 8.09429852527344373968162284544935083e200l,
195 9.87504420083360136241157987144820801e202l,
196 1.21463043670253296757662432418812959e205l,
197 1.50614174151114087979501416199328069e207l,
198 1.88267717688892609974376770249160086e209l,
199 2.37217324288004688567714730513941708e211l,
200 3.01266001845765954480997707752705969e213l,
201 3.85620482362580421735677065923463641e215l,
202 4.97450422247728744039023415041268096e217l,
203 6.46685548922047367250730439553648525e219l,
204 8.47158069087882051098456875815279568e221l,
205 1.11824865119600430744996307607616903e224l,
206 1.48727070609068572890845089118130481e226l,
207 1.99294274616151887673732419418294845e228l,
208 2.6904727073180504835953876621469804e230l,
209 3.65904288195254865768972722051989335e232l,
210 5.01288874827499166103492629211225388e234l,
211 6.91778647261948849222819828311491036e236l,
212 9.6157231969410890041971956135297254e238l,
213 1.34620124757175246058760738589416156e241l,
214 1.89814375907617096942852641411076779e243l,
215 2.69536413788816277658850750803729027e245l,
216 3.85437071718007277052156573649332508e247l,
217 5.55029383273930478955105466055038812e249l,
218 8.04792605747199194484902925779806277e251l,
219 1.17499720439091082394795827163851716e254l,
220 1.72724589045463891120349865930862023e256l,
221 2.55632391787286558858117801577675794e258l,
222 3.80892263763056972698595524350736934e260l,
223 5.713383956445854590478932865261054e262l,
224 8.62720977423324043162318862654419154e264l,
225 1.31133588568345254560672467123471711e267l,
226 2.00634390509568239477828874698911719e269l,
227 3.08976961384735088795856467036324047e271l,
228 4.78914290146339387633577523906302272e273l,
229 7.47106292628289444708380937293831545e275l,
230 1.17295687942641442819215807155131553e278l,
231 1.85327186949373479654360975305107853e280l,
232 2.94670227249503832650433950735121486e282l,
233 4.71472363599206132240694321176194378e284l,
234 7.59070505394721872907517857093672949e286l,
235 1.22969421873944943411017892849175018e289l,
236 2.00440157654530257759959165344155279e291l,
237 3.28721858553429622726333031164414657e293l,
238 5.42391066613158877498449501421284184e295l,
239 9.00369170577843736647426172359331746e297l,
240 1.50361651486499904020120170784008402e300l,
241 2.52607574497319838753801886917134115e302l,
242 4.26906800900470527493925188889956654e304l,
243 7.25741561530799896739672821112926311e306l}};
250template <
typename Int,
typename =
typename std::enable_if<
251 std::is_integral<Int>::value>::type>
252constexpr int64_t fac_int(Int k) {
253#if LIBINT2_CPLUSPLUS_STD >= 2014
254 assert(!std::is_signed<Int>::value || k >= 0);
255 assert(k < fac.size());
266 typename Real,
typename Int,
267 typename =
typename std::enable_if<std::is_integral<Int>::value>::type>
268constexpr Real fac_real(Int k) {
269#if LIBINT2_CPLUSPLUS_STD >= 2014
270 assert(!std::is_signed<Int>::value || k >= 0);
271 assert(k < fac.size() || k < fac_ld.size());
273 assert(k < fac.size() || (std::is_same<Real, double>::value ||
274 std::is_same<Real, long double>::value));
278 return (k < fac.size()) ?
static_cast<Real
>(fac[k])
279 : static_cast<Real>(fac_ld[k]);
283static constexpr std::array<int64_t, 35> df_Kminus1 = {{1LL,
315 191898783962510625LL,
316 1371195958099968000LL,
317 6332659870762850625LL}};
324static constexpr std::array<long double, 302> df_Kminus1_ld = {
353 2.13458046676875e14l,
355 6.190283353629375e15l,
357 1.91898783962510625e17l,
358 1.371195958099968e18l,
359 6.332659870762850625e18l,
360 4.6620662575398912e19l,
361 2.21643095476699771875e20l,
362 1.678343852714360832e21l,
363 8.200794532637891559375e21l,
364 6.3777066403145711616e22l,
365 3.19830986772877770815625e23l,
366 2.55108265612582846464e24l,
367 1.3113070457687988603440625e25l,
368 1.0714547155728479551488e26l,
369 5.63862029680583509947946875e26l,
370 4.71440074852053100265472e27l,
371 2.5373791335626257947657609375e28l,
372 2.1686243443194442612211712e29l,
373 1.192568192774434123539907640625e30l,
374 1.040939685273333245386162176e31l,
375 5.8435841445947272053455474390625e31l,
376 5.20469842636666622693081088e32l,
377 2.980227913743310874726229193921875e33l,
378 2.7064431817106664380040216576e34l,
379 1.57952079428395476360490147277859375e35l,
380 1.461479318123759876522171695104e36l,
381 8.68736436856175119982695810028226562e36l,
382 8.1842841814930553085241614925824e37l,
383 4.95179769008019818390136611716089141e38l,
384 4.746884825265972078944013665697792e39l,
385 2.92156063714731692850180600912492593e40l,
386 2.8481308951595832473664081994186752e41l,
387 1.78215198865986332638610166556620482e42l,
388 1.76584115499894161336717308363957862e43l,
389 1.12275575285571389562324404930670903e44l,
390 1.13013833919932263255499077352933032e45l,
391 7.29791239356214032155108632049360873e45l,
392 7.45891303871552937486293910529358011e46l,
393 4.88960130368663401543922783473071785e47l,
394 5.07206086632655997490679859159963447e48l,
395 3.37382489954377747065306720596419531e49l,
396 3.55044260642859198243475901411974413e50l,
397 2.39541567867608200416367771623457867e51l,
398 2.55631867662858622735302649016621577e52l,
399 1.74865344543353986303948473285124243e53l,
400 1.89167582070515380824123960272299967e54l,
401 1.31149008407515489727961354963843182e55l,
402 1.43767362373591689426334209806947975e56l,
403 1.0098473647378692709053024332215925e57l,
404 1.12138542651401517752540683649419421e58l,
405 7.97779418142916724015188922245058078e58l,
406 8.97108341211212142020325469195355365e59l,
407 6.46201328695762546452303027018497043e60l,
408 7.35628839793193956456666884740191399e61l,
409 5.36347102817482913555411512425352546e62l,
410 6.17928225426282923423600183181760775e63l,
411 4.55895037394860476522099785561549664e64l,
412 5.31418273866603314144296157536314267e65l,
413 3.96628682533528614574226813438548208e66l,
414 4.67648081002610916446980618631956555e67l,
415 3.52999527454840466971061863960307905e68l,
416 4.20883272902349824802282556768760899e69l,
417 3.21229569983904824943666296203880193e70l,
418 3.87212611070161838818099952227260027e71l,
419 2.9874350008503148719760965546960858e72l,
420 3.63979854405952128489013955093624426e73l,
421 2.83806325080779912837729172696128151e74l,
422 3.49420660229714043349453396889879449e75l,
423 2.75292135328356515452597297515244306e76l,
424 3.4243224702511976248246432895208186e77l,
425 2.72539213975072950298071324540091863e78l,
426 3.4243224702511976248246432895208186e79l,
427 2.75264606114823679801052037785492782e80l,
428 3.49280891965622157732113615531123497e81l,
429 2.83522544298268390195083598919057565e82l,
430 3.63252127644247044041398160152368437e83l,
431 2.97698671513181809704837778865010444e84l,
432 3.85047255302901866683882049761510543e85l,
433 3.18537578519104536384176423385561175e86l,
434 4.15851035727134016018592613742431386e87l,
435 3.4720596058582394465875230149026168e88l,
436 4.57436139299847417620451875116674525e89l,
437 3.85398616250264578571215054654190465e90l,
438 5.12328476015829107734906100130675468e91l,
439 4.35500436362798973785473011759235226e92l,
440 5.84054462658045182817792954148970034e93l,
441 5.0082550181721881985329396352312051e94l,
442 6.77503176683332412068639826812805239e95l,
443 5.85965837126146019228353937322050996e96l,
444 7.99453748486332246240994995639110182e97l,
445 6.97299346180113762881741185413240686e98l,
446 9.59344498183598695489193994766932219e99l,
447 8.4373220887793765308690683435002123e100l,
448 1.17040028778399040849681667361565731e102l,
449 1.03779061691986331329689540625052611e103l,
450 1.45129635685214810653605267528341506e104l,
451 1.29723827114982914162111925781315764e105l,
452 1.82863340963370661423542637085710298e106l,
453 1.6474926043602830098588214574227102e107l,
454 2.34065076433114446622134575469709181e108l,
455 2.12526545962476508271787968007529616e109l,
456 3.04284599363048780608774948110621935e110l,
457 2.78409775210844225836042238089863797e111l,
458 4.01655671159224390403582931506020954e112l,
459 3.7028500103042282036193617665951885e113l,
460 5.38218599353360683140801128218068079e114l,
461 4.99884751391070807488613838490350448e115l,
462 7.31977295120570529071489534376572587e116l,
463 6.84842109405767006259400958731780114e117l,
464 1.01012866726638733011865555743967017e119l,
465 9.51930532074016138700567332637174358e119l,
466 1.41418013417294226216611778041553824e121l,
467 1.34222205022436275556779993901841585e122l,
468 2.0081357905255780122758872481900643e123l,
469 1.91937753182083874046195391279633466e124l,
470 2.89171553835683233767727763739369259e125l,
471 2.78309742114021617366983317355468525e126l,
472 4.22190468600097521300882535059479118e127l,
473 4.09115320907611777529465476512538732e128l,
474 6.24841893528144331525306151888029095e129l,
475 6.09581828152341548518903560003682711e130l,
476 9.37262840292216497287959227832043642e131l,
477 9.20468560510035738263544375605560894e132l,
478 1.42463951724416907587769802630470634e134l,
479 1.40831689758035467954322289467650817e135l,
480 2.19394485655602037685165496050924776e136l,
481 2.18289119124954975329199548674858766e137l,
482 3.4225539762273917878885817383944265e138l,
483 3.42713917026179311266843291419528263e139l,
484 5.40763528243927902486395914666319387e140l,
485 5.44915128071625104914280833357049938e141l,
486 8.6522164519028464397823346346611102e142l,
487 8.773133561953164189119921417048504e143l,
488 1.40165906520826112324473821081509985e145l,
489 1.43002077059836576282654719097890615e146l,
490 2.29872086694154824212137066573676376e147l,
491 2.35953427148730350866380286511519515e148l,
492 3.81587663912297008192147530512302784e149l,
493 3.9404222333837968594685507847423759e150l,
494 6.41067275372658973762807851260668677e151l,
495 6.65931357441861669250185082621461527e152l,
496 1.08981436813352025539677334714313675e154l,
497 1.13874262122558345441781649128269921e155l,
498 1.87448071318965483928245015708619521e156l,
499 1.97002473472025937614282252991906964e157l,
500 3.26159644094999942035146327332997967e158l,
501 3.44754328576045390824993942735837186e159l,
502 5.74040973607199897981857536106076421e160l,
503 6.1021516157960034176023927864243182e161l,
504 1.02179293302081581840770641426881603e163l,
505 1.09228513922748461175082830876995296e164l,
506 1.83922727943746847313387154568386885e165l,
507 1.97703610200174714726899923887361485e166l,
508 3.34739364857619262110364621314464131e167l,
509 3.61797606666319727950226860713871518e168l,
510 6.15920431338019442283070903218614002e169l,
511 6.69325572332691496707919692320662308e170l,
512 1.14561200228871616264651187998662204e172l,
513 1.25163882026213309884380982463963852e173l,
514 2.15375056430278638577544233437484944e174l,
515 2.3655973702954315568148005685689168e175l,
516 4.09212607217529413297334043531221394e176l,
517 4.51829097726427427351626908596663108e177l,
518 7.85688205857656473530881363579945076e178l,
519 8.72030158612004934788639933591559799e179l,
520 1.52423511936385355864990984534509345e181l,
521 1.70045880929340962283784787050354161e182l,
522 2.98750083395315297495382329687638316e183l,
523 3.34990385430801695699056030489197697e184l,
524 5.91525165122724289040857012781523865e185l,
525 6.66630867007295374441121500673503416e186l,
526 1.18305033024544857808171402556304773e188l,
527 1.33992804268466370262665421635374187e189l,
528 2.38976166709580612772506233163735642e190l,
529 2.72005392664986731633210805919809599e191l,
530 4.87511380087544450055912715654020709e192l,
531 5.57611054963222799848082152135609678e193l,
532 1.00427344298034156711518019424728266e195l,
533 1.15425488377387119568553005492071203e196l,
534 2.08888876139911045959957480403434793e197l,
535 2.41239270708739079898275781478428815e198l,
536 4.38666639893813196515910708847213066e199l,
537 5.090148611954394585853618989194848e200l,
538 9.299732765748839766137307027560917e201l,
539 1.08420165434628604678682084469850262e203l,
540 1.99014281187025170995338370389803624e204l,
541 2.33103355684451500059166481610178064e205l,
542 4.29870847363974369349930880041975827e206l,
543 5.05834281835259755128391265094086399e207l,
544 9.37118447253464125182849318491507304e208l,
545 1.10777707721921886373117687055604921e210l,
546 2.06166058395762107540226850068131607e211l,
547 2.44818734065447368884590088392886876e212l,
548 4.57688649638591878739303607151252167e213l,
549 5.45945776965947632612635897116137734e214l,
550 1.02522257519044580837604008001880485e216l,
551 1.2283779981733821733784307685113099e217l,
552 2.31700301993040752692985058084249897e218l,
553 2.78841805585357753356903784452067348e219l,
554 5.28276688544132916140005932432089765e220l,
555 6.38547734790469255187309666395234226e221l,
556 1.21503638365150570712201364459380646e223l,
557 1.47504526736598397948268532937299106e224l,
558 2.81888441007149324052307165545763099e225l,
559 3.43685547296274267219465681743906917e226l,
560 6.59618951956729418282398767377085651e227l,
561 8.07661036146244527965744352098181256e228l,
562 1.55670072661788142714646109100992214e230l,
563 1.91415665566659953127881411447268958e231l,
564 3.70494772935055779660857739660361469e232l,
565 4.57483440704317287975636573358972809e233l,
566 8.89187455044133871186058575184867524e234l,
567 1.10253509209740466402128414179512447e236l,
568 2.15183364120680396827026175194737941e237l,
569 2.67916027379669333357172046456215246e238l,
570 5.25047408454460168257943867475160576e239l,
571 6.56394267080189866725071513817727353e240l,
572 1.29161662479797201391454191398889502e242l,
573 1.62129383968806897081092663912978656e243l,
574 3.20320922949897059450806394669245964e244l,
575 4.03702166082329173731920733143316854e245l,
576 8.0080230737474264862701598667311491e246l,
577 1.0132924368666462260671210401897253e248l,
578 2.01802181458435147454008028641624957e249l,
579 2.56362986527261495194981623168000502e250l,
580 5.12577540904425274533180392749727392e251l,
581 6.53725615644516812747203139078401279e252l,
582 1.31219850471532870280494180543930212e254l,
583 1.68007483220640820876031206743149129e255l,
584 3.38547214216554805323674985803339948e256l,
585 4.35139381541459726068920825464756243e257l,
586 8.80222756963042493841554963088683864e258l,
587 1.1357137858232098850398833544630138e260l,
588 2.30618362324317133386487400329235172e261l,
589 2.98692725671504199765489322223772628e262l,
590 6.08832476536197232140326736869180855e263l,
591 7.91535723029486129378546703892997465e264l,
592 1.61949438758628463749326912007202107e266l,
593 2.11340038048872796544071969939430323e267l,
594 4.34024495873124282848196124179301648e268l,
595 5.68504702351467822703553599137067569e269l,
596 1.17186613885743556369012953528411445e271l,
597 1.54064774337247779952663025366145311e272l,
598 3.1874758976922247332371523359727913e273l,
599 4.205968339406864392707700592495767e274l,
600 8.73368395967669576906979740056544817e275l,
601 1.15664129333688770799461766293633592e277l,
602 2.41049677287076803226326408255606369e278l,
603 3.20389638254317895114509092633365051e279l,
604 6.70118102858073512969187414950585707e280l,
605 8.93887090729546927369480368447088492e281l,
606 1.87633068800260583631372476186163998e283l,
607 2.51182272495002686590823983533631866e284l,
608 5.29125254016734845840470382844982474e285l,
609 7.10845831160857603052031873400178182e286l,
610 1.50271572140752696218693588727975023e288l,
611 2.02591061880844416869829083919050782e289l,
612 4.29776696322552711185463663762008565e290l,
613 5.81436347598023476416409470847675744e291l,
614 1.23775688540895180821413535163458467e293l,
615 1.6803510445582878468434233707497829e294l,
616 3.58949496768596024382099251974029553e295l,
617 4.88982153966461763431436200888186824e296l,
618 1.0481325305643003911957298157641663e298l,
619 1.43271771112173296685410806860238739e299l,
620 3.08150963985904315011544565834664891e300l,
621 4.22651724780911225221961880237704281e301l,
622 9.12126853398276772434171914870608078e302l,
623 1.25527562259930633890922678430598171e304l,
624 2.71813802312686478185383230631441207e305l,
625 3.75327411157192595333858808507488533e306l,
626 8.15441406938059434556149691894323621e307l}};
633template <
typename Int,
typename =
typename std::enable_if<
634 std::is_integral<Int>::value>::type>
635constexpr int64_t df_Kminus1_int(Int k) {
636#if LIBINT2_CPLUSPLUS_STD >= 2014
637 assert(!std::is_signed<Int>::value || k >= 0);
638 assert(k < df_Kminus1.size());
640 return df_Kminus1[k];
650 typename Real,
typename Int,
651 typename =
typename std::enable_if<std::is_integral<Int>::value>::type>
652constexpr Real df_Kminus1_real(Int k) {
653#if LIBINT2_CPLUSPLUS_STD >= 2014
654 assert(!std::is_signed<Int>::value || k >= 0);
655 assert(k < df_Kminus1.size() || k < df_Kminus1_ld.size());
657 assert(k < df_Kminus1.size() || (std::is_same<Real, double>::value ||
658 std::is_same<Real, long double>::value));
661 return (k < df_Kminus1.size()) ?
static_cast<Real
>(df_Kminus1[k])
662 : static_cast<Real>(df_Kminus1_ld[k]);
671template <
typename Int,
typename =
typename std::enable_if<
672 std::is_integral<Int>::value>::type>
673constexpr int64_t bc_int(Int i, Int j) {
674#if LIBINT2_CPLUSPLUS_STD >= 2014
677 return fac_int(i) / (fac_int(j) * fac_int(i - j));
688 typename Real,
typename Int,
689 typename =
typename std::enable_if<std::is_integral<Int>::value>::type>
690constexpr Real bc_real(Int i, Int j) {
691#if LIBINT2_CPLUSPLUS_STD >= 2014
692 assert(!std::is_signed<Int>::value || (i >= 0 && j >= 0));
695 return fac_real<Real>(i) / (fac_real<Real>(j) * fac_real<Real>(i - j));
721 typedef double real_t;
728 svector<real_t> coeff;
731 return &other ==
this ||
732 (l == other.l && pure == other.pure && coeff == other.coeff);
735 return not this->operator==(other);
737 size_t cartesian_size()
const {
return (l + 1) * (l + 2) / 2; }
738 size_t size()
const {
return pure ? (2 * l + 1) : cartesian_size(); }
743 std::array<real_t, 3>
O;
751 :
alpha(std::move(other.alpha)),
752 contr(std::move(other.contr)),
753 O(std::move(other.O)),
758 alpha = std::move(other.alpha);
759 contr = std::move(other.contr);
760 O = std::move(other.O);
767 Shell(svector<real_t> _alpha, svector<Contraction> _contr,
768 std::array<real_t, 3> _O,
769 bool embed_normalization_into_coefficients =
true)
770 :
alpha(std::move(_alpha)),
contr(std::move(_contr)),
O(std::move(_O)) {
772 if (embed_normalization_into_coefficients)
775 update_max_ln_coeff();
779 Shell& move(std::array<real_t, 3> new_origin) {
780 O = std::move(new_origin);
784 size_t cartesian_size()
const {
786 for (
const auto& c :
contr) {
787 s += c.cartesian_size();
791 size_t size()
const {
793 for (
const auto& c :
contr) {
799 size_t ncontr()
const {
return contr.size(); }
800 size_t nprim()
const {
return alpha.size(); }
802 bool operator==(
const Shell& other)
const {
803 return &other ==
this ||
804 (
O == other.O &&
alpha == other.alpha &&
contr == other.contr);
806 bool operator!=(
const Shell& other)
const {
807 return not this->operator==(other);
815 assert(l <=
sizeof(LIBINT_AM2SYMBOL) - 1);
816 static char lsymb[] = LIBINT_AM2SYMBOL;
828 const char AM_SYMBOL = ::toupper(
am_symbol);
873 throw std::invalid_argument{
"invalid angular momentum label"};
878 typedef enum { false_value = 0, true_value = 1, default_value = 2 } value_t;
881 bool is_default()
const {
return value_ == default_value; }
882 operator bool()
const {
883 assert(value_ != default_value);
884 return value_ == true_value;
897 static bool result{
true};
898 if (not flag.is_default()) {
907 static const Shell unitshell{make_unit()};
916 const auto alpha = this->alpha.at(p);
917 assert(
alpha >= 0.0);
918 const auto l =
contr.at(c).l;
920 using libint2::math::df_Kminus1_real;
921 const auto sqrt_Pi_cubed = real_t{5.56832799683170784528481798212};
922 const auto two_alpha = 2 *
alpha;
923 const auto two_alpha_to_am32 = pow(two_alpha, l + 1) * sqrt(two_alpha);
924 const auto one_over_N =
925 sqrt((sqrt_Pi_cubed * df_Kminus1_real<real_t>(2 * l)) /
926 (pow(2, l) * two_alpha_to_am32));
927 return contr.at(c).coeff[p] * one_over_N;
938 svector<Contraction> prim_contr;
939 prim_contr.reserve(ncontr());
940 for (
auto&& c :
contr) {
941 prim_contr.emplace_back(
Contraction{c.l, c.pure, {1.}});
943 return Shell({
alpha[p]}, prim_contr,
O, unit_normalized);
951 contr{{0,
false, {1}}},
959 using libint2::math::df_Kminus1_real;
961 const auto sqrt_Pi_cubed = real_t{5.56832799683170784528481798212};
962 const auto np = nprim();
963 for (
auto& c : contr) {
964 for (
auto p = 0ul; p != np; ++p) {
965 assert(alpha[p] >= 0);
967 const auto two_alpha = 2 * alpha[p];
968 const auto two_alpha_to_am32 =
969 pow(two_alpha, c.l + 1) * sqrt(two_alpha);
970 const auto normalization_factor =
971 sqrt(pow(2, c.l) * two_alpha_to_am32 /
972 (sqrt_Pi_cubed * df_Kminus1_real<real_t>(2 * c.l)));
974 c.coeff[p] *= normalization_factor;
979 if (do_enforce_unit_normalization()) {
983 for (
auto p = 0ul; p != np; ++p) {
984 for (
decltype(p) q = 0ul; q <= p; ++q) {
985 auto gamma = alpha[p] + alpha[q];
986 norm += (p == q ? 1 : 2) * df_Kminus1_real<real_t>(2 * c.l) *
987 sqrt_Pi_cubed * c.coeff[p] * c.coeff[q] /
988 (pow(2, c.l) * pow(gamma, c.l + 1) * sqrt(gamma));
991 auto normalization_factor = 1 / sqrt(norm);
992 for (
auto p = 0ul; p != np; ++p) {
993 c.coeff[p] *= normalization_factor;
998 update_max_ln_coeff();
1001 void update_max_ln_coeff() {
1003 max_ln_coeff.resize(nprim());
1004 for (
auto p = 0ul; p != nprim(); ++p) {
1005 real_t max_ln_c = -std::numeric_limits<real_t>::max();
1006 for (
auto& c : contr) {
1007 max_ln_c = std::max(max_ln_c, std::log(std::abs(c.coeff[p])));
1009 max_ln_coeff[p] = max_ln_c;
1014inline std::ostream& operator<<(std::ostream& os,
const Shell& sh) {
1015 os <<
"Shell:( O={" << sh.O[0] <<
"," << sh.O[1] <<
"," << sh.O[2] <<
"}"
1018 for (
const auto& c : sh.contr) {
1019 os <<
" {l=" << c.l <<
",sph=" << c.pure <<
"}";
1023 for (
auto i = 0ul; i < sh.alpha.size(); ++i) {
1024 os <<
" " << sh.alpha[i];
1025 for (
const auto& c : sh.contr) {
1026 os <<
" " << c.coeff.at(i);
1063inline ScreeningMethod& default_screening_method_accessor() {
1064 static ScreeningMethod default_screening_method = ScreeningMethod::Original;
1065 return default_screening_method;
1070 return detail::default_screening_method_accessor();
1073inline void default_screening_method(ScreeningMethod screening_method) {
1074 detail::default_screening_method_accessor() = screening_method;
1080 typedef Shell::real_t real_t;
1095 std::vector<PrimPairData> primpairs;
1097 real_t ln_prec = std::numeric_limits<real_t>::lowest();
1101 for (
int i = 0; i != 3; ++i) AB[i] = 0.;
1104 ShellPair(
size_t max_nprim) : primpairs() {
1105 primpairs.reserve(max_nprim * max_nprim);
1106 for (
int i = 0; i != 3; ++i) AB[i] = 0.;
1108 template <
typename Real>
1109 ShellPair(
const Shell& s1,
const Shell& s2, Real ln_prec,
1110 ScreeningMethod screening_method = default_screening_method()) {
1111 init(s1, s2, ln_prec, screening_method);
1113 template <
typename Real,
typename SchwarzFactorEvaluator>
1114 ShellPair(
const Shell& s1,
const Shell& s2, Real ln_prec,
1115 ScreeningMethod screening_method,
1116 SchwarzFactorEvaluator&& schwarz_factor_evaluator) {
1117 init(s1, s2, ln_prec, screening_method,
1118 std::forward<SchwarzFactorEvaluator>(schwarz_factor_evaluator));
1125 for (
int i = 0; i != 3; ++i) AB[i] = 0.;
1126 ln_prec = std::numeric_limits<real_t>::lowest();
1127 screening_method_ = ScreeningMethod::Invalid;
1130 void resize(std::size_t max_nprim) {
1131 const auto max_nprim2 = max_nprim * max_nprim;
1132 if (max_nprim * max_nprim > primpairs.size()) primpairs.resize(max_nprim2);
1137 template <
typename Real>
1140 assert(screening_method == ScreeningMethod::Original ||
1141 screening_method == ScreeningMethod::Conservative);
1147 const auto& A = s1.
O;
1148 const auto& B = s2.
O;
1150 for (
int i = 0; i != 3; ++i) {
1151 AB[i] = A[i] - B[i];
1152 AB2 += AB[i] * AB[i];
1155 auto max_l = [](
const Shell& s) {
1158 return std::max_element(
1159 begin(s.contr), end(s.contr),
1164 const auto max_l1 = max_l(s1);
1165 const auto max_l2 = max_l(s2);
1167 const auto nprim1 = s1.
alpha.size();
1168 const auto nprim2 = s2.
alpha.size();
1170 for (
size_t p1 = 0; p1 != nprim1; ++p1) {
1171 for (
size_t p2 = 0; p2 != nprim2; ++p2) {
1172 const auto& a1 = s1.
alpha[p1];
1173 const auto& a2 = s2.
alpha[p2];
1174 const auto gamma = a1 + a2;
1175 const auto oogamma = 1 / gamma;
1177 const auto rho = a1 * a2 * oogamma;
1178 const auto minus_rho_times_AB2 = -rho * AB2;
1179 real_t ln_screen_fac =
1181 if (screening_method == ScreeningMethod::Original &&
1182 ln_screen_fac < ln_prec)
1191 P[0] = (a1 * A[0] + a2 * B[0]) * oogamma;
1192 P[1] = (a1 * A[1] + a2 * B[1]) * oogamma;
1193 P[2] = (a1 * A[2] + a2 * B[2]) * oogamma;
1207 real_t nonspherical_scr_factor = 0;
1208 if (screening_method == ScreeningMethod::Conservative) {
1209 const auto maxabs_PA_i_to_l1 = std::pow(
1210 std::max(std::max(std::abs(P[0] - A[0]), std::abs(P[1] - A[1])),
1211 std::abs(P[2] - A[2])),
1213 const auto maxabs_PB_i_to_l2 = std::pow(
1214 std::max(std::max(std::abs(P[0] - B[0]), std::abs(P[1] - B[1])),
1215 std::abs(P[2] - B[2])),
1217 const auto fac_l1_fac_l2_oogamma_to_l =
1218 math::fac_real<Real>(max_l1) * math::fac_real<Real>(max_l2) *
1219 std::pow(oogamma, max_l1 + max_l2);
1220 nonspherical_scr_factor =
1221 std::max(maxabs_PA_i_to_l1 * maxabs_PB_i_to_l2,
1222 fac_l1_fac_l2_oogamma_to_l);
1223 const auto ln_nonspherical_scr_factor =
1224 log(std::max(nonspherical_scr_factor,
static_cast<real_t
>(1)));
1226 constexpr decltype(rho) ln_sqrt_two_times_M_PI_to_1pt25 =
1227 1.777485947591722872387900;
1228 const auto ln_spherical_scr_extra_factor =
1229 ln_sqrt_two_times_M_PI_to_1pt25 + log(oogamma);
1230 const auto ln_nprim = log(nprim1 * nprim2);
1231 ln_screen_fac += ln_spherical_scr_extra_factor +
1232 ln_nonspherical_scr_factor + ln_nprim;
1233 if (ln_screen_fac < ln_prec)
continue;
1236 primpairs.resize(c + 1);
1238 p.
ln_scr = ln_screen_fac;
1241 constexpr decltype(rho) sqrt_two_times_M_PI_to_1pt25 =
1242 5.9149671727956128778;
1243 p.
K = sqrt_two_times_M_PI_to_1pt25 * exp(minus_rho_times_AB2) * oogamma;
1254 this->ln_prec = ln_prec;
1255 this->screening_method_ = screening_method;
1259 template <
typename Real,
typename SchwarzFactorEvaluator>
1262 SchwarzFactorEvaluator&& schwarz_factor_evaluator) {
1263 assert(screening_method == ScreeningMethod::Schwarz ||
1264 screening_method == ScreeningMethod::SchwarzInf);
1270 const auto& A = s1.
O;
1271 const auto& B = s2.
O;
1273 for (
int i = 0; i != 3; ++i) {
1274 AB[i] = A[i] - B[i];
1275 AB2 += AB[i] * AB[i];
1278 const auto nprim1 = s1.
alpha.size();
1279 const auto nprim2 = s2.
alpha.size();
1280 const auto nprim12 = nprim1 * nprim2;
1282 for (
size_t p1 = 0; p1 != nprim1; ++p1) {
1283 for (
size_t p2 = 0; p2 != nprim2; ++p2) {
1284 const auto ln_screen_fac =
1285 log(nprim12 * schwarz_factor_evaluator(s1, p1, s2, p2)) +
1287 if (ln_screen_fac < ln_prec)
continue;
1289 const auto& a1 = s1.
alpha[p1];
1290 const auto& a2 = s2.
alpha[p2];
1291 const auto gamma = a1 + a2;
1292 const auto oogamma = 1 / gamma;
1294 const auto rho = a1 * a2 * oogamma;
1295 const auto minus_rho_times_AB2 = -rho * AB2;
1303 P[0] = (a1 * A[0] + a2 * B[0]) * oogamma;
1304 P[1] = (a1 * A[1] + a2 * B[1]) * oogamma;
1305 P[2] = (a1 * A[2] + a2 * B[2]) * oogamma;
1308 primpairs.resize(c + 1);
1310 p.
ln_scr = ln_screen_fac;
1313 constexpr decltype(rho) sqrt_two_times_M_PI_to_1pt25 =
1314 5.9149671727956128778;
1315 p.
K = sqrt_two_times_M_PI_to_1pt25 * exp(minus_rho_times_AB2) * oogamma;
1326 this->ln_prec = ln_prec;
1327 this->screening_method_ = screening_method;
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
ScreeningMethod
describes method for primitive screening used by ShellPair and Engine
Definition shell.h:1041
@ Original
standard screening method:
@ Conservative
conservative screening:
@ Schwarz
Schwarz screening method using Frobenius norm:
@ SchwarzInf
Schwarz screening method using infinity norm:
PrimPairData contains pre-computed primitive pair data.
Definition shell.h:1084
real_t ln_scr
natural log of the primitive pair screening factor (see ScreeningMethod )
Definition shell.h:1089
int p1
first primitive index
Definition shell.h:1090
real_t nonsph_screen_fac
used only when screening_method_==ScreeningMethod::Conservative: approximate upper bound for the modu...
Definition shell.h:1088
real_t P[3]
Definition shell.h:1085
real_t K
Definition shell.h:1086
int p2
second primitive index
Definition shell.h:1091
real_t one_over_gamma
Definition shell.h:1087
ShellPair contains pre-computed shell-pair data, primitive pairs are screened to finite precision.
Definition shell.h:1079
void init(const Shell &s1, const Shell &s2, Real ln_prec, ScreeningMethod screening_method=ScreeningMethod::Original)
initializes the shell pair data using original or conservative screening methods
Definition shell.h:1138
void reset()
makes this equivalent to a default-initialized ShellPair, however the memory allocated in primpairs i...
Definition shell.h:1123
void init(const Shell &s1, const Shell &s2, Real ln_prec, ScreeningMethod screening_method, SchwarzFactorEvaluator &&schwarz_factor_evaluator)
initializes the shell pair data using Schwarz screening methods
Definition shell.h:1260
contracted Gaussian = angular momentum + sph/cart flag + contraction coefficients
Definition shell.h:725
generally-contracted Solid-Harmonic/Cartesion Gaussian Shell
Definition shell.h:720
svector< Contraction > contr
contractions
Definition shell.h:742
svector< real_t > max_ln_coeff
maximum ln of (absolute) contraction coefficient for each primitive
Definition shell.h:744
Shell(svector< real_t > _alpha, svector< Contraction > _contr, std::array< real_t, 3 > _O, bool embed_normalization_into_coefficients=true)
Definition shell.h:767
static bool do_enforce_unit_normalization(defaultable_boolean flag=defaultable_boolean())
sets and/or reports whether the auto-renormalization to unity is set if called without arguments,...
Definition shell.h:895
static char am_symbol(size_t l)
Definition shell.h:814
static unsigned short am_symbol_to_l(char am_symbol)
inverse of am_symbol()
Definition shell.h:827
static const Shell & unit()
Definition shell.h:906
real_t coeff_normalized(size_t c, size_t p) const
Definition shell.h:915
std::array< real_t, 3 > O
origin
Definition shell.h:743
Shell extract_primitive(size_t p, bool unit_normalized=true) const
extract primitive shell
Definition shell.h:936
svector< real_t > alpha
exponents
Definition shell.h:741