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()-1; ++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 = (Size-Origin).array() / 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. for (auto leaf : LeafDict) {
  175. kr->InsertTuple1( leaf.first, std::real(leaf.second) );
  176. ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
  177. km->InsertTuple1( leaf.first, std::abs(leaf.second) );
  178. kid->InsertTuple1( leaf.first, leaf.first );
  179. }
  180. for (auto leaf : LeafDictIdx) {
  181. kerr->InsertTuple1( leaf.first, leaf.second );
  182. }
  183. oct->GetLeafData()->AddArray(kr);
  184. oct->GetLeafData()->AddArray(ki);
  185. oct->GetLeafData()->AddArray(km);
  186. oct->GetLeafData()->AddArray(kid);
  187. oct->GetLeafData()->AddArray(kerr);
  188. auto write = vtkXMLHyperOctreeWriter::New();
  189. //write.SetDataModeToAscii()
  190. write->SetInputData(oct);
  191. std::string fname = std::string("octree-") + to_string(ilay)
  192. + std::string("-") + to_string(iq) + std::string(".vto");
  193. write->SetFileName(fname.c_str());
  194. write->Write();
  195. write->Delete();
  196. //kerr->Delete();
  197. kid->Delete();
  198. kr->Delete();
  199. ki->Delete();
  200. km->Delete();
  201. curse->Delete();
  202. oct->Delete();
  203. #else
  204. throw std::runtime_error("IntegrateOnOctreeGrid with vtkOutput requires Lemma with VTK support");
  205. #endif
  206. }
  207. std::cout << "\nVOLSUM=" << VOLSUM << "\tActual=" << Size(0)*Size(1)*Size(2)
  208. << "\tDifference=" << VOLSUM - (Size(0)*Size(1)*Size(2)) << std::endl;
  209. std::cout << "nleaves\t" << nleaves << std::endl;
  210. std::cout << "KSUM\t" << SUM << std::endl;
  211. return SUM;
  212. }
  213. //--------------------------------------------------------------------------------------
  214. // Class: KernelV0
  215. // Method: f
  216. //--------------------------------------------------------------------------------------
  217. Complex KernelV0::f( const Vector3r& r, const Real& volume, const Vector3cr& Ht, const Vector3cr& Hr ) {
  218. //return Complex(volume*Ht.dot(Hr));
  219. return ComputeV0Cell(MU0*Ht, MU0*Hr, volume, 1.0);
  220. }
  221. //--------------------------------------------------------------------------------------
  222. // Class: KernelV0
  223. // Method: ComputeV0Cell
  224. //--------------------------------------------------------------------------------------
  225. Complex KernelV0::ComputeV0Cell(const Vector3cr& Bt,
  226. const Vector3cr& Br, const Real& vol, const Real& phi) {
  227. // Compute the elliptic fields
  228. Vector3r B0hat = SigmaModel->GetMagneticFieldUnitVector();
  229. Vector3r B0 = SigmaModel->GetMagneticField();
  230. // Elliptic representation
  231. EllipticB EBT = EllipticFieldRep(Bt, B0hat);
  232. EllipticB EBR = EllipticFieldRep(Br, B0hat);
  233. // Compute Mn0
  234. Vector3r Mn0 = ComputeMn0(phi, B0);
  235. Real Mn0Abs = Mn0.norm();
  236. // Compute the tipping angle
  237. Real sintheta = std::sin(0.5*GAMMA*Ip*Taup*std::abs(EBT.alpha-EBT.beta));
  238. // Compute phase delay, TODO add transmiiter phase and delay time phase!
  239. Real phase = EBR.zeta+EBT.zeta;
  240. return ComputeV0Cell(EBT, EBR, sintheta, phase, Mn0Abs, vol);
  241. }
  242. //--------------------------------------------------------------------------------------
  243. // Class: KernelV0
  244. // Method: ComputeV0Cell
  245. //--------------------------------------------------------------------------------------
  246. Complex KernelV0::ComputeV0Cell(const EllipticB& EBT, const EllipticB& EBR,
  247. const Real& sintheta, const Real& phase, const Real& Mn0Abs,
  248. const Real& vol) {
  249. Vector3r B0hat = {1,0,0};
  250. // earth response of receiver adjoint field
  251. Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
  252. Complex PhaseTerm = EBR.bhat.dot(EBT.bhat) +
  253. (B0hat.dot(EBR.bhat.cross(EBT.bhat) ));
  254. return -vol*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
  255. }
  256. //--------------------------------------------------------------------------------------
  257. // Class: KernelV0
  258. // Method: ComputeV0Cell
  259. //--------------------------------------------------------------------------------------
  260. Vector3r KernelV0::ComputeMn0(const Real& Porosity, const Vector3r& B0) {
  261. Real chi_n = NH2O*((GAMMA*GAMMA*HBAR*HBAR)/(4.*KB*Temperature));
  262. return chi_n*Porosity*B0;
  263. }
  264. //--------------------------------------------------------------------------------------
  265. // Class: KernelV0
  266. // Method: ComputeV0Cell
  267. //--------------------------------------------------------------------------------------
  268. EllipticB KernelV0::EllipticFieldRep (const Vector3cr& B, const Vector3r& B0hat) {
  269. EllipticB ElipB = EllipticB();
  270. Vector3cr Bperp = B.array() - B0hat.dot(B)*B0hat.array();
  271. Real BperpNorm = Bperp.norm();
  272. Complex Bp2 = Bperp.transpose() * Bperp;
  273. VectorXcr iB0 = Complex(0,1)*B0hat.cast<Complex>().array();
  274. ElipB.eizt = std::sqrt(Bp2 / std::abs(Bp2));
  275. ElipB.alpha = INVSQRT2*std::sqrt(BperpNorm*BperpNorm + std::abs(Bp2));
  276. ElipB.beta = sgn(std::real(iB0.dot(Bperp.cross(Bperp.conjugate())))) *
  277. (INVSQRT2)*std::sqrt(std::abs(BperpNorm*BperpNorm-std::abs(Bp2)));
  278. ElipB.bhat = ((Real)1./ElipB.alpha)*(((Real)1./ElipB.eizt)*Bperp.array()).real().array();
  279. ElipB.bhatp = B0hat.cross(ElipB.bhat);
  280. ElipB.zeta = std::real(std::log(ElipB.eizt)/Complex(0,1));
  281. return ElipB;
  282. }
  283. //--------------------------------------------------------------------------------------
  284. // Class: KernelV0
  285. // Method: EvaluateKids
  286. //--------------------------------------------------------------------------------------
  287. bool KernelV0::EvaluateKids( const Vector3r& size, const int& level, const Vector3r& cpos,
  288. const Complex& parentVal ) {
  289. std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
  290. std::cout.flush();
  291. // Next level step, interested in one level below
  292. // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
  293. Vector3r step = size.array() / (Real)(1 << (level+1) );
  294. Vector3r step2 = size.array() / (Real)(1 << (level+2) );
  295. Real vol = (step2(0)*step2(1)*step2(2)); // volume of each child
  296. Vector3r pos = cpos - step/2.;
  297. Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
  298. 0, 0, 0,
  299. step[0], 0, 0,
  300. 0, step[1], 0,
  301. step[0], step[1], 0,
  302. 0, 0, step[2],
  303. step[0], 0, step[2],
  304. 0, step[1], step[2],
  305. step[0], step[1], step[2] ).finished();
  306. VectorXcr kvals(8); // individual kernel vals
  307. cpoints->ClearFields();
  308. for (int ichild=0; ichild<8; ++ichild) {
  309. Vector3r cp = pos; // Eigen complains about combining these
  310. cp += posadd.row(ichild);
  311. cpoints->SetLocation( ichild, cp );
  312. }
  313. Eigen::Matrix<Complex, 3, 8> Ht = Eigen::Matrix<Complex, 3, 8>::Zero();
  314. Eigen::Matrix<Complex, 3, 8> Hr = Eigen::Matrix<Complex, 3, 8>::Zero();
  315. //Eigen::Matrix< Complex, 8, 3 > Bt;
  316. for ( auto EMCalc : EMEarths ) {
  317. //EMCalc->GetFieldPoints()->ClearFields();
  318. EMCalc.second->CalculateWireAntennaFields();
  319. switch (EMCalc.second->GetTxRxMode()) {
  320. case TX:
  321. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  322. break;
  323. case RX:
  324. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  325. break;
  326. case TXRX:
  327. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  328. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  329. break;
  330. default:
  331. break;
  332. }
  333. }
  334. for (int ichild=0; ichild<8; ++ichild) {
  335. Vector3r cp = pos; // Eigen complains about combining these
  336. cp += posadd.row(ichild);
  337. kvals(ichild) = f(cp, vol, Ht.col(ichild), Hr.col(ichild));
  338. }
  339. Complex ksum = kvals.sum(); // Kernel sum
  340. // Evaluate whether or not furthur splitting is needed
  341. if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
  342. for (int ichild=0; ichild<8; ++ichild) {
  343. Vector3r cp = pos; // Eigen complains about combining these
  344. cp += posadd.row(ichild);
  345. bool isleaf = EvaluateKids( size, level+1, cp, kvals(ichild) );
  346. if (isleaf) { // Include result in final integral
  347. SUM += ksum;
  348. VOLSUM += 8.*vol;
  349. nleaves += 1;
  350. }
  351. }
  352. return false; // not leaf
  353. }
  354. // Save here instead?
  355. return true; // leaf
  356. }
  357. #ifdef LEMMAUSEVTK
  358. //--------------------------------------------------------------------------------------
  359. // Class: KernelV0
  360. // Method: EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
  361. //--------------------------------------------------------------------------------------
  362. bool 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. Vector3r step2 = size.array() / (Real)(1 << (level+2) );
  370. Real vol = (step2(0)*step2(1)*step2(2)); // volume of each child
  371. Vector3r pos = cpos - step/2.;
  372. Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
  373. 0, 0, 0,
  374. step[0], 0, 0,
  375. 0, step[1], 0,
  376. step[0], step[1], 0,
  377. 0, 0, step[2],
  378. step[0], 0, step[2],
  379. 0, step[1], step[2],
  380. step[0], step[1], step[2] ).finished();
  381. VectorXcr kvals(8); // individual kernel vals
  382. cpoints->ClearFields();
  383. for (int ichild=0; ichild<8; ++ichild) {
  384. Vector3r cp = pos; // Eigen complains about combining these
  385. cp += posadd.row(ichild);
  386. cpoints->SetLocation( ichild, cp );
  387. }
  388. Eigen::Matrix<Complex, 3, 8> Ht = Eigen::Matrix<Complex, 3, 8>::Zero();
  389. Eigen::Matrix<Complex, 3, 8> Hr = Eigen::Matrix<Complex, 3, 8>::Zero();
  390. for ( auto EMCalc : EMEarths ) {
  391. //EMCalc->GetFieldPoints()->ClearFields();
  392. EMCalc.second->CalculateWireAntennaFields();
  393. switch (EMCalc.second->GetTxRxMode()) {
  394. case TX:
  395. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  396. break;
  397. case RX:
  398. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  399. break;
  400. case TXRX:
  401. Ht += EMCalc.second->GetFieldPoints()->GetHfield(0);
  402. Hr += EMCalc.second->GetFieldPoints()->GetHfield(0);
  403. break;
  404. default:
  405. break;
  406. }
  407. }
  408. for (int ichild=0; ichild<8; ++ichild) {
  409. Vector3r cp = pos; // Eigen complains about combining these
  410. cp += posadd.row(ichild);
  411. kvals(ichild) = f(cp, vol, Ht.col(ichild), Hr.col(ichild));
  412. }
  413. Complex ksum = kvals.sum(); // Kernel sum
  414. // Evaluate whether or not furthur splitting is needed
  415. Real err = std::abs(ksum - parentVal);
  416. if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
  417. oct->SubdivideLeaf(curse);
  418. for (int ichild=0; ichild<8; ++ichild) {
  419. curse->ToChild(ichild);
  420. Vector3r cp = pos; // Eigen complains about combining these
  421. cp += posadd.row(ichild);
  422. /* Test for position via alternative means
  423. Real p[3];
  424. GetPosition(curse, p);
  425. std::cout << cp[0] << "\t" << p[0] << "\t" << cp[1] << "\t" << p[1]
  426. << "\t" << cp[2] << "\t" << p[2] << "\t" << vol<< std::endl;
  427. */
  428. bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
  429. if (isleaf) { // Include result in final integral
  430. LeafDict[curse->GetLeafId()] = kvals(ichild); // VTK
  431. LeafDictIdx[curse->GetLeafId()] = nleaves; // VTK
  432. SUM += ksum;
  433. VOLSUM += 8*vol;
  434. nleaves += 1;
  435. }
  436. curse->ToParent();
  437. }
  438. return false; // not leaf
  439. }
  440. return true; // leaf
  441. }
  442. //--------------------------------------------------------------------------------------
  443. // Class: KernelV0
  444. // Method: GetPosition
  445. //--------------------------------------------------------------------------------------
  446. void KernelV0::GetPosition( vtkHyperOctreeCursor* Cursor, Real* p ) {
  447. Real ratio=1.0/(1<<(Cursor->GetCurrentLevel()));
  448. //step = ((Size).array() / std::pow(2.,Cursor->GetCurrentLevel()));
  449. p[0]=(Cursor->GetIndex(0)+.5)*ratio*this->Size[0]+this->Origin[0] ;//+ .5*step[0];
  450. p[1]=(Cursor->GetIndex(1)+.5)*ratio*this->Size[1]+this->Origin[1] ;//+ .5*step[1];
  451. p[2]=(Cursor->GetIndex(2)+.5)*ratio*this->Size[2]+this->Origin[2] ;//+ .5*step[2];
  452. }
  453. #endif
  454. } // ---- end of namespace Lemma ----
  455. /* vim: set tabstop=4 expandtab */
  456. /* vim: set filetype=cpp */