 All right, let's start the lesson on ion exchange. I discussed in the text that ion exchange is somewhere similar to surface complexation. But then you have multiple cations. And these cations have different affinity to the solid surface. So essentially, they are competing with each other. And the one with high affinity and higher concentration in the water phase, it end up to have more on the solid phase. So if you look at the key Q values or the different, you can get more or less a sense of their relative affinity. But also, if you have more or one particular species have high concentration in the water, it also ends up to be more on the solid phase. Because it has high concentration. If you write the key Q values, in order to get the key Q, you need a higher corresponding solid phase concentration. So let's look at example. Actually, this really should be 4.1, not 3.1. OK, so let's go through this example. And we'll talk about how to set it up. This example, I'm kind of thinking about massage shear water, produced water, or flowback water. And you have some concentration. We know there are a lot of different cations in these type of water. So I'm giving you a typical composition of massage shear water with high sodium, chloride, calcium. But you also have barium strontium. Actually, the barium strontium concentration is relatively low in what you have here. So we are here, and I'm giving you both PPM and more per kilogram water. Actually, both of them you can put in directly. So it's your choice. Now, I'm saying you have a 2,000 milliliter, a batch reactor of 300 milliliter. And this water is in equilibrium with partial pressure of CO2, which is this atmospheric concentration of CO2. Try to assume the condition in soil. And then I'm giving you this table that essentially can document the k-value for each reaction process. And the question I'm asking you the first is, without any equiscomplexation reaction, so you are still going to put OH-minors, carbonate, and all that. But you are not going to put, for example, calcium chloride, calcium OH-plus, and all these second species. I'm asking you to see, OK, with this, how much is absorbed on the exchange site? How much is absorbed on the end? And what is the percentage of the absorption on the exchange sites compared to its original total contribution? Essentially, I'm asking you to make a table for each major cation and list equiscomplexation column and list another exchange site column and then compare different species. But also calculate the percentage of the ones on the exchange site, because they all start with different equiscomplexation. So comparing the absolute value of something does not tell a lot of things. So you need to normalize them to the original total contribution. But then I also want you to look at on the exchange site, how much is occupied by each of these cations? It's how much is sodium, how much is calcium, how much is baryon, strontium, et cetera. So that's the first question. And then the second question is, running the submission with a complexation reaction, leads to the formation chloride species and ocean minus species, all these listed here. And then I'm asking to answer the same question. So comparing one to essentially you getting some information about how important are these equiscomplexation? Does it equiscomplexation help or not helping these cation to go on the surface side? So let's start doing this. We had a discussion today, and then you are saying, OK, maybe you can start with a blank one. So today I'm going to start with a blank input file. Essentially, there's not much information there, except that you will be doing like Aussie runtime parameters out there. And I also put a bit of output keyword specification there. I put two spatial profile time points, so it will be running into 100 minutes. And then initial condition, this is already specified, but we will specify initial condition later. OK, so let's go through each keyword block. First one is discretization. This one here, you essentially would specify the size, and we know it's one grid block. So you will be doing, first of all, you need to kind of putting the units for length. And we talk about this is 300 milliliters. So if you want to put centimeters or meters, that's fine. Last time we put a centimeter, so this time maybe we're just putting meters to have some variation. So the distance units will be meters. And then before, we always specify x zones. You essentially only have one species. So that will give you, let me see, you will specify one zone. And then because it's 300 milliliter, so that's 300 centimeter cube, and converting to meters would be three times 10 to the minus 4 meter cube. So I mentioned before, this is essentially when we do this, we specify that this is essentially the length of x zone. But by default, you actually have y zone and z zone. And the code is going to assume in these other two directions that you don't specify, it's going to 1 meter and 1 meter. So here you have specified 0.003 meters. So essentially your volume is 0.0003 cubic meters, which is 300 millimeter. Milliliter, I'm sorry. OK, so here now you specify the concentration of, you specify essentially the size of your system. Now, we probably can try this now just to be sure that you are not making any mistakes in this block. I always think it's a good practice to input one by one. And after each keyword block, you kind of check if everything is correct. You didn't make any wrong mistakes or whatever in the input file. OK, so because we, OK, so the top one is ring right. But because we didn't specify any condition, then it doesn't know what to do. That's OK. At least it didn't give me anything about like it's not specified correct or something like that. So let's do that again. Let's continue. All right, so let's specify primary species. And for that, we need to look at our table. So always put H plus first. I mentioned that before probably multiple times, but it was to mention again, always put H plus. And we know we have CO2-AQ, right? So we put CO2. So essentially, you follow that table. CO2-AQ. And it says the system is in equilibrium with CO2 gas. So you will need to put CO2-AQ. And then CO2, OK, now actually you don't need because it's just primary species. And then you'll be putting all the different species like sodium, just follow the list, calcium, potassium, magnesium, barium, strontium. That's your primary species on the table. But remember that we also have kaolinite. And I mentioned that for each mineral, so later on we'll put kaolinite in the mineral block. But remember that if you're going to put it to work, for the mineral, you will need to look up what this mineral is made up of. So let's look through. Let's open with notepad. OK, so let's search for kaolinite. Let's see what it can pose. So kaolinite coming up. You have H plus, you already have. You have aluminum, right? You have aluminum. You have silica, SiO2-AQ, H2O, it doesn't need to be there. So essentially it's aluminum, silica, right? So that means we need to because aluminum silica is not there on the list. So let's put these two in so we don't get messed up. All right, so you will have aluminum. And then you have SiO2-AQ. So these are the species we can think about it, right? OK, so that's the primary species list. Now I'm saying that we don't put any second species, like the chloride OH species. But we still need to put OH minusing because you can't do anything without OH minusing because that's the water dissociation association. And then you also have SiO2 species. So you have to have bicarbonate and carbonate species. OK, so these are the main species that you will have to complete. OK, now, OK, so that's the second species. And gases, do we have gases? We do because we have the SiO2-AQ that is in equilibrium with gas. So you do need a SiO2 gas phase. And then you have iXchange. So this is a new keyword block. We learned this in this unit. So here is exchange, the keyword exchange. I shouldn't do it in word. Crazy, OK. And then I'm going to give it a name, which X-representing surface species. But this one is on kaolinite. So let's do this. Let's call that. And this is on the mineral kaolinite, right? So essentially, you put this exchange at the keyword block and name of the surface site, exchange site, and then the name of the mineral. But also, the other thing you need to specify is what convention are you using for the calculation? We talk about three different, like Vanslow, Gaines, Thomas, for example. And let's hear, let's do Vanslow. Vanslow is one of the most commonly used exchange. So that's iXchange. So this keyword block is somewhat new, and you will need to think about doing that. Your folks will be here. But again, here, you have the kaolinite, and you need to put in the mineral kaolinite. There, the name there. If it's a mineral dissolution precipitation, you would need to put in kinetic information, for example, dissolution rays and everything. But here, we are not really looking at the dissolution precipitation clearance. We can just specify kaolinite. OK, so these are all the kind of building blocks of your system, chemistry building block of your system. And now we are going to specify what condition we have. And again, we are looking at, let's see, the table we have, the table three. OK, so let's just copy the species from aqueous, the species we had before, and we'll copy it. And then we will add whatever constitution they need to be. All right, we probably should have units first. Actually, we always need to specify, and condition, we all need to specify units. And this would let's say do PPM. And we can do temperature. Let's always do temperature, which is 25.0. And H plus, you can specify H plus. But in this table, I'm giving you 7.02. So it's easier to do just pH, which would be 7.02. And you have CO2-AQ. We discussed last time in the last lesson. You can specify the CO2 concentration with gas phase in this way when you have a specific partial pressure of that gas, E minus 4. So that's for CO2. And then we have sodium, which is 7900.0, potassium 277, 4.0, and then you have potassium 82, 82.5. I always think it's good to line up and make it neat and clean, because if you're not clean and line up and all that, it's very easy to make mistakes. It's almost like when you write code, you want to keep it very clean and organized so that it minimizes the chance of making mistakes. And when you check, it's easier to see. So it's a worse effort. 6.5 and chloride will be doing that with charge. OK, so you just put a charge there. How do I know that this is going to be positive charge without this? You can try data-based sweep first if you want. But I kind of know, because I know there's a lot of cations there. You'll see there's a lot of cations there, but there's almost the only species for now will be chloride and OH minus. And pH is 7, so OH will be 10 to the minus 7 assumptions. So it must be positive charged. And then we don't really have much of the aluminum. But we can put, for example, let's say we did before with this small concentration, just represent. It's there. OK, so these are the primary species. These are total concentration primary species. Now, I need to, so in the beaker, that's a water-faced composition. But then you also need to specify how much solids is there and how much surface area of a solid, how much CEC, and all that. So let's say we have volume fraction of the kaolinite is 0.005. OK, I think I didn't specify that in the file. Let's do that. With a sediment with kaolinite being the major with specific surface area. And OK, that. And then I'll add the kaolinite occupies 0.005 of the total volume. So you can actually calculate that because you have 0.005. And then the total volume is 300 milliliters. So I mean you have about 1.5 milliliters of the kaolinite. And we should specify the same thing in the input file. So I leave a space line here just to have the division between the solid-faced and aqueous face, especially the solid-soaked kaolinite. First thing you need to specify is 0.005 volume fraction actually of the solid face. All these, so essentially you have 0.005 actually. So that's actually smaller. We started talking about we didn't really put a porosity. We actually should put a porosity there. Let's finish this minute for specific surface area. We said it's 13.9 meters squared per. So it's volume fraction first on solid face. And then specific surface area is in SSA in meter squared per gram. So that's a meaner. But you also need to specify the surface side and exchange. So you have x kao, which is your name that's specifying the exchange. Is this need to be consistent with the exchange grid block? And then you have this keyword cc, which is to specify how much kaolinite exchange capacity you have. And we had, let's do a bit of calculation here. So it's 100, let me just make some notes here. You have 100.0 meq per kilogram, which is essentially 100.0 eq per gram. And this is equivalent to 1.0 e minus 2 eq per 100 gram. And also equivalent to 1.0 e minus 4. Oh, I'm sorry, this is actually not right. You have kilogram to gram. And then that's a sergeant. And meq to eq is 10 to minus 3. So this is actually 1.0 e minus 4. This is essentially the same as, let me check, the units of crunch flow. It's eq per gram. So essentially, eq per kilogram. So this will be actually, we should convert to eq per kilogram, already kilogram. So 100 times 10 to minus 3, which is 10 to minus 2. I'm sorry, this should be 10 to minus 1. Essentially, 0.1 eq per kilogram. We actually don't really need that. We can directly convert that. Now, so that means you need to put, because this is crunch flow units. So this will be essentially 0.1. So you specify the mineral volume fraction, keq. But actually, OK, here I said, we need actually need a little bit of porosity. So let's say you have, we probably should say 99.5% is water. So you actually positive 9. So actually, I should put the keolinite being 100%, 1.0, meaning all the solid phase of the keolinite should, because this is seeing the total volume. So the rest of it is all water. And then, so your price is 0.995. And you have 100%, they are all on the solid phase. This is volume fraction on solid. You only have keolinite. That's what I mean. So that's the condition. So I guess, do we need anything else? We have the dimension, let's just check dimension, vent flow, second species, primary species, and all that. So we should be OK. We don't have any, we don't need to do any time stepping. Let's try if it works. This will be less than 4.1 point. Specified price is smaller than 0, I think. There must be somewhere something wrong in the input file. Maybe it's error, I don't know. 0.0, OK, I'm sure. Let's just try again. 4.1 point in, interesting. A lot of time, when we say, when it reports one error, it's a lot of time it's because something else is wrong. I wonder if this is because I have the opening, the word format. Let me just copy everything and open a notepad and see if it's because of that. And we're going to call it less than 4.1 again, sorry. And we specify less than 4.1 in. All right, let's see, let's try it again. Do have this just specified, OK, let's see. I think it's still the original one. Now it's in the, let's do this, very interesting. Oh, the volume should probably, let me just think about it. I might have forgot it. It does need to be the volume fraction of total. So then you can, OK, I just realized that, OK. So the original file was right. It is a total, but it's not as a solid phase. You can mistake with different type of information. Anyway, so OK, let's try, I think that's the reason. Because I specified one here. And then I still have this, it will see a specific as that was one. So it will say, plus it is smaller than one, or equal to 0, essentially. OK, let's try it again. I believe that is error. Nine to ones. OK, great. So you now see the process of doing this. That I also make mistakes. And it takes time to debug and to realize what's wrong. And in this case, actually, what is wrong here? It is a processing. So it does point out to the right location. So the lesson here is volume fraction on total volume system. So later on, for example, if you have multiple minerals here, let's say you have your specific curinide, your specific calcite, another mineral. So volume fraction of the mineral and the volume fraction of the porosity needs to be add up to be 1.0. That's what you need to remember as a batch reactor. OK, so now we can look at the output file, essentially. Let's see, look at, we have two files here for each because I specified two different times. But you can imagine that they should be the same. I can tell you because the exchange direction occur really fast. It doesn't have time dimension. So it doesn't really matter if it's 100 minutes or it's 0.1 minutes because it reached equilibrium instantaneously. So if you compare this exchange 1 versus exchange 2, they should have the same concentration, essentially. So you have 1 and 2. It's exactly the same. So this is the exchange output, essentially specify in more per gram solid how much sodium on the surface, how much potassium, how much calcium, magnesium, strontium. And you can see from the list the dominant species sodium and then followed by calcium. Both of these species are very high concentration in the solution. Let's look at the input file again. Let's look at the table again. So sodium and calcium are the highest two concentration. Potassium have relative low. Magnesium, barium is in hundreds. And strontium have lowest concentration. So let's look at this again. So more or less, I mean, in here, because of the huge difference in concentration, you end up the sodium have the highest concentration, calcium have a second high. And then you have magnesium, barium, and strontium. So magnesium is a bit higher than barium, too. So the last one is barium. OK, so that's for the exchange side. And then if you look at the equest side, let's look at total concentration. That'll give you how much is in the total concentration. It's not in log units. So you have pH, you have CO2, sodium go from, actually, it's now you think about it. The output is already in more per kilogram water. So it's actually probably better if you use an input 5 milligram more per kilogram water. So you can look at the differences between the output, which is after the reaction, to before the reaction. So now you have sodium at 0.34, potential is this much. And you actually can calculate, for example, so these are the concentrations. This is per kilogram water. So you know there's 300 milliliter water. So this concentration times the volume of the water that gives you the mass in the water phase. And for the exchange side, it gives you in units of more per kilogram solid. And you can assume that we know that this is 0.05 of the total volume of the Kylian. So you actually can calculate from the 300 milliliter times 0.05, which is 1.5 milliliter of Kylianite. And so it's 1.5 centimeter cube of Kylianite. You can convert that to gram of Kylianite using the density of the Kylianite, give you the total gram of the solid phase. And that you can convert to how much massing on the exchange side. So with that calculation, you essentially will be able to calculate how much for each species is in water, and how much is actually in the solid phase for each species percentage. So you know which one participate more, actually. All right, so that's for aqueous phase and solid phase and all that. And then, OK, so the second question for that is, second question is, when you do include these aqueous compressations, let's do that. I'm closing this, I'm going to add the second species, more species, right? So this you will be having all the OH species and the chloride species. So let's see, let's go through the list. You have sodium chloride, which is AQ, because it doesn't have charge. And then you could have NaOH AQ. Let's just go through each species. And then there's sodium. You could have chasium chloride positive, chasium OH positive, potassium chloride AQ, and CKOH AQ. Mg, MgOH plus Bacl, BacOH, what else? John Shim, OK, John Shim, Cl plus John Shim, OH plus. I always, when I impose these, I always try to be very careful. And I probably mentioned you cannot use tab in the input file. Also, you cannot use comments in the middle of the line. You should, when you need a comment, you need to start a new line. Otherwise, it could get confused. So I typically get to be more careful when putting these input files, because if you are not careful, you end up spending more time debugging and all the frustration and all that. So keep things neat and be careful when you impose these. That will minimize the trends of making mistakes now that I mentioned that before. OK, so then you can save the original output file to a different folder. So you don't, otherwise, because I rerun it, it will be overwrite the original file. Here, just for demonstration, I don't do that. So if I run it again, it will surely make, rewrite everything. That's fine. OK, second specie input file not found in database. Let's see what happens. We just ran it and it works. So I must say I either made some mistake or, let's see, second specie input file not found in database. I'm pretty sure that's not true. I'm sure there is a database for CO3. Let's search for CO3. It should be there because otherwise the previous run wouldn't finish. OK, so it's there. So there's nothing wrong with the database. So it must be the input file. It's almost always our fault, as you can tell. Second species, just make sure everything is, looks like there might be something wrong there because I couldn't go up. So there's a lot of space there. And when I start line, that space might be too long so it couldn't. OK, let's just do it again. This is probably it, I think. So when you do this, I always look, man, OK, so you have this. Try to not have too much space in between. Otherwise the code cannot handle it if it's too long. There's a certain character limit in each line that the code can process. Let's do it again. I think that's 4.1.9 runs. OK, so it runs. And you can see from the data, it manifests just the right time. So that means it's all the output file are updated. And if you look at the exchange again, and compared to the previous one, if you save it, so when you do homework, you will need to save it and compare and see how much different does it make. All right, so we went through the output file, so I don't think I need to talk more. What you will need to do is, in each quest for the one without equisputation, make a table for the mass fraction of each of equisphase and mass fraction of the solid phase on the exchange side, and then do that for each major cations. And then do it the second question when you do have these equisputation. How much different does it make? And you can also track the specific concentration of all the equispecies to see which one is dominant and all that. And for this, if you want all the dominant species, you don't need to specify open each exchange file and everything. You actually can just look at the output file, less than 4.1 output file. Everything, all the concentration should be there. I use that output file just for you to see what is in these output files. But in here, this part should have everything there. And this part might not give you the units so you can actually dig into the exchange or exchange.out in this file to look if you forgot about units. For solid, it's more per gram. For equis, it's more per kilogram water. So it has all the different species. It also has all the exchange concentration. It also has all the equis concentration there. So you have everything you need. Okay, so I'm going to stop here and you see me made a mistake. And then we debug it actually in both time. The code point, the right place that I made a mistake. The first one was positive because it didn't put positive right. I put high coordinate 1.0 so there's no room for positive. The second one is CO3 minus minus and there's too many blank space in front so the code doesn't realize it. Anyway, so that's a two mistake. I mean, everything try to make it kind of no space. Just do enter for each species, you'll be fine. All right, so I'm going to stop here and you'll be working on the homework and everything have fun.