function [phys_data,...
bound_data] = bht_solids_data_init(gene_data,...
bound_data,...
phys_data)
% BHT_SOLIDS_DATA_INIT
%
% Compute solids' areas, centers of mass, momenta of inertia and bodies'
% masses.
%
% Syntax
%
% [phys_data,bound_data] =
% BHT_SOLIDS_DATA_INIT(gene_data,bound_data,phys_data)
%
% Description
%
% The function is ran by BHT_DATA_COMPILE. It calls the M-Files fluid's
% boundaries are described in and computes the areas and centers of
% mass of the solids. When necessary, it translates all of the
% discretization points computed by the function BHT_BOUNDARIES_INIT in
% order to put the center of mass at the origin ; a warning message is
% next displayed in the current workspace. The momenta of inertia and
% the masses of the solids are also computed and the mass matrix is
% built. The masses of the bodies are computed as well. The input
% variables gene_data, bound_data and phys_data are structure array
% variables which have been prealocated and partly set up during the
% compilation by the functions BHT_TRANSLATION and BHT_BOUNDARIES_INIT.
%
% Output variables
%
% The following fields are set up by BHT_SOLIDS_DATA_INIT (see the List
% of output variables for a description).
%
% * Field(s) of phys_data: Ms, solids_area, fishes_mass.
% * Field(s) of bound_data: X (if necessary).
%
% See also BHT_DATA_COMPILE, BHT_TRANSLATION, BHT_BOUNDARIES_INIT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% BIOHYDRODYNAMICS MATLAB TOOLBOX %
% %
% A. MUNNIER and B. PINCON %
% %
% alexandre.munnier@iecn.u-nancy.fr bruno.pincon@iecn.u-nancy.fr %
% http://www.iecn.u-nancy.fr/~munnier http://www.iecn.u-nancy.fr/~pincon %
% %
% INSTITUT ELIE CARTAN, NANCY 1 %
% http://www.iecn.u-nancy.fr/ %
% %
% INRIA Lorraine, Projet CORIDA %
% http://www.iecn.u-nancy.fr/~corida/ %
% %
% %
% %
% August 15th 2008 %
% %
% GNU GPL v3 licence %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%##########################################################################
% Allocation or Preallocation of local variables:
%-----------------------------------------------
%-----------------------------
nb_solids = gene_data.nb_solids;
%-----------------------------
surface = zeros(nb_solids,1);
mass = zeros(nb_solids,1);
h1 = zeros(nb_solids,1);
h2 = zeros(nb_solids,1);
J = zeros(nb_solids,1);
vect = zeros(3*nb_solids,1);
%##########################################################################
% Computation of the area, mass, center of mass, momentum of inertia and
% mass matrix of the solids.
disp('Mass and momentum of inertia of each solid: ');
%==========================================================================
% Main loop (on the solids)
%--------------------------
for k = 1:nb_solids
%======================================================================
% Computation of the area and mass of solid k
%--------------------------------------------
surface(k) = -0.5*bound_data(k).dt*sum(bound_data(k).dl.*...
(bound_data(k).X(1,:).*bound_data(k).Nn(1,:)...
+bound_data(k).X(2,:).*bound_data(k).Nn(2,:)));
mass(k) = surface(k)*phys_data.rhos(k);
%======================================================================
% Computation of the center of mass coordinates for solid k
%---------------------------------------------------------
h1(k) = -0.5*(phys_data.rhos(k)/mass(k))*bound_data(k).dt*sum(bound_data(k).dl.*...
(bound_data(k).X(1,:).^2).*bound_data(k).Nn(1,:));
h2(k) = -0.5*(phys_data.rhos(k)/mass(k))*bound_data(k).dt*sum(bound_data(k).dl.*...
(bound_data(k).X(2,:).^2).*bound_data(k).Nn(2,:));
%======================================================================
% Adjusting inertia center of solid k
%-------------------------------------
bound_data(k).X = bound_data(k).X - ...
repmat([h1(k);h2(k)],1,bound_data(k).nbr_points);
if norm([h1(k);h2(k)]) > 1e-3;
warning('WarnTests:convertTest',['Center of mass is no longer [0;0] ',...
'for solid defined from file ',...
bound_data(k).mfilename,'.m.\n This may affect the geometry of the fish.']);
end
%======================================================================
% Computation of the momentum of inertia of solid k
%--------------------------------------------------
J(k) = - phys_data.rhos(k)*bound_data(k).dt*sum(bound_data(k).dl.*...
(bound_data(k).X(1,:).*bound_data(k).X(2,:).^2.*bound_data(k).Nn(1,:)...
+ bound_data(k).X(1,:).^2.*bound_data(k).X(2,:).*bound_data(k).Nn(2,:)));
%======================================================================
% Built of the mass matrix Ms
%----------------------------
vect(3*(k-1)+1) = mass(k);
vect(3*(k-1)+2) = vect(3*(k-1)+1);
vect(3*(k-1)+3) = J(k);
%======================================================================
% Display of solids' physical data
%---------------------------------
disp(['m',num2str(k),' = ',num2str(mass(k),'%6.3f'),' ','J',num2str(k),' = ',num2str(J(k),'%6.2f')]);
end
%==========================================================================
% The definitive mass Matrix
%---------------------------
Ms = diag(vect);
%==========================================================================
% Physiscal data of the fishes
%-----------------------------
disp('Mass of each fish: ');
nb_fishes = gene_data.nb_fishes;
mm = zeros(1,nb_fishes); % preallocation of the array containing the mass
% of the fishes
nb_solids_cumul = 0;
%==========================================================================
% Loop on the fishes
%-------------------
for k=1:nb_fishes
nb_solids = gene_data.array_fishes_solids(k);
%--------------------------------------------------------------
mm(k) = sum(mass(nb_solids_cumul+1:nb_solids_cumul+nb_solids));
disp(['Fish ',num2str(k),': ',num2str(mm(k),'%6.2f')]);
nb_solids_cumul = nb_solids_cumul + nb_solids;
end
%==========================================================================
% Storage of the physical amounts into struct array variable 'phys_data'
%-----------------------------------------------------------------------
%+++++++++++++++++++++++++++++++
phys_data.Ms = Ms;
phys_data.solids_area = surface;
phys_data.fishes_mass = mm;
%+++++++++++++++++++++++++++++++
end