OTSClassifyEng.cpp 65 KB

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