CElement.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace OTSDataType
  7. {
  8. public static class GlobalMembersElement
  9. {
  10. public static readonly string[] ELEMENT_NAMES = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hq", "TI", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Mc", "No", "Lr" };
  11. public static readonly double[] ELEMENT_ATOMIC_WEIGHT_VALUES =
  12. {
  13. 1.008,4.003,
  14. 6.941,9.012,10.811,12.011,14.007,15.999,18.998,20.180,
  15. 22.990,24.305,26.982,28.086,30.974,32.066,35.453,39.948,
  16. 39.098,40.08,44.956,47.88,50.942,51.996,54.938,55.847,58.933,58.70,63.546,65.39,69.72,72.61,74.922,78.96,79.904,83.80,
  17. 85.468,87.62,88.906,91.22,92.906,95.94,98.00,101.07,102.906,106.42,107.868,112.41,114.82,118.71,121.76,127.60,126.905,131.29,
  18. 132.905,137.33,138.906,
  19. 140.12,140.908,144.24,145.0,150.36,151.97,157.25,158.925,162.50,64.93,167.26,168.934,173.04,174.967,
  20. 178.49,180.948,183.85,186.207,190.20,192.22,195.08,196.967,200.59,204.38,207.2,208.980,209.00,210.00,222.00,
  21. 223.00,226.025,227.028,
  22. };
  23. public static readonly double[] ELEMENT_ENERGY_VALUES_K =
  24. {
  25. 0.0,0.0,
  26. 0.0,0.108,0.185,0.277,0.392,0.523,0.677,0.848,
  27. 1.040,1.254,1.486,1.740,2.013,2.307,2.622,2.957,
  28. 2.313,3.691,4.090,4.510,4.952,5.414,5.898,6.403,6.929,7.477,8.040,8.637,9.250,9.885,10.542,11.220,11.922,12.649,
  29. 13.393,14.163,14.955,15.776,16.617,17.481,18.368,19.282,20.217,21.180,22.166,23.175,24.209,25.272,26.359,27.471,28.615,29.779,
  30. 30.971,32.196,33.441,
  31. 34.717,36.031,37.358,38.725,40.118,41.534,42.992,44.476,45.997,47.534,49.100,50.730,52.362,54.078,
  32. 55.801,57.450,59.305,61.122,62.989,64.906,66.834,68.804,70.806,72.769,74.989,77.091,79.272,81.513,83.771,
  33. 86.098,88.480,90.880,
  34. 93.382,95.886,98.434,100.800,103.320,105.970,109.737,111.676,114.776,0.0,0.0,0.0,0.0,0.0
  35. };
  36. public static readonly double[] ELEMENT_ENERGY_VALUES_L =
  37. {
  38. 0.0,0.0,
  39. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  40. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  41. 0.0,0.341,0.395,0.452,0.511,0.573,0.637,0.705,0.776,0.851,0.930,1.012,1.098,1.188,1.282,1.379,1.480,1.586,
  42. 1.694,1.806,1.922,2.042,2.166,2.293,2.424,2.558,2.696,2.838,2.984,3.133,3.286,3.443,3.604,3.768,3.937,4.109,
  43. 4.286,4.465,4.650,
  44. 4.839,5.033,5.229,5.432,5.636,5.845,6.056,6.272,6.494,6.719,6.947,7.179,7.414,7.654,
  45. 7.898,8.145,8.396,8.651,8.910,9.174,9.441,9.712,9.987,10.256,10.550,10.837,11.129,11.425,11.725,
  46. 12.029,12.338,12.650,
  47. 12.967,13.288,13.612,13.941,14.275,14.615,14.961,15.309,15.661,16.018,0.0,0.0,0.0,0.0
  48. };
  49. public static readonly double[] ELEMENT_ENERGY_VALUES_M =
  50. {
  51. 0.0,0.0,
  52. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  53. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  54. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  55. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  56. 0.0,0.779,0.833,
  57. 0.883,0.929,0.978,1.032,1.081,1.137,1.185,1.240,1.293,1.347,1.405,1.462,1.521,1.581,
  58. 1.644,1.709,1.774,1.842,1.910,1.978,2.048,2.120,2.191,2.268,2.342,2.419,2.505,2.585,2.665,
  59. 2.747,2.830,2.915,
  60. 2.991,3.077,3.165,3.253,3.344,3.435,3.539,3.634,3.731,3.829,0.0,0.0,0.0,0.0
  61. };
  62. }
  63. public class CElementChemistry
  64. {
  65. // name
  66. protected string m_strName;
  67. // percentage (element)
  68. public double m_dPercentage;
  69. public CElementChemistry() // constructor
  70. {
  71. // initialization
  72. Init();
  73. }
  74. public CElementChemistry(string a_strName, double a_dPercentage) // constructor
  75. {
  76. m_strName = a_strName;
  77. m_dPercentage = a_dPercentage;
  78. }
  79. // copy constructor
  80. public CElementChemistry(CElementChemistry a_oSource)
  81. {
  82. // can't copy itself
  83. if (a_oSource == this)
  84. {
  85. return;
  86. }
  87. // copy data over
  88. Duplicate(a_oSource);
  89. }
  90. //c#无指针
  91. //CElementChemistry(CElementChemistry*); // copy constructor
  92. // ==operator
  93. //public static bool operator ==(CElementChemistry ImpliedObject, CElementChemistry a_oSource)
  94. //{
  95. // // return test result
  96. // return String.Compare(ImpliedObject.m_strName,a_oSource.m_strName) == 0 && Math.Abs(ImpliedObject.m_dPercentage - a_oSource.m_dPercentage) < 0.00000000001;
  97. //}
  98. //// ==和!= 重载必须成对出现
  99. //public static bool operator !=(CElementChemistry ImpliedObject, CElementChemistry a_oSource)
  100. //{
  101. // // return test result
  102. // return String.Compare(ImpliedObject.m_strName,a_oSource.m_strName) != 0 || Math.Abs(ImpliedObject.m_dPercentage - a_oSource.m_dPercentage) < 0.00000000001;
  103. //}
  104. public bool Equals(CElementChemistry a_oSource)
  105. {
  106. // return test result
  107. return String.Compare(m_strName, a_oSource.m_strName) == 0 && Math.Abs(m_dPercentage - a_oSource.m_dPercentage) < otsdataconst.MIN_DOUBLE_VALUE;
  108. }
  109. //无实际操作
  110. //virtual ~CElementChemistry(); // detractor
  111. // serialization
  112. //void Serialize(bool isStoring, tinyxml2::XMLDocument* classDoc, tinyxml2::XMLElement* rootNode);
  113. // name
  114. public string GetName()
  115. {
  116. return m_strName;
  117. }
  118. public void SetName(string a_strName)
  119. {
  120. m_strName = a_strName;
  121. }
  122. // percentage
  123. public double GetPercentage()
  124. {
  125. return m_dPercentage;
  126. }
  127. public void SetPercentage(double a_dPercentage)
  128. {
  129. m_dPercentage = a_dPercentage;
  130. }
  131. // MolarRatio
  132. public double GetMolarPercentage()
  133. {
  134. // molar percentage
  135. double dMolarPercentage = 0.0;
  136. // get atomic weight of the element
  137. double dAtomWeight = CElement.GetAtomWeight(m_strName);
  138. // make sure atomic weight is valid
  139. if (dAtomWeight > 0.0)
  140. {
  141. // calculate molar percentage
  142. dMolarPercentage = m_dPercentage / dAtomWeight;
  143. }
  144. return dMolarPercentage;
  145. }
  146. public void SetMolarPercentage(double a_dMolarPer)
  147. {
  148. // get atomic weight of the element
  149. double dAtomWeight = CElement.GetAtomWeight(m_strName);
  150. // set percentage
  151. m_dPercentage = a_dMolarPer * dAtomWeight / 100.0;
  152. }
  153. // cleanup
  154. protected void Cleanup()
  155. {
  156. // nothing needs to be done at the moment
  157. }
  158. // initialization
  159. protected void Init()
  160. {
  161. m_strName = "";
  162. m_dPercentage = 0.0;
  163. }
  164. // duplication
  165. protected void Duplicate(CElementChemistry a_oSource)
  166. {
  167. // initialization
  168. Init();
  169. // copy data over
  170. m_strName = a_oSource.m_strName;
  171. m_dPercentage = a_oSource.m_dPercentage;
  172. }
  173. }
  174. public class CElementArea
  175. {
  176. // element chemistry list
  177. protected List<CElementChemistry> m_listCElementChemistries = new List<CElementChemistry>();
  178. // area (element)
  179. protected double m_dArea;
  180. public CElementArea()
  181. {
  182. // initialization
  183. Init();
  184. }
  185. public CElementArea(CElementArea a_oSource)
  186. {
  187. // can't copy itself
  188. if (a_oSource == this)
  189. {
  190. return;
  191. }
  192. // copy data over
  193. Duplicate(a_oSource);
  194. }
  195. //CElementArea(CElementArea*); // copy constructor
  196. //public CElementArea CopyFrom(CElementArea a_oSource) //CElementArea& operator=(const CElementArea&); // =operator
  197. //{
  198. // // cleanup
  199. // Cleanup();
  200. // // copy the class data over
  201. // Duplicate(a_oSource);
  202. // // return class
  203. // return this;
  204. //}
  205. public virtual void Dispose() //virtual ~CElementArea(); // detractor
  206. {
  207. Cleanup();
  208. }
  209. //public static bool operator ==(CElementArea ImpliedObject, CElementArea a_oSource)
  210. //{
  211. // // element chemistry list
  212. // if ((int)ImpliedObject.m_listCElementChemistries.Count() != (int)a_oSource.m_listCElementChemistries.Count())
  213. // {
  214. // return false;
  215. // }
  216. // for (int i = 0; i < (int)ImpliedObject.m_listCElementChemistries.Count(); i++)
  217. // {
  218. // if (!(ImpliedObject.m_listCElementChemistries[i] == a_oSource.m_listCElementChemistries[i]))
  219. // {
  220. // return false;
  221. // }
  222. // }
  223. // if (Math.Abs(ImpliedObject.m_dArea - a_oSource.m_dArea) >= 0.00000000001)
  224. // {
  225. // return false;
  226. // }
  227. // return true;
  228. //}
  229. //public static bool operator !=(CElementArea ImpliedObject, CElementArea a_oSource)
  230. //{
  231. // // element chemistry list
  232. // if ((int)ImpliedObject.m_listCElementChemistries.Count() != (int)a_oSource.m_listCElementChemistries.Count())
  233. // {
  234. // return true;
  235. // }
  236. // for (int i = 0; i < (int)ImpliedObject.m_listCElementChemistries.Count(); i++)
  237. // {
  238. // if (!(ImpliedObject.m_listCElementChemistries[i] == a_oSource.m_listCElementChemistries[i]))
  239. // {
  240. // return true;
  241. // }
  242. // }
  243. // if(Math.Abs(ImpliedObject.m_dArea - a_oSource.m_dArea) >= 0.00000000001)
  244. // {
  245. // return true;
  246. // }
  247. // return false;
  248. //}
  249. public bool Equals(CElementArea a_oSource)
  250. {
  251. // element chemistry list
  252. if (m_listCElementChemistries.Count() != a_oSource.m_listCElementChemistries.Count())
  253. {
  254. return false;
  255. }
  256. for (int i = 0; i <m_listCElementChemistries.Count(); i++)
  257. {
  258. if (!(m_listCElementChemistries[i] == a_oSource.m_listCElementChemistries[i]))
  259. {
  260. return false;
  261. }
  262. }
  263. if (Math.Abs(m_dArea - a_oSource.m_dArea) >= otsdataconst.MIN_DOUBLE_VALUE)
  264. {
  265. return false;
  266. }
  267. return true;
  268. }
  269. // element chemistry list
  270. public List<CElementChemistry> GetElementList()
  271. {
  272. return m_listCElementChemistries;
  273. }
  274. // element chemistry list
  275. public void SetElementList(List<CElementChemistry> a_listElementChemistries)
  276. {
  277. foreach (var pElementChemisty in a_listElementChemistries)
  278. {
  279. CElementChemistry pElementChemistyNew = new CElementChemistry(pElementChemisty);
  280. m_listCElementChemistries.Add(pElementChemistyNew);
  281. }
  282. }
  283. // area (element)
  284. public double GetArea()
  285. {
  286. return m_dArea;
  287. }
  288. public void SetArea(double a_dArea)
  289. {
  290. m_dArea = a_dArea;
  291. }
  292. // cleanup
  293. protected void Cleanup()
  294. {
  295. m_listCElementChemistries.Clear();
  296. }
  297. // initialization
  298. protected void Init()
  299. {
  300. m_listCElementChemistries.Clear();
  301. }
  302. // duplication
  303. protected void Duplicate(CElementArea a_oSource)
  304. {
  305. // initialization
  306. Init();
  307. // copy data over
  308. m_dArea = a_oSource.m_dArea;
  309. SetElementList(a_oSource.m_listCElementChemistries);
  310. }
  311. }
  312. public class CElement
  313. {
  314. // atomic number
  315. protected long m_nAtomNum;
  316. // percentage
  317. protected double m_dPercentage;
  318. protected static List<string> m_theElementNameVector = new List<string>();
  319. //static const CString theElementNameList;
  320. protected readonly string theElementNameList = "H,He,Li,Be,B,C,N,O,F,Ne,Na,Mg,Al,Si,P,S,Cl,Ar,K,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr,Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn,Sb,Te,I,Xe,Cs,Ba,La,Ce,Pr,Nd,Pm,Sm,Eu,Gd,Tb,Dy,Ho,Er,Tm,Yb,Lu,Hf,Ta,W,Re,Os,Ir,Pt,Au,Hg,Tl,Pb,Bi,Po,At,Rn,Fr,Ra,Ac,Th,Pa,U,Np,Pu,Am,Cm,Bk,Cf,Es,Fm,Md,No,Lr";
  321. // constructor
  322. public CElement()
  323. {
  324. // initialization
  325. Init();
  326. }
  327. public CElement(long a_nAtomNum)
  328. {
  329. // initialization
  330. Init();
  331. // assign class member
  332. if (a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MIN && a_nAtomNum <= otsdataconst.ATOMIC_NUMBER_MAX)
  333. {
  334. m_nAtomNum = a_nAtomNum;
  335. }
  336. }
  337. public CElement(string a_strName)
  338. {
  339. // initialization
  340. Init();
  341. // try to find matched name
  342. //InitNamesList();
  343. for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; ++i)
  344. {
  345. if (GlobalMembersElement.ELEMENT_NAMES[i].Equals(a_strName))
  346. {
  347. // got it
  348. m_nAtomNum = i + 1;
  349. break;
  350. }
  351. }
  352. }
  353. // copy constructor
  354. public CElement(CElement a_poSource)
  355. {
  356. // input check
  357. //Debug.Assert(a_poSource);
  358. if (a_poSource == null)
  359. {
  360. return;
  361. }
  362. // copy data over
  363. Duplicate(a_poSource);
  364. }
  365. //public CElement CopyFrom(CElement a_oSource) //ORIGINAL LINE: CElement& operator =(const CElement& a_oSource)
  366. //{
  367. // // cleanup
  368. // Cleanup();
  369. // // copy the class data over
  370. // Duplicate(a_oSource);
  371. // // return class
  372. // return this;
  373. //}
  374. public bool Equals(CElement a_oSource) //BOOL operator==(const CElement&); // ==operator
  375. {
  376. if (m_nAtomNum == a_oSource.m_nAtomNum && Math.Abs(m_dPercentage - a_oSource.m_dPercentage) < otsdataconst.MIN_DOUBLE_VALUE)
  377. {
  378. return true;
  379. }
  380. else
  381. {
  382. return false;
  383. }
  384. }
  385. // destructor
  386. //public virtual void Dispose() //virtual ~CElement(); // detractor
  387. //{
  388. // // cleanup
  389. // Cleanup();
  390. //}
  391. // valid element
  392. public bool IsValid()
  393. {
  394. return IsValidAtomNum(m_nAtomNum);
  395. }
  396. // atomic number
  397. public int GetAtomNum() //int GetAtomNum() const { return m_nAtomNum; }
  398. {
  399. return (int)m_nAtomNum;
  400. }
  401. public void SetAtomNum(long a_nAtomNum)
  402. {
  403. m_nAtomNum = a_nAtomNum;
  404. }
  405. // percentage
  406. public double GetPercentage() //double GetPercentage() const { return m_dPercentage; }
  407. {
  408. return m_dPercentage;
  409. }
  410. // percentage
  411. public void SetPercentage(double a_dPercentage)
  412. {
  413. if (a_dPercentage >= otsdataconst.PERCENTAGE_MIN && a_dPercentage <= otsdataconst.PERCENTAGE_MAX)
  414. {
  415. m_dPercentage = a_dPercentage;
  416. }
  417. }
  418. public double GetMolarPercentage()
  419. {
  420. double dMolarPercentage = otsdataconst.MIN_DOUBLE_VALUE;
  421. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  422. {
  423. double dAtomWeight = GetAtomWeight();
  424. dMolarPercentage = m_dPercentage / dAtomWeight;
  425. }
  426. return dMolarPercentage;
  427. }
  428. // name
  429. public string GetName()
  430. {
  431. string strName = "";
  432. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  433. {
  434. return strName;
  435. }
  436. strName = GlobalMembersElement.ELEMENT_NAMES[m_nAtomNum - 1];
  437. return strName;
  438. }
  439. public static string GetName(long a_nAtomNum)
  440. {
  441. string strName = "";
  442. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  443. {
  444. return strName;
  445. }
  446. strName = GlobalMembersElement.ELEMENT_NAMES[a_nAtomNum - 1];
  447. return strName;
  448. }
  449. public static long GetAtomicNum(string a_strName)
  450. {
  451. long nNum = -1;
  452. for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; i++)
  453. {
  454. if (a_strName==GlobalMembersElement.ELEMENT_NAMES[i])
  455. {
  456. nNum = (i + 1);
  457. break;
  458. }
  459. }
  460. return nNum;
  461. }
  462. // atomic weight
  463. public double GetAtomWeight()
  464. {
  465. double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
  466. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  467. {
  468. return dAtomWeight;
  469. }
  470. dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[m_nAtomNum - 1];
  471. return dAtomWeight;
  472. }
  473. public static double GetAtomWeight(int a_nAtomNum)
  474. {
  475. double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
  476. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  477. {
  478. return dAtomWeight;
  479. }
  480. dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[a_nAtomNum - 1];
  481. return dAtomWeight;
  482. }
  483. public static double GetAtomWeight(string a_strName)
  484. {
  485. double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
  486. for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; i++)
  487. {
  488. if (a_strName==GlobalMembersElement.ELEMENT_NAMES[i])
  489. {
  490. dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[i];
  491. break;
  492. }
  493. }
  494. return dAtomWeight;
  495. }
  496. // energy values
  497. public double GetEnergyValueK()
  498. {
  499. double dEnergyValueK = otsdataconst.ENERGY_VALUE_INVALID;
  500. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  501. {
  502. return dEnergyValueK;
  503. }
  504. dEnergyValueK = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[m_nAtomNum - 1];
  505. return dEnergyValueK;
  506. }
  507. public static double GetEnergyValueK(int a_nAtomNum)
  508. {
  509. double dEnergyValueK = otsdataconst.ENERGY_VALUE_INVALID;
  510. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  511. {
  512. return dEnergyValueK;
  513. }
  514. dEnergyValueK = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[a_nAtomNum - 1];
  515. return dEnergyValueK;
  516. }
  517. public double GetEnergyValueL()
  518. {
  519. double dEnergyValueL = otsdataconst.ENERGY_VALUE_INVALID;
  520. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  521. {
  522. return dEnergyValueL;
  523. }
  524. dEnergyValueL = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[m_nAtomNum - 1];
  525. return dEnergyValueL;
  526. }
  527. public static double GetEnergyValueL(int a_nAtomNum)
  528. {
  529. double dEnergyValueL = otsdataconst.ENERGY_VALUE_INVALID;
  530. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  531. {
  532. return dEnergyValueL;
  533. }
  534. dEnergyValueL = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[a_nAtomNum - 1];
  535. return dEnergyValueL;
  536. }
  537. public double GetEnergyValueM()
  538. {
  539. double dEnergyValueM = otsdataconst.ENERGY_VALUE_INVALID;
  540. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  541. {
  542. return dEnergyValueM;
  543. }
  544. dEnergyValueM = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[m_nAtomNum - 1];
  545. return dEnergyValueM;
  546. }
  547. public static double GetEnergyValueM(int a_nAtomNum)
  548. {
  549. double dEnergyValueM = otsdataconst.ENERGY_VALUE_INVALID;
  550. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  551. {
  552. return dEnergyValueM;
  553. }
  554. dEnergyValueM = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[a_nAtomNum - 1];
  555. return dEnergyValueM;
  556. }
  557. public List<double> GetEnergyValues()
  558. {
  559. List<double> vEnergyValues = new List<double>();
  560. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  561. {
  562. return vEnergyValues;
  563. }
  564. double dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[m_nAtomNum - 1];
  565. vEnergyValues.Add(dEnergyValue);
  566. dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[m_nAtomNum - 1];
  567. vEnergyValues.Add(dEnergyValue);
  568. dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[m_nAtomNum - 1];
  569. vEnergyValues.Add(dEnergyValue);
  570. return vEnergyValues;
  571. }
  572. public static List<double> GetEnergyValues(int a_nAtomNum)
  573. {
  574. List<double> vEnergyValues = new List<double>();
  575. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  576. {
  577. return vEnergyValues;
  578. }
  579. double dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[a_nAtomNum - 1];
  580. vEnergyValues.Add(dEnergyValue);
  581. dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[a_nAtomNum - 1];
  582. vEnergyValues.Add(dEnergyValue);
  583. dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[a_nAtomNum - 1];
  584. vEnergyValues.Add(dEnergyValue);
  585. return vEnergyValues;
  586. }
  587. // atomic number validation
  588. public static bool IsValidAtomNum(long a_nAtomNum)
  589. {
  590. return a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MIN && a_nAtomNum <= otsdataconst.ATOMIC_NUMBER_MAX;
  591. }
  592. public List<string> GetElementNameList()
  593. {
  594. if (m_theElementNameVector.Count == 0)
  595. {
  596. int tokenPos = 0;
  597. var strToken = theElementNameList.Split(',')[tokenPos]; //auto strToken = theElementNameList.Tokenize(",", tokenPos);
  598. while (strToken!=null)
  599. {
  600. m_theElementNameVector.Add(strToken);
  601. strToken = theElementNameList.Split(',')[tokenPos]; //strToken = theElementNameList.Tokenize(_T(","), tokenPos);
  602. }
  603. }
  604. return m_theElementNameVector;
  605. }
  606. public List<CElementChemistry> ExtractElementChemistrys(string a_strSource)
  607. {
  608. List<CElementChemistry> listElementChemistrys = new List<CElementChemistry>();
  609. List<string> vElementNames = GetElementNameList();
  610. // separate the source strings into strings
  611. string strSeperator = "\n";
  612. List<string> vLineStrings = SplitString(a_strSource, strSeperator);
  613. // strings to elements
  614. const int ELEMENT_STRING_NUMBER = 3;
  615. const int EXTRA_CHAR_NUMBER = 6;
  616. //int count = 1;
  617. foreach (var str in vLineStrings)
  618. {
  619. str.Trim('\n');
  620. if (str.Length<= EXTRA_CHAR_NUMBER)
  621. {
  622. continue;
  623. }
  624. strSeperator = ",";
  625. List<string> vStrings = SplitString(str, strSeperator);
  626. if (vStrings.Count == ELEMENT_STRING_NUMBER)
  627. {
  628. // create an element chemistry data
  629. CElementChemistry oElementChemistry = new CElementChemistry();
  630. // name (extra char "Quant=")
  631. string strTemp = vStrings[0];
  632. int nNameStringLength = strTemp.Length;
  633. // invalid name string?
  634. if (nNameStringLength <= EXTRA_CHAR_NUMBER)
  635. {
  636. continue;
  637. }
  638. // element name
  639. string strName = strTemp.Substring(nNameStringLength - EXTRA_CHAR_NUMBER);
  640. // make sure the element name is valid
  641. if (!vElementNames.Contains(strName)) //auto itr = std::find(vElementNames.begin(), vElementNames.end(), strName); if (itr == vElementNames.end())
  642. {
  643. // invalid element name
  644. continue;
  645. }
  646. oElementChemistry.SetName(strName);
  647. // percentage
  648. double dPercentge = double.Parse(vStrings[2]);
  649. oElementChemistry.SetPercentage(dPercentge);
  650. listElementChemistrys.Add(oElementChemistry);
  651. }
  652. }
  653. return listElementChemistrys;
  654. }
  655. // cleanup
  656. // cleanup
  657. protected void Cleanup()
  658. {
  659. // nothing needs to be done at the moment
  660. }
  661. // initialization
  662. protected void Init()
  663. {
  664. m_nAtomNum = otsdataconst.ATOMIC_NUMBER_INVALID;
  665. m_dPercentage = otsdataconst.PERCENTAGE_DEFAULT;
  666. }
  667. // duplication
  668. protected void Duplicate(CElement a_oSource)
  669. {
  670. // initialization
  671. Init();
  672. // copy data over
  673. m_nAtomNum = a_oSource.m_nAtomNum;
  674. m_dPercentage = a_oSource.m_dPercentage;
  675. }
  676. // const CString& a_sSource
  677. // LPCTSTR a_sSep -- separator
  678. protected static List<string> SplitString(string a_strSource, string a_strSep) //std::vector<CString> CElement::SplitString(const CString& a_strSource, LPCTSTR a_strSep)
  679. {
  680. // string list
  681. List<string> listString = new List<string>();
  682. // source string
  683. string strSource = a_strSource;
  684. // find the first separator
  685. int nPosLast = 0;
  686. var nPos = strSource.IndexOf(a_strSep, nPosLast); //var nPos = strSource.Find(a_strSep, nPosLast);
  687. // found the separator?
  688. while (nPos >= nPosLast)
  689. {
  690. // there is no string between two seperator if nPos == nPosLast
  691. if (nPos == nPosLast)
  692. {
  693. listString.Add("");
  694. nPosLast++;
  695. }
  696. else
  697. {
  698. // get the string between two separator
  699. string strValue = strSource.Substring(nPosLast, nPos - nPosLast); //string strValue = strSource.Mid(nPosLast, nPos - nPosLast);
  700. strValue.Trim();
  701. // add the string into the string list
  702. listString.Add(strValue);
  703. nPosLast = nPos + 1;
  704. }
  705. // try to find the next separator
  706. nPos = strSource.IndexOf(a_strSep, nPosLast); //nPos = strSource.Find(a_strSep, nPosLast);
  707. }
  708. // push the last one into the string list
  709. string strLastValue = strSource.Substring(strSource.Length - nPosLast);
  710. strLastValue.Trim();
  711. listString.Add(strLastValue);
  712. // return the string list
  713. return listString;
  714. }
  715. }
  716. }