Surface NMR forward modelling
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

KernelV0.cpp 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 11/11/2016 01:47:25 PM
  11. * @author Trevor Irons (ti)
  12. * @email tirons@egi.utah.edu
  13. * @copyright Copyright (c) 2016, University of Utah
  14. * @copyright Copyright (c) 2016, Lemma Software, LLC
  15. * @copyright Copyright (c) 2008, Colorado School of Mines
  16. */
  17. #include "KernelV0.h"
  18. #include "FieldPoints.h"
  19. namespace Lemma {
  20. // ==================== FRIEND METHODS =====================
  21. std::ostream &operator << (std::ostream &stream, const KernelV0 &ob) {
  22. stream << ob.Serialize() << "\n---\n"; // End of doc ---
  23. return stream;
  24. }
  25. // ==================== LIFECYCLE =======================
  26. //--------------------------------------------------------------------------------------
  27. // Class: KernelV0
  28. // Method: KernelV0
  29. // Description: constructor (locked)
  30. //--------------------------------------------------------------------------------------
  31. KernelV0::KernelV0 (const ctor_key&) : LemmaObject( ) {
  32. } // ----- end of method KernelV0::KernelV0 (constructor) -----
  33. //--------------------------------------------------------------------------------------
  34. // Class: KernelV0
  35. // Method: KernelV0
  36. // Description: DeSerializing constructor (locked)
  37. //--------------------------------------------------------------------------------------
  38. KernelV0::KernelV0 (const YAML::Node& node, const ctor_key&) : LemmaObject(node) {
  39. } // ----- end of method KernelV0::KernelV0 (constructor) -----
  40. //--------------------------------------------------------------------------------------
  41. // Class: KernelV0
  42. // Method: NewSP()
  43. // Description: public constructor returing a shared_ptr
  44. //--------------------------------------------------------------------------------------
  45. std::shared_ptr< KernelV0 > KernelV0::NewSP() {
  46. return std::make_shared< KernelV0 >( ctor_key() );
  47. }
  48. //--------------------------------------------------------------------------------------
  49. // Class: KernelV0
  50. // Method: ~KernelV0
  51. // Description: destructor (protected)
  52. //--------------------------------------------------------------------------------------
  53. KernelV0::~KernelV0 () {
  54. } // ----- end of method KernelV0::~KernelV0 (destructor) -----
  55. //--------------------------------------------------------------------------------------
  56. // Class: KernelV0
  57. // Method: Serialize
  58. //--------------------------------------------------------------------------------------
  59. YAML::Node KernelV0::Serialize ( ) const {
  60. YAML::Node node = LemmaObject::Serialize();
  61. node.SetTag( GetName() );
  62. // Coils Transmitters & Receivers
  63. for ( auto txm : TxRx) {
  64. node[txm.first] = txm.second->Serialize();
  65. }
  66. // LayeredEarthEM
  67. node["SigmaModel"] = SigmaModel->Serialize();
  68. return node;
  69. } // ----- end of method KernelV0::Serialize -----
  70. //--------------------------------------------------------------------------------------
  71. // Class: KernelV0
  72. // Method: DeSerialize
  73. //--------------------------------------------------------------------------------------
  74. std::shared_ptr<KernelV0> KernelV0::DeSerialize ( const YAML::Node& node ) {
  75. if (node.Tag() != "KernelV0" ) {
  76. throw DeSerializeTypeMismatch( "KernelV0", node.Tag());
  77. }
  78. return std::make_shared< KernelV0 > ( node, ctor_key() );
  79. } // ----- end of method KernelV0::DeSerialize -----
  80. //--------------------------------------------------------------------------------------
  81. // Class: KernelV0
  82. // Method: DeSerialize
  83. //--------------------------------------------------------------------------------------
  84. void KernelV0::CalculateK0 (const std::vector< std::string>& Tx, const std::vector<std::string >& Rx,
  85. bool vtkOutput ) {
  86. // Set up
  87. Larmor = SigmaModel->GetMagneticFieldMagnitude()*GAMMA; // in rad 2246.*2.*PI;
  88. // All EM calculations will share same field points
  89. cpoints = FieldPoints::NewSP();
  90. cpoints->SetNumberOfPoints(8);
  91. for (auto tx : Tx) {
  92. // Set up EMEarth
  93. EMEarths[tx] = EMEarth1D::NewSP();
  94. EMEarths[tx]->AttachWireAntenna(TxRx[tx]);
  95. EMEarths[tx]->AttachLayeredEarthEM(SigmaModel);
  96. EMEarths[tx]->AttachFieldPoints( cpoints );
  97. EMEarths[tx]->SetFieldsToCalculate(H);
  98. // TODO query for method, altough with flat antennae, this is fastest
  99. EMEarths[tx]->SetHankelTransformMethod(ANDERSON801);
  100. EMEarths[tx]->SetTxRxMode(TX);
  101. TxRx[tx]->SetCurrent(1.);
  102. }
  103. for (auto rx : Rx) {
  104. if (EMEarths.count(rx)) {
  105. EMEarths[rx]->SetTxRxMode(TXRX);
  106. } else {
  107. EMEarths[rx] = EMEarth1D::NewSP();
  108. EMEarths[rx]->AttachWireAntenna(TxRx[rx]);
  109. EMEarths[rx]->AttachLayeredEarthEM(SigmaModel);
  110. EMEarths[rx]->AttachFieldPoints( cpoints );
  111. EMEarths[rx]->SetFieldsToCalculate(H);
  112. // TODO query for method, altough with flat antennae, this is fastest
  113. EMEarths[rx]->SetHankelTransformMethod(ANDERSON801);
  114. EMEarths[rx]->SetTxRxMode(RX);
  115. TxRx[rx]->SetCurrent(1.);
  116. }
  117. }
  118. std::cout << "Calculating K0 kernel\n";
  119. Kern = MatrixXcr::Zero( Interfaces.size()-1, PulseI.size() );
  120. for (ilay=0; ilay<Interfaces.size()-1; ++ilay) {
  121. std::cout << "Layer " << ilay << std::endl; //<< " q " << iq << std::endl;
  122. Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
  123. Origin(2) = Interfaces(ilay);
  124. IntegrateOnOctreeGrid( vtkOutput );
  125. }
  126. std::cout << "\rFinished KERNEL\n";
  127. std::cout << "#real\n";
  128. std::cout << Kern.real() << std::endl;
  129. std::cout << "#imag\n";
  130. std::cout << Kern.imag() << std::endl;
  131. }
  132. //--------------------------------------------------------------------------------------
  133. // Class: KernelV0
  134. // Method: IntegrateOnOctreeGrid
  135. //--------------------------------------------------------------------------------------
  136. void KernelV0::IntegrateOnOctreeGrid( bool vtkOutput) {
  137. Vector3r cpos = Origin + Size/2.;
  138. SUM = 0;
  139. VOLSUM = 0;
  140. nleaves = 0;
  141. if (!vtkOutput) {
  142. EvaluateKids( Size, 0, cpos, VectorXcr::Ones(PulseI.size()) );
  143. } else {
  144. #ifdef LEMMAUSEVTK
  145. vtkHyperOctree* oct = vtkHyperOctree::New();
  146. oct->SetDimension(3);
  147. oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
  148. oct->SetSize( Size(0), Size(1), Size(2) );
  149. vtkHyperOctreeCursor* curse = oct->NewCellCursor();
  150. curse->ToRoot();
  151. EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
  152. for (int iq=0; iq<PulseI.size(); ++iq) {
  153. // Fill in leaf data
  154. vtkDoubleArray* kr = vtkDoubleArray::New();
  155. kr->SetNumberOfComponents(1);
  156. kr->SetName("Re($K_0$)");
  157. kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
  158. vtkDoubleArray* ki = vtkDoubleArray::New();
  159. ki->SetNumberOfComponents(1);
  160. ki->SetName("Im($K_0$)");
  161. ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
  162. vtkDoubleArray* km = vtkDoubleArray::New();
  163. km->SetNumberOfComponents(1);
  164. km->SetName("mod($K_0$)");
  165. km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
  166. vtkIntArray* kid = vtkIntArray::New();
  167. kid->SetNumberOfComponents(1);
  168. kid->SetName("ID");
  169. kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
  170. vtkIntArray* kerr = vtkIntArray::New();
  171. kerr->SetNumberOfComponents(1);
  172. kerr->SetName("nleaf");
  173. //Real LeafVol(0);
  174. for (auto leaf : LeafDict) {
  175. kr->InsertTuple1( leaf.first, std::real(leaf.second(iq)) );
  176. ki->InsertTuple1( leaf.first, std::imag(leaf.second(iq)) );
  177. km->InsertTuple1( leaf.first, std::abs(leaf.second(iq)) );
  178. kid->InsertTuple1( leaf.first, leaf.first );
  179. //LeafVol += std::real(leaf.second);
  180. }
  181. //std::cout << "\n\nLeafVol=" << LeafVol << std::endl;
  182. for (auto leaf : LeafDictIdx) {
  183. kerr->InsertTuple1( leaf.first, leaf.second );
  184. }
  185. auto kri = oct->GetLeafData()->AddArray(kr);
  186. auto kii = oct->GetLeafData()->AddArray(ki);
  187. auto kmi = oct->GetLeafData()->AddArray(km);
  188. auto kidi = oct->GetLeafData()->AddArray(kid);
  189. auto keri = oct->GetLeafData()->AddArray(kerr);
  190. auto write = vtkXMLHyperOctreeWriter::New();
  191. //write.SetDataModeToAscii()
  192. write->SetInputData(oct);
  193. std::string fname = std::string("octree-") + to_string(ilay)
  194. + std::string("-") + to_string(iq) + std::string(".vto");
  195. write->SetFileName(fname.c_str());
  196. write->Write();
  197. write->Delete();
  198. oct->GetLeafData()->RemoveArray( kri );
  199. oct->GetLeafData()->RemoveArray( kii );
  200. oct->GetLeafData()->RemoveArray( kmi );
  201. oct->GetLeafData()->RemoveArray( kidi );
  202. oct->GetLeafData()->RemoveArray( keri );
  203. kerr->Delete();
  204. kid->Delete();
  205. kr->Delete();
  206. ki->Delete();
  207. km->Delete();
  208. }
  209. curse->Delete();
  210. oct->Delete();
  211. #else
  212. throw std::runtime_error("IntegrateOnOctreeGrid with vtkOutput requires Lemma with VTK support");
  213. #endif
  214. }
  215. std::cout << "\nVOLSUM=" << VOLSUM << "\tActual=" << Size(0)*Size(1)*Size(2)
  216. << "\tDifference=" << VOLSUM - (Size(0)*Size(1)*Size(2)) << std::endl;
  217. }
  218. //--------------------------------------------------------------------------------------
  219. // Class: KernelV0
  220. // Method: f
  221. //--------------------------------------------------------------------------------------
  222. VectorXcr KernelV0::f( const Vector3r& r, const Real& volume, const Vector3cr& Ht, const Vector3cr& Hr ) {
  223. // Compute the elliptic fields
  224. Vector3r B0hat = SigmaModel->GetMagneticFieldUnitVector();
  225. Vector3r B0 = SigmaModel->GetMagneticField();
  226. // Elliptic representation
  227. EllipticB EBT = EllipticFieldRep(MU0*Ht, B0hat);
  228. EllipticB EBR = EllipticFieldRep(MU0*Hr, B0hat);
  229. // Compute Mn0
  230. Vector3r Mn0 = ComputeMn0(1.0, B0);
  231. Real Mn0Abs = Mn0.norm();
  232. // Compute phase delay
  233. // TODO add transmiiter current phase and delay induced apparent time phase!
  234. Complex PhaseTerm = EBR.bhat.dot(EBT.bhat) + (B0hat.dot(EBR.bhat.cross(EBT.bhat) ));
  235. Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
  236. // Calcuate vector of all responses
  237. VectorXcr F = VectorXcr::Zero( PulseI.size() );
  238. for (int iq=0; iq<PulseI.size(); ++iq) {
  239. // Compute the tipping angle
  240. Real sintheta = std::sin(0.5*GAMMA*PulseI(iq)*Taup*std::abs(EBT.alpha-EBT.beta));
  241. F(iq) = -volume*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
  242. }
  243. return F;
  244. }
  245. // //--------------------------------------------------------------------------------------
  246. // // Class: KernelV0
  247. // // Method: ComputeV0Cell
  248. // //--------------------------------------------------------------------------------------
  249. // Complex KernelV0::ComputeV0Cell(const EllipticB& EBT, const EllipticB& EBR,
  250. // const Real& sintheta, const Real& phase, const Real& Mn0Abs,
  251. // const Real& vol) {
  252. // // earth response of receiver adjoint field
  253. // Vector3r B0hat = SigmaModel->GetMagneticFieldUnitVector();
  254. // Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
  255. // Complex PhaseTerm = EBR.bhat.dot(EBT.bhat) + (B0hat.dot(EBR.bhat.cross(EBT.bhat) ));
  256. // return -vol*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
  257. // }
  258. //--------------------------------------------------------------------------------------
  259. // Class: KernelV0
  260. // Method: ComputeV0Cell
  261. //--------------------------------------------------------------------------------------
  262. Vector3r KernelV0::ComputeMn0(const Real& Porosity, const Vector3r& B0) {
  263. Real chi_n = NH2O*((GAMMA*GAMMA*HBAR*HBAR)/(4.*KB*Temperature));
  264. return chi_n*Porosity*B0;
  265. }
  266. //--------------------------------------------------------------------------------------
  267. // Class: KernelV0
  268. // Method: ComputeV0Cell
  269. //--------------------------------------------------------------------------------------
  270. EllipticB KernelV0::EllipticFieldRep (const Vector3cr& B, const Vector3r& B0hat) {
  271. EllipticB ElipB = EllipticB();
  272. Vector3cr Bperp = B.array() - B0hat.dot(B)*B0hat.array();
  273. Real BperpNorm = Bperp.norm();
  274. Complex Bp2 = Bperp.transpose() * Bperp;
  275. VectorXcr iB0 = Complex(0,1)*B0hat.cast<Complex>().array();
  276. ElipB.eizt = std::sqrt(Bp2 / std::abs(Bp2));
  277. ElipB.alpha = INVSQRT2*std::sqrt(BperpNorm*BperpNorm + std::abs(Bp2));
  278. ElipB.beta = sgn(std::real(iB0.dot(Bperp.cross(Bperp.conjugate())))) *
  279. (INVSQRT2)*std::sqrt(std::abs(BperpNorm*BperpNorm-std::abs(Bp2)));
  280. ElipB.bhat = ((Real)1./ElipB.alpha)*(((Real)1./ElipB.eizt)*Bperp.array()).real().array();
  281. ElipB.bhatp = B0hat.cross(ElipB.bhat);
  282. ElipB.zeta = std::real(std::log(ElipB.eizt)/Complex(0,1));
  283. return ElipB;
  284. }
  285. //--------------------------------------------------------------------------------------
  286. // Class: KernelV0
  287. // Method: EvaluateKids
  288. //--------------------------------------------------------------------------------------
  289. void KernelV0::EvaluateKids( const Vector3r& size, const int& level, const Vector3r& cpos,
  290. const VectorXcr& parentVal ) {
  291. std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
  292. std::cout.flush();
  293. // Next level step, interested in one level below
  294. // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
  295. Vector3r step = size.array() / (Real)(1 << (level+1) );
  296. Real vol = (step(0)*step(1)*step(2)); // volume of each child
  297. Vector3r pos = cpos - step/2.;
  298. Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
  299. 0, 0, 0,
  300. step[0], 0, 0,
  301. 0, step[1], 0,
  302. step[0], step[1], 0,
  303. 0, 0, step[2],
  304. step[0], 0, step[2],
  305. 0, step[1], step[2],
  306. step[0], step[1], step[2] ).finished();
  307. MatrixXcr kvals(8, PulseI.size()); // individual kernel vals
  308. cpoints->ClearFields();
  309. for (int ichild=0; ichild<8; ++ichild) {
  310. Vector3r cp = pos; // Eigen complains about combining these
  311. cp += posadd.row(ichild);
  312. cpoints->SetLocation( ichild, cp );
  313. }
  314. Eigen::Matrix<Complex, 3, 8> Ht = Eigen::Matrix<Complex, 3, 8>::Zero();
  315. Eigen::Matrix<Complex, 3, 8> Hr = Eigen::Matrix<Complex, 3, 8>::Zero();
  316. //Eigen::Matrix< Complex, 8, 3 > Bt;
  317. for ( auto EMCalc : EMEarths ) {
  318. //EMCalc->GetFieldPoints()->ClearFields();
  319. EMCalc.second->CalculateWireAntennaFields();
  320. switch (EMCalc.second->GetTxRxMode()) {
  321. case TX:
  322. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  323. break;
  324. case RX:
  325. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  326. break;
  327. case TXRX:
  328. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  329. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  330. break;
  331. default:
  332. break;
  333. }
  334. }
  335. for (int ichild=0; ichild<8; ++ichild) {
  336. Vector3r cp = pos; // Eigen complains about combining these
  337. cp += posadd.row(ichild);
  338. kvals.row(ichild) = f(cp, vol, Ht.col(ichild), Hr.col(ichild));
  339. }
  340. VectorXcr ksum = kvals.colwise().sum(); // Kernel sum
  341. // Evaluate whether or not furthur splitting is needed
  342. if ( ((ksum - parentVal).array().abs() > tol).any() || level < minLevel && level < maxLevel ) {
  343. // Not a leaf dive further in
  344. for (int ichild=0; ichild<8; ++ichild) {
  345. Vector3r cp = pos; // Eigen complains about combining these
  346. cp += posadd.row(ichild);
  347. EvaluateKids( size, level+1, cp, kvals.row(ichild) );
  348. }
  349. return; // not leaf
  350. }
  351. // implicit else, is a leaf
  352. Kern.row(ilay) += ksum;
  353. VOLSUM += 8.*vol;
  354. nleaves += 1;
  355. return; // is leaf
  356. }
  357. #ifdef LEMMAUSEVTK
  358. //--------------------------------------------------------------------------------------
  359. // Class: KernelV0
  360. // Method: EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
  361. //--------------------------------------------------------------------------------------
  362. void KernelV0::EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
  363. const VectorXcr& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
  364. std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
  365. std::cout.flush();
  366. // Next level step, interested in one level below
  367. // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
  368. Vector3r step = size.array() / (Real)(1 << (level+1) );
  369. Real vol = (step(0)*step(1)*step(2)); // volume of each child
  370. Vector3r pos = cpos - step/2.;
  371. Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
  372. 0, 0, 0,
  373. step[0], 0, 0,
  374. 0, step[1], 0,
  375. step[0], step[1], 0,
  376. 0, 0, step[2],
  377. step[0], 0, step[2],
  378. 0, step[1], step[2],
  379. step[0], step[1], step[2] ).finished();
  380. MatrixXcr kvals(8, PulseI.size()); // individual kernel vals
  381. cpoints->ClearFields();
  382. for (int ichild=0; ichild<8; ++ichild) {
  383. Vector3r cp = pos; // Eigen complains about combining these
  384. cp += posadd.row(ichild);
  385. cpoints->SetLocation( ichild, cp );
  386. }
  387. Eigen::Matrix<Complex, 3, 8> Ht = Eigen::Matrix<Complex, 3, 8>::Zero();
  388. Eigen::Matrix<Complex, 3, 8> Hr = Eigen::Matrix<Complex, 3, 8>::Zero();
  389. for ( auto EMCalc : EMEarths ) {
  390. //EMCalc->GetFieldPoints()->ClearFields();
  391. EMCalc.second->CalculateWireAntennaFields();
  392. switch (EMCalc.second->GetTxRxMode()) {
  393. case TX:
  394. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  395. break;
  396. case RX:
  397. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  398. break;
  399. case TXRX:
  400. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  401. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  402. break;
  403. default:
  404. break;
  405. }
  406. }
  407. for (int ichild=0; ichild<8; ++ichild) {
  408. Vector3r cp = pos; // Eigen complains about combining these
  409. cp += posadd.row(ichild);
  410. kvals.row(ichild) = f(cp, vol, Ht.col(ichild), Hr.col(ichild));
  411. }
  412. VectorXcr ksum = kvals.colwise().sum(); // Kernel sum
  413. // Evaluate whether or not furthur splitting is needed
  414. if ( ((ksum - parentVal).array().abs() > tol).any() || level < minLevel && level < maxLevel ) {
  415. oct->SubdivideLeaf(curse);
  416. for (int ichild=0; ichild<8; ++ichild) {
  417. curse->ToChild(ichild);
  418. Vector3r cp = pos; // Eigen complains about combining these
  419. cp += posadd.row(ichild);
  420. /* Test for position via alternative means */
  421. /*
  422. Real p[3];
  423. GetPosition(curse, p);
  424. if ( (Vector3r(p) - cp).norm() > 1e-8 ) {
  425. std::cout << "ERROR @ nleaves" << nleaves << "\n" << cp[0] << "\t" << p[0] << "\t" << cp[1] << "\t" << p[1]
  426. << "\t" << cp[2] << "\t" << p[2] << "\t" << vol<< std::endl;
  427. throw std::runtime_error("doom");
  428. }
  429. */
  430. /* End of position test */
  431. EvaluateKids2( size, level+1, cp, kvals.row(ichild), oct, curse );
  432. curse->ToParent();
  433. }
  434. return; // not a leaf
  435. }
  436. LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
  437. LeafDictIdx[curse->GetLeafId()] = nleaves;
  438. Kern.row(ilay) += ksum;
  439. VOLSUM += 8*vol;
  440. nleaves += 1;
  441. return; // is a leaf
  442. }
  443. //--------------------------------------------------------------------------------------
  444. // Class: KernelV0
  445. // Method: GetPosition
  446. //--------------------------------------------------------------------------------------
  447. void KernelV0::GetPosition( vtkHyperOctreeCursor* Cursor, Real* p ) {
  448. Real ratio=1.0/(1<<(Cursor->GetCurrentLevel()));
  449. //step = ((Size).array() / std::pow(2.,Cursor->GetCurrentLevel()));
  450. p[0]=(Cursor->GetIndex(0)+.5)*ratio*this->Size[0]+this->Origin[0] ;//+ .5*step[0];
  451. p[1]=(Cursor->GetIndex(1)+.5)*ratio*this->Size[1]+this->Origin[1] ;//+ .5*step[1];
  452. p[2]=(Cursor->GetIndex(2)+.5)*ratio*this->Size[2]+this->Origin[2] ;//+ .5*step[2];
  453. }
  454. #endif
  455. } // ---- end of namespace Lemma ----
  456. /* vim: set tabstop=4 expandtab */
  457. /* vim: set filetype=cpp */