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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. void 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. Real vol = (step(0)*step(1)*step(2)); // volume of each child
  298. Vector3r pos = cpos - step/2.;
  299. Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
  300. 0, 0, 0,
  301. step[0], 0, 0,
  302. 0, step[1], 0,
  303. step[0], step[1], 0,
  304. 0, 0, step[2],
  305. step[0], 0, step[2],
  306. 0, step[1], step[2],
  307. step[0], step[1], step[2] ).finished();
  308. VectorXcr kvals(8); // individual kernel vals
  309. cpoints->ClearFields();
  310. for (int ichild=0; ichild<8; ++ichild) {
  311. Vector3r cp = pos; // Eigen complains about combining these
  312. cp += posadd.row(ichild);
  313. cpoints->SetLocation( ichild, cp );
  314. }
  315. Eigen::Matrix<Complex, 3, 8> Ht = Eigen::Matrix<Complex, 3, 8>::Zero();
  316. Eigen::Matrix<Complex, 3, 8> Hr = Eigen::Matrix<Complex, 3, 8>::Zero();
  317. //Eigen::Matrix< Complex, 8, 3 > Bt;
  318. for ( auto EMCalc : EMEarths ) {
  319. //EMCalc->GetFieldPoints()->ClearFields();
  320. EMCalc.second->CalculateWireAntennaFields();
  321. switch (EMCalc.second->GetTxRxMode()) {
  322. case TX:
  323. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  324. break;
  325. case RX:
  326. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  327. break;
  328. case TXRX:
  329. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  330. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  331. break;
  332. default:
  333. break;
  334. }
  335. }
  336. for (int ichild=0; ichild<8; ++ichild) {
  337. Vector3r cp = pos; // Eigen complains about combining these
  338. cp += posadd.row(ichild);
  339. kvals(ichild) = f(cp, vol, Ht.col(ichild), Hr.col(ichild));
  340. }
  341. Complex ksum = kvals.sum(); // Kernel sum
  342. // Evaluate whether or not furthur splitting is needed
  343. if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
  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(ichild) );
  348. }
  349. return; // not leaf
  350. }
  351. // Save here instead?
  352. SUM += 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 Complex& 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. VectorXcr kvals(8); // 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(ichild) = f(cp, vol, Ht.col(ichild), Hr.col(ichild));
  411. }
  412. Complex ksum = kvals.sum(); // Kernel sum
  413. // Evaluate whether or not furthur splitting is needed
  414. if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
  415. //if ( std::abs(ksum.real()-parentVal.real())>tol || std::abs(ksum.imag()-parentVal.imag()) >tol ) {
  416. oct->SubdivideLeaf(curse);
  417. for (int ichild=0; ichild<8; ++ichild) {
  418. curse->ToChild(ichild);
  419. Vector3r cp = pos; // Eigen complains about combining these
  420. cp += posadd.row(ichild);
  421. /* Test for position via alternative means */
  422. /*
  423. Real p[3];
  424. GetPosition(curse, p);
  425. if ( (Vector3r(p) - cp).norm() > 1e-8 ) {
  426. std::cout << "ERROR @ nleaves" << nleaves << "\n" << cp[0] << "\t" << p[0] << "\t" << cp[1] << "\t" << p[1]
  427. << "\t" << cp[2] << "\t" << p[2] << "\t" << vol<< std::endl;
  428. throw std::runtime_error("doom");
  429. }
  430. */
  431. /* End of position test */
  432. EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
  433. curse->ToParent();
  434. }
  435. return; // not a leaf
  436. }
  437. LeafDict[curse->GetLeafId()] = ksum/(8.*vol); //kvals(ichild) / vol; // VTK
  438. LeafDictIdx[curse->GetLeafId()] = nleaves; // VTK
  439. SUM += ksum;
  440. VOLSUM += 8*vol;
  441. nleaves += 1;
  442. return; // is a leaf
  443. }
  444. //--------------------------------------------------------------------------------------
  445. // Class: KernelV0
  446. // Method: GetPosition
  447. //--------------------------------------------------------------------------------------
  448. void KernelV0::GetPosition( vtkHyperOctreeCursor* Cursor, Real* p ) {
  449. Real ratio=1.0/(1<<(Cursor->GetCurrentLevel()));
  450. //step = ((Size).array() / std::pow(2.,Cursor->GetCurrentLevel()));
  451. p[0]=(Cursor->GetIndex(0)+.5)*ratio*this->Size[0]+this->Origin[0] ;//+ .5*step[0];
  452. p[1]=(Cursor->GetIndex(1)+.5)*ratio*this->Size[1]+this->Origin[1] ;//+ .5*step[1];
  453. p[2]=(Cursor->GetIndex(2)+.5)*ratio*this->Size[2]+this->Origin[2] ;//+ .5*step[2];
  454. }
  455. #endif
  456. } // ---- end of namespace Lemma ----
  457. /* vim: set tabstop=4 expandtab */
  458. /* vim: set filetype=cpp */