
# -*- coding: utf-8 -*-
"""
Created on Wed May 19 23:26:10 2021

@author: Pierre Jouannais, Department of Planning, DCEA, Aalborg University
pijo@plan.aau.dk

"""
'''
Script containing the functions simulation the cultivation over a day including 
the temperature evolution and associated thermoregulation.

'''

import os


# Set working directory to file location 
# (works only when executing the whole file and not only sections (Run Current cell))

currentfolder=os.path.dirname(os.path.realpath(__file__))
os.chdir(currentfolder)

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import itertools
import Functions_for_physical_and_biological_calculations_2nd as functions
import Retrieving_solar_and_climatic_data_2nd as solardata
import math
import pandas as pd
import sys



###
# Execute to run the functions individually if needed

elemental_contents = pd.read_csv(
                    "../Data/elemental_contents.csv", sep=";",
                    header=0, encoding='unicode_escape',
                    engine='python')
elemental_contents = elemental_contents.iloc[:, 1:]
###


###
#  The dictionnaries can be generated by running the lines below to
#    test some functions individually

# Biodict={'rhoalgae':1100,
#           'lipid_af_dw':0.10,
#           'ash_dw':0.05,
#           'MJ_kglip' :36.3,
#           'MJ_kgcarb' :17.3,
#           'MJ_kgprot' :23.9,
#           'PAR' :0.45,
#           'losspigmentantenna' :0.21,
#           'quantumyield' :8,
#           'lossvoltagejump' :1-1267/1384,
#           'losstoATPNADPH' :1-590/1267,
#           'losstohexose' :1-469/590,
#           'lossrespiration' :0.10,
#           'bioact_fraction_molec' : 0.5,  #0<x<1
#           'prob_no3' :0.5,
#           'Topt':16,
#           'T_plateau':5,
#           'dcell':20*10**-6,
#           'incorporation_rate':0.10,
#           'nutrient_utilisation': 0.85,
#           'co2_utilisation': 0.85,
#           'phospolip_percent' : 0.10

#           }


# Physicdict={'hconv':6.6189 ,  #W m−2 K−1  Fernández, Ignacio, F. Gabriel Acién, Manuel Berenguel, and José Luis Guzmán. 2014. “First Principles Model of a Tubular Photobioreactor for Microalgal Production.” Industrial and Engineering Chemistry Research 53(27): 11121–36.
#           'Cp':4.186,  #kJ(kg.K)-1
#           'rhomedium':1000,
#           'rhowater':1000, #kg m-3
#           'Cw':2256}    #kJ.kg-1


# Locationdict={'lat':43.695,
#           'long':1.922,
#           'Twell' :10,  #C
#           'depth_well' :10,# m
#           'azimuthfrontal':90}

# Tech_opdict={'height':1.5,  #m
#           'tubediameter':0.03,  #m
#           'gapbetweentubes' :0.01,     #m
#           'horizontaldistance' :0.2,  #m
#           'length_of_PBRunit':20,    # m
#           'width_of_PBR_unit':20,   # m
#           'biomassconcentration':10,   #kg.m-3
#           'flowrate':0.38,     # m.s-1
#           'centrifugation_efficiency':0.95,
#           'pumpefficiency':0.90,
#           'slurry_concentration':0.15,
#           'water_after_drying':0.05,
#           'recyclingrateaftercentrifuge':0.3,
#           'rhosuspension':1015, #kg.m-3  ##suspension density should actually be a function of biomass concentration. But for now fixed to 1015 kg.m-3
#           'roughness':0.0000015, #m
#           'cleaningvolumeVSfacilityvolume':4,
#           'concentration_hypo': 2*10**-3,# kg.m-3
#           'concentration_hydro': 30, # kg.m-3
#           'boilerefficiency': 0.75,
#           'glass_life_expectancy' : 1500,
#           'prob_night_monitoring':0.5,

#           'extraction': 'yes',

#           'prob_market_subst_animal_feed': 0.5 #fish feed, animal feed, AD
#           }



'''
Important : these functions host modifications of a model in which continuous
harvest, supernatant and vapor recycling were assumed.
In tthe current version, no vapor recycling is assumed and harvest is only
performed at 9 in the evening. The lines where the modification may lead to 
confusion are marked with "#MODIF#"
'''

