function solverState = newBinForNucleation(solverState, pbeDefinition, ...
    optionStruct)
% remove nucleation handling to solver structure
%
% THIS FUNCTION IS NO USER FUNCTION.

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2012 Alexander Reinhold
%
% This program is free software: you can redistribute it and/or modify it 
%   under the terms of the GNU General Public License as published by the 
%   Free Software Foundation, either version 3 of the License, or (at your 
%   option) any later version.
%
% This program is distributed in the hope that it will be useful, but 
%   WITHOUT ANY WARRANTY; without even the implied warranty of 
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
%   General Public License for more details.
%
% You should have received a copy of the GNU General Public License along 
%   with this program.  If not, see <http://www.gnu.org/licenses/>.

if solverState.flagNucleation
   
    % overwrites old boundary with old pivot (now inactive)
    solverState.hcMatrix(:, 2) = solverState.hcMatrix(:, 2);
    solverState.numberVector(2) = solverState.numberVector(1);
    solverState.indexVector(2) = -1;
    
    % overwrite old pivot with new boundary  
    solverState.hcMatrix(:, 1) = pbeDefinition.nucleationSize;
    solverState.numberVector(1) = 0;
    solverState.indexVector(1) = 0;
    
    % add new nucleation pivot
    solverState.hcMatrix = [pbeDefinition.nucleationSize ...
                            solverState.hcMatrix];
    solverState.numberVector = [0 solverState.numberVector];
    solverState.indexVector = [-2 solverState.indexVector];
    
    [hcMatrixDump upVector] = ensureProperDecData(...
        pbeDefinition.nucleationSize(1:pbeDefinition.nDecCoordinate, 1), ...
        1, pbeDefinition);
    solverState.upVector = [upVector, solverState.upVector];
    
    %! Dev: the below lines should be obsolete by the above lines
%     solverState.upVector = [computePartitionIndexDec(pbeDefinition.dec, ...
%         pbeDefinition.nucleationSize(1:pbeDefinition.nDecCoordinate, :), [], 1) ...
%         solverState.upVector];
%     
%     solverState.upVector = computeUpVector(pbeDefinition, ...
%         pbeDefinition.nucleationSize(1:pbeDefinition.nDecCoordinate, :), ...
%         optionStruct);
%     solverState.upVector = [computePartitionIndexDec(pbeDefinition.dec, ...
%           pbeDefinition.nucleationSize(1:pbeDefinition.nDecCoordinate, :), [], 1) ...
%         solverState.upVector];
    %/

    if solverState.flagDensity
        error('density not yet supported')
    end
else
    error('elk:solver:generalError', ['new bin for nucleation phenomena ' ...
        ' shall be added while it not presend']);
end

end