OTSClassifyEng.cpp 68 KB

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