def modelthermo_1hour_timestep10(x, 
                                 t,  
                                 Qsun,
                                 Tair,
                                 Twell, 
                                 depth_well ,
                                 Cp,
                                 exchangearea,
                                 hconv,  
                                 Tmax,
                                 Tmin,
                                 m, 
                                 centrifugedvolumepers,  
                                 supernatant_pers,  
                                 volumetodrypers,  
                                 recyclingrateaftercentrifuge, 
                                 pumpefficiency,
                                 night_monitoring):
    '''
    Differential equations system solving.
    Defines the derivatives for temperature, energy, water pumping,
    energy to centrifugate
    #Returns the derivatives of the temperature, the energy uses,
    the water pumping , the energy needed to centrifugate.
    Over 1 hour.
    
    Time step = 10s
    
     #Inputs :
            
          #x : vector with initial values for integration (odeint) 
          #t : vector with Time points for integration (odeint)
          #Qsun : average solar power received by the system (by m2) ; W
          #Tair : Air temperature ; °C
          #Twell : temperature of the well/water ; °C
          #Cp : Calorific value of water   ; kJ kg-C−1
          #exchangearea: Total exchange area with air per m2 ; m2
          #Tmax, Tmin _ Maximum and minimum temperature within which the strain must be kept ; °C
          #m : mass of water (by m2)   #  kg
          #centrifugedvolumepers : average centrifuged volume per s  ; L.s-1
          #supernatant_pers : average share fo this centriguged volume which
          is not part of the slurry and will be reinjected or replaced according
          to recyclingrateaftercentrifuge ; L.s-1
          
          #volumetodrypers : average volume to vaporate per s ; L.s-1
          #recyclingrateaftercentrifuge : share of the supernatant which can
          be reinjected in the PBR ; 0<x<1
          
          #pumpefficiency _: efficiency of the pump ; .
          #night_monitoring: 'yes' = Thermoregulation  at night,
          'no' = No Thermoregulation  at night 


      #Outputs : 
          
          Derivatives for every 20 seconds during for further integration over an hour: 
              All powers in kW. Volumes in L         
         
          #dEcooldt ; derivative cooling energy (asbolute thermal energy) ; kW
          #dEheatdt ; derivative heating energy ; kW
          #dtempdt ; derivative temperature evolution ; °C.s-1
          #dEcentrifugdt ; derivative  energy provided by replacing
          the supernatant after centrifuge  ; kW
          
          #dEdryingheatdt ; derivative energy provided by recycling hot vapor ; kW
          #dEdryingcooldt ; derivative energy provided by replacing vaporized 
          water with water from the well/river ; kW
          
          #dEdryingmixdt ; derivative energy provided by replacing supernatant 
          and vapor when there is no need for thermoregulation (well water)

          #dWaterpumpedwelldt ; derivative  water pumped from the well/river ; L.s-1
          
          #dWaterpumpedfacilitydt ; derivative water pumped from the well/river ; L.s-1
          
          #dEpumping_heat_exchanger ; derivative energy to pump well/river 
          water in the heat exchanger ; kW
          
         
          '''
    ##
    Ecool = x[0] 
    Eheat = x[1] 
    temp = x[2] 
    Ecentrifug = x[3] 
    Edryingheat = x[4] 
    Edryingcool = x[5]            
    Edryingmix = x[6] 
    Waterpumpedwell = x[7]  
    Waterpumpedfacility = x[8]  
    Epumping_heat_exchanger = x[9]  
    Waterpumpedheatechanger = x[10]  

    #############
    # Convective exchange with air
    #############

    # * 20 because time step 20 s
    Qenv = hconv*exchangearea*(Tair-temp)*20  # W


    #############
    # If it's night time and there is no thermoregulation
    #############    
    if Qsun == 0 and night_monitoring == 'no':

        '''Modif for 1 harvest per day at 9PM :
        Vapor is never reinjected and always replaced by water from the well
        All thermal exchanges due to vapor repalcement are assigned to
        dEdryingcooldt (even if sometimes positive because Twell>Temp) '''


        dEcooldtpre = 0  # kW , No cooling
        # "pre" as the actual active cooling which is needed will depend on
        # the cooling provided by the harvesting/recycling system

        dEheatdt = 0  # kW , # No heating

        # Volume to vaporize is replaced by water from the well


        """HERE MODIF : WE NEGLECT THIS EXCHANGE """
        dEdryingcooldt = 0
        
        # * 20 because time step 20 s
        # dEdryingcooldt = volumetodrypers*Cp*(Twell-temp)*20  # kW

        

        dEcooldt = 0  # kW , No cooling

        dWaterpumpedwelldt = volumetodrypers*20  # L.s-1

        dWaterpumpedfacilitydt = 0  # L.s-1

        dEdryingheatdt = 0  # kW

        dEdryingmixdt = 0  # kW

        dEpumping_heat_exchanger = 0  # kW # No cooling

        dWaterpumpedheatechanger = 0   # kW # No cooling

        # Temperature of the reinjected water which replaces supernatant
        # and which is a mix of supernatant and water from the well
        Trecylecedaftercentrifuge = (temp * (recyclingrateaftercentrifuge)
                                     + Twell*(1-recyclingrateaftercentrifuge))  # °C

        # Q provided by injecting this water
        
        # * 20 because time step 20 s

        # Qwateraftercentrifugation = (supernatant_pers*Cp
        #                              * (Trecylecedaftercentrifuge - temp)*20)  # kW

        # dEcentrifugdt = Qwateraftercentrifugation  # kW
        
        """HERE MODIF : WE NEGLECT THIS EXCHANGE """
        Qwateraftercentrifugation = 0
        dEcentrifugdt = 0
        
        
        
        # The supernatant which is not reinjected needs to be
        # replaced by water pumped from the well
        
        # * 20 because time step 20 s

        dWaterpumpedwelldt += (supernatant_pers
                               * (1 - recyclingrateaftercentrifuge)*20)  # L.s-1

        # The supernatant which isreinjected needs to be
        # replaced by water pumped from the facility
        dWaterpumpedfacilitydt += supernatant_pers*recyclingrateaftercentrifuge*20  # L.s-1

        # /1000 for conversion W to kW
        dtempdt = ((Qsun*20/1000)
                   + (Qenv/1000)
                   + dEdryingcooldt
                   + dEdryingheatdt
                   + Qwateraftercentrifugation
                   + dEdryingmixdt)/(m*Cp)  # °C.s-1

    #############
    # If it's not night time or if it's thermoregulated at night
    #############
    else:
        if temp > Tmax:  # If the culture is too hot

            # Cooling necessary to bring culture back to Tmax
            dEcooldtpre = m*Cp*(Tmax - temp)*20  # kW, negative
            # "pre" as the actual active cooling which is needed will depend on
            # the cooling provided by the harvesting/recycling system

            dEheatdt = 0  # kW, No heating

            # Volume to vaporize is replaced by water from the well

            dEdryingcooldt = volumetodrypers*Cp*(Twell-temp)*20  # kW
       
            """HERE MODIF : WE NEGLECT THIS EXCHANGE """
            dEdryingcooldt = 0
            
            # * 20 because time step 20 s
            # dEdryingcooldt = volumetodrypers*Cp*(Twell-temp)*20  # kW




            dEcooldt = dEcooldtpre-dEdryingcooldt  # Actual necessary Cooling, kW, negative

            # Volume to vaporize is replaced by water from the well

            dWaterpumpedwelldt = volumetodrypers*20    # L.s-1

            dWaterpumpedfacilitydt = 0  # L.s-1

            dEdryingheatdt = 0  # kW

            dEdryingmixdt = 0  # kW

            #############
            # Heat exchanger (See appendix)
            #############

            Vm_heat_exchanger = -dEcooldt/((Tmax-Twell)*Cp)  # kg.s-1
            

            dEpumping_heat_exchanger = (
                Vm_heat_exchanger*depth_well*1.05*9.81)/(pumpefficiency*1000)  # kW

            dWaterpumpedheatechanger = Vm_heat_exchanger  # kg.s-1

        elif temp < Tmin:  # If the culture is too cold

            dEheatdtpre = m*Cp*(Tmin - temp)*20  # kW , positive

            dEcooldt = 0  # kW, No Cooling


            """HERE MODIF : WE NEGLECT THIS EXCHANGE """
            dEdryingcooldt = 0
             # # Volume to vaporize is replaced by water from the well
            # dEdryingcooldt = volumetodrypers*Cp*(Twell-temp)*20  # kW
           


            # MODIF : The vaporized water is never recycled and
            # always replaced by well/river water
            dEdryingheatdt = 0  # kW

            # Heating must also compensate the injection of cold water
            dEheatdt = dEheatdtpre - dEdryingcooldt

            dWaterpumpedwelldt = volumetodrypers*20    # L.s-1

            dWaterpumpedfacilitydt = 0    # L.s-1

            dEdryingmixdt = 0  # kW

            dEpumping_heat_exchanger = 0  # kW

            dWaterpumpedheatechanger = 0  # kg.s-1

        else:  # If the culture'temperature is within the good thermal range

            dEcooldt = 0  # kW, No cooling

            dEheatdt = 0  # kW, No heating

            
            
            """HERE MODIF : WE NEGLECT THIS EXCHANGE """
            dEdryingmixdt = 0
            #dEdryingmixdt = volumetodrypers*Cp*(Twell - temp)*20  # kW
             # # Volume to vaporize is replaced by water from the well
            # dEdryingcooldt = volumetodrypers*Cp*(Twell-temp)*20  # kW
           



            dWaterpumpedwelldt = volumetodrypers*20   # L.s-1

            dWaterpumpedfacilitydt = 0    # L.s-1

            dEdryingcooldt = 0  # kW

            dEdryingheatdt = 0  # kW

            dEpumping_heat_exchanger = 0  # kW

            dWaterpumpedheatechanger = 0  # kg.s-1

        # Q brought by water reinjection after centrifugation
        Trecylecedaftercentrifuge = (temp *
                                     (recyclingrateaftercentrifuge)+Twell
                                     * (1 - recyclingrateaftercentrifuge))  # °C

        # dEcentrifugdt = (supernatant_pers*Cp
        #                  * (Trecylecedaftercentrifuge-temp)*20)  # kW
        
        """HERE MODIF : WE NEGLECT THIS EXCHANGE """
        
        dEcentrifugdt = 0

        # The harvested volume which is not reinjected needs to
        # be replaced by water pumped from the well/river
        dWaterpumpedwelldt += (supernatant_pers
                               * (1 - recyclingrateaftercentrifuge)*20)  # L.s-1
       
        # The supernatant which is reinjected needs to be pumped back
        # from the facility
        dWaterpumpedfacilitydt += supernatant_pers*recyclingrateaftercentrifuge*20

        dtempdt = ((Qsun*20/1000)
                   + (Qenv/1000)
                   + dEcooldt
                   + dEheatdt
                   + dEcentrifugdt 
                   + dEdryingmixdt)/(m*Cp)  # °C.s-1
        
        


    return [dEcooldt,
            dEheatdt,
            dtempdt,
            dEcentrifugdt,
            dEdryingheatdt,
            dEdryingcooldt,
            dEdryingmixdt,
            dWaterpumpedwelldt,
            dWaterpumpedfacilitydt,
            dEpumping_heat_exchanger,
            dWaterpumpedheatechanger]


