OTSClassifyEng.cpp 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "OTSClassifyEng.h"
  4. #include "OTSHelper.h"
  5. namespace OTSClassifyEngine
  6. {
  7. using namespace OTSClassifyEngine;
  8. COTSClassifyEng::COTSClassifyEng() // constructor
  9. {
  10. }
  11. COTSClassifyEng::~COTSClassifyEng() // detractor
  12. {
  13. }
  14. //Dispose ClassifyXray
  15. BOOL COTSClassifyEng::ClassifyXray(CInclutionSTDDataPtr a_pPartSTDData, STEEL_TECHNOLOGY steelTech, CElementChemistriesList& a_listElementChemistries, int& a_nIncId)
  16. {
  17. // safety check
  18. ASSERT(a_pPartSTDData);
  19. if (!a_pPartSTDData)
  20. {
  21. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: invalid CPartSTDDataPtr."));
  22. return FALSE;
  23. }
  24. // the element chemistries list is an inclusion
  25. CElementChemistriesList listElChemsInc;
  26. CElementChemistriesList listElChemsIncNoFe;
  27. double dMolarSum = 0.0f;
  28. double dMolarSumNoFe = 0.0f;
  29. if (!IsAnIncXRay(a_listElementChemistries, listElChemsInc, listElChemsIncNoFe, dMolarSum, dMolarSumNoFe, a_nIncId))
  30. {
  31. // this is not an inclusion, mark it as not identified
  32. if(a_nIncId < 7)
  33. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  34. return TRUE;
  35. }
  36. // sum > min_sum return NOT_IDENTIFIED
  37. if (dMolarSumNoFe < MIN_ELEMENT_SUM)
  38. {
  39. // this is not an inclusion, mark it as not identified
  40. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  41. return TRUE;
  42. }
  43. // system STD classification
  44. int nIncId = (int)OTS_PARTICLE_TYPE::INVALID;
  45. if (!SystemClassify(a_pPartSTDData, steelTech, listElChemsIncNoFe, dMolarSumNoFe, nIncId))
  46. {
  47. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call SystemClassify method."));
  48. return FALSE;
  49. }
  50. // identified?
  51. if (nIncId > (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  52. {// identified, return TRUE
  53. a_nIncId = nIncId;
  54. return TRUE;
  55. }
  56. // user STD classification
  57. if (!UserClassify(a_pPartSTDData, listElChemsInc, dMolarSum, nIncId))
  58. {
  59. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call UserClassify method."));
  60. return FALSE;
  61. }
  62. // identified?
  63. if (nIncId > (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  64. {
  65. // identified, return TRUE
  66. a_nIncId = nIncId;
  67. return TRUE;
  68. }
  69. // can't identify this inclusion
  70. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  71. return TRUE;
  72. }
  73. // public
  74. // check if the x-ray is an inc x-ray
  75. BOOL COTSClassifyEng::IsAnIncXRay(
  76. CElementChemistriesList& a_listElementChemistries,
  77. CElementChemistriesList& a_listElChemsInc,
  78. CElementChemistriesList& a_listElChemsIncNoFe,
  79. double& a_dMolarSum,
  80. double& a_dMolarSumNoFe,
  81. int& a_nIncId)
  82. {
  83. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  84. // go through all elementS
  85. a_listElChemsInc.clear();
  86. a_listElChemsIncNoFe.clear();
  87. a_dMolarSum = 0;
  88. a_dMolarSumNoFe = 0;
  89. double dSumKeyElements = 0;
  90. double dSumSubElements = 0;
  91. double dCarbonMolar = 0;
  92. double dOMolar = 0;
  93. double dSiMolar = 0;
  94. double dFeMolar = 0;
  95. for (auto pElChem : a_listElementChemistries)
  96. {
  97. // create a new element chemistry
  98. CElementChemistryPtr pElChemNew = CElementChemistryPtr(new CElementChemistry(*pElChem.get()));
  99. // key element? S,O,N
  100. if (IsKeyElement(pElChem))
  101. {
  102. // this is a key element
  103. // get molar percentage of this element
  104. double dMolarPercentage = pElChem->GetMolarPercentage();
  105. // cal molar percentage sum (both lists)
  106. a_dMolarSum += dMolarPercentage;
  107. a_dMolarSumNoFe += pElChem->GetMolarPercentage();
  108. // cal key element molar percentage sum
  109. dSumKeyElements += dMolarPercentage;
  110. // add the element into the two lists
  111. a_listElChemsInc.push_back(pElChemNew);
  112. a_listElChemsIncNoFe.push_back(pElChemNew);
  113. if (pElChem->GetName().CompareNoCase(STR_O) == 0)
  114. {
  115. dOMolar = pElChem->GetMolarPercentage();
  116. }
  117. }
  118. // sub element?, include Fe
  119. else if (IsSubElement(pElChem))
  120. {
  121. // this is a sub element
  122. // get molar percentage of this element
  123. double dMolarPercentage = pElChem->GetMolarPercentage();
  124. // cal molar percentage sum list
  125. a_dMolarSum += dMolarPercentage;
  126. // cal key element molar percentage sum
  127. dSumSubElements += dMolarPercentage;
  128. // add the element into the list
  129. a_listElChemsInc.push_back(pElChemNew);
  130. // Fe?
  131. if (pElChem->GetName().CompareNoCase(STR_FE) != 0)
  132. {
  133. // Si
  134. if (pElChem->GetName().CompareNoCase(STR_SI) == 0)
  135. {
  136. dSiMolar = pElChem->GetMolarPercentage();
  137. }
  138. // cal molar percentage sum list (no Fe)
  139. a_dMolarSumNoFe += pElChem->GetMolarPercentage();
  140. // add the element into the list (no Fe)
  141. a_listElChemsIncNoFe.push_back(pElChemNew);
  142. }
  143. else
  144. {
  145. dFeMolar = pElChem->GetMolarPercentage();
  146. }
  147. }
  148. //
  149. else if (pElChem->GetName().CompareNoCase(STR_C) == 0)
  150. {
  151. dCarbonMolar = pElChem->GetMolarPercentage();
  152. }
  153. }
  154. // both key molar percentage sum and sub molar percentage sum have to be over certain values
  155. double dSumKeyElementsMolar = Cal100NorValue(dSumKeyElements, a_dMolarSumNoFe);
  156. double dSumSubElementsMolar = Cal100NorValue(dSumSubElements, a_dMolarSumNoFe);
  157. return dSumKeyElementsMolar > INC_SUB_ELEMENT_TOTAL_100 && dSumSubElementsMolar > INC_SUB_ELEMENT_TOTAL_100;
  158. }
  159. // system classification
  160. BOOL COTSClassifyEng::SystemClassify(CInclutionSTDDataPtr a_pPartSTDData,
  161. STEEL_TECHNOLOGY steelTech,
  162. CElementChemistriesList& a_listElChemsIncNoFe,
  163. double a_dMolarSumNoFe,
  164. int& a_nIncId)
  165. {
  166. // safety check
  167. ASSERT(a_pPartSTDData);
  168. if (!a_pPartSTDData)
  169. {
  170. // something wrong
  171. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: invalid CPartSTDDataPtr."));
  172. return FALSE;
  173. }
  174. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  175. {
  176. // something wrong
  177. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: invalid molar sum value."));
  178. return FALSE;
  179. }
  180. // try sulfide classification
  181. int nIncId = (int)OTS_PARTICLE_TYPE::INVALID;
  182. if (!SulClassify(a_pPartSTDData, steelTech, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  183. {
  184. // something wrong
  185. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call SulClassify method."));
  186. return FALSE;
  187. }
  188. // inclusion identified?
  189. if (nIncId != (int)OTS_PARTICLE_TYPE::INVALID)
  190. {
  191. // yes, this is a sulfide
  192. a_nIncId = nIncId;
  193. return TRUE;
  194. }
  195. // nitride classification
  196. if (!NitrideClassify(a_pPartSTDData, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  197. {
  198. // something wrong
  199. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call NitrideClassify method."));
  200. return FALSE;
  201. }
  202. // inclusion identified?
  203. if (nIncId != (int)OTS_PARTICLE_TYPE::INVALID)
  204. {
  205. // yes, this is a nitride
  206. a_nIncId = nIncId;
  207. return TRUE;
  208. }
  209. // oxide classification
  210. if (!OxideClassify(a_pPartSTDData, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  211. {
  212. // something wrong
  213. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call OxideClassify method."));
  214. return FALSE;
  215. }
  216. // inclusion identified?
  217. if (nIncId != (int)OTS_PARTICLE_TYPE::INVALID)
  218. {
  219. // yes, this is a oxide
  220. a_nIncId = nIncId;
  221. return TRUE;
  222. }
  223. // CarbonClassify classification
  224. if (!CarbonClassify(a_pPartSTDData, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  225. {
  226. // something wrong
  227. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call CarbonClassify method."));
  228. return FALSE;
  229. }
  230. // inclusion identified?
  231. if (nIncId != (int)OTS_PARTICLE_TYPE::INVALID)
  232. {
  233. // yes, this is a oxide
  234. a_nIncId = nIncId;
  235. return TRUE;
  236. }
  237. // can't identify this inclusion
  238. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  239. return TRUE;
  240. }
  241. // sulfides classification
  242. BOOL COTSClassifyEng::SulClassify(CInclutionSTDDataPtr a_pPartSTDData,
  243. STEEL_TECHNOLOGY steelTech,
  244. CElementChemistriesList& a_listElChemsIncNoFe,
  245. double a_dMolarSumNoFe,
  246. int& a_nIncId)
  247. {
  248. // safety check
  249. ASSERT(a_pPartSTDData);
  250. if (!a_pPartSTDData)
  251. {
  252. // something wrong
  253. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: invalid CPartSTDDataPtr."));
  254. return FALSE;
  255. }
  256. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  257. {
  258. // something wrong
  259. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: invalid molar sum value."));
  260. return FALSE;
  261. }
  262. // get all sulfides STD items
  263. CSTDItemsList listSulfideSTD;
  264. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::SUL, listSulfideSTD))
  265. {
  266. // something is wrong
  267. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call GetClassifySTDItem method."));
  268. return FALSE;
  269. }
  270. // check if element chemistries list contain any sulfur
  271. CElementChemistryPtr pSulElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_SUL);
  272. if (!pSulElChem)
  273. {
  274. // contains no sulfur, this is not a sulfide
  275. return TRUE;
  276. }
  277. // calculate sulfur 100 percentage molar
  278. double dSulMolar100 = Cal100NorValue(pSulElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  279. // check if sulfur amount enough
  280. if (dSulMolar100 < MIN_SUL_MOLAR)
  281. {
  282. // no enough sulfur, this is not a sulfide
  283. return TRUE;
  284. }
  285. // this is a sulfide
  286. // any sulfides STD items
  287. if (listSulfideSTD.empty())
  288. {
  289. // no sulfides std items. can't identify sulfide
  290. // can't identify this inclusion
  291. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  292. return TRUE;
  293. }
  294. // mapping Mn first
  295. BOOL bMnMapped = FALSE;
  296. {
  297. CElementChemistryPtr pElChemMn = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[0]);
  298. double dMappingRatio = INC_SULFILSES_MAPPING_RADIO[0];
  299. if (pElChemMn)
  300. {
  301. // there Mn in the element list, map S & Mn
  302. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRatio, pElChemMn, pSulElChem, bMnMapped))
  303. {
  304. // something is wrong
  305. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call ElementsMapping method."));
  306. return FALSE;
  307. }
  308. }
  309. }
  310. // need to re-calculate sulfur 100% molar value if Mn mapped
  311. if(bMnMapped)
  312. {
  313. dSulMolar100 = Cal100NorValue(pSulElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  314. }
  315. // process mapping if sulfur amount enough
  316. CString strProMappingSulName = _T("");
  317. BOOL bProMapped = FALSE;
  318. if (dSulMolar100 > MIN_SUL_MOLAR)
  319. {
  320. // still have enough sulfur, mapping Ca, Mg or Ce, La
  321. double dMappingRadio;
  322. switch ( steelTech)
  323. {
  324. // Ca process
  325. case STEEL_TECHNOLOGY::CaProcessMode:
  326. {
  327. // try to get Ca element chemistry
  328. CElementChemistryPtr pElChemCa = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[1]);
  329. if (pElChemCa)
  330. {
  331. // there Ca in the element list, map Ca & S
  332. dMappingRadio = INC_SULFILSES_MAPPING_RADIO[1];
  333. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pElChemCa, pSulElChem, bProMapped))
  334. {
  335. // something is wrong
  336. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call ElementsMapping method."));
  337. return FALSE;
  338. }
  339. // mapping successful?
  340. if (bProMapped)
  341. {
  342. strProMappingSulName = INC_SULFILSES_NAMES[1];
  343. }
  344. }
  345. }
  346. break;
  347. // Mg process
  348. case STEEL_TECHNOLOGY::MgProcessMode:
  349. {
  350. // try to get Mg element chemistry
  351. CElementChemistryPtr pElChemMg = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[2]);
  352. if (pElChemMg)
  353. {
  354. // there Mg in the element list, map Mg & S
  355. dMappingRadio = INC_SULFILSES_MAPPING_RADIO[2];
  356. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pElChemMg, pSulElChem, bProMapped))
  357. {
  358. // something is wrong
  359. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call ElementsMapping method."));
  360. return FALSE;
  361. }
  362. // mapping successful?
  363. if (bProMapped)
  364. {
  365. strProMappingSulName = INC_SULFILSES_NAMES[2];
  366. }
  367. }
  368. }
  369. break;
  370. // real earth elements process
  371. case STEEL_TECHNOLOGY::RareEarthMode:
  372. {
  373. // try to get Ce element chemistry
  374. CElementChemistryPtr pElChemCe = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[3]);
  375. BOOL bCeMapped = FALSE;
  376. if (pElChemCe)
  377. {
  378. // there Ce in the element list, map S with Ce
  379. dMappingRadio = INC_SULFILSES_MAPPING_RADIO[3];
  380. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pElChemCe, pSulElChem, bCeMapped))
  381. {
  382. // something is wrong
  383. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call ElementsMapping method."));
  384. return FALSE;
  385. }
  386. }
  387. // try to get La element chemistry
  388. CElementChemistryPtr pElChemLa = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[4]);
  389. BOOL bLaMapped = FALSE;
  390. if (pElChemLa)
  391. {
  392. // there La in the element list, map S with La
  393. dMappingRadio = INC_SULFILSES_MAPPING_RADIO[4];
  394. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pElChemLa, pSulElChem, bLaMapped))
  395. {
  396. // something is wrong
  397. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call ElementsMapping method."));
  398. return FALSE;
  399. }
  400. }
  401. // mapped both
  402. if (bCeMapped && bLaMapped)
  403. {
  404. strProMappingSulName = INC_SULFILSES_NAMES[3] + STR_CONNECT + INC_SULFILSES_NAMES[4];
  405. bProMapped = TRUE;
  406. }
  407. else if (bCeMapped)
  408. {
  409. strProMappingSulName = INC_SULFILSES_NAMES[3];
  410. bProMapped = TRUE;
  411. }
  412. else if (bLaMapped)
  413. {
  414. strProMappingSulName = INC_SULFILSES_NAMES[4];
  415. bProMapped = TRUE;
  416. }
  417. }
  418. break;
  419. }
  420. }
  421. // set sulfide base name
  422. CString strSulfideBaseName = _T("");
  423. if (bMnMapped && bProMapped)
  424. {
  425. // both Mn and process mapped
  426. strSulfideBaseName = INC_SULFILSES_NAMES[0] + strProMappingSulName;
  427. }
  428. else if (bMnMapped)
  429. {
  430. // Mn mapped only
  431. strSulfideBaseName = INC_SULFILSES_NAMES[0];
  432. }
  433. else if (bProMapped)
  434. {
  435. // process mapped only
  436. strSulfideBaseName = strProMappingSulName;
  437. }
  438. else
  439. {
  440. // mapped nothing
  441. // force sulfide base name as "Sulfide" if sulfur 100% molar value over cutting off value
  442. if (dSulMolar100 > SULFIDE_MOLAR_CUTOFF)
  443. {
  444. strSulfideBaseName = SULFIDE_STR;
  445. }
  446. else
  447. {
  448. // no enough sulfur, consider that it is not a sulfide
  449. return TRUE;
  450. }
  451. }
  452. // check if the rest element chemistries map an oxide
  453. int nIncId = (int)OTS_PARTICLE_TYPE::INVALID;
  454. if (!OxideClassify(a_pPartSTDData, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  455. {
  456. // something wrong
  457. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call OxideClassify method."));
  458. return FALSE;
  459. }
  460. // mapped?
  461. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  462. {
  463. // this is an oxide sulfide
  464. // confirm the oxide sulfide id
  465. // get the STD item of the mapped oxide
  466. CSTDItemPtr pOxideSTDItem = a_pPartSTDData->GetSTDItemById(nIncId);
  467. if (pOxideSTDItem)
  468. {
  469. // get mapped oxide name
  470. CString strOxideName = pOxideSTDItem->GetName();
  471. // oxide sulfide name: oxide + "-" + sulfide base string
  472. CString strOxide_SulName = strOxideName + STR_CONNECT + strSulfideBaseName;
  473. // try to find the STD item
  474. CSTDItemPtr pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  475. if (pOxideSulSTDItem)
  476. {
  477. // found the STD item
  478. a_nIncId = pOxideSulSTDItem->GetSTDId();
  479. return TRUE;
  480. }
  481. // rename the oxide sulfide name as "Oxide" + "-" + sulfide base string
  482. strOxide_SulName = OXIDE_STR + STR_CONNECT + strSulfideBaseName;
  483. // try to find the STD item
  484. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  485. if (pOxideSulSTDItem)
  486. {
  487. // found the STD item
  488. a_nIncId = pOxideSulSTDItem->GetSTDId();
  489. return TRUE;
  490. }
  491. // rename the oxide sulfide name as strOxideName + "-" + "Sulfide"
  492. strOxide_SulName = strOxideName + STR_CONNECT + SULFIDE_STR;
  493. // try to find the STD item
  494. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  495. if (pOxideSulSTDItem)
  496. {
  497. // found the STD item
  498. a_nIncId = pOxideSulSTDItem->GetSTDId();
  499. return TRUE;
  500. }
  501. // rename the oxide sulfide name as "Oxide" + "-" + "Sulfide"
  502. strOxide_SulName = OXIDE_STR + STR_CONNECT + SULFIDE_STR;
  503. // try to find the STD item
  504. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  505. if (pOxideSulSTDItem)
  506. {
  507. // found the STD item
  508. a_nIncId = pOxideSulSTDItem->GetSTDId();
  509. return TRUE;
  510. }
  511. // rename the oxide sulfide name as "Sulfide"
  512. strOxide_SulName = SULFIDE_STR;
  513. // try to find the STD item
  514. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  515. if (pOxideSulSTDItem)
  516. {
  517. // found the STD item
  518. a_nIncId = pOxideSulSTDItem->GetSTDId();
  519. return TRUE;
  520. }
  521. }
  522. // can't identify this inclusion
  523. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  524. return TRUE;
  525. }
  526. // this is a general sulfide
  527. // confirm the sulfide id
  528. // try to find the STD item
  529. CSTDItemPtr pSulSTDItem = GetSTDItemByName(listSulfideSTD, strSulfideBaseName);
  530. if (pSulSTDItem)
  531. {
  532. // found the STD item
  533. a_nIncId = pSulSTDItem->GetSTDId();
  534. return TRUE;
  535. }
  536. // rename the sulfides name as "Sulfide" if it is not
  537. if (strSulfideBaseName.CompareNoCase(SULFIDE_STR) != 0)
  538. {
  539. strSulfideBaseName = SULFIDE_STR;
  540. pSulSTDItem = GetSTDItemByName(listSulfideSTD, strSulfideBaseName);
  541. if (pSulSTDItem)
  542. {
  543. // found the STD item
  544. a_nIncId = pSulSTDItem->GetSTDId();
  545. return TRUE;
  546. }
  547. }
  548. // can't identify this inclusion
  549. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  550. return TRUE;
  551. }
  552. // oxides classification
  553. BOOL COTSClassifyEng::OxideClassify(CInclutionSTDDataPtr a_pPartSTDData,
  554. CElementChemistriesList& a_listElChemsIncNoFe,
  555. double a_dMolarSumNoFe,
  556. int& a_nIncId)
  557. {
  558. // safety check
  559. ASSERT(a_pPartSTDData);
  560. if (!a_pPartSTDData)
  561. {
  562. // something wrong
  563. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: invalid CPartSTDDataPtr."));
  564. return FALSE;
  565. }
  566. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  567. {
  568. // something wrong
  569. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: invalid molar sum value."));
  570. return FALSE;
  571. }
  572. // get all oxides STD items
  573. CSTDItemsList listOxideSTD;
  574. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::OXIDE, listOxideSTD))
  575. {
  576. // something wrong
  577. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: failed to call GetClassifySTDItem method."));
  578. return FALSE;
  579. }
  580. // check if element chemistries list contain any oxygen
  581. CElementChemistryPtr pOElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_OXIDE);
  582. if (!pOElChem)
  583. {
  584. // contains no oxygen, this is not an oxide
  585. return TRUE;
  586. }
  587. // check if oxygen amount enough
  588. double dOMolar100 = Cal100NorValue(pOElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  589. if (dOMolar100 < MIN_OXIDE_MOLAR)
  590. {
  591. // no enough oxygen, this is not an oxide
  592. return TRUE;
  593. }
  594. // this is an oxide
  595. // any oxide STD items
  596. if (listOxideSTD.empty())
  597. {
  598. // no oxide STD items, can't identify oxide
  599. // can't identify this inclusion
  600. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  601. return TRUE;
  602. }
  603. // build oxide sub elements list
  604. // =========================================
  605. // get all possible oxide sub element chemistries
  606. CElementChemistriesList listTempOxideSubElChems;
  607. double dTempOxideSubElMolarSum = 0;
  608. for (int i = 0; i < INC_OXIDE_SUB_ELEMENT_MAX; ++i)
  609. {
  610. // try to get the oxide sub element
  611. CElementChemistryPtr pSubElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_OXIDE_SUB_ELEMENT_NAMES[i]);
  612. // found it?
  613. if (pSubElChem)
  614. {
  615. // got one
  616. // get the %molar value of the sub element chemistries
  617. double dSubElMolar = pSubElChem->GetMolarPercentage();
  618. // add the sub element chemistries into the oxides element chemistries list
  619. listTempOxideSubElChems.push_back(pSubElChem);
  620. dTempOxideSubElMolarSum += dSubElMolar;
  621. }
  622. }
  623. // clear oxide sub element chemistries list
  624. CElementChemistriesList listOxideSubElChems;
  625. double dOxideSubElMolarSum = 0;
  626. for (auto pElChem : listTempOxideSubElChems)
  627. {
  628. // get the %molar value of the sub element chemistries
  629. double dSubElMolar = pElChem->GetMolarPercentage();
  630. // the %molar value of the sub element chemistries of the sub element chemistries list
  631. double dSubElMolarMolar100 = Cal100NorValue(dSubElMolar, dTempOxideSubElMolarSum);
  632. // remove the sub element chemistries less than the cut off (2%)
  633. if (dSubElMolarMolar100 > MIN_OXIDE_SUB_MOLAR_CUTOFF)
  634. {
  635. // keep it
  636. listOxideSubElChems.push_back(pElChem);
  637. dOxideSubElMolarSum += dSubElMolar;
  638. }
  639. }
  640. // =========================================
  641. // check oxide elements list
  642. CString strOxideName = _T("");
  643. if (listOxideSubElChems.empty())
  644. {
  645. // no oxide sub elements
  646. // consider this is not a oxide (may be it just is a dust)
  647. return TRUE;
  648. }
  649. // is a simple oxide?
  650. else if(IsASimpleOxide(listOxideSubElChems, dOxideSubElMolarSum, strOxideName))
  651. {
  652. // this is a simple oxide
  653. // named already during checking
  654. }
  655. // is it a REOxide (La-Ce-Oxide)?
  656. else if (IsAREOxide(listOxideSubElChems, dOxideSubElMolarSum))
  657. {
  658. // REOxcide
  659. strOxideName = REOXIDE_STR;
  660. }
  661. // should be a complex oxide
  662. // is it a REAlOxide?
  663. else if (IsAnREAlOxide(listOxideSubElChems, dOxideSubElMolarSum))
  664. {
  665. // REOxcide
  666. strOxideName = REALOXIDE_STR;
  667. }
  668. // is it a Spinel?
  669. else if (IsASpinel(listOxideSubElChems, dOxideSubElMolarSum))
  670. {
  671. // Spinel
  672. strOxideName = SPINEL_STR;
  673. }
  674. // is it a Silicate?
  675. else if (IsASilicate(listOxideSubElChems, dOxideSubElMolarSum))
  676. {
  677. // Silicate
  678. strOxideName = SILICATE_STR;
  679. }
  680. // is it an Aluminate?
  681. else if (IsAnAluminate(listOxideSubElChems, dOxideSubElMolarSum))
  682. {
  683. // Aluminate
  684. strOxideName = ALUMINATE_STR;
  685. }
  686. // fit none of them, simply name it as an oxide
  687. else
  688. {
  689. strOxideName = OXIDE_STR;
  690. }
  691. // confirm the oxide id
  692. // try to find the STD
  693. auto pSTDItem = GetSTDItemByName(listOxideSTD, strOxideName);
  694. if (pSTDItem)
  695. {
  696. // found the STD item
  697. a_nIncId = pSTDItem->GetSTDId();
  698. return TRUE;
  699. }
  700. // rename the oxide as "Oxide" if it is not
  701. if (strOxideName.CompareNoCase(OXIDE_STR) != 0)
  702. {
  703. strOxideName = OXIDE_STR;
  704. auto pSTDItem = GetSTDItemByName(listOxideSTD, strOxideName);
  705. if (pSTDItem)
  706. {
  707. // found the STD item
  708. a_nIncId = pSTDItem->GetSTDId();
  709. return TRUE;
  710. }
  711. }
  712. // can't identify this inclusion
  713. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  714. return TRUE;
  715. }
  716. // nitrides classification
  717. BOOL COTSClassifyEng::NitrideClassify(CInclutionSTDDataPtr a_pPartSTDData,
  718. CElementChemistriesList& a_listElChemsIncNoFe,
  719. double a_dMolarSumNoFe,
  720. int& a_nIncId)
  721. {
  722. // safety check
  723. ASSERT(a_pPartSTDData);
  724. if (!a_pPartSTDData)
  725. {
  726. // something wrong
  727. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: invalid CPartSTDDataPtr."));
  728. return FALSE;
  729. }
  730. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  731. {
  732. // something wrong
  733. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: invalid molar sum value."));
  734. return FALSE;
  735. }
  736. // get all nitride STD items
  737. CSTDItemsList listNitrideSTD;
  738. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::NITR, listNitrideSTD))
  739. {
  740. // something wrong
  741. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call GetClassifySTDItem method."));
  742. return FALSE;
  743. }
  744. // check if element chemistries list contain any nitrogen
  745. CElementChemistryPtr pNitrElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_NITR);
  746. if (!pNitrElChem)
  747. {
  748. // contains no nitrogen, this is not a nitride
  749. return TRUE;
  750. }
  751. // check if nitrogen amount enough
  752. double dNitrMolar100 = Cal100NorValue(pNitrElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  753. if (dNitrMolar100 < MIN_NITR_MOLAR)
  754. {
  755. // have no enough nitrogen, this is not a nitride
  756. return TRUE;
  757. }
  758. // this is a nitride
  759. // any nitride STD items
  760. if (listNitrideSTD.empty())
  761. {
  762. // no nitrides std items.
  763. // can't identify this inclusion
  764. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  765. return TRUE;
  766. }
  767. // mapping nitride sub elements
  768. CString strNitrideName = _T("");
  769. BOOL bMapped = FALSE;
  770. for (int i = 0; i < INC_NITR_SUB_ELEMENT_MAX; ++i)
  771. {
  772. CElementChemistryPtr pNitrSubElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_NITR_SUB_ELEMENT_NAMES[i]);
  773. if (pNitrSubElChem)
  774. {
  775. // this is a nitride sub element chemistry
  776. // get %molar value of this sub element chemistry
  777. double dNitr_Sub_Molar = Cal100NorValue(pNitrSubElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  778. // make sure the sub element molar value is over mapping min value
  779. if (dNitr_Sub_Molar > MIN_NITR_SUB_MOLAR)
  780. {
  781. // mapping this sub element chemistry
  782. double dMappingRadio = INC_NITR_MAPPING_RADIO[i];
  783. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pNitrSubElChem, pNitrElChem, bMapped))
  784. {
  785. // something is wrong
  786. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call ElementsMapping method."));
  787. return FALSE;
  788. }
  789. // mapping succeed?
  790. if(bMapped)
  791. {
  792. // is mapped Ti?
  793. if (i == 0)
  794. {
  795. // the first mapped nitride is "TiN"
  796. // try to map Nb
  797. BOOL bNbMapped = FALSE;
  798. // get molar % of the rest nitrogen
  799. dNitrMolar100 = Cal100NorValue(pNitrElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  800. // make sure nitrogen amount is enough
  801. if (dNitrMolar100 > MIN_NITR_MOLAR)
  802. {
  803. // get element "Nb"
  804. CElementChemistryPtr pElChemNb = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_Nb);
  805. // is there Nb in the list
  806. if (pElChemNb)
  807. {
  808. // get %molar value of Nb
  809. double dNb_Molar = Cal100NorValue(pElChemNb->GetMolarPercentage(), a_dMolarSumNoFe);
  810. // make sure Nb molar value is over mapping min value
  811. double dNbMappingRadio = INC_NITR_MAPPING_RADIO[2];
  812. if (dNb_Molar > MIN_NITR_SUB_MOLAR)
  813. {
  814. if (!ElementsMapping(a_dMolarSumNoFe, dNbMappingRadio, pElChemNb, pNitrElChem, bNbMapped))
  815. {
  816. // something is wrong
  817. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call ElementsMapping method."));
  818. return FALSE;
  819. }
  820. }
  821. }
  822. }
  823. // mapped "Nb"
  824. if (bNbMapped)
  825. {
  826. // nitride name is "TiN-NbN"
  827. strNitrideName = INC_NITR_NAMES[0] + STR_CONNECT + INC_NITR_NAMES[2];
  828. }
  829. else
  830. {
  831. // nitride name is "TiN"
  832. strNitrideName = INC_NITR_NAMES[0];
  833. }
  834. }
  835. else
  836. {
  837. // get the nitride name
  838. strNitrideName = INC_NITR_NAMES[i];
  839. }
  840. // completed mapping, get out the loop
  841. break;
  842. }
  843. }
  844. }
  845. }
  846. // not mapped?
  847. if (!bMapped)
  848. {
  849. // force to name it as "Nitride" if N 100% molar value over cutting off value
  850. if (dNitrMolar100 > NITRIDE_MOLAR_CUTOFF)
  851. {
  852. strNitrideName = NITRIDE_STR;
  853. }
  854. else
  855. {
  856. // no enough nitride, consider that it is not a nitride
  857. return TRUE;
  858. }
  859. }
  860. // check if the rest element chemistries map an oxide
  861. int nIncId = (int)OTS_PARTICLE_TYPE::INVALID;
  862. if (!OxideClassify(a_pPartSTDData, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  863. {
  864. // something wrong
  865. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call OxideClassify method."));
  866. return FALSE;
  867. }
  868. // mapped?
  869. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  870. {
  871. // this is an oxide nitride
  872. // confirm the oxide nitride id
  873. // get the STD item of the mapped oxide
  874. CSTDItemPtr pOxideSTDItem = a_pPartSTDData->GetSTDItemById(nIncId);
  875. if (pOxideSTDItem)
  876. {
  877. // get mapped oxide name
  878. CString strOxideName = pOxideSTDItem->GetName();
  879. // oxide nitride name: oxide + "-" + nitride base string
  880. CString strOxide_NitrName = strOxideName + STR_CONNECT + strNitrideName;
  881. // try to find the STD item
  882. CSTDItemPtr pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  883. if (pOxideNitrSTDItem)
  884. {
  885. // found the STD item
  886. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  887. return TRUE;
  888. }
  889. // can't find the STD item
  890. // rename the oxide nitride name as "Oxide" + "-" + nitride base string
  891. strOxide_NitrName = OXIDE_STR + STR_CONNECT + strOxide_NitrName;
  892. // try to find the STD item
  893. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  894. if (pOxideNitrSTDItem)
  895. {
  896. // found the STD item
  897. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  898. return TRUE;
  899. }
  900. // rename the oxide nitride name as strOxideName + "-" + "Nitride"
  901. strOxide_NitrName = strOxideName + STR_CONNECT + NITRIDE_STR;
  902. // try to find the STD item
  903. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  904. if (strOxide_NitrName)
  905. {
  906. // found the STD item
  907. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  908. return TRUE;
  909. }
  910. // rename the oxide nitride name as "Oxide" + "-" + "Nitride"
  911. strOxide_NitrName = OXIDE_STR + STR_CONNECT + NITRIDE_STR;
  912. // try to find the STD item
  913. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  914. if (pOxideNitrSTDItem)
  915. {
  916. // found the STD item
  917. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  918. return TRUE;
  919. }
  920. // rename the oxide nitride name as "Nitride"
  921. strOxide_NitrName = NITRIDE_STR;
  922. // try to find the STD item
  923. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  924. if (pOxideNitrSTDItem)
  925. {
  926. // found the STD item
  927. a_nIncId = pOxideSTDItem->GetSTDId();
  928. return TRUE;
  929. }
  930. }
  931. // can't identify this inclusion
  932. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  933. return TRUE;
  934. }
  935. // confirm the nitride id
  936. // try to find the STD
  937. auto pSTDItem = GetSTDItemByName(listNitrideSTD, strNitrideName);
  938. if (pSTDItem)
  939. {
  940. // found the STD item
  941. a_nIncId = pSTDItem->GetSTDId();
  942. return TRUE;
  943. }
  944. // rename the nitride as "Nitride" if it is not
  945. if (strNitrideName.CompareNoCase(NITRIDE_STR) != 0)
  946. {
  947. strNitrideName = NITRIDE_STR;
  948. auto pSTDItem = GetSTDItemByName(listNitrideSTD, strNitrideName);
  949. if (pSTDItem)
  950. {
  951. // found the STD item
  952. a_nIncId = pSTDItem->GetSTDId();
  953. return TRUE;
  954. }
  955. }
  956. // can't identify this inclusion
  957. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  958. return TRUE;
  959. }
  960. // nitrides classification
  961. BOOL COTSClassifyEng::CarbonClassify(CInclutionSTDDataPtr a_pPartSTDData,
  962. CElementChemistriesList& a_listElChemsIncNoFe,
  963. double a_dMolarSumNoFe,
  964. int& a_nIncId)
  965. {
  966. // safety check
  967. ASSERT(a_pPartSTDData);
  968. if (!a_pPartSTDData)
  969. {
  970. // something wrong
  971. LogErrorTrace(__FILE__, __LINE__, _T("CClassifyEng::CarbonClassify: invalid CPartSTDDataPtr."));
  972. return FALSE;
  973. }
  974. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  975. {
  976. // something wrong
  977. LogErrorTrace(__FILE__, __LINE__, _T("CClassifyEng::CarbonClassify: invalid molar sum value."));
  978. return FALSE;
  979. }
  980. // get all nitride STD items
  981. CSTDItemsList listCarbonSTD;
  982. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::CARBON, listCarbonSTD))
  983. {
  984. // something wrong
  985. LogErrorTrace(__FILE__, __LINE__, _T("CClassifyEng::NitrideClassify: failed to call GetClassifySTDItem method."));
  986. return FALSE;
  987. }
  988. // check if element chemistries list contain any nitrogen
  989. CElementChemistryPtr pCarElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_CAR);
  990. if (!pCarElChem)
  991. {
  992. // contains no nitrogen, this is not a nitride
  993. return TRUE;
  994. }
  995. // check if nitrogen amount enough
  996. double dCarMolar100 = Cal100NorValue(pCarElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  997. if (dCarMolar100 < MIN_CAR_MOLAR)
  998. {
  999. // have no enough nitrogen, this is not a nitride
  1000. return TRUE;
  1001. }
  1002. // this is a carbon
  1003. // any carbon STD items
  1004. if (listCarbonSTD.empty())
  1005. {
  1006. // no nitrides std items.
  1007. // can't identify this inclusion
  1008. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1009. return TRUE;
  1010. }
  1011. // mapping carbon sub elements
  1012. CString strCarbonName = _T("");
  1013. BOOL bMapped = FALSE;
  1014. for (int i = 0; i < INC_CAR_SUB_ELEMENT_MAX; ++i)
  1015. {
  1016. CElementChemistryPtr pCarSubElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_CAR_SUB_ELEMENT_NAMES[i]);
  1017. if (pCarSubElChem)
  1018. {
  1019. // this is a nitride sub element chemistry
  1020. // get %molar value of this sub element chemistry
  1021. double dCar_Sub_Molar = Cal100NorValue(pCarSubElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  1022. // make sure the sub element molar value is over mapping min value
  1023. if (dCar_Sub_Molar > MIN_CAR_SUB_MOLAR)
  1024. {
  1025. // try to map Nb
  1026. BOOL bNbMapped = FALSE;
  1027. // get molar % of the rest nitrogen
  1028. dCarMolar100 = Cal100NorValue(pCarElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  1029. // make sure nitrogen amount is enough
  1030. if (dCarMolar100 > MIN_CAR_MOLAR)
  1031. {
  1032. // get element "Nb"
  1033. CElementChemistryPtr pElChemNb = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_Nb);
  1034. // is there Nb in the list
  1035. if (pElChemNb)
  1036. {
  1037. // get %molar value of Nb
  1038. double dNb_Molar = Cal100NorValue(pElChemNb->GetMolarPercentage(), a_dMolarSumNoFe);
  1039. // make sure Nb molar value is over mapping min value
  1040. double dNbMappingRadio = INC_NITR_MAPPING_RADIO[2];
  1041. if (dNb_Molar > MIN_CAR_SUB_MOLAR)
  1042. {
  1043. if (!ElementsMapping(a_dMolarSumNoFe, dNbMappingRadio, pElChemNb, pCarElChem, bNbMapped))
  1044. {
  1045. // something is wrong
  1046. LogErrorTrace(__FILE__, __LINE__, _T("CClassifyEng::NitrideClassify: failed to call ElementsMapping method."));
  1047. return FALSE;
  1048. }
  1049. }
  1050. }
  1051. }
  1052. // mapped "Nb"
  1053. if (bNbMapped)
  1054. {
  1055. // carbon name is "NbC"
  1056. strCarbonName = INC_CAR_NAMES[0];
  1057. }
  1058. // completed mapping, get out the loop
  1059. break;
  1060. }
  1061. }
  1062. }
  1063. // mapped?
  1064. if (a_nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  1065. {
  1066. // this is an oxide nitride
  1067. // confirm the oxide nitride id
  1068. CSTDItemPtr pCarSTDItem = GetSTDItemByName(listCarbonSTD, strCarbonName);
  1069. // get the STD item of the mapped oxide
  1070. if (pCarSTDItem)
  1071. {
  1072. // found the STD item
  1073. a_nIncId = pCarSTDItem->GetSTDId();
  1074. return TRUE;
  1075. }
  1076. // can't identify this inclusion
  1077. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1078. return TRUE;
  1079. }
  1080. // confirm the carben id
  1081. // try to find the STD
  1082. auto pSTDItem = GetSTDItemByName(listCarbonSTD, strCarbonName);
  1083. if (pSTDItem)
  1084. {
  1085. // found the STD item
  1086. a_nIncId = pSTDItem->GetSTDId();
  1087. return TRUE;
  1088. }
  1089. // rename the Carbon as "Carbon" if it is not
  1090. if (strCarbonName.CompareNoCase(CARBON_STR) != 0)
  1091. {
  1092. strCarbonName = NITRIDE_STR;
  1093. auto pSTDItem = GetSTDItemByName(listCarbonSTD, strCarbonName);
  1094. if (pSTDItem)
  1095. {
  1096. // found the STD item
  1097. a_nIncId = pSTDItem->GetSTDId();
  1098. return TRUE;
  1099. }
  1100. }
  1101. // can't identify this inclusion
  1102. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1103. return TRUE;
  1104. }
  1105. // user STD items classification
  1106. BOOL COTSClassifyEng::UserClassify(CInclutionSTDDataPtr a_pPartSTDData,
  1107. CElementChemistriesList& a_listEltChemsInc,
  1108. double dSum,
  1109. int& a_nIncId)
  1110. {
  1111. // safety check
  1112. ASSERT(a_pPartSTDData);
  1113. if (!a_pPartSTDData)
  1114. {
  1115. // something wrong
  1116. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: invalid CPartSTDDataPtr."));
  1117. return FALSE;
  1118. }
  1119. if (dSum < MIN_ELEMENT_SUM)
  1120. {
  1121. // something wrong
  1122. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: invalid molar sum value."));
  1123. return FALSE;
  1124. }
  1125. // get user STD items
  1126. CSTDItemsList listUserSTD;
  1127. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::USER, listUserSTD))
  1128. {
  1129. // something wrong
  1130. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: failed to call GetClassifySTDItem method."));
  1131. return FALSE;
  1132. }
  1133. // try to identify the oxide
  1134. for (auto pUserSTD : listUserSTD)
  1135. {
  1136. // matching STD?
  1137. if (MatchingSTD(a_listEltChemsInc, pUserSTD, dSum))
  1138. {
  1139. // found matching STD
  1140. a_nIncId = pUserSTD->GetSTDId();
  1141. return TRUE;
  1142. }
  1143. }
  1144. // can't identify this inclusion
  1145. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1146. return TRUE;
  1147. }
  1148. // nominate element chemistries list
  1149. BOOL COTSClassifyEng::NomiNateElChemsList( CElementChemistriesList& a_listElChemsInc,
  1150. CElementChemistriesList& a_listNomiElChemsInc)
  1151. {
  1152. // return FALSE if nothing in the input list
  1153. if (a_listElChemsInc.empty())
  1154. {
  1155. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NomiNateElChemsList: invalid inclusion x-ray data."));
  1156. return FALSE;
  1157. }
  1158. // initialize outputs
  1159. a_listNomiElChemsInc.clear();
  1160. // go thought all element chemistry objects of the input lit
  1161. double dWeightPerSum = 0;
  1162. for (auto pElChem : a_listElChemsInc)
  1163. {
  1164. // create a new element chemistry
  1165. CElementChemistryPtr pElChemNew = CElementChemistryPtr(new CElementChemistry(*pElChem.get()));
  1166. // key element?
  1167. if (IsKeyElement(pElChem))
  1168. {
  1169. // this is a key element
  1170. // cal weight percentage sum
  1171. dWeightPerSum += pElChem->GetPercentage();
  1172. // add the element into the output list
  1173. a_listNomiElChemsInc.push_back(pElChemNew);
  1174. }
  1175. // sub element?
  1176. else if (IsSubElement(pElChem))
  1177. {
  1178. // this is a sub element
  1179. // Fe?
  1180. if (pElChem->GetName().CompareNoCase("Fe") != 0)
  1181. {
  1182. // cal weight percentage sum
  1183. dWeightPerSum += pElChem->GetPercentage();
  1184. // add the element into the output list
  1185. a_listNomiElChemsInc.push_back(pElChemNew);
  1186. }
  1187. }
  1188. }
  1189. // return FALSE if nothing in the input list or sum less than cut off value
  1190. if (a_listNomiElChemsInc.empty() || dWeightPerSum < INC_SUB_ELEMENT_CUT_OFF)
  1191. {
  1192. // something wrong
  1193. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NomiNateElChemsList: invalid inclusion x-ray data."));
  1194. return FALSE;
  1195. }
  1196. // go thought all element chemistry objects of the output lit
  1197. for (auto pElChem : a_listNomiElChemsInc)
  1198. {
  1199. // reset weight % value
  1200. // get weight % value
  1201. double dWeightPer = pElChem->GetPercentage();
  1202. // calculate new weight % value
  1203. double dWeightPerNew = Cal100NorValue(dWeightPer, dWeightPerSum);
  1204. // reset
  1205. pElChem->SetPercentage(dWeightPerNew);
  1206. }
  1207. // ok, return TRUE
  1208. return TRUE;
  1209. }
  1210. // protected
  1211. // check if this is a key element
  1212. BOOL COTSClassifyEng::IsKeyElement(CElementChemistryPtr a_pElChem)
  1213. {
  1214. // safety check
  1215. ASSERT(a_pElChem);
  1216. if (!a_pElChem)
  1217. {
  1218. // something wrong
  1219. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::IsKeyElement: invalid CElementChemistryPtr."));
  1220. return FALSE;
  1221. }
  1222. // go thought all key element
  1223. for (long i = 0; i < INC_KEY_ELEMENT_MAX; ++i)
  1224. {
  1225. // compare
  1226. if ((a_pElChem->GetName().CompareNoCase(INC_KEY_ELEMENT_NAMES[i]) == 0) && (a_pElChem->GetPercentage() >= INC_KEY_ELEMENT_CUT_OFF))
  1227. {
  1228. // this is a key element, return TRUE
  1229. return TRUE;
  1230. }
  1231. }
  1232. // this is not a key element, return FALSE
  1233. return FALSE;
  1234. }
  1235. // check if this is a sub element
  1236. BOOL COTSClassifyEng::IsSubElement(CElementChemistryPtr a_pElChem)
  1237. {
  1238. // safety check
  1239. ASSERT(a_pElChem);
  1240. if (!a_pElChem)
  1241. {
  1242. // something wrong
  1243. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::IsSubElement: invalid CElementChemistryPtr."));
  1244. return FALSE;
  1245. }
  1246. // go thought all sub element
  1247. for (long i = 0; i < INC_SUB_ELEMENT_MAX; ++i)
  1248. {
  1249. // compare
  1250. if ((a_pElChem->GetName().CompareNoCase(INC_SUB_ELEMENT_NAMES[i]) == 0) && (a_pElChem->GetPercentage() >= INC_SUB_ELEMENT_CUT_OFF))
  1251. {
  1252. // this is a key element, return TRUE
  1253. return TRUE;
  1254. }
  1255. }
  1256. // this is not a key element, return FALSE
  1257. return FALSE;
  1258. }
  1259. // get named element chemistry
  1260. CElementChemistryPtr COTSClassifyEng::GetNamedElementChemistry(CElementChemistriesList & a_listChemistriesElements, const CString a_strElementName)
  1261. {
  1262. CElementChemistryPtr pElChem = nullptr;
  1263. CString strName = a_strElementName;
  1264. auto itr = std::find_if(a_listChemistriesElements.begin(), a_listChemistriesElements.end(), [strName](CElementChemistryPtr& poElementChemistry) { return poElementChemistry->GetName().CompareNoCase(strName) == 0; });
  1265. if (itr != a_listChemistriesElements.end())
  1266. {
  1267. pElChem = *itr;
  1268. }
  1269. return pElChem;
  1270. }
  1271. bool SortBySTDID(const std::shared_ptr< CSTDItem> &v1, const std::shared_ptr< CSTDItem> &v2)
  1272. {
  1273. return v1->GetSTDId() < v2->GetSTDId();
  1274. }
  1275. // get classify STD items
  1276. BOOL COTSClassifyEng::GetClassifySTDItem(CInclutionSTDDataPtr a_pPartSTDDataPtr, INC_CLASSIFY_TYPE a_nClassifyType, CSTDItemsList& a_listSTDItems)
  1277. {
  1278. // safety check
  1279. ASSERT(a_pPartSTDDataPtr);
  1280. if (!a_pPartSTDDataPtr)
  1281. {
  1282. // something wrong
  1283. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::GetClassifySTDItem: invalid CPartSTDDataPtr."));
  1284. return FALSE;
  1285. }
  1286. // cal STD item id value range
  1287. OTS_STD_ITEM_VALUE nSTDIdRangeMin = OTS_STD_ITEM_VALUE::INVALID;
  1288. OTS_STD_ITEM_VALUE nSTDIdRangeMax = OTS_STD_ITEM_VALUE::INVALID;
  1289. switch (a_nClassifyType)
  1290. {
  1291. case INC_CLASSIFY_TYPE::SIMPLE_OXIDE:
  1292. {
  1293. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_MIN;
  1294. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_MAX;
  1295. }
  1296. break;
  1297. case INC_CLASSIFY_TYPE::COMPLEX_OXIDE:
  1298. {
  1299. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_MIN;
  1300. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_MAX;
  1301. }
  1302. break;
  1303. case INC_CLASSIFY_TYPE::OXIDE:
  1304. {
  1305. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_OXIDE_MIN;
  1306. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_OXIDE_MAX;
  1307. }
  1308. break;
  1309. case INC_CLASSIFY_TYPE::SUL:
  1310. {
  1311. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_SUL_MIN;
  1312. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_SUL_MAX;
  1313. }
  1314. break;
  1315. case INC_CLASSIFY_TYPE::NITR:
  1316. {
  1317. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_NITRIDE_MIN;
  1318. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_NITRIDE_MAX;
  1319. }
  1320. break;
  1321. case INC_CLASSIFY_TYPE::CARBON:
  1322. {
  1323. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_CARBON_MIN;
  1324. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_CARBON_MAX;
  1325. }
  1326. break;
  1327. case INC_CLASSIFY_TYPE::USER:
  1328. {
  1329. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::USER_MIN;
  1330. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::USER_MAX;
  1331. }
  1332. break;
  1333. default:
  1334. {
  1335. // wrong classify type value, return FALSE
  1336. return FALSE;
  1337. }
  1338. break;
  1339. }
  1340. // go through all STD items
  1341. a_listSTDItems.clear();
  1342. for (auto pSTDItem : a_pPartSTDDataPtr->GetSTDItemsList())
  1343. {
  1344. // is matching STD item?
  1345. if (pSTDItem->GetSTDId() >= (int)nSTDIdRangeMin && pSTDItem->GetSTDId() <= (int)nSTDIdRangeMax)
  1346. {
  1347. // get matching STD item
  1348. a_listSTDItems.push_back(pSTDItem);
  1349. }
  1350. }
  1351. // sort std item by std id
  1352. sort(a_listSTDItems.begin(), a_listSTDItems.end(), SortBySTDID);
  1353. // ok, return TRUE
  1354. return TRUE;
  1355. }
  1356. // get STD item by name
  1357. CSTDItemPtr COTSClassifyEng::GetSTDItemByName(CSTDItemsList& a_listSTDItems, CString a_strName)
  1358. {
  1359. CSTDItemPtr pSTDItem = nullptr;
  1360. auto itr = std::find_if(a_listSTDItems.begin(), a_listSTDItems.end(), [a_strName](CSTDItemPtr& pSTD) { return pSTD->GetName().CompareNoCase(a_strName) == 0; });
  1361. if (itr != a_listSTDItems.end())
  1362. {
  1363. // found the STD item
  1364. pSTDItem = *itr;
  1365. }
  1366. return pSTDItem;
  1367. }
  1368. // get STD item name by id
  1369. CString COTSClassifyEng::GetSTDItemNameById(CSTDItemsList& a_listSTDItems, int a_nItemId)
  1370. {
  1371. CString strName = _T("");
  1372. CSTDItemPtr pSTDItem = nullptr;
  1373. auto itr = std::find_if(a_listSTDItems.begin(), a_listSTDItems.end(), [a_nItemId](CSTDItemPtr& pSTD) { return pSTD->GetSTDId() == a_nItemId; });
  1374. if (itr != a_listSTDItems.end())
  1375. {
  1376. // found the STD item
  1377. pSTDItem = *itr;
  1378. strName = pSTDItem->GetName();
  1379. }
  1380. return strName;
  1381. }
  1382. // elements mapping
  1383. BOOL COTSClassifyEng::ElementsMapping(double a_dMolarSumNoFe,
  1384. double a_dMappingRatio,
  1385. CElementChemistryPtr a_pFirstElChem,
  1386. CElementChemistryPtr a_pSecondElChem,
  1387. BOOL& a_bMapped)
  1388. {
  1389. // safety check
  1390. ASSERT(a_pFirstElChem);
  1391. if (!a_pFirstElChem)
  1392. {
  1393. // something wrong
  1394. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ElementsMapping: invalid a_pFirstElChem."));
  1395. return FALSE;
  1396. }
  1397. ASSERT(a_pSecondElChem);
  1398. if (!a_pSecondElChem)
  1399. {
  1400. // something wrong
  1401. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ElementsMapping: invalid a_pSecondElChem."));
  1402. return FALSE;
  1403. }
  1404. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  1405. {
  1406. // something wrong
  1407. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ElementsMapping: invalid molar sum value."));
  1408. return FALSE;
  1409. }
  1410. if (a_dMappingRatio < MIN_DOUBLE_VALUE)
  1411. {
  1412. // something wrong
  1413. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ElementsMapping: invalid mapping radio value."));
  1414. return FALSE;
  1415. }
  1416. // set mapped flag to FALSE as default
  1417. a_bMapped = FALSE;
  1418. // get first mapping element molar value
  1419. double dFirstMolar = a_pFirstElChem->GetMolarPercentage();
  1420. // make sure molar value of the first mapping element chemistry is enough
  1421. double dFirstMolar100 = Cal100NorValue(dFirstMolar, a_dMolarSumNoFe);
  1422. if (dFirstMolar100 > ELEMENT_MAPPING_100MOLAR)
  1423. {
  1424. // get second mapping element chemistry molar value
  1425. double dSecondElMolar = a_pSecondElChem->GetMolarPercentage();
  1426. // make sure second mapping element chemistry value is enough
  1427. double dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSumNoFe);
  1428. if (dSecondElMolar100 > ELEMENT_MAPPING_100MOLAR)
  1429. {
  1430. // set mapped flag to true
  1431. a_bMapped = TRUE;
  1432. // reset mapping element chemistry molar values
  1433. // is there any first element left?
  1434. if (dFirstMolar - dSecondElMolar * a_dMappingRatio > 0)
  1435. {
  1436. // no more second element chemistry left;
  1437. a_pSecondElChem->SetPercentage(0.0);
  1438. // still there are some first element left
  1439. // calculate left first element molar value
  1440. dFirstMolar = dFirstMolar - (dSecondElMolar * a_dMappingRatio);
  1441. dFirstMolar100 = Cal100NorValue(dFirstMolar100, a_dMolarSumNoFe);
  1442. // is there enough first element left?
  1443. if (dFirstMolar100 > ELEMENT_MAPPING_100MOLAR)
  1444. {
  1445. // still have enough first element left
  1446. a_pFirstElChem->SetMolarPercentage(dFirstMolar);
  1447. }
  1448. else
  1449. {
  1450. // no enough enough first element left, set to 0.0
  1451. a_pFirstElChem->SetPercentage(0.0);
  1452. }
  1453. }
  1454. else
  1455. {
  1456. // no more first element chemistry left
  1457. a_pFirstElChem->SetPercentage(0.0);
  1458. // still there are some second element left
  1459. // calculate left second element molar value
  1460. dSecondElMolar = dSecondElMolar - dFirstMolar / a_dMappingRatio;
  1461. dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSumNoFe);
  1462. // is there enough second element left?
  1463. if (dSecondElMolar100 > ELEMENT_MAPPING_100MOLAR)
  1464. {
  1465. // still have enough second element left
  1466. a_pSecondElChem->SetMolarPercentage(dSecondElMolar);
  1467. }
  1468. else
  1469. {
  1470. // no enough enough second element left, set to 0.0
  1471. a_pSecondElChem->SetPercentage(0.0);
  1472. }
  1473. }
  1474. }
  1475. }
  1476. // ok, return TRUE
  1477. return TRUE;
  1478. }
  1479. // check if is a REOxide
  1480. BOOL COTSClassifyEng::IsASimpleOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum, CString& a_strSimOxName)
  1481. {
  1482. // go through oxide sub element chemistries
  1483. for (auto pOxideSubElChems : a_listElChems)
  1484. {
  1485. // calculate the %molar value of the sub element chemistry in the list
  1486. double dSubElMolar100 = Cal100NorValue(pOxideSubElChems->GetMolarPercentage(), a_dMolarSum);
  1487. // over simple oxide cut_off
  1488. if (dSubElMolar100 > SIMPLE_OXIDE_MOLAR_CUTOFF)
  1489. {
  1490. // this is a simple oxide, name it
  1491. for (int i = 0; i < INC_OXIDE_SUB_ELEMENT_MAX; ++i)
  1492. {
  1493. if (pOxideSubElChems->GetName().CompareNoCase(INC_OXIDE_SUB_ELEMENT_NAMES[i]) == 0)
  1494. {
  1495. // found it
  1496. // assign simple oxide name
  1497. a_strSimOxName = INC_OXIDE_NAMES[i];
  1498. // return TRUE
  1499. return TRUE;
  1500. }
  1501. }
  1502. }
  1503. }
  1504. // not a simple oxide, return FALSE
  1505. return FALSE;
  1506. }
  1507. // check if is a REOxide (deal with La-Ce-Oxide)
  1508. BOOL COTSClassifyEng::IsAREOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1509. {
  1510. // calculate real element molar %
  1511. double dREElementMolarSum = 0;
  1512. for (int i = 0; i < REOXIDE_KEY_ELEMENT_MAX; ++i)
  1513. {
  1514. CElementChemistryPtr pREElement = GetNamedElementChemistry(a_listElChems, REOXIDE_KEY_ELEMENT_NAMES[i]);
  1515. if (pREElement)
  1516. {
  1517. // got a real element
  1518. // calculate the %molar value of the real element chemistry in the list
  1519. double dSubElMolar100 = Cal100NorValue(pREElement->GetMolarPercentage(), a_dMolarSum);
  1520. // calculate real element molar %
  1521. dREElementMolarSum += dSubElMolar100;
  1522. }
  1523. }
  1524. // is real element molar % over REAlOxide elements molar % cut_off
  1525. if (dREElementMolarSum > REALOXIDE_ELEMELTS_MOLAR_CUTOFF)
  1526. {
  1527. // this is a REAlOxide, return TRUE
  1528. return TRUE;
  1529. }
  1530. // not a REOxide, return FALSE
  1531. return FALSE;
  1532. }
  1533. // check if is a REAlOxide
  1534. BOOL COTSClassifyEng::IsAnREAlOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1535. {
  1536. // calculate real element molar %
  1537. double dREElementMolarSum = 0;
  1538. for (int i = 0; i < REOXIDE_KEY_ELEMENT_MAX; ++i)
  1539. {
  1540. CElementChemistryPtr pREElement = GetNamedElementChemistry(a_listElChems, REOXIDE_KEY_ELEMENT_NAMES[i]);
  1541. if (pREElement)
  1542. {
  1543. // got a real element
  1544. // calculate the %molar value of the real element chemistry in the list
  1545. double dSubElMolar100 = Cal100NorValue(pREElement->GetMolarPercentage(), a_dMolarSum);
  1546. // calculate real element molar %
  1547. dREElementMolarSum += dSubElMolar100;
  1548. }
  1549. }
  1550. // is real element molar % over REAlOxide element molar % min cut_off
  1551. if (dREElementMolarSum < REALOXIDE_ELEMENT_MOLAR_LOW_CUTOFF)
  1552. {
  1553. // no, this is not a REALOxide, return FALSE
  1554. return FALSE;
  1555. }
  1556. // calculate Al/Si elements molar %
  1557. double dAl_Si_ElementMolarSum = 0;
  1558. for (int i = 0; i < REALOXIDE_SUB_ELEMENT_MAX; ++i)
  1559. {
  1560. CElementChemistryPtr pAlSiElement = GetNamedElementChemistry(a_listElChems, REALOXIDE_SUB_ELEMENT_NAMES[i]);
  1561. if (pAlSiElement)
  1562. {
  1563. // got a Al or Si element
  1564. // calculate the %molar value of the Al and Si element chemistry in the list
  1565. double dAl_SiElMolar100 = Cal100NorValue(pAlSiElement->GetMolarPercentage(), a_dMolarSum);
  1566. // calculate Al/Si elements molar %
  1567. dAl_Si_ElementMolarSum += dAl_SiElMolar100;
  1568. }
  1569. }
  1570. // is Al/Si elements molar % over REAlOxide element molar % min cut_off
  1571. if (dAl_Si_ElementMolarSum < REALOXIDE_ELEMENT_MOLAR_LOW_CUTOFF)
  1572. {
  1573. // no, this is not a REALOxide, return FALSE
  1574. return FALSE;
  1575. }
  1576. // is real element molar % + Al/Si elements molar % over the cut off
  1577. if (dREElementMolarSum + dAl_Si_ElementMolarSum > SIMPLE_OXIDE_MOLAR_CUTOFF)
  1578. {
  1579. // this is a REAlOxide, return TRUE
  1580. return TRUE;
  1581. }
  1582. // not a REAlOxide, return FALSE
  1583. return FALSE;
  1584. }
  1585. // check if is a Spinel
  1586. BOOL COTSClassifyEng::IsASpinel(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1587. {
  1588. // we deal with Mg, Al Spinel only
  1589. // get the first key element of Spinel
  1590. CElementChemistryPtr pFirstElChem = GetNamedElementChemistry(a_listElChems, SPINEL_KEY_ELEMENT_NAMES[0]);
  1591. if (!pFirstElChem)
  1592. {
  1593. // not a Spinel, return FALSE
  1594. return FALSE;
  1595. }
  1596. // get the second key element of Spinel
  1597. CElementChemistryPtr pSecondElChem = GetNamedElementChemistry(a_listElChems, SPINEL_KEY_ELEMENT_NAMES[1]);
  1598. if (!pSecondElChem)
  1599. {
  1600. // not a Spinel, return FALSE
  1601. return FALSE;
  1602. }
  1603. // check ratio between the two elements
  1604. double dFirstElMolar = pFirstElChem->GetMolarPercentage();
  1605. double dSecondElMolar = pSecondElChem->GetMolarPercentage();
  1606. if (dFirstElMolar < MIN_DOUBLE_VALUE)
  1607. {
  1608. // something wrong
  1609. // not a Spinel, return FALSE
  1610. return FALSE;
  1611. }
  1612. double dRatio = dSecondElMolar / dFirstElMolar;
  1613. if (dRatio < SPINEL_ELEMENT_RATIO_MIN || dRatio > SPINEL_ELEMENT_RATIO_MAX)
  1614. {
  1615. // not a Spinel, return FALSE
  1616. return FALSE;
  1617. }
  1618. // molar % amount check
  1619. double dFirstElMolar100 = Cal100NorValue(dFirstElMolar, a_dMolarSum);
  1620. double dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSum);
  1621. if (dFirstElMolar100 + dSecondElMolar100 > SPINEL_KEY_ELEMENT_MOLAR_TOTAL)
  1622. {
  1623. // this is a Spinel
  1624. return TRUE;
  1625. }
  1626. // not a Spinel, return FALSE
  1627. return FALSE;
  1628. }
  1629. // check if is a Silicate
  1630. BOOL COTSClassifyEng::IsASilicate(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1631. {
  1632. // get key element of Silicate
  1633. CElementChemistryPtr pKeyElChem = GetNamedElementChemistry(a_listElChems, SILICATE_KEY_ELEMENT_NAME);
  1634. if (!pKeyElChem)
  1635. {
  1636. // not a Silicate, return FALSE
  1637. return FALSE;
  1638. }
  1639. // molar % amount check
  1640. double dKeyElMolar100 = Cal100NorValue(pKeyElChem->GetMolarPercentage(), a_dMolarSum);
  1641. if (dKeyElMolar100 > SILICATE_KEY_ELEMENT_MOLAR_TOTAL_MIN && dKeyElMolar100 < SILICATE_KEY_ELEMENT_MOLAR_TOTAL_MAX)
  1642. {
  1643. // this is a Silicate, return TRUE
  1644. return TRUE;
  1645. }
  1646. // not a Silicate, return FALSE
  1647. return FALSE;
  1648. }
  1649. // check if is a Aluminate
  1650. BOOL COTSClassifyEng::IsAnAluminate(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1651. {
  1652. // get key element of Aluminate
  1653. CElementChemistryPtr pKeyElChem = GetNamedElementChemistry(a_listElChems, ALUMINATE_KEY_ELEMENT_NAME);
  1654. if (!pKeyElChem)
  1655. {
  1656. // not an Aluminate, return FALSE
  1657. return FALSE;
  1658. }
  1659. // molar % amount check
  1660. double dKeyElMolar100 = Cal100NorValue(pKeyElChem->GetMolarPercentage(), a_dMolarSum);
  1661. if (dKeyElMolar100 > ALUMINAT_KEY_ELEMENT_MOLAR_TOTAL_MIN && dKeyElMolar100 < ALUMINAT_KEY_ELEMENT_MOLAR_TOTAL_MAX)
  1662. {
  1663. // this is a Aluminate, return TRUE
  1664. return TRUE;
  1665. }
  1666. // not a Aluminate, return FALSE
  1667. return FALSE;
  1668. }
  1669. // check if the element chemistries list matching the STD
  1670. BOOL COTSClassifyEng::MatchingSTD(CElementChemistriesList& a_listElChems, CSTDItemPtr a_pSTDItem, double a_dMolarSum)
  1671. {
  1672. // safety check
  1673. ASSERT(a_pSTDItem);
  1674. if (!a_pSTDItem)
  1675. {
  1676. // something wrong
  1677. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::MatchingSTD: invalid CSTDItemPtr."));
  1678. return FALSE;
  1679. }
  1680. if (a_dMolarSum < MIN_ELEMENT_SUM)
  1681. {
  1682. // something wrong
  1683. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::MatchingSTD: invalid molar sum value."));
  1684. return FALSE;
  1685. }
  1686. // find out how many elements need for the STD
  1687. CElementRangeList& listElementRange = a_pSTDItem->GetElementRangeList();
  1688. int nElNoMin = 0;
  1689. for (auto pElmentRange : listElementRange)
  1690. {
  1691. int nStart = pElmentRange->GetRange()->GetStart();
  1692. if (nStart > 0)
  1693. {
  1694. // this element has to have
  1695. ++nElNoMin;
  1696. }
  1697. }
  1698. int nElNoMax = (int)listElementRange.size();
  1699. // a_listChemistriesElements size has to be between nElNoMin and nElNoMax
  1700. int nElementSize = (int)a_listElChems.size();
  1701. //if (nElementSize < nElNoMin || nElementSize > nElNoMax)
  1702. if (nElementSize < nElNoMin)
  1703. {
  1704. // a_listChemistriesElements size not match
  1705. return FALSE;
  1706. }
  1707. // all element chemistries have to be in listElementRange and in the range
  1708. for (auto pElChems : a_listElChems)
  1709. {
  1710. CString strElement = pElChems->GetName();
  1711. auto itr = std::find_if(listElementRange.begin(), listElementRange.end(), [strElement](CElementRangePtr& poElemenRange) { return poElemenRange->GetElement()->GetName().CompareNoCase(strElement) == 0; });
  1712. if (itr == listElementRange.end())
  1713. {
  1714. // not in the element range list, not match then
  1715. return FALSE;
  1716. }
  1717. // molar value has to be in the range
  1718. double dMolar = pElChems->GetMolarPercentage();
  1719. dMolar = Cal100NorValue(dMolar, a_dMolarSum);
  1720. if (dMolar < (double)(*itr)->GetRange()->GetStart() || dMolar >(double)(*itr)->GetRange()->GetEnd())
  1721. {
  1722. // molar value has to be in the range, not match then
  1723. return FALSE;
  1724. }
  1725. }
  1726. // the two are matching each other, return TRUE
  1727. return TRUE;
  1728. }
  1729. // calculate 100% normalize value (molar)
  1730. double COTSClassifyEng::Cal100NorValue(double a_dValue, double a_dSumValue)
  1731. {
  1732. double d100NorCalue = MIN_DOUBLE_VALUE;
  1733. // sum has a cut off
  1734. if (a_dSumValue < MIN_ELEMENT_SUM)
  1735. {
  1736. return d100NorCalue;
  1737. }
  1738. d100NorCalue = a_dValue / a_dSumValue * 100;
  1739. return d100NorCalue;
  1740. }
  1741. }