github.com/archlabjp/eeslism-go@v0.0.0-20231109122333-4bb7bfcdf292/eeslism/mcstanklb.go (about)

     1  //This file is part of EESLISM.
     2  //
     3  //Foobar is free software : you can redistribute itand /or modify
     4  //it under the terms of the GNU General Public License as published by
     5  //the Free Software Foundation, either version 3 of the License, or
     6  //(at your option) any later version.
     7  //
     8  //Foobar is distributed in the hope that it will be useful,
     9  //but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
    11  //GNU General Public License for more details.
    12  //
    13  //You should have received a copy of the GNU General Public License
    14  //along with Foobar.If not, see < https://www.gnu.org/licenses/>.
    15  
    16  /* mcstanklb.c  */
    17  
    18  package eeslism
    19  
    20  import "math"
    21  
    22  const TSTOLE = 0.04
    23  
    24  /*  蓄熱槽仮想分割 */
    25  
    26  func stoint(N int, Vol float64, KAside float64, KAtop float64, KAbtm float64,
    27  	dvol, Mdt, KS, Tss, Tssold []float64, Jva, Jvb *int) {
    28  
    29  	for i := 0; i < N; i++ {
    30  		dvol[i] = Vol / float64(N)
    31  		Mdt[i] = (Cw * Row * Vol / float64(N)) / DTM
    32  		KS[i] = KAside / float64(N)
    33  
    34  		Tss[i] = Tssold[i]
    35  	}
    36  
    37  	KS[0] += KAtop
    38  	KS[N-1] += KAbtm
    39  
    40  	*Jva = 0
    41  	*Jvb = 0
    42  }
    43  
    44  /* ----------------------------------------------------------- */
    45  
    46  func stofc(N, Nin int, Jcin, Jcout []int,
    47  	ihex []rune, ihxeff []float64, Jva, Jvb int, Mdt, KS []float64,
    48  	gxr float64, Tenv *float64, Tssold, cGwin, EGwin, B, R, d, fg []float64) {
    49  	N2 := N * N
    50  	for j := 0; j < N2; j++ {
    51  		B[j] = 0.0
    52  	}
    53  
    54  	for j := 0; j < N; j++ {
    55  		B[j*N+j] = Mdt[j] + KS[j]
    56  		R[j] = Mdt[j]*Tssold[j] + KS[j]**Tenv
    57  	}
    58  
    59  	for j := 0; j < N-1; j++ {
    60  		B[j*N+j+1] = -Mdt[j] * gxr
    61  		B[(j+1)*N+j] = -Mdt[j+1] * gxr
    62  	}
    63  
    64  	if Jva >= 0 {
    65  		for j := Jva; j <= Jvb; j++ {
    66  			B[j*N+j+1] = -Mdt[j] * 1.0e6
    67  			B[(j+1)*N+j] = -Mdt[j] * 1.0e6
    68  		}
    69  	}
    70  
    71  	for i := 0; i < Nin; i++ {
    72  		Jin := Jcin[i]
    73  		if cGwin[i] > 0.0 {
    74  			B[Jin*N+Jin] += EGwin[i]
    75  
    76  			if Jin < Jcout[i] {
    77  				for j := Jin + 1; j <= Jcout[i]; j++ {
    78  					B[j*N+j-1] -= cGwin[i]
    79  				}
    80  			} else if Jin > Jcout[i] {
    81  				for j := Jcout[i]; j < Jin; j++ {
    82  					B[j*N+j+1] -= cGwin[i]
    83  				}
    84  			}
    85  		}
    86  	}
    87  
    88  	for j := 1; j < N-1; j++ {
    89  		B[j*N+j] += math.Abs(B[j*N+j-1]) + math.Abs(B[j*N+j+1])
    90  	}
    91  
    92  	B[0] += math.Abs(B[1])
    93  	B[N*N-1] += math.Abs(B[N*N-2])
    94  
    95  	Matinv(B, N, N, "<stofc>")
    96  	Matmalv(B, R, N, N, d)
    97  
    98  	fgIndex := 0
    99  	for k := 0; k < Nin; k++ {
   100  		Jo := Jcout[k]
   101  		if ihex[k] == 'y' {
   102  			d[Jo] *= ihxeff[k]
   103  			for i := 0; i < Nin; i++ {
   104  				Jin := Jcin[i]
   105  				fg[fgIndex] = B[Jo*N+Jin] * EGwin[i] * ihxeff[k]
   106  				if k == i {
   107  					fg[fgIndex] += (1.0 - ihxeff[k])
   108  				}
   109  				fgIndex++
   110  			}
   111  		} else {
   112  			for i := 0; i < Nin; i++ {
   113  				Jin := Jcin[i]
   114  				fg[fgIndex] = B[Jo*N+Jin] * EGwin[i]
   115  				fgIndex++
   116  			}
   117  		}
   118  	}
   119  }
   120  
   121  /* -------------------------------------------------------------- */
   122  
   123  /*  蓄熱槽水温の計算 */
   124  
   125  func stotss(N, Nin int, Jcin []int, B, R, EGwin, Twin, Tss []float64) {
   126  	for i := 0; i < Nin; i++ {
   127  		Jin := Jcin[i]
   128  		R[Jin] += EGwin[i] * Twin[i]
   129  	}
   130  
   131  	Matmalv(B, R, N, N, Tss)
   132  }
   133  
   134  /* -------------------------------------------------------------- */
   135  
   136  /*  蓄熱槽水温分布の検討 */
   137  
   138  func stotsexm(N int, Tss []float64, Jva, Jvb *int, dtankF []rune, cfcalc *rune) {
   139  	*Jvb = -1
   140  	*Jva = -1
   141  
   142  	for j := N - 2; j >= 0; j-- {
   143  		if dtankF[j] == TANK_FULL {
   144  			if Tss[j+1] > (Tss[j] + TSTOLE) {
   145  				*Jvb = j
   146  			}
   147  			if *Jvb >= 0 {
   148  				break
   149  			}
   150  		}
   151  	}
   152  
   153  	if *Jvb >= 0 {
   154  		for j := *Jvb - 1; j >= 0; j-- {
   155  			if dtankF[j] == TANK_FULL {
   156  				if Tss[*Jvb+1] > (Tss[j] + TSTOLE) {
   157  					*Jva = j
   158  				}
   159  			}
   160  		}
   161  		if *Jva == -1 {
   162  			*Jva = *Jvb
   163  		}
   164  	}
   165  
   166  	if *Jva < 0 {
   167  		*cfcalc = 'n'
   168  	} else {
   169  		*cfcalc = 'y'
   170  	}
   171  }
   172  
   173  /*-----------------------------------------------------------------*/