def thermosimulation_1day_timestep10(hconv,
                                     Twell,
                                     depth_well,
                                     Cp,
                                     facility_volume,
                                     exchangearea,
                                     Tmax,
                                     Tmin,
                                     fraction_maxyield,
                                     biomassconcentration,
                                     flowrate,
                                     m,
                                     centrifugation_efficiency,
                                     pumpefficiency,
                                     slurry_concentration,
                                     water_after_drying,
                                     recyclingrateaftercentrifuge,
                                     volumetodrypers_list,
                                     supernatant_pers_list,
                                     centrifugedvolumepers_list,
                                     centrifugedvolumepers_list_wholeunit,
                                     hourly_temperature_list,
                                     hourly_collected_power_list,
                                     rhoalgae,
                                     rhomedium,
                                     dcell,
                                     night_monitoring):
    '''Integrates the function "modelthermo_1hour_timestep10" over the whole day,
    Calculates the temperature evolution and thermal energy requirements over a day.

    #Inputs :

        #hconv : Convective coefficient air  ; W.m−2.K−1
        #Twell : Well water temperature ; °C
        #depth_well : Well depth ; m
        #facility_volume : PBR volume per m2 ; m3
        #exchangearea :Total exchange area with air per m2 ; m2
        #Tmax : Maximal temperature for the strain ; °C
        #Tmin : Minimal temperature for the strain ; °C
        #percentage yield : Fraction of the maximum yield achieved ; .
        # biomassconcentration : Biomass concentration ; g.L-1
        #flowrate : Flow rate in the pipe ; m.s-1
        #m : Water mass in the PBR per m2; kg
        #centrifugation_efficiency : Fraction of the biomass which is separated
        and harvested ; .

        #pumpefficiency, efficiency of the pump ; .

        # slurry_concentration : Mass Fraction biomass in the slurry ; kg dw.kg slurry-1
        #water_after_drying : Mass fraction of water in the dried biomass ; kg water.kg dbio-1
        #recyclingrateaftercentrifuge : share of the supernatant which can
          be reinjected in the PBR ; .

        #volumetodrypers_list : List of the averaged(from 1 hour to 1 s)
        volumetric flows to vaporize for every hour of the day. 24 values in L.s-1

        #supernatant_pers_list : List of the averaged(from 1 hour to 1 s)
        volumetric flows of supernatant produced for every hour of the day.
        24 values in L.s-1

        #centrifugedvolumepers_list : List of the averaged(from 1 hour to 1 s)
        volumetric flows centrifuged every hour of the day.
        24 values in L.s-1

        #centrifugedvolumepers_list_wholeunit : List of the averaged(from 1 hour to 1 s)
        volumetric flows centrifuged every hour of the day,
        considering the whole PBR unit and not just 1m2.
        24 values in L.s-1

        #hourly_temperature_list : list of the air temperatures, for every hour of the day
        24 values in °C


        #hourly_collected_power_list : list of solar irradiance powers collected by 1m2 of the PBR, 
        for every hour of the day
        24 values in W.

        #rhoalgae : Density of the algae cell ; kg.m-3
        #rhomedium : Density of the medium (without algae) ; kg.m-3
        #dcell : Diameter of the cell ; m
        #night_monitoring: 'yes' = Thermoregulation  at night,
        'no' = No Thermoregulation  at night


    #Outputs :

        #totalenergycool : Total thermal energy demand for cooling over a day ; kWh.d-1
        #totalenergyheat : total thermal energy demand for heating over a day ; kWh.d-1
        #totalwaterpumpedfacility : Total water needed to be pumped from the facility  over a day ; L.d-1
        #totalwaterpumpedwell : Total water needed to be pumped from the well over a day ; L.d-1
        #totalenergytocentrifugeaverage : Total enery needed to centrifuge and harvest the culture, over a day ; kwH.day-1
        #flatdaytotaltemp : Temperature evolution over a day ;  °C
        #flatdaytotalEcentrifugkwh : Evolution of the thermal energy provided
        by the recyling/recplacement of the supernatant, over a day; kWh

        #flatdaytotalEdryingheatkw : Evolution of the thermal energy provided
        by the recycling of vapor(0 due to the modificaton), over a day ; kWh

        #flatdaytotalEdryingcoolkwh : Evolution of the thermal energy provided
        by the replacement of vaporized water by well/river water, over a day ; kWh

        #flatdaytotalEdryingmixkwh : Evolution of the thermal energy provided
        by the replacement of vaporized water by well/river water when there is
        no need for thermoregulation, over a day  ; kWh

        #flatdaytotalEheatkwh : Evolution of the thermal energy demand for heating over a day ; kWh

        #flatdaytotalEcoolkwh : Evolution of the thermal energy demand for cooling over a day ; kWh

        #flatdaytotalenergyforheatexchangerkwh : Evolution of the energy demand
        for the cooling heat exchanger over a day ; kWh

        #totalenergyheatexchanger : total  energy demand for the cooling
        heat exchanger, over a day ; kWh.d-1

        #flatdaytotalwaterforheatexchanger : Evolution of water demand for the cooling
        heat exchanger over a day; L

        #totalwaterpumpedheatexchanger : Total water demand for the cooling
        heat exchanger over a day; L.d-1

        '''

    t = range(1, 181)  # 3600s per hour, but time step 20s
    #Initializing the lists that will contain the reuslts of the integration
    # of all variables over a day
    daytotaltemp = []  # °C
    daytotalEcool = []  # kJ  (1 kW for 1 s = 1kJ  )
    daytotalEheat = []  # kJ
    daytotalEcentrifug = []  # kJ
    daytotalEdryingheat = []  # kJ
    daytotalEdryingcool = []  # kJ
    daytotalEdryingmix = []  # kJ
    daytotalwaterpumpedwell = []  # L
    daytotalwaterpumpedfacility = []  # L
    daytotalenergyforheatexchanger = []  # kJ
    daytotalwaterforheatexchanger = []  # L


    # Initializing values for the integration over the first hour
    x0 = [0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0]

    #By default, temperature at 12.00 PM is set at 5 degrees but this
    #has no influence on the final result

    # Initializing the variable that will contain the total energy demand for
    # centrifugation
    totalenergytocentrifugeaverage = 0

    # For each hour, we integrate all the variables starting with the last
    # point of the previous hour.
    for hour in range(0, 24):
        # For each hour, the associated value of each variable is chosen
        Tair = hourly_temperature_list[hour]

        Qsun = hourly_collected_power_list[hour]

        centrifugedvolumepers = centrifugedvolumepers_list[hour]

        supernatant_pers = supernatant_pers_list[hour]

        volumetodrypers = volumetodrypers_list[hour]

        # Only needed for centrifugation energy requirement as non linear.
        centrifugedvolumepers_wholeunit = centrifugedvolumepers_list_wholeunit[hour]

        # Integration of all variables over an hour
        x = odeint(modelthermo_1hour_timestep10,
                   x0,
                   t,
                   args=(Qsun, Tair, Twell, depth_well,  # environment
                         Cp, exchangearea, hconv,  # thermo
                         Tmax, Tmin, m,  # strain
                         centrifugedvolumepers,
                         supernatant_pers,
                         volumetodrypers,
                         recyclingrateaftercentrifuge,
                         pumpefficiency,
                         night_monitoring,))

        x0[0] = x[-1, 0]  # new starting temperature for next hour 
        
        if x0[0]>70:
            sys.exit(('whatthehell',hour,hconv,
                                     Twell,
                                     depth_well,
                                     Cp,
                                     facility_volume,
                                     exchangearea,
                                     Tmax,
                                     Tmin,
                                     fraction_maxyield,
                                     biomassconcentration,
                                     flowrate,
                                     m,
                                     centrifugation_efficiency,
                                     pumpefficiency,
                                     slurry_concentration,
                                     water_after_drying,
                                     recyclingrateaftercentrifuge,
                                     volumetodrypers_list,
                                     supernatant_pers_list,
                                     centrifugedvolumepers_list,
                                     centrifugedvolumepers_list_wholeunit,
                                     hourly_temperature_list,
                                     hourly_collected_power_list,
                                     rhoalgae,
                                     rhomedium,
                                     dcell,
                                     night_monitoring))

            
        
        x0[1] = x[-1, 1]  # new starting Cooling energy demand for next hour
        x0[2] = x[-1, 2]  # etc.
        x0[3] = x[-1, 3]
        x0[4] = x[-1, 4]
        x0[5] = x[-1, 5]
        x0[6] = x[-1, 6]
        x0[7] = x[-1, 7]
        x0[8] = x[-1, 8]
        x0[9] = x[-1, 9]
        x0[10] = x[-1, 10]

        # Each list for each variable receives the evolution of the variable over this hour.
        
        daytotalEcool.append(x[:, 0])  # kJ
        daytotalEheat.append(x[:, 1])  # kJ
        daytotaltemp.append(x[:, 2])   # °C
        daytotalEcentrifug.append(x[:, 3])  # kJ
        daytotalEdryingheat.append(x[:, 4])  # kJ
        daytotalEdryingcool.append(x[:, 5])  # kJ
        daytotalEdryingmix.append(x[:, 6])  # kJ
        daytotalwaterpumpedwell.append(x[:, 7])  # L
        daytotalwaterpumpedfacility.append(x[:, 8])  # L
        daytotalenergyforheatexchanger.append(x[:, 9])  # kJ
        daytotalwaterforheatexchanger.append(x[:, 10])  # L

        #############
        # Centrifuging energy calculation
        #############

        # The energey to centrifuge 1m3 depends on the temperature
        # So we collect the average temperature during this hour
        Tmeanperhour = sum(x[:, 2])/181

        # The energy requirement to centrifuge 1m3 depends non linearly on the
        # centrifugating flow (harvesting flow).
        # Assuming that there is one centrifuge for each square meter is wrong
        #and we instead assume that there is one centrifuge for the whole PBR unit.

        #MODIF : In this version, the harvesting flow is constant and fixed at
        #5m3.h-1 for the whole unit
        #This does not change the validity of the line below.
        
        # Conversion flow from L.s-1 to m3.h-1  #Disk centrifuge
        centrifuging_energy_averaged = ((centrifugedvolumepers/1000)
                                        * 3600
                                        * functions.Centrifugationenergy_m3(rhoalgae,
                                                                          rhomedium,
                                                                          Tmeanperhour,
                                                                          dcell,
                                                                          (centrifugedvolumepers_wholeunit/1000) * 3600)[0])  




        # Summing over the day
        totalenergytocentrifugeaverage += centrifuging_energy_averaged
        
        
        
        
        if totalenergytocentrifugeaverage>50000:
            sys.exit(('whatthehel_centril',centrifugedvolumepers,hour,hconv,
                                     Twell,
                                     depth_well,
                                     Cp,
                                     facility_volume,
                                     exchangearea,
                                     Tmax,
                                     Tmin,
                                     fraction_maxyield,
                                     biomassconcentration,
                                     flowrate,
                                     m,
                                     centrifugation_efficiency,
                                     pumpefficiency,
                                     slurry_concentration,
                                     water_after_drying,
                                     recyclingrateaftercentrifuge,
                                     volumetodrypers_list,
                                     supernatant_pers_list,
                                     centrifugedvolumepers_list,
                                     centrifugedvolumepers_list_wholeunit,
                                     hourly_temperature_list,
                                     hourly_collected_power_list,
                                     rhoalgae,
                                     rhomedium,
                                     dcell,
                                     night_monitoring))

    #############
    # If there is no thermoregulation at night,
    # then the initial temperature value at 12 PM must be the final temperature
    # value of the simulated day (simulate steady state over a month)
    #############

    # We resimulate the day with the new initial value for the temperature
    if night_monitoring == 'no':

        # Modification of the initial temperature
        x0 = [0, 0, daytotaltemp[-1][-1], 0, 0, 0, 0, 0, 0, 0, 0]

        # Identical section to simulate the day

        daytotaltemp = []  # C
        daytotalEcool = []  # kJ
        daytotalEheat = []  # kJ
        daytotalEcentrifug = []  # kJ
        daytotalEdryingheat = []  # kJ
        daytotalEdryingcool = []  # kJ
        daytotalEdryingmix = []  # kJ
        daytotalwaterpumpedwell = []  # L
        daytotalwaterpumpedfacility = []  # L
        daytotalenergyforheatexchanger = []  # kJ
        daytotalwaterforheatexchanger = []  # L

        totalenergytocentrifugeaverage = 0

        # For each hour, we integrate all the variables starting with the last
        # point of the previous hour.
        for hour in range(0, 24):
            # For each hour, the associated value of each variable is chosen
            Tair = hourly_temperature_list[hour]
            Qsun = hourly_collected_power_list[hour]
            centrifugedvolumepers = centrifugedvolumepers_list[hour]
            supernatant_pers = supernatant_pers_list[hour]
            volumetodrypers = volumetodrypers_list[hour]

            # Only needed for centrifugation energy requirement as non linear.
            centrifugedvolumepers_wholeunit = centrifugedvolumepers_list_wholeunit[hour]
    
            # Integration of all variables over an hour
            x = odeint(modelthermo_1hour_timestep10,
                       x0,
                       t,
                       args=(Qsun, Tair, Twell, depth_well,  # environment
                             Cp, exchangearea, hconv,  # thermo
                             Tmax, Tmin, m,  # strain
                             centrifugedvolumepers,
                             supernatant_pers,
                             volumetodrypers,
                             recyclingrateaftercentrifuge,
                             pumpefficiency,
                             night_monitoring,))

            x0[0] = x[-1, 0]  # new starting temperature for next hour
            
            if x0[0]>70:
                sys.exit(('whatthehell_2ndloop',hour,hconv,
                                         Twell,
                                         depth_well,
                                         Cp,
                                         facility_volume,
                                         exchangearea,
                                         Tmax,
                                         Tmin,
                                         fraction_maxyield,
                                         biomassconcentration,
                                         flowrate,
                                         m,
                                         centrifugation_efficiency,
                                         pumpefficiency,
                                         slurry_concentration,
                                         water_after_drying,
                                         recyclingrateaftercentrifuge,
                                         volumetodrypers_list,
                                         supernatant_pers_list,
                                         centrifugedvolumepers_list,
                                         centrifugedvolumepers_list_wholeunit,
                                         hourly_temperature_list,
                                         hourly_collected_power_list,
                                         rhoalgae,
                                         rhomedium,
                                         dcell,
                                         night_monitoring))
            x0[1] = x[-1, 1]  # new starting Cooling energy demand for next hour
            x0[2] = x[-1, 2]  # etc.
            x0[3] = x[-1, 3]
            x0[4] = x[-1, 4]
            x0[5] = x[-1, 5]
            x0[6] = x[-1, 6]
            x0[7] = x[-1, 7]
            x0[8] = x[-1, 8]
            x0[9] = x[-1, 9]
            x0[10] = x[-1, 10]

            # Each list for each variable receives the evolution of the variable over this hour.
            daytotaltemp.append(x[:, 2])

            daytotalEcool.append(x[:, 0])  # kJ

            daytotalEheat.append(x[:, 1])  # kJ

            daytotalEcentrifug.append(x[:, 3])  # kJ

            daytotalEdryingheat.append(x[:, 4])  # kJ

            daytotalEdryingcool.append(x[:, 5])  # kJ

            daytotalEdryingmix.append(x[:, 6])  # kJ

            daytotalwaterpumpedwell.append(x[:, 7])  # L
            
            daytotalwaterpumpedfacility.append(x[:, 8])  # L

            daytotalenergyforheatexchanger.append(x[:, 9])  # kJ

            daytotalwaterforheatexchanger.append(x[:, 10])  # L

            #############
            # Centrifuging energy calculation
            #############

            # The energey to centrifuge 1m3 depends on the temperature
            # So we collect the average temperature during this hour
            Tmeanperhour = sum(x[:, 2])/181


            # The energy requirement to centrifuge 1m3 depends non linearly on the
            #centrifugating flow (harvesting flow).
            #Assuming that there is one centrifuge for each square meter is wrong 
            #and we instead assume that there is one centrifuge for the whole PBR unit.

            #MODIF : In this version, the harvesting flow is constant and fixed at 
            #5m3.h-1 for the whole unit
            #This does not change the validity of the line below.

            centrifuging_energy_averaged = ((centrifugedvolumepers/1000)
                                          * 3600
                                          * functions.Centrifugationenergy_m3(rhoalgae,
                                                                              rhomedium,
                                                                              Tmeanperhour,
                                                                              dcell,
                                                                              (centrifugedvolumepers_wholeunit/1000) * 3600)[0])  

            # Conversion flow from L.s-1 to m3.h-1  #Disk centrifuge

            # Summing over the day
            totalenergytocentrifugeaverage += centrifuging_energy_averaged


            if totalenergytocentrifugeaverage>50000:
                sys.exit(('whatthehel_centril',centrifugedvolumepers,hour,hconv,
                                         Twell,
                                         depth_well,
                                         Cp,
                                         facility_volume,
                                         exchangearea,
                                         Tmax,
                                         Tmin,
                                         fraction_maxyield,
                                         biomassconcentration,
                                         flowrate,
                                         m,
                                         centrifugation_efficiency,
                                         pumpefficiency,
                                         slurry_concentration,
                                         water_after_drying,
                                         recyclingrateaftercentrifuge,
                                         volumetodrypers_list,
                                         supernatant_pers_list,
                                         centrifugedvolumepers_list,
                                         centrifugedvolumepers_list_wholeunit,
                                         hourly_temperature_list,
                                         hourly_collected_power_list,
                                         rhoalgae,
                                         rhomedium,
                                         dcell,
                                         night_monitoring))
            ### End of the second simulation of the day for no night thermoregulation


    # Flaten the lists to obtain the whole day in one list
    flatdaytotaltemp = list(itertools.chain(*daytotaltemp))  # kJ

    flatdaytotalEcool = list(itertools.chain(*daytotalEcool))  # kJ

    flatdaytotalEheat = list(itertools.chain(*daytotalEheat))  # kJ

    flatdaytotalEcentrifug = list(itertools.chain(*daytotalEcentrifug))  # kJ

    flatdaytotalEdryingheat = list(itertools.chain(*daytotalEdryingheat))  # kJ

    flatdaytotalEdryingcool = list(itertools.chain(*daytotalEdryingcool))  # kJ

    flatdaytotalEdryingmix = list(itertools.chain(*daytotalEdryingmix))  # kJ

    flatdaytotalwaterpumpedwell = list(
        itertools.chain(*daytotalwaterpumpedwell))  # L

    flatdaytotalwaterpumpedfacility = list(
        itertools.chain(*daytotalwaterpumpedfacility))  # L

    flatdaytotalenergyforheatexchanger = list(
        itertools.chain(*daytotalenergyforheatexchanger))    # kJ

    flatdaytotalwaterforheatexchanger = list(
        itertools.chain(*daytotalwaterforheatexchanger))    # L

    # Conversion from kJ to kWh
    flatdaytotalEcoolkwh = [a/3600 for a in flatdaytotalEcool]

    flatdaytotalEheatkwh = [a/3600 for a in flatdaytotalEheat]

    flatdaytotalEcentrifugkwh = [a/3600 for a in flatdaytotalEcentrifug]

    flatdaytotalEdryingheatkwh = [a/3600 for a in flatdaytotalEdryingheat]

    flatdaytotalEdryingcoolkwh = [a/3600 for a in flatdaytotalEdryingcool]

    flatdaytotalEdryingmixkwh = [a/3600 for a in flatdaytotalEdryingmix]

    flatdaytotalenergyforheatexchangerkwh = [a/3600 for a in flatdaytotalenergyforheatexchanger]

    # Total  and water demands are  the last values of the list - the second values
    # Removing the initial energies and water consumptions (first 20 sec of the day)
    # allows to erase the effect of the arbitrary choice of an initial value for 
    # the temperature in the case of a thermoregulation at night.
    # It's a way to make the model operate at steady state.

    totalenergycool = flatdaytotalEcoolkwh[-1]-flatdaytotalEcoolkwh[1] # kWh.d-1

    totalenergyheat = flatdaytotalEheatkwh[-1] - flatdaytotalEheatkwh[1]  # kWh.d-1


    totalenergyheatexchanger = (flatdaytotalenergyforheatexchangerkwh[-1] 
                                - flatdaytotalenergyforheatexchangerkwh[1]) # kWh.d-1

    totalwaterpumpedheatexchanger =(flatdaytotalwaterforheatexchanger[-1]
                                    - flatdaytotalenergyforheatexchangerkwh[1]) # kWh.d-1

    totalwaterpumpedfacility = flatdaytotalwaterpumpedfacility[-1]  # L

    totalwaterpumpedwell = flatdaytotalwaterpumpedwell[-1]  # L

    return [totalenergycool,
            totalenergyheat,
            totalwaterpumpedfacility,
            totalwaterpumpedwell,
            totalenergytocentrifugeaverage,
            flatdaytotaltemp,
            flatdaytotalEcentrifugkwh,
            flatdaytotalEdryingheatkwh,
            flatdaytotalEdryingcoolkwh,
            flatdaytotalEdryingmixkwh,
            flatdaytotalEheatkwh,
            flatdaytotalEcoolkwh,
            flatdaytotalenergyforheatexchangerkwh,
            totalenergyheatexchanger,
            flatdaytotalwaterforheatexchanger,
            totalwaterpumpedheatexchanger]


