Surface NMR forward modelling
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

KernelV0.cpp 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email tirons@egi.utah.edu
  14. * @copyright Copyright (c) 2016, University of Utah
  15. * @copyright Copyright (c) 2016, Lemma Software, LLC
  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. }
  102. for (auto rx : Rx) {
  103. if (EMEarths.count(rx)) {
  104. EMEarths[rx]->SetTxRxMode(TXRX);
  105. } else {
  106. EMEarths[rx] = EMEarth1D::NewSP();
  107. EMEarths[rx]->AttachWireAntenna(TxRx[rx]);
  108. EMEarths[rx]->AttachLayeredEarthEM(SigmaModel);
  109. EMEarths[rx]->AttachFieldPoints( cpoints );
  110. EMEarths[rx]->SetFieldsToCalculate(H);
  111. // TODO query for method, altough with flat antennae, this is fastest
  112. EMEarths[rx]->SetHankelTransformMethod(ANDERSON801);
  113. EMEarths[rx]->SetTxRxMode(RX);
  114. }
  115. }
  116. std::cout << "Calculating K0 kernel\n";
  117. MatrixXcr Kern = MatrixXcr::Zero( Interfaces.size()-1, PulseI.size() );
  118. for (int ilay=0; ilay<Interfaces.size()-1; ++ilay) {
  119. for (int iq=0; iq< PulseI.size(); ++iq) {
  120. std::cout << "Layer " << ilay << " q " << iq << std::endl;
  121. Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
  122. Origin(2) = Interfaces(ilay);
  123. Ip = PulseI(iq);
  124. Kern(ilay, iq) = IntegrateOnOctreeGrid( ilay, iq, vtkOutput );
  125. }
  126. }
  127. std::cout << "\rFinished KERNEL\n";
  128. std::cout << "real\n";
  129. std::cout << Kern.real() << std::endl;
  130. std::cout << "imag\n";
  131. std::cout << Kern.imag() << std::endl;
  132. //IntegrateOnOctreeGrid( vtkOutput );
  133. }
  134. //--------------------------------------------------------------------------------------
  135. // Class: KernelV0
  136. // Method: IntegrateOnOctreeGrid
  137. //--------------------------------------------------------------------------------------
  138. Complex KernelV0::IntegrateOnOctreeGrid( const int& ilay, const int& iq, bool vtkOutput) {
  139. Vector3r cpos = Origin + Size/2.;
  140. SUM = 0;
  141. VOLSUM = 0;
  142. nleaves = 0;
  143. if (!vtkOutput) {
  144. EvaluateKids( Size, 0, cpos, 1e6 );
  145. } else {
  146. #ifdef LEMMAUSEVTK
  147. vtkHyperOctree* oct = vtkHyperOctree::New();
  148. oct->SetDimension(3);
  149. oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
  150. oct->SetSize( Size(0), Size(1), Size(2) );
  151. vtkHyperOctreeCursor* curse = oct->NewCellCursor();
  152. curse->ToRoot();
  153. EvaluateKids2( Size, 0, cpos, 1e6, oct, curse );
  154. // Fill in leaf data
  155. vtkDoubleArray* kr = vtkDoubleArray::New();
  156. kr->SetNumberOfComponents(1);
  157. kr->SetName("Re($K_0$)");
  158. kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
  159. vtkDoubleArray* ki = vtkDoubleArray::New();
  160. ki->SetNumberOfComponents(1);
  161. ki->SetName("Im($K_0$)");
  162. ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
  163. vtkDoubleArray* km = vtkDoubleArray::New();
  164. km->SetNumberOfComponents(1);
  165. km->SetName("mod($K_0$)");
  166. km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
  167. vtkIntArray* kid = vtkIntArray::New();
  168. kid->SetNumberOfComponents(1);
  169. kid->SetName("ID");
  170. kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
  171. vtkIntArray* kerr = vtkIntArray::New();
  172. kerr->SetNumberOfComponents(1);
  173. kerr->SetName("nleaf");
  174. //Real LeafVol(0);
  175. for (auto leaf : LeafDict) {
  176. kr->InsertTuple1( leaf.first, std::real(leaf.second) );
  177. ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
  178. km->InsertTuple1( leaf.first, std::abs(leaf.second) );
  179. kid->InsertTuple1( leaf.first, leaf.first );
  180. //LeafVol += std::real(leaf.second);
  181. }
  182. //std::cout << "\n\nLeafVol=" << LeafVol << std::endl;
  183. for (auto leaf : LeafDictIdx) {
  184. kerr->InsertTuple1( leaf.first, leaf.second );
  185. }
  186. oct->GetLeafData()->AddArray(kr);
  187. oct->GetLeafData()->AddArray(ki);
  188. oct->GetLeafData()->AddArray(km);
  189. oct->GetLeafData()->AddArray(kid);
  190. oct->GetLeafData()->AddArray(kerr);
  191. auto write = vtkXMLHyperOctreeWriter::New();
  192. //write.SetDataModeToAscii()
  193. write->SetInputData(oct);
  194. std::string fname = std::string("octree-") + to_string(ilay)
  195. + std::string("-") + to_string(iq) + std::string(".vto");
  196. write->SetFileName(fname.c_str());
  197. write->Write();
  198. write->Delete();
  199. //kerr->Delete();
  200. kid->Delete();
  201. kr->Delete();
  202. ki->Delete();
  203. km->Delete();
  204. curse->Delete();
  205. oct->Delete();
  206. #else
  207. throw std::runtime_error("IntegrateOnOctreeGrid with vtkOutput requires Lemma with VTK support");
  208. #endif
  209. }
  210. std::cout << "\nVOLSUM=" << VOLSUM << "\tActual=" << Size(0)*Size(1)*Size(2)
  211. << "\tDifference=" << VOLSUM - (Size(0)*Size(1)*Size(2)) << std::endl;
  212. std::cout << "nleaves\t" << nleaves << std::endl;
  213. std::cout << "KSUM\t" << SUM << std::endl;
  214. return SUM;
  215. }
  216. //--------------------------------------------------------------------------------------
  217. // Class: KernelV0
  218. // Method: f
  219. //--------------------------------------------------------------------------------------
  220. Complex KernelV0::f( const Vector3r& r, const Real& volume, const Vector3cr& Ht, const Vector3cr& Hr ) {
  221. //return Complex(volume*Ht.dot(Hr));
  222. return ComputeV0Cell(MU0*Ht, MU0*Hr, volume, 1.0);
  223. }
  224. //--------------------------------------------------------------------------------------
  225. // Class: KernelV0
  226. // Method: ComputeV0Cell
  227. //--------------------------------------------------------------------------------------
  228. Complex KernelV0::ComputeV0Cell(const Vector3cr& Bt,
  229. const Vector3cr& Br, const Real& vol, const Real& phi) {
  230. // Compute the elliptic fields
  231. Vector3r B0hat = SigmaModel->GetMagneticFieldUnitVector();
  232. Vector3r B0 = SigmaModel->GetMagneticField();
  233. // Elliptic representation
  234. EllipticB EBT = EllipticFieldRep(Bt, B0hat);
  235. EllipticB EBR = EllipticFieldRep(Br, B0hat);
  236. // Compute Mn0
  237. Vector3r Mn0 = ComputeMn0(phi, B0);
  238. Real Mn0Abs = Mn0.norm();
  239. // Compute the tipping angle
  240. Real sintheta = std::sin(0.5*GAMMA*Ip*Taup*std::abs(EBT.alpha-EBT.beta));
  241. // Compute phase delay, TODO add transmiiter phase and delay time phase!
  242. Real phase = EBR.zeta+EBT.zeta;
  243. return ComputeV0Cell(EBT, EBR, sintheta, phase, Mn0Abs, vol);
  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. Vector3r B0hat = {1,0,0};
  253. // earth response of receiver adjoint field
  254. Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
  255. Complex PhaseTerm = EBR.bhat.dot(EBT.bhat) +
  256. (B0hat.dot(EBR.bhat.cross(EBT.bhat) ));
  257. return -vol*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
  258. }
  259. //--------------------------------------------------------------------------------------
  260. // Class: KernelV0
  261. // Method: ComputeV0Cell
  262. //--------------------------------------------------------------------------------------
  263. Vector3r KernelV0::ComputeMn0(const Real& Porosity, const Vector3r& B0) {
  264. Real chi_n = NH2O*((GAMMA*GAMMA*HBAR*HBAR)/(4.*KB*Temperature));
  265. return chi_n*Porosity*B0;
  266. }
  267. //--------------------------------------------------------------------------------------
  268. // Class: KernelV0
  269. // Method: ComputeV0Cell
  270. //--------------------------------------------------------------------------------------
  271. EllipticB KernelV0::EllipticFieldRep (const Vector3cr& B, const Vector3r& B0hat) {
  272. EllipticB ElipB = EllipticB();
  273. Vector3cr Bperp = B.array() - B0hat.dot(B)*B0hat.array();
  274. Real BperpNorm = Bperp.norm();
  275. Complex Bp2 = Bperp.transpose() * Bperp;
  276. VectorXcr iB0 = Complex(0,1)*B0hat.cast<Complex>().array();
  277. ElipB.eizt = std::sqrt(Bp2 / std::abs(Bp2));
  278. ElipB.alpha = INVSQRT2*std::sqrt(BperpNorm*BperpNorm + std::abs(Bp2));
  279. ElipB.beta = sgn(std::real(iB0.dot(Bperp.cross(Bperp.conjugate())))) *
  280. (INVSQRT2)*std::sqrt(std::abs(BperpNorm*BperpNorm-std::abs(Bp2)));
  281. ElipB.bhat = ((Real)1./ElipB.alpha)*(((Real)1./ElipB.eizt)*Bperp.array()).real().array();
  282. ElipB.bhatp = B0hat.cross(ElipB.bhat);
  283. ElipB.zeta = std::real(std::log(ElipB.eizt)/Complex(0,1));
  284. return ElipB;
  285. }
  286. //--------------------------------------------------------------------------------------
  287. // Class: KernelV0
  288. // Method: EvaluateKids
  289. //--------------------------------------------------------------------------------------
  290. bool KernelV0::EvaluateKids( const Vector3r& size, const int& level, const Vector3r& cpos,
  291. const Complex& parentVal ) {
  292. std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
  293. std::cout.flush();
  294. // Next level step, interested in one level below
  295. // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
  296. Vector3r step = size.array() / (Real)(1 << (level+1) );
  297. Vector3r step2 = size.array() / (Real)(1 << (level+2) );
  298. Real vol = (step2(0)*step2(1)*step2(2)); // volume of each child
  299. Vector3r pos = cpos - step/2.;
  300. Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
  301. 0, 0, 0,
  302. step[0], 0, 0,
  303. 0, step[1], 0,
  304. step[0], step[1], 0,
  305. 0, 0, step[2],
  306. step[0], 0, step[2],
  307. 0, step[1], step[2],
  308. step[0], step[1], step[2] ).finished();
  309. VectorXcr kvals(8); // individual kernel vals
  310. cpoints->ClearFields();
  311. for (int ichild=0; ichild<8; ++ichild) {
  312. Vector3r cp = pos; // Eigen complains about combining these
  313. cp += posadd.row(ichild);
  314. cpoints->SetLocation( ichild, cp );
  315. }
  316. Eigen::Matrix<Complex, 3, 8> Ht = Eigen::Matrix<Complex, 3, 8>::Zero();
  317. Eigen::Matrix<Complex, 3, 8> Hr = Eigen::Matrix<Complex, 3, 8>::Zero();
  318. //Eigen::Matrix< Complex, 8, 3 > Bt;
  319. for ( auto EMCalc : EMEarths ) {
  320. //EMCalc->GetFieldPoints()->ClearFields();
  321. EMCalc.second->CalculateWireAntennaFields();
  322. switch (EMCalc.second->GetTxRxMode()) {
  323. case TX:
  324. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  325. break;
  326. case RX:
  327. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  328. break;
  329. case TXRX:
  330. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  331. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  332. break;
  333. default:
  334. break;
  335. }
  336. }
  337. for (int ichild=0; ichild<8; ++ichild) {
  338. Vector3r cp = pos; // Eigen complains about combining these
  339. cp += posadd.row(ichild);
  340. kvals(ichild) = f(cp, vol, Ht.col(ichild), Hr.col(ichild));
  341. }
  342. Complex ksum = kvals.sum(); // Kernel sum
  343. // Evaluate whether or not furthur splitting is needed
  344. if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
  345. for (int ichild=0; ichild<8; ++ichild) {
  346. Vector3r cp = pos; // Eigen complains about combining these
  347. cp += posadd.row(ichild);
  348. bool isleaf = EvaluateKids( size, level+1, cp, kvals(ichild) );
  349. if (isleaf) { // Include result in final integral
  350. SUM += ksum;
  351. VOLSUM += 8.*vol;
  352. nleaves += 1;
  353. }
  354. }
  355. return false; // not leaf
  356. }
  357. // Save here instead?
  358. return true; // leaf
  359. }
  360. #ifdef LEMMAUSEVTK
  361. //--------------------------------------------------------------------------------------
  362. // Class: KernelV0
  363. // Method: EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
  364. //--------------------------------------------------------------------------------------
  365. bool KernelV0::EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
  366. const Complex& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
  367. std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
  368. std::cout.flush();
  369. // Next level step, interested in one level below
  370. // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
  371. Vector3r step = size.array() / (Real)(1 << (level+1) );
  372. Real vol = (step(0)*step(1)*step(2)); // volume of each child
  373. Vector3r step2 = size.array() / (Real)(1 << (level+2) );
  374. Real vol2 = (step2(0)*step2(1)*step2(2)); // volume of each child
  375. Vector3r pos = cpos - step/2.;
  376. Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
  377. 0, 0, 0,
  378. step[0], 0, 0,
  379. 0, step[1], 0,
  380. step[0], step[1], 0,
  381. 0, 0, step[2],
  382. step[0], 0, step[2],
  383. 0, step[1], step[2],
  384. step[0], step[1], step[2] ).finished();
  385. VectorXcr kvals(8); // individual kernel vals
  386. cpoints->ClearFields();
  387. for (int ichild=0; ichild<8; ++ichild) {
  388. Vector3r cp = pos; // Eigen complains about combining these
  389. cp += posadd.row(ichild);
  390. cpoints->SetLocation( ichild, cp );
  391. }
  392. Eigen::Matrix<Complex, 3, 8> Ht = Eigen::Matrix<Complex, 3, 8>::Zero();
  393. Eigen::Matrix<Complex, 3, 8> Hr = Eigen::Matrix<Complex, 3, 8>::Zero();
  394. for ( auto EMCalc : EMEarths ) {
  395. //EMCalc->GetFieldPoints()->ClearFields();
  396. EMCalc.second->CalculateWireAntennaFields();
  397. switch (EMCalc.second->GetTxRxMode()) {
  398. case TX:
  399. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  400. break;
  401. case RX:
  402. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  403. break;
  404. case TXRX:
  405. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  406. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  407. break;
  408. default:
  409. break;
  410. }
  411. }
  412. for (int ichild=0; ichild<8; ++ichild) {
  413. Vector3r cp = pos; // Eigen complains about combining these
  414. cp += posadd.row(ichild);
  415. kvals(ichild) = f(cp, vol, Ht.col(ichild), Hr.col(ichild));
  416. }
  417. Complex ksum = kvals.sum(); // Kernel sum
  418. // Evaluate whether or not furthur splitting is needed
  419. if ( std::abs(ksum-parentVal) > tol ) { // || level < minLevel && level < maxLevel ) {
  420. //if ( std::abs(ksum.real()-parentVal.real())>tol || std::abs(ksum.imag()-parentVal.imag()) >tol ) {
  421. //if ( std::abs(ksum) > tol && level < maxLevel ) {
  422. oct->SubdivideLeaf(curse);
  423. for (int ichild=0; ichild<8; ++ichild) {
  424. curse->ToChild(ichild);
  425. Vector3r cp = pos; // Eigen complains about combining these
  426. cp += posadd.row(ichild);
  427. /* Test for position via alternative means */
  428. /*
  429. Real p[3];
  430. GetPosition(curse, p);
  431. if ( (Vector3r(p) - cp).norm() > 1e-8 ) {
  432. std::cout << "ERROR @ nleaves" << nleaves << "\n" << cp[0] << "\t" << p[0] << "\t" << cp[1] << "\t" << p[1]
  433. << "\t" << cp[2] << "\t" << p[2] << "\t" << vol<< std::endl;
  434. throw std::runtime_error("doom");
  435. }
  436. */
  437. /* End of position test */
  438. bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
  439. /*
  440. if (isleaf) { // Include result in final integral
  441. LeafDict[curse->GetLeafId()] = ksum/(8.*vol); //kvals(ichild) / vol; // VTK
  442. LeafDictIdx[curse->GetLeafId()] = nleaves; // VTK
  443. SUM += ksum;
  444. VOLSUM += 8*vol;
  445. nleaves += 1;
  446. }
  447. */
  448. curse->ToParent();
  449. }
  450. return false; // not leaf
  451. }
  452. LeafDict[curse->GetLeafId()] = ksum/(8.*vol); //kvals(ichild) / vol; // VTK
  453. LeafDictIdx[curse->GetLeafId()] = nleaves; // VTK
  454. SUM += ksum;
  455. VOLSUM += 8*vol;
  456. nleaves += 1;
  457. return true; // leaf
  458. }
  459. //--------------------------------------------------------------------------------------
  460. // Class: KernelV0
  461. // Method: GetPosition
  462. //--------------------------------------------------------------------------------------
  463. void KernelV0::GetPosition( vtkHyperOctreeCursor* Cursor, Real* p ) {
  464. Real ratio=1.0/(1<<(Cursor->GetCurrentLevel()));
  465. //step = ((Size).array() / std::pow(2.,Cursor->GetCurrentLevel()));
  466. p[0]=(Cursor->GetIndex(0)+.5)*ratio*this->Size[0]+this->Origin[0] ;//+ .5*step[0];
  467. p[1]=(Cursor->GetIndex(1)+.5)*ratio*this->Size[1]+this->Origin[1] ;//+ .5*step[1];
  468. p[2]=(Cursor->GetIndex(2)+.5)*ratio*this->Size[2]+this->Origin[2] ;//+ .5*step[2];
  469. }
  470. #endif
  471. } // ---- end of namespace Lemma ----
  472. /* vim: set tabstop=4 expandtab */
  473. /* vim: set filetype=cpp */