function solverState = addNucleation(solverState, pbeDefinition)
% add 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/>.

%% Task
% it adds:
%   * nucleation pivot at nucleation size (number=0)
%   * nucleation boundary at nucleation size (number=0)

if ~solverState.flagNucleation
    
    solverState.flagNucleation = 1;
    
    solverState.hcMatrix = [pbeDefinition.nucleationSize ...
                            pbeDefinition.nucleationSize ...
                            solverState.hcMatrix];
    [hcMatrixDump upVector ~] = ensureProperDecData(...
        pbeDefinition.nucleationSize(1:pbeDefinition.nDecCoordinate, 1), ... 
        1, pbeDefinition);
    solverState.upVector = [[1 1] * upVector, solverState.upVector];
    %! Dev: the below should now be obsolete by the above lines
%     solverState.upVector = [[1 1] * computeUpVector(pbeDefinition, ...
%         pbeDefinition.nucleationSize(1:pbeDefinition.nDecCoordinate, :), ...
%         elkZerotol) ...
%         solverState.upVector];
    %/
%     solverState.upVector = [...
%         [1 1] * computePartitionIndexDec(pbeDefinition.dec, ...
%           pbeDefinition.nucleationSize(1:pbeDefinition.nDecCoordinate, :), [], 1) ...
%         solverState.upVector];
   

    solverState.numberVector = [0 0 solverState.numberVector];
    
    solverState.indexVector = [-2 0 solverState.indexVector];
    
    if solverState.flagDensity
        solverState.probabilityVector = [inf inf solverState.probabilityVector];
    end
else
    error('elk:solver:generalError', ['nucleation phenomena shall be ' ...
        'added while it is already presend']);
end