OTSClassifyEng.cpp 60 KB

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