OTSClassifyEng.cpp 62 KB

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