OTSClassifyEng.cpp 59 KB

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