The economic and environmental costs are calculated using a versatile, easily adjusted C program, and modeled using a python program (so that we could take advantage of matplotlib.pyplot, an easy, beautiful plotting library). The C program uses a header file that has all of the functions necessary for the calculations, and asks the user for values (in variables) to change from the default. It then calculates the costs to be plotted and analyzed. The C calculator consists of the following variables (Note: We made all the variables doubles so as to avoid conflicts in trying to operate with integers and floats. We chose double instead of float to utilize the extra memory for most accurate results. Also note that all variables and functions are in italics).
The calculator would use those variables in certain functions (from the header file) to determine different aspects, such as cost, of the desalination plant. The first of these functions is energy, which calculates the electricity used by the mangrove-like method, using the formula php*0.75*hrs, where php represents the pump horsepower in hp, and hrs is the hours the plant is run per day. It requires 0.75 Kw of power per hp.
The next function is pump_cost, which calculates the cost to run the pump (which is just the cost for electricity), uses the function energy (see previous paragraph). The formula is energy(php, hrs)*costelectricity, where php represents the pump horsepower in hp, hrs is the hours the plant is run per day, and costelectricity is the cost of electricity. This is the cost to desalinate the water.
The function that converts cost per day of electricity (found using pump_cost) to cost per liter is called filter_cost. This divides the cost to filter per day by the hours run per day and divides that by 60 minutes to get cost per minute. That is then multiplied by the time to filter one liter (min/L) to get cost per liter of water.
The next function is filter, calculating the amount of water produced, is calculated by removing the quantity of salt and subtracting 1% of the water, to represent leaks and such.
Afterward comes time_filter, which calculates the amount of time to filter all of the water. This is done by finding how much time it would take to filter all of the water, using tliter*waterin where tliter is the amount of time to filter one liter of water, and waterin is the amount of water put into the system. That quantity is then divided by the number of filters to distribute the water around the filters.
The function maintaining comes next, to calculate the maintenance cost of the filter. This is done with costmaintenance+(employees*salary*hrs), where costmaintencance is the cost to maintain the plant for one day, employees is the number of employees working, salary is the employee salary, and hrs is the number of hours per day.
The next functions calculate the total cost to run the plant. The first one, total_cost, requires the cost of water per day, and adds that to the maintenance cost per day. The other, total_cost_complex converts water cost per liter to water cost per day using the time to filter one liter and the hours run per day (mangrove desalination uses the former, distillation the latter).
The next three functions are the distillation equivalent of filter, pump_cost, and time_filter (they only differ in that there are different methods of calculating for each). The function distill_out returns the distillation output of water, by removing 1/7 of the input (It takes 1L or water to distill 6L). The time_filter equivalent, time_distill, multiplies the water input by 63 minutes, as it takes 63 minutes to distill 1L of water. The final, distill_cost, calculates the distillation cost (just for filtering water) by multiplying the water input by $1.136, as it costs that much to distill per liter of water.
The function build_cost is the function that estimates the cost of building the plant. If no init_cost is given (the init_cost is at 0 after settings are exited), this function will run. It multiplies the cost of a pump by the number of filters and adds the approximate cost of a building to it to create a crude estimate.
The functions that calculate the waste factors (there is always waste) are waste and distill_waste. The former takes 1% of the water input and calls that waste, as this is the function used for mangrove-mimicking filters, and there shouldn't be any waste, but there should be some accommodated for. Because you waste 1 in 7 liters to distill water, we remove one-seventh of the water for waste.
The calculator also checks for the electricity used in distillation the function known as distill_energy, approximately 5 kWh per L of water.[9] So, this calculator multiplies 5 by the water input.
The last function the calculator has is called filter_time_base. This function calculates approximately how long it takes to filter one liter of water. First, it solves for flow rate, using the flow rate formula 3960php/(distance+head)*3.7854, where php is the horsepower of the pump, distance is the vertical distance above the water, and head is the head of the filter. This is multiplied by 3.7854 to convert gal/min to L/min. Then, it finds the reciprocal to change L/min to min/L.
The python modeling program creates five graphs, comparing the mangrove-mimicking desalination technique to distillation. The calculated values from the C calculator are then transferred to a text file where they will be read in a python file where the data will be graphed.