def cultivation_simulation_timestep10(hconv,
                                      Twell,
                                      depth_well,
                                      lat,
                                      long,
                                      azimuthfrontal,
                                      month,
                                      Cp, 
                                      height,
                                      tubediameter,
                                      gapbetweentubes,
                                      horizontaldistance,
                                      length_of_PBRunit,
                                      width_of_PBR_unit, 
                                      rhoalgae,
                                      rhomedium,
                                      rhosuspension,
                                      dcell,
                                      Tmax,
                                      Tmin,
                                      Biodict,
                                      ash_dw,
                                      Nsource, 
                                      fraction_maxyield, 
                                      biomassconcentration,
                                      flowrate,  
                                      centrifugation_efficiency,
                                      pumpefficiency, 
                                      slurry_concentration,
                                      water_after_drying,
                                      recyclingrateaftercentrifuge,
                                      night_monitoring,
                                      elemental_contents):


    '''
    #function that simulates the cultivation over a day.

    #Inputs :

        #hconv : convective coefficient air  ; W m−2 K−1
        #Twell : Well water temperature ; °C
        #depth_well : Well depth ; m
        #PBR geometry parameters :
            height ; m
            tubediameter ; m
            gapbetweentube ; m
            horizontaldistance ; m
            length_of_PBRunit ; m
            width_of_PBR_unit ; m

        #location parameters :
            lat : latitute expressed in format ; XX.XXX or X.XXX
            long : longitude expressed in format ; XX.XXX or X.XXX
            azimuthfrontal : azimuth of the frontal side of the PBR unit ;  180:-180

        #rhoalgae : Density of the algae cell ; kg.m-3
        #rhomedium : Density of the medium (without algae) ; kg.m-3
        #rhosuspension : Density of the culture suspension ; kg.m-3
        #dcell : Diameter of the cell ; m
        #Tmax : Maximal temperature for the strain ; °C
        #Tmin : Minimal temperature for the strain ; °C


        #Biodict : Dictionnary containing all strain specific parameters.

        *No conflict with other parameters called individually.
        Avoids having too many input parameters in the function.

        #ash_dw : ash content in dry biomass ; g.g-1 dw
        #Nsource :Source of nitrogen ; Nitrate or Ammonium (no3 or nh3)
        #pourcentage yield : Fraction of the maximum yield achieved ; .
        # biomassconcentration : Biomass concentration ; g.L-1
        #flowrate : Flow rate in the pipe ; m.s-1
        #centrifugation_efficiency : Fraction of the biomass which is separated
        and harvested ; .

        #pumpefficiency, efficiency of the pump ; .
        # slurry_concentration : Mass Fraction biomass in the slurry ; kg dw.kg slurry-1
        #water_after_drying : Mass fraction of water in the dried biomass ; kg water.kg dbio-1
        #recyclingrateaftercentrifuge : share of the supernatant which can
          be reinjected in the PBR ; .

        #night_monitoring: 'yes' = Thermoregulation  at night,
        'no' = No Thermoregulation  at night


    # Outputs :
  
       #totalenergyneeded_tocool_perday : Total thermal enery demand for cooling the system over a day  ; kWh.d-1
       #totalenergyneeded_toheat_perday : Total thermal energy demand for heating over a day ; kWh.d-1
       #totalwaterpumpedfromthefacility_perday : Total water which needs to be pumped from the facility  over a day ; L.d-1
       #totalwaterpumpedfromthewell_perday : Total water which needs to be pumped from the well over a day ; L.d-1
       #totalproduction : Total daily production ; g.d-1
       #totalproduction_harvested : Total harvested daily production ; g.d-1
       #totalproduction_loss : Total lost daily production ; g.d-1
       #volumetric_yield : Volumetric yield ; g.m-3
       #totalenergyneededtocentrifuge : Total energy demand for centrifugation ; kWh.d-1
       #temperature_evolution ; Temperature evolution over the day (8640 points) ; °C  
       #energy_evolution_supernatant_recycling_replacing_kWh : Evolution of the energy
       provided by supernatant recycling/replacement ; kWh

       #energy_evolution_drying_heat_kWh : Evolution of the energy provided by 
       recycling vapor when heating is required ; kWh# MODIF: Always 0.

       #energy_evolution_drying_cool_kWh : Evolution of the energy provided by 
       replacing the vapor  ; kWh
       MODIF: The vapor is always replaced by well water.

       #energy_evolution_drying_mix_kWh : Evolution of the energy provided by 
       replacing the vapor when no thermoregulation is needed  ; kWh 
       MODIF: The vapor is always replaced by well water.
              
       #heatingenergyevolution : Evolution of the thermal energy demand for heating ; kWh   
       #coolingenergyevolution : Evolution of the thermal energy demand for cooling ; kWh
       #energyevolution_heatexchanger : Evolution of the energy demand for 
       the cooling heat exchanger ; kWh

       #totalenergyneeded_heatexchanger_perday : Total energy demand for the cooling heating exchanger over a day ; kWh.d-1 
       #heatexchanger_water_evolution : Evolution of water demand for the heat exchanger ; kWh
       #totalwaterheatexchanger : Total water demand for the heat exchanger over a day; kWh.d-1
       
       
       
       #centrifugedvolumepers_list_wholeunit : List of the averaged(from 1 hour to 1 s)
        volumetric flows centrifuged every hour of the day,
        considering the whole PBR unit and not just 1m2.
        24 values in L.s-1
        
        
       #totalwater_centrifuged_perday : total amount of water centrifuged over a day ; L.d-1

       '''

    # Collecting some geometric features
    geometry = functions.PBR_geometry(height,
                                      tubediameter,
                                      gapbetweentubes,
                                      horizontaldistance,
                                      length_of_PBRunit,
                                      width_of_PBR_unit)

    facility_volume = geometry[0]  # m3
    exchangearea = geometry[5]  # m2

    # Collecting climatic data
    data = solardata.Qreceived_bym2PBR_month(lat,
                                             long,
                                             month,
                                             azimuthfrontal,
                                             height,
                                             tubediameter,
                                             gapbetweentubes,
                                             horizontaldistance,
                                             length_of_PBRunit,
                                             width_of_PBR_unit)



    # List of sunlight powers collected by the PBR (averaged over 1m2), for each hour    
    hourly_collected_power_list = data[0]['Average']  # W
    # Also equivalent to Wh as it's the average power over an hour. 
    # 1 W during 1h = 1Wh 
    
    # List of air temperature, for each hour
    hourly_temperature_list = data[1]  # °C

    # List of ground irradiances, for each hour    
    hourly_ground_irradiance_list = data[2]

    # Maximum theoretical yield in g ashfree dw.h-1    
    yieldbiomass_on_energy = functions.energeticyield_biomass_perkjenergy(Biodict['lipid_af_dw'], #g ashfree dw.kJsunlight-1
                                                                          ash_dw,
                                                                          water_after_drying,
                                                                          Biodict['PAR'],
                                                                          Biodict['losspigmentantenna'],
                                                                          Biodict['quantumyield'],
                                                                          Biodict['lossvoltagejump'],
                                                                          Biodict['losstoATPNADPH'],
                                                                          Biodict['losstohexose'],
                                                                          Biodict['lossrespiration'],
                                                                          Nsource,
                                                                          Biodict['phospholipid_fraction'],
                                                                          elemental_contents)  

    # Maximum theoretical productions per hour without ash
    # *3.6 to convert irradiance (Wh) into kJ
    maximum_production_per_hour_list = (hourly_ground_irradiance_list #g ashfree dw.h-1
                                        * 3.6
                                        * yieldbiomass_on_energy)
    
    # Maximum theoretical production with ash
    maximum_production_per_hour_list_with_ash = (maximum_production_per_hour_list  # g dw .h-1
                                                 / (1 - ash_dw))  

    # Actual production depending on how much of the maximum yield can be achieved
    actual_production_per_hour_list = maximum_production_per_hour_list_with_ash*fraction_maxyield  # g dw.h-1

    # Total production over the dat
    totalproduction = sum(actual_production_per_hour_list)  # g dw.d-1

    # The biomass at the end of the day
    biomass_at_harvest = (biomassconcentration                   # g.L-1
                          + totalproduction/(facility_volume*1000))

    ###
    # Centrifuged volumes and water recycling/reinjection
    ###

    # We consider the centrifugation efficiency and the recycling of part of 
    # the biomass so that the biomass concentration at the end of the day is
    # exactly the same as at the beginning
    totalwater_centrifuged_perday = (totalproduction           # L.d-1
                                     / (biomass_at_harvest
                                        * (centrifugation_efficiency
                                           + (1 - centrifugation_efficiency)
                                           * (1-recyclingrateaftercentrifuge))))


    # To simplify the code, we assume that all the thermal exchanges due to the 
    #harvesting are concentrated over 1h (21h), even if  the real harvest (5m3.h-1 for the whole unit) 
    # may take more or less time

    centrifugedvolumeperhour_list = [0]*24

    # Harvest at 9PM.
    centrifugedvolumeperhour_list[21] = totalwater_centrifuged_perday  # L

    centrifugedvolumepers_list = [a/3600 for a in centrifugedvolumeperhour_list]

    centrifugedvolumepers_list = pd.Series(centrifugedvolumepers_list)


    # The energy requirement to centrifuge 1m3 depends non linearly on the
    # centrifugating flow (harvesting flow).
    # Assuming that there is one centrifuge for each square meter is wrong
    # and we instead assume that there is one centrifuge for the whole PBR unit.
    
    centrifugedvolumepers_list_wholeunit = [0]*24

    centrifugedvolumepers_list_wholeunit[21] = 5000/3600  # L.s-1 # 5m3.h-1

    centrifugedvolumepers_list_wholeunit = pd.Series(centrifugedvolumepers_list_wholeunit)


    # Calculation of the volumes of water to vaporize and the volumes of
    # supernatant for each hour

    modified_harvested_production_per_hour_list = [0]*24

    modified_harvested_production_per_hour_list[21] = totalproduction

    modified_harvested_production_per_hour_list = pd.Series(modified_harvested_production_per_hour_list)

    Water_in_1kg_slurry = 1-slurry_concentration  # kgwater.kgslurry-1

    Water_in_slurry__producedperhour_list = (Water_in_1kg_slurry    #  L
                                             * modified_harvested_production_per_hour_list 
                                             / (1000*slurry_concentration))  

    Water_in_slurry__producedpers_list = [
        a/3600 for a in Water_in_slurry__producedperhour_list]  # L

    #If the centrifuged water is not in the slurry, it is in the supernatant
    supernatant_perhour_list =(centrifugedvolumeperhour_list
                                -Water_in_slurry__producedperhour_list)

    supernatant_pers_list = [a/3600 for a in supernatant_perhour_list]

    volumetodrypers_list = [(1-water_after_drying/slurry_concentration)
                            * a for a in Water_in_slurry__producedpers_list]  # L



    # Calculating the mass of the culture in 1 m2 of PBR
    m = rhosuspension*facility_volume  # kg


    ###
    # Temperature
    ###

    # Call the function that simulates temperature and thermoregulation
    resultsthermo = thermosimulation_1day_timestep10(hconv,
                                                     Twell,
                                                     depth_well,
                                                     Cp,
                                                     facility_volume,
                                                     exchangearea,
                                                     Tmax,
                                                     Tmin,
                                                     fraction_maxyield,
                                                     biomassconcentration,
                                                     flowrate,
                                                     m,
                                                     centrifugation_efficiency,
                                                     pumpefficiency,
                                                     slurry_concentration,
                                                     water_after_drying,
                                                     recyclingrateaftercentrifuge,
                                                     volumetodrypers_list,
                                                     supernatant_pers_list,
                                                     centrifugedvolumepers_list,
                                                     centrifugedvolumepers_list_wholeunit,
                                                     hourly_temperature_list,
                                                     hourly_collected_power_list,
                                                     rhoalgae,
                                                     rhomedium,
                                                     dcell,
                                                     night_monitoring)

    #Collecting results

    totalenergyneeded_tocool_perday = resultsthermo[0]

    totalenergyneeded_toheat_perday = resultsthermo[1]

    totalwaterpumpedfromthefacility_perday = resultsthermo[2]

    totalwaterpumpedfromthewell_perday = resultsthermo[3]

    totalenergyneededtocentrifuge = resultsthermo[4]

    temperature_evolution = resultsthermo[5]

    energy_evolution_supernatant_recycling_replacing_kWh = resultsthermo[6]

    energy_evolution_drying_heat_kWh = resultsthermo[7]

    energy_evolution_drying_cool_kWh = resultsthermo[8]

    energy_evolution_drying_mix_kWh = resultsthermo[9]

    heatingenergyevolution = resultsthermo[10]

    coolingenergyevolution = resultsthermo[11]

    energyevolution_heatexchanger = resultsthermo[12]

    totalenergyneeded_heatexchanger_perday = resultsthermo[13]

    heatexchanger_water_evolution = resultsthermo[14]

    totalwaterheatexchanger = resultsthermo[15]



    #Adjusting the actual harvested and lost productions

    totalproduction_harvested = (totalproduction                
                                 * (centrifugation_efficiency
                                    + (1 - centrifugation_efficiency)
                                    * recyclingrateaftercentrifuge))
    
    totalproduction_loss = totalproduction - totalproduction_harvested #g.d-1

    volumetric_yield = totalproduction/facility_volume  # g.m-3

    return [totalenergyneeded_tocool_perday,
            totalenergyneeded_toheat_perday,
            totalwaterpumpedfromthefacility_perday,
            totalwaterpumpedfromthewell_perday,
            totalproduction,
            totalproduction_harvested,
            totalproduction_loss,
            volumetric_yield,
            totalenergyneededtocentrifuge,
            temperature_evolution,
            energy_evolution_supernatant_recycling_replacing_kWh,
            energy_evolution_drying_heat_kWh,
            energy_evolution_drying_cool_kWh,
            energy_evolution_drying_mix_kWh,
            heatingenergyevolution,
            coolingenergyevolution,
            energyevolution_heatexchanger,
            totalenergyneeded_heatexchanger_perday,
            heatexchanger_water_evolution,
            totalwaterheatexchanger,
            centrifugedvolumepers_list_wholeunit,
            totalwater_centrifuged_perday]



