OTSClassifyEng.cpp 61 KB

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