1 /*     CalculiX - A 3-dimensional finite element program                 */
2 /*              Copyright (C) 1998-2021 Guido Dhondt                          */
3 
4 /*     This program is free software; you can redistribute it and/or     */
5 /*     modify it under the terms of the GNU General Public License as    */
6 /*     published by the Free Software Foundation(version 2);    */
7 /*                    */
8 
9 /*     This program is distributed in the hope that it will be useful,   */
10 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of    */
11 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      */
12 /*     GNU General Public License for more details.                      */
13 
14 /*     You should have received a copy of the GNU General Public License */
15 /*     along with this program; if not, write to the Free Software       */
16 /*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         */
17 
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <math.h>
21 #include <stdlib.h>
22 #include <pthread.h>
23 #include "CalculiX.h"
24 
25 static ITG *ia1,*ja1,*nestart1;
26 
27 static double *a1,*b1,*au1,*x1,*res1=NULL,*xmin1=NULL,*xmax1=NULL;
28 
calcrestfluidmain(ITG * n,double * a,double * b,double * au,ITG * ia,ITG * ja,double * x,double * res,ITG * nestart,ITG * num_cpus)29 void calcrestfluidmain(ITG *n,double *a,double *b,double *au,ITG *ia,
30 		ITG *ja,double *x,double *res,ITG *nestart,ITG *num_cpus){
31 
32     ITG i;
33 
34     double xmin,xmax;
35 
36     /* variables for multithreading procedure */
37 
38     ITG *ithread=NULL;
39 
40     pthread_t tid[*num_cpus];
41 
42     /* residue of momentum equations in x */
43 
44     NNEW(res1,double,*num_cpus);
45     NNEW(xmin1,double,*num_cpus);
46     NNEW(xmax1,double,*num_cpus);
47 
48     a1=a;b1=b;au1=au;ia1=ia;ja1=ja;x1=x;nestart1=nestart;
49 
50     /* create threads and wait */
51 
52     NNEW(ithread,ITG,*num_cpus);
53     for(i=0; i<*num_cpus; i++)  {
54 	ithread[i]=i;
55 	pthread_create(&tid[i], NULL, (void *)calcrestfluidmt, (void *)&ithread[i]);
56     }
57     for(i=0; i<*num_cpus; i++)  pthread_join(tid[i], NULL);
58 
59     SFREE(ithread);
60 
61     /* total residual */
62 
63     *res=0;
64     for(i=0;i<*num_cpus;i++){
65 	*res+=res1[i];
66     }
67     SFREE(res1);
68 
69     /* maximum and minimum temperature */
70 
71     xmax=0.;
72     xmin=0.;  /* is this correct? not 1.e30 ? */
73     for(i=0;i<*num_cpus;i++){
74 	if(xmax1[i]>xmax){xmax=xmax1[i];}
75 	if(xmin1[i]<xmin){xmin=xmin1[i];}
76     }
77     SFREE(xmax1);SFREE(xmin1);
78 
79     /* normalizing the momentum residue */
80 
81     *res=sqrt(*res/(*n))/(xmax-xmin);
82 
83     return;
84 
85 }
86 
87 /* subroutine for multithreading of calcresvfluid1 */
88 
calcrestfluidmt(ITG * i)89 void *calcrestfluidmt(ITG *i){
90 
91     ITG n;
92 
93     /* number of equations for this thread */
94 
95     n=nestart1[*i+1]-nestart1[*i];
96 
97     FORTRAN(calcrestfluid,(&n,a1,&b1[nestart1[*i]],&au1[nestart1[*i]],
98 			   ia1,&ja1[nestart1[*i]],&x1[nestart1[*i]],
99 			   &res1[*i],&xmin1[*i],&xmax1[*i]));
100 
101     return NULL;
102 }
103