Beispiel #1
0
Fluid::Fluid()
{
	int i;

	for (i=0; i<10; i++)
		clear_buffer(buffers[i]);

	i=0;
	d=buffers[i++]; d0=buffers[i++];
	T=buffers[i++]; T0=buffers[i++];
	u=buffers[i++]; u0=buffers[i++];
	v=buffers[i++]; v0=buffers[i++];
	w=buffers[i++]; w0=buffers[i++];

	clear_sources();

	int size=(N+2)*(N+2)*(N+2);
	for (i=0; i<size; i++)
		v[i] = -0.5f;
}
Beispiel #2
0
	void Alert::set_sources(const std::vector<Alert::Node> &sources) {
		clear_sources();
		for (unsigned int i = 0; i < sources.size(); i++)
			add_source(sources[i]);
	}
int	vtt_ini (void)
{
	int	i, j, cnst_delay;
	float	Alip;
	float	pi = 3.141593;

	/*** Initialize decimation filter ***/

	deci = simfrq/smpfrq;
	dt_sim = 1./simfrq;
	cnst_delay = decim_init();

	/*** Initialize random number generation ***/

	if(noise_source == ON)
	{  frictionNoise3(0, inMemGlt, outMemGlt, &lowMemGlt);
	frictionNoise3(0, inMemAc, outMemAc, &lowMemAc);
	}

	/*** Coefficients for computing acoustic-aerodynamic elements ***/

	/* flow registance */

	K_Bernoulli = Kc*ro;		/* Bernoulli kinetic resistance */
	/* The Kc value depends on the cross-section shape: =1.42 for
	the glottis (rectangular) and more close to 1. for a supraglottal
	constriction.  For the simplicity sake, the single value is
	used for the two cases. R = K_Bernoulli*Udc/(A*A) for full length
	*/

	K_viscous_glotte = 12.*lg*lg*xg*mu/2.;
	/* The K formula assumes a rectangular duct, and is applicable
	only at the glottis.  R = K_viscous_glotte/(A*A*A) for a half
	length */

	K_viscous_const = (8.*pi*mu)/2.0;	/* viscous resistance  */
	/* The K formula assumes a circular duct, and is applicable
	only at the superglottal constriction (Stevens, 1971).
	R = K_viscous_const*dx/(A*A) for a half length.  Note that
	viscous resistance is not same as "wall friction loss" used
	in the frequency domain calculation, which is a function of
	wall surface and frequency */

	/* acoustic elements */
	La = (2.0/dt_sim)*(ro/2.0);	/* acoustic mass (La)		*/
	Ca = (2.0/dt_sim)/(ro*c*c);	/* acoustic stiffness (1/Ca)	*/

	/* walls */
	Rw = wall_resi/(2.0*sqrt(pi));			/* VT walls */
	Lw = (2.0/dt_sim)*wall_mass/(2.0*sqrt(pi));
	Cw = (dt_sim/2.0)*wall_comp/(2.0*sqrt(pi));

	if(subGLTsystem == ON)
	{  Rt = trachea_resi/(2.0*sqrt(pi));		/* VT walls */
	Lt = (2.0/dt_sim)*trachea_mass/(2.0*sqrt(pi));
	Ct = (dt_sim/2.0)*trachea_comp/(2.0*sqrt(pi));
	}

	/* radiation impedance; 1/G_rad and 1/S_rad in parallel */
	Grad = (9.0*pi*pi)/(128.0*ro*c);	  /* conductance (G_rad) */
	Srad = (dt_sim/2.0)*(3.0*pi*sqrt(pi))/(8.0*ro);/* suceptance  (S_rad) */

	/* radiated sound pressure at 1 m */
	Kr = ro*simfrq/(2.0*pi*100.0);

	/*** address and memory allocation ***/

	/* tracheal tube */

	Ng = 0;
	if(subGLTsystem == ON)
	{  Ng    = ntr;
	ntr1  = ntr + 1;
	actr  = (td_acoustic_elements *) calloc(ntr1, sizeof(td_acoustic_elements));
	}

	/* main tract : parynx + {mouth} */

	if(nasal_tract == ON) nvt0 = nbp;	/* pharynx */
	else		      nvt0 = nvt;	/* parynx + mouth */
	nvt1 = nvt0 + 1;

	af  = (area_function *) calloc(nvt0, sizeof(area_function));
	daf = (area_function *) calloc(nvt0, sizeof(area_function));
	ac  = (td_acoustic_elements *) calloc(nvt1, sizeof(td_acoustic_elements));

	/* entire tract for equation elements : {trachea}+glottis+pyarynx+{mouth} */

	if(nasal_tract == ON) n0 = nbp;		/* pharynx */
	else		      n0 = nvt;		/* parynx + mouth */
	n0++;					/* +1 for glottal section */
	if(subGLTsystem == ON) n0 += ntr;	/* + tracheal sections */
	n2 = 2*n0;
	n3 = n2 + 1;
	n4 = n2 + 2;
	n5 = n2 + 3;
	eq  = (td_linear_equation *) calloc(n5, sizeof(td_linear_equation));

	if(nasal_tract == ON)
	{
		/* mouth cavity */
		nbu0 = nvt - nbp;			/* # of bucal sections */
		nbu1 = nbu0 + 1;
		nbu3 = 2*nbu0 + 1;
		nbu4 = 2*nbu0 + 2;
		nbu5 = 2*nbu0 + 3;
		nbu6 = 2*nbu0 + 4;
		afbu  = (area_function *) calloc(nbu0, sizeof(area_function));
		dafbu = (area_function *) calloc(nbu0, sizeof(area_function));
		acbu = (td_acoustic_elements *) calloc(nbu1, sizeof(td_acoustic_elements));
		eqbu = (td_linear_equation *) calloc(nbu6, sizeof(td_linear_equation));

		/* nasal coupling sections */
		nnc1 = nnc + 1;
		afnc   = (area_function *) calloc(nnc, sizeof(area_function));
		dafnc  = (area_function *) calloc(nnc, sizeof(area_function));
		acnc = (td_acoustic_elements *) calloc(nnc1, sizeof(td_acoustic_elements));

		/* fixed nasal tract */
		nna0 = nnt - nnc;
		nna1 = nna0 + 1;
		afna = (area_function *) calloc(nna0, sizeof(area_function));
		acna = (td_acoustic_elements *) calloc(nna1, sizeof(td_acoustic_elements));

		/* entire nasal tract */
		nnt3 = 2*nnt + 1;
		nnt4 = 2*nnt + 2;
		nnt5 = 2*nnt + 3;
		nnt6 = 2*nnt + 4;
		eqnt = (td_linear_equation *) calloc(nnt6, sizeof(td_linear_equation));
	}

	/***  Clear memories ***/

	/* current/voltage sources associated with reactances */

	if(subGLTsystem == ON) clear_sources(ntr1, actr);
	clear_sources(nglt1, acglt);
	clear_sources(nvt1, ac);
	iLrad_lip = 0.;

	if(nasal_tract == ON)
	{  clear_sources(nbu1, acbu);
	clear_sources(nnc1, acnc);
	clear_sources(nna1, acna);
	iLrad_nos = 0.;
	}

	/* clear volume velocities and central pressures */

	clear_PU(n5, eq);
	U1_lip = 0;
	if(nasal_tract == ON)
	{  clear_PU(nbu6, eqbu);
	clear_PU(nnt6, eqnt);
	U1_nos = 0;
	}

	/* set constant values for S and W */

	eq[0].S = H2O_bar*Psub;		/* lung air-pressure */
	eq[0].W = 1.0;
	if(nasal_tract == ON)
	{  eqbu[nbu5].S = 0.;
	eqbu[nbu5].W = 1.0;
	eqnt[nnt5].S = 0;
	eqnt[nnt5].W = 1.0;
	}

	/*** Copy initial area function of time-varying tubes ***/

	copy_initial_af_t();

	/*** find the constriction forward and farest from the glottis ***/

	find_constriction();

	/**** Fixed acoustic elements ****/

	/* lungs */
	Rlungs = 1.5/sqrt(600);			/* ?? */

	/* trachea */
	if(subGLTsystem == ON) acous_elements_t(TRACHEA, ntr, aftr, actr);

	/* fixed part of the nasal tract */
	if(nasal_tract == ON)
	{  NTacous_elements_t(nna0, afna, acna);
	/* radiation load at the nostrils */
	if(rad_boundary == RL_CIRCUIT)
	{  Grad_nos = Grad*afnt[nnt-1].A;
	Lrad_nos = Srad*sqrt(afnt[nnt-1].A);
	}
	else
	{  Grad_nos = 5000.;				/* short circuit */
	Lrad_nos = 0.;
	}
	eqnt[nnt4].w = Grad_nos + Lrad_nos;
	}

	/* stationary case */

	if(vocal_tract == STATIONARY) refresh_acoustic_elements();

	return( cnst_delay );
}
int	vtt_ini ( void )
{
	int	i, cnst_delay;
	float	pi = 3.141593f;

	nph2 = 2*nph; nph3 = nph2+1; nph4 = nph2+2;
	nbu2 = 2*nbu; nbu3 = nbu2+1; nbu4 = nbu2+2;
	nna2 = 2*nna; nna3 = nna2+1; nna4 = nna2+2;

	deci = (int)(simfrq/smpfrq);
	dt_sim = (float)(1./simfrq);
	cnst_delay = decim_init();

/*** Coefficients for computing acoustic-aerodynamic elements ***/

/* flow registance */
	Rk = (float)(1.2*ro);		/* kinetic resistance */

	/* The Rk value depends on the cross-section shape: =1.38 for
	   the glottis (rectangular) and =1. for a supragrottal
	   constriction.  For the simplicity sake, the single value is
	   used for the two cases. */

	Rv = (float)((0.8*pi*mu)/2.0);	/* viscus resistance  */
	/* The vr value depends on the shapes.  The difference is
	   relativly small, and the single value will be used. */

/* acoustic elements */
	La = (float)((2.0/dt_sim)*(ro/2.0));	/* acoustic mass (La)		*/
	Ca = (float)((2.0/dt_sim)/(ro*c*c));	/* acoustic stiffness (1/Ca)	*/

/* walls */
	Rw = (float)(wall_resi/(2.0*sqrt(pi)));
	Lw = (float)((2.0/dt_sim)*wall_mass/(2.0*sqrt(pi)));
	Cw = (float)((dt_sim/2.0)*wall_comp/(2.0*sqrt(pi)));

/* radiation impedance; 1/G_rad and 1/S_rad in parallel */
	Grad = (float)((9.0*pi*pi)/(128.0*ro*c));	  /* conductance (G_rad) */
	Srad = (float)((dt_sim/2.0)*(3.0*pi*sqrt(pi))/(8.0*ro));/* suceptance  (S_rad) */

/* radiated sound pressure at 1 m */
	Kr = (float)(ro*simfrq/(2.0*pi*100.0));

/*** memory allocations ***/

	afph = (area_function *) calloc( nph, sizeof(area_function) );
	dph  = (area_function *) calloc( nph, sizeof(area_function) );
	acph = (td_acoustic_elements *) calloc( nph+1, sizeof(td_acoustic_elements) );
	eqph = (td_linear_equation *) calloc( 2*nph+3, sizeof(td_linear_equation) );

	afbu = (area_function *) calloc( nbu, sizeof(area_function) );
	dbu  = (area_function *) calloc( nbu, sizeof(area_function) );
	acbu = (td_acoustic_elements *) calloc( nbu+1, sizeof(td_acoustic_elements) );
	eqbu = (td_linear_equation *) calloc( 2*nbu+3, sizeof(td_linear_equation) );

	dna  = (area_function *) calloc( nna, sizeof(area_function) );
	acna = (td_acoustic_elements *) calloc( nna+1, sizeof(td_acoustic_elements) );
	eqna = (td_linear_equation *) calloc( 2*nna+3, sizeof(td_linear_equation) );

/***  Initalization of memory terms  ***/

/* current/voltage sources associated with reactances */
	clear_sources( nph, acph );
	clear_sources( nbu, acbu );
	irad_lips = 0;
	clear_sources( nna, acna );
	irad_nose = 0;

/* initial volume velocities and central pressures (the rest condition) */
	clear_pu( nph4, eqph );
	clear_pu( nbu4, eqbu );
	U1_lips = 0;
	clear_pu( nna4, eqna );
	U1_nose = 0;

/**** Acoustic and matrix elements ****/

	copy_initial_af_t();		/* copy the initial area function */
	dax();

/* pharyngeal tract */
	acou_mtrx( nph, afph, dph, acph, eqph, 0., 0.);
	Ag = nonzero_t( Ag );			/* add glottal resistance */
	eqph[1].w =  (float)(eqph[1].w +( Rv*xg/Ag + Rk*fabs(eqph[1].x) )/(Ag*Ag));

/* bucal cavity */
	acou_mtrx( nbu, afbu, dbu, acbu, eqbu, 0., 0.);

/* nasal tract */
	acou_mtrx( nna-1, afnt, dna, acna, eqna, 0., 0. );
	for(i=1; i<=nna3; i+=2) eqna[i].w += 0.1f;  /* add some extra loss */

	Rs_na = acna[nna-2].Rs;			  /* left arm of the inlet*/
	Ls_na = acna[nna-2].Ls;			  /* to the nasal tract.  */
	acou_mtrx(1, afnc, dnc, acna+nna-1, eqna+2*(nna-1), Rs_na, Ls_na);

/* Radiation loads */
	if( rad_boundary == RL_CIRCUIT )
	{  Grad_lips = Grad*afbu[0].A;		/* radiation conductance */
	   Lrad_lips = (float)(Srad*sqrt(afbu[0].A));	/* radiation suceptance  */
	   eqbu[0].w = Grad_lips + Lrad_lips;	/* rad. admitance        */

	   Grad_nose = Grad*afnt[0].A;
	   Lrad_nose = (float)(Srad*sqrt(afnt[0].A));
	   eqna[0].w = Grad_nose + Lrad_nose;
	}
	else
	{  eqbu[0].w = 5.0;			/* short circuit	 */
	   eqna[0].w = 5.0;
	}

	return( cnst_delay );
}