prepare_update_s.c 3.26 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1
/*-----------------------------------------------------------------------------------------
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
Tilman Steinweg's avatar
Tilman Steinweg committed
3
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
4
 * This file is part of IFOS.
Tilman Steinweg's avatar
Tilman Steinweg committed
5
 * 
Florian Wittkamp's avatar
Florian Wittkamp committed
6
 * IFOS is free software: you can redistribute it and/or modify
Tilman Steinweg's avatar
Tilman Steinweg committed
7 8 9
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 * 
Florian Wittkamp's avatar
Florian Wittkamp committed
10
 * IFOS is distributed in the hope that it will be useful,
Tilman Steinweg's avatar
Tilman Steinweg committed
11 12 13 14 15
 * 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
Florian Wittkamp's avatar
Florian Wittkamp committed
16
 * along with IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
Tilman Steinweg's avatar
Tilman Steinweg committed
17 18 19 20 21 22 23 24 25
-----------------------------------------------------------------------------------------*/

#include "fd.h"

void prepare_update_s(float *etajm, float *etaip, float *peta, float **fipjp, float **pu,
		float **puipjp, float **ppi, float **prho, float **ptaus, float **ptaup,
		float **ptausipjp, float **f, float **g, float *bip, float *bjm,
		float *cip, float *cjm, float ***dip, float ***d, float ***e) {

26
	extern int NX, NY, L, PARAMETERIZATION, MYID;
Tilman Steinweg's avatar
Tilman Steinweg committed
27 28 29 30
	extern float DT, *FL;
	int i, j, l;
	extern char  MFILE[STRING_SIZE];
	extern float F_REF;
31 32
    extern int VERBOSE;

Tilman Steinweg's avatar
Tilman Steinweg committed
33 34 35 36 37 38 39 40 41 42 43 44
	float sumu, sumpi, ws, *pts;
	float mu, pi, muipjp;
	
	/* vector for maxwellbodies */
	pts=vector(1,L);
	for (l=1;l<=L;l++) {
		pts[l]=1.0/(2.0*PI*FL[l]);
	}
	
	
	/*ws=2.0*PI*FL[1];*/
	ws=2.0*PI*F_REF;
45
	if(MYID==0&&VERBOSE)printf("MYID %d: F_REF = %f\n",MYID,F_REF);
Tilman Steinweg's avatar
Tilman Steinweg committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59
	
	sumu=0.0;
	sumpi=0.0;
	for (l=1;l<=L;l++){
		sumu=sumu+((ws*ws*pts[l]*pts[l])/(1.0+ws*ws*pts[l]*pts[l]));
		sumpi=sumpi+((ws*ws*pts[l]*pts[l])/(1.0+ws*ws*pts[l]*pts[l]));
	}
	

	for (l=1;l<=L;l++){
		etajm[l] = peta[l];
		etaip[l] = peta[l];
	}
	
60
	if (PARAMETERIZATION==1){
Tilman Steinweg's avatar
Tilman Steinweg committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
		for (j=1;j<=NY;j++){
			for (i=1;i<=NX;i++){
				mu=(pu[j][i]*pu[j][i]*prho[j][i])/(1.0+sumu*ptaus[j][i]);
				pi=(ppi[j][i]*ppi[j][i]*prho[j][i])/(1.0+sumpi*ptaup[j][i]);
				muipjp=puipjp[j][i]/(1.0+sumu*ptausipjp[j][i]);
				
				fipjp[j][i] = muipjp*DT*(1.0+L*ptausipjp[j][i]);
				f[j][i] = mu*DT*(1.0+L*ptaus[j][i]);
				g[j][i] = pi*DT*(1.0+L*ptaup[j][i]);
				for (l=1;l<=L;l++){
					bip[l] = 1.0/(1.0+(etaip[l]*0.5));
					bjm[l] = 1.0/(1.0+(etajm[l]*0.5));
					cip[l] = 1.0-(etaip[l]*0.5);
					cjm[l] = 1.0-(etajm[l]*0.5);
					dip[j][i][l] = muipjp*etaip[l]*ptausipjp[j][i];
					d[j][i][l] = mu*etajm[l]*ptaus[j][i];
					e[j][i][l] = pi*etajm[l]*ptaup[j][i];
				}
			}
		}
	}
	
83
	if (PARAMETERIZATION==3){
Tilman Steinweg's avatar
Tilman Steinweg committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
		for (j=1;j<=NY;j++){
			for (i=1;i<=NX;i++){
				mu=pu[j][i]/(1.0+sumu*ptaus[j][i]);
				pi=(ppi[j][i]+2*pu[j][i])/(1.0+sumpi*ptaup[j][i]);
				muipjp=puipjp[j][i]/(1.0+sumu*ptausipjp[j][i]);
				
				fipjp[j][i] = muipjp*DT*(1.0+L*ptausipjp[j][i]);
				f[j][i] = mu*DT*(1.0+L*ptaus[j][i]);
				g[j][i] = pi*DT*(1.0+L*ptaup[j][i]);
				for (l=1;l<=L;l++){
					bip[l] = 1.0/(1.0+(etaip[l]*0.5));
					bjm[l] = 1.0/(1.0+(etajm[l]*0.5));
					cip[l] = 1.0-(etaip[l]*0.5);
					cjm[l] = 1.0-(etajm[l]*0.5);
					dip[j][i][l] = muipjp*etaip[l]*ptausipjp[j][i];
					d[j][i][l] = mu*etajm[l]*ptaus[j][i];
					e[j][i][l] = pi*etajm[l]*ptaup[j][i];
				}
			}
		}
	}	
	
	
	free_vector(pts,1,L);
}