File: initialnet.f

package info (click to toggle)
calculix-ccx 2.11-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 10,188 kB
  • sloc: fortran: 115,312; ansic: 34,480; sh: 374; makefile: 35; perl: 15
file content (906 lines) | stat: -rw-r--r-- 31,139 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
!     
!     CalculiX - A 3-dimensional finite element program
!     Copyright (C) 1998-2015 Guido Dhondt
!     
!     This program is free software; you can redistribute it and/or
!     modify it under the terms of the GNU General Public License as
!     published by the Free Software Foundation(version 2);
!     
!     
!     This program is distributed in the hope that it will be useful,
!     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
!     along with this program; if not, write to the Free Software
!     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!
!     calculate the initial conditions for the gas 
!         - the initial pressure
!         - identifying the chambers and gas pipe nodes
!           for gas networks
!         - the initial flow
!         - calculating the static temperature for gas networks
!     
      subroutine initialnet(itg,ieg,ntg,ac,bc,lakon,v,
     &     ipkon,kon,nflow,ikboun,nboun,prop,ielprop,
     &     nactdog,ndirboun,nodeboun,xbounact,
     &     ielmat,ntmat_,shcon,nshcon,physcon,ipiv,nteq,
     &     rhcon,nrhcon,ipobody,ibody,xbodyact,co,nbody,network,
     &     iin_abs,vold,set,istep,iit,mi,ineighe,ilboun,channel,
     &     iaxial,nmpc,labmpc,ipompc,nodempc,coefmpc,ttime,time,
     &     iponoel,inoel)
!     
      implicit none
     
      logical identity,gravity,gaspipe
!
      character*8 lakon(*)
      character*20 labmpc(*)
      character*81 set(*)
!           
      integer mi(*),ieg(*),nflow,i,j,ntg,ielmat(mi(3),*),ntmat_,id,
     &     node1,node2,ider,iaxial,nmpc,nodempc(3,*),ipompc(*),
     &     nelem,index,nshcon(*),ipkon(*),kon(*),ikboun(*),nboun,idof,
     &     nodem,idirf(8),nactdog(0:3,*),imat,ielprop(*),id1,id2,
     &     nodef(8),ndirboun(*),nodeboun(*),itg(*),node,kflag,ipiv(*),
     &     nrhs,info,idof1,idof2,nteq,nrhcon(*),ipobody(2,*),ibody(3,*),
     &     nbody,numf,network,iin_abs,icase,index2,index1,nelem1,nelem2,
     &     node11,node21,node12,node22,istep,iit,ineighe(*),iponoel(*),
     &     ilboun(*),nelemup,k,node2up,idir,channel,inoel(2,*)
!     
      real*8 ac(nteq,nteq), bc(nteq),prop(*),shcon(0:3,ntmat_,*),
     &     f,df(8),xflow,xbounact(*),v(0:mi(2),*),cp,r,tg1,
     &     tg2,gastemp,physcon(*),pressmin,dvi,rho,g(3),z1,z2,
     &     rhcon(0:1,ntmat_,*),co(3,*),xbodyact(7,*),kappa,
     &     a,Tt,Pt,Ts,pressmax,constant,vold(0:mi(2),*),href,
     &     coefmpc(*),ttime,time,xflow360
!
      kflag=1
      ider=0
      channel=0
      gaspipe=.false.
!
!     applying the boundary conditions
!
      do j=1,nboun
         v(ndirboun(j),nodeboun(j))=xbounact(j)
      enddo
!
!     check for channel elements
!     
      do i=1,nflow
         nelem=ieg(i)
         if(lakon(nelem)(2:5).eq.'LICH') then
            channel=1
            return
         endif
      enddo
!     
!     initializing ac and bc
!     
      do i=1,nteq
         do j=1,nteq
            ac(i,j)=0.d0
         enddo
         bc(i)=0.d0
      enddo
!     
!     for all but purely thermal networks:
!     determining the initial pressure
!     and identifying the chamber and gas pipe nodes
!     
      if(network.ne.0) then
!
         call preinitialnet(ieg,lakon,v,ipkon,kon,nflow,prop,ielprop,
     &     ielmat,ntmat_,shcon,nshcon,rhcon,nrhcon,mi,iponoel,inoel,
     &     itg,ntg)
!     
!     determining whether pressure initial conditions 
!     are provided for all nodes
!     
         pressmin=-1.d0
         pressmax=0.d0
         constant=1.55d0
         
         do i=1,ntg
            node=itg(i)
            if(v(2,node).lt.1.d-10) then
               v(2,node)=0.d0
            else
               if(pressmin.lt.0.d0) then
                  pressmin=v(2,node)
               elseif(v(2,node).lt.pressmin) then
                  pressmin=v(2,node)
               endif
!     
               if(v(2,node).gt.pressmax)then
                  pressmax=v(2,node)
               endif
!     
            endif
         enddo
!     
         if(pressmin.lt.0.d0) then
            write(*,*) 
     &           '*ERROR in initialnet: minimum initial pressure'
            write(*,*) '       is smaller than zero'
            call exit(201)
         endif
!     
!     in nodes in which no initial pressure is given v(2,*)
!     is replaced by -n, where n is the number of elements the
!     node belongs to: allows to find boundary nodes of the 
!     network
!     
         do i=1,nflow
            nelem=ieg(i)
            index=ipkon(nelem)
            node1=kon(index+1)
            node2=kon(index+3)
            call nident(itg,node1,ntg,id1)
            call nident(itg,node2,ntg,id2)
!     
            if ((((lakon(nelem)(1:5).eq.'DGAPF')
     &           .or.(lakon(nelem)(1:5).eq.'DGAPI')).and.
     &           (iin_abs.eq.0))
     &           .or.((lakon(nelem)(1:3).eq.'DRE')
     &           .and.(lakon(nelem)(1:7).ne.'DREWAOR')
     &           .and.(iin_abs.eq.0))) then 
!     
!     In the case of a element of type GASPIPE or RESTRICTOR 
!     (except TYPE= RESTRICTOR WALL ORIFICE)
!     the number of pipes connected to node 1 and 2
!     are computed and stored in ineighe(id1)
!     respectively ineighe(id2)
!     
               gaspipe=.true.
               if(node1.ne.0) then
                  if (ineighe(id1).ge.0) then
!     
                     if(node2.ne.0)then
                        ineighe(id1)=ineighe(id1)+1
                     endif
                  endif
               endif
               if(node2.ne.0) then
                  if (ineighe(id2).ge.0) then
                     if(node1.ne.0) then
                        ineighe(id2)=ineighe(id2)+1
                     endif
                  endif
               endif
            else
               if(iin_abs.eq.0) then
!     
!     for all other elements (different from GASPIPE or 
!     RESTRICTOR), including RESTRICTOR WALL ORIFICE 
!     ineighe(idi)=-1
!     which means that they are connected to chambers
!     i.e. static and total values are equal
!     
                  if (node1.ne.0) then
                     ineighe(id1)=-1
                  endif
                  if(node2.ne.0) then
                     ineighe(id2)=-1
                  endif
               endif
            endif
!     
            if((node1.eq.0).or.(node2.eq.0)) cycle
            if(v(2,node1).lt.1.d-10) then
               v(2,node1)=v(2,node1)-1.d0
            endif
            if(v(2,node2).lt.1.d-10) then
               v(2,node2)=v(2,node2)-1.d0
            endif
         enddo
!     
!     for each end node i: if ineighe(i)<0: chamber
!     else: ineighe(i)=number of pipe connections
!     
!     assigning values to the boundary nodes of the network
!     (i.e. nodes belonging to only one element)
!     
         do i=1,ntg
            node=itg(i)
!     boundary condition nodes
            if(nactdog(2,node).eq.0) then 
               v(2,node)=dtan(v(2,node)
     &              *constant/pressmax) 
               cycle 
            endif
!     initial condition nodes
            if((nactdog(2,node).ne.0)
     &           .and.(v(2,node).gt.0d0)) then
               v(2,node) = dtan(v(2,node)
     &              *constant/pressmax) 
               cycle
            endif
!     nodes neither defined as *BOUNDARY nor as *INITIAL CONDITIONS
            if(abs(v(2,node)+1.d0).lt.1.d-10) then
               v(2,node)=0.95d0*pressmin
               pressmin=0.95d0*pressmin
               v(2,node)=dtan(v(2,node)
     &              *constant/pressmax)
            endif              
         enddo
!     
!     mass flow and geometry dofs: 1 on the diagonal
!     
         do i=1,ntg
            node=itg(i)
            do j=1,1
               if(nactdog(j,node).ne.0) then
                  idof=nactdog(j,node)
                  ac(idof,idof)=1.d0
               endif
            enddo
            do j=3,3
               if(nactdog(j,node).ne.0) then
                  idof=nactdog(j,node)
                  ac(idof,idof)=1.d0
               endif
            enddo
         enddo
!     
!     pressure dofs
!     
         do i=1,nflow
            nelem=ieg(i)
            index=ipkon(nelem)
            node1=kon(index+1)
            node2=kon(index+3)
            if((node1.eq.0).or.(node2.eq.0)) cycle
            idof1=nactdog(2,node1)
            idof2=nactdog(2,node2)
            if(idof1.ne.0) then
               if(v(2,node1).gt.0.d0) then
!     initial pressure given in node1
                  ac(idof1,idof1)=1.d0
                  bc(idof1)=v(2,node1)
               else
                  ac(idof1,idof1)=ac(idof1,idof1)+1.d0
                  if(v(2,node2).gt.0.d0) then
!     initial pressure given in node2
                     bc(idof1)=bc(idof1)+v(2,node2)
                  else
                     ac(idof1,idof2)=ac(idof1,idof2)-1.d0
                  endif
               endif
            endif
            if(idof2.ne.0) then
               if(v(2,node2).gt.0.d0) then
!     initial pressure given in node2
                  ac(idof2,idof2)=1.d0
                  bc(idof2)=v(2,node2)
               else
                  ac(idof2,idof2)=ac(idof2,idof2)+1.d0
                  if(v(2,node1).gt.0.d0) then
!     initial pressure given in node1
                     bc(idof2)=bc(idof2)+v(2,node1)
                  else
                     ac(idof2,idof1)=ac(idof2,idof1)-1.d0
                  endif
               endif
            endif
         enddo
!     
!     checking for nodes not belonging to network elements
!     
         do i=1,ntg
            node=itg(i)
            if(nactdog(2,node).ne.0) then
               idof=nactdog(2,node)
               if(ac(idof,idof).eq.0.d0) then
                  ac(idof,idof)=1.d0
                  bc(idof)=v(2,node)
               endif
            endif
         enddo
      endif
!     
!     temperature conditions for all but purely hydrodynamic
!     networks
!     
      if(network.ne.2) then
!     
!     temperature dofs
!     
         do i=1,nflow
            nelem=ieg(i)
            index=ipkon(nelem)
            node1=kon(index+1)
            nodem=kon(index+2)
            node2=kon(index+3)
            if((node1.eq.0).or.(node2.eq.0)) cycle
            idof1=nactdog(0,node1)
            idof2=nactdog(0,node2)
            if(idof1.ne.0) then
               if(v(0,node1).gt.0.d0) then
!     initial temperature given in node1
                  ac(idof1,idof1)=1.d0
                  bc(idof1)=v(0,node1)
!
!                 temperature taken into account only for incoming
!                 flux (from the viewpoint of node1).
!
               elseif(v(1,nodem).lt.0.d0) then
                  ac(idof1,idof1)=ac(idof1,idof1)+1.d0
                  if(v(0,node2).gt.0.d0) then
!     initial temperature given in node2
                     bc(idof1)=bc(idof1)+v(0,node2)
                  else
                     ac(idof1,idof2)=ac(idof1,idof2)-1.d0
                  endif
               endif
            endif
            if(idof2.ne.0) then
               if(v(0,node2).gt.0.d0) then
!     initial temperature given in node2
                  ac(idof2,idof2)=1.d0
                  bc(idof2)=v(0,node2)
!
!                 temperature taken into account only for incoming
!                 flux (from the viewpoint of node2). Default (if
!                 no flux is predefined) is positive flux.
!
               elseif(v(1,nodem).ge.0.d0) then
                  ac(idof2,idof2)=ac(idof2,idof2)+1.d0
                  if(v(0,node1).gt.0.d0) then
!     initial temperature given in node1
                     bc(idof2)=bc(idof2)+v(0,node1)
                  else
                     ac(idof2,idof1)=ac(idof2,idof1)-1.d0
                  endif
               endif
            endif
         enddo
!     
!     checking for nodes not belonging to network elements
!     
         do i=1,ntg
            node=itg(i)
            if(nactdog(0,node).ne.0) then
               idof=nactdog(0,node)
               if(ac(idof,idof).eq.0.d0) then
                  ac(idof,idof)=1.d0
                  bc(idof)=v(0,node)
               endif
            endif
         enddo
      endif
!
!     additional multiple point constraints
!
      do j=1,nteq
         if(dabs(ac(j,j)).lt.1.d-20) ac(j,j)=1.d0
      enddo
cc      j=nteq+1
c      j=0
c      do i=nmpc,1,-1
c         if(labmpc(i)(1:7).ne.'NETWORK') cycle
c!
c!        looking of a row in the matrix which has not been used yet
c!
c         do
c            j=j+1
c            if(dabs(ac(j,j)).lt.1.d-20) exit
c            if(j.eq.nteq) then
c               write(*,*) '*ERROR in initialnet: MPC cannot'
c               write(*,*) '       be inserted'
c               call stop()
c            endif
c         enddo
c         j=j-1
c         index=ipompc(i)
c!
c         do
c            node=nodempc(1,index)
c            idir=nodempc(2,index)
c            if(nactdog(idir,node).ne.0) then
c               ac(j,nactdog(idir,node))=coefmpc(index)
c            endif
c            index=nodempc(3,index)
c            if(index.eq.0) exit
c         enddo
c      enddo
!     
!     solving the system
!     
      if(nteq.gt.0) then
         nrhs=1
         call dgesv(nteq,nrhs,ac,nteq,ipiv,bc,nteq,info)
         if(info.ne.0) then
            write(*,*) '*ERROR in initialnet: singular matrix'
            call exit(201)
         endif
      endif
!     
!     storing the initial pressure in v
!     (not for purely thermal networks)
!     
      if(network.ne.0) then
         do i=1,ntg
            node=itg(i)
            if(nactdog(2,node).eq.0) then
c               write(*,*) 'initialnet ',node,v(2,node)
               v(2,node)=pressmax
     &              *datan(v(2,node))/constant
               cycle
            endif
c               write(*,*) 'initialnet ',node,bc(nactdog(2,node))
            v(2,node)=pressmax
     &           *datan(bc(nactdog(2,node)))/constant
         enddo
      endif
!     
!     storing the initial temperature in v
!     (not for purely hydrodynamic networks)
!     
      if(network.ne.2) then
         do i=1,ntg
            node=itg(i)
            if(nactdog(0,node).ne.0) v(0,node)=bc(nactdog(0,node))
         enddo
      endif
!     
!     for ELEMENT TYPE BRANCH
!     initial pressures in branch 1 and 2 are equal and set to the 
!     maximum of the two pressures
!     
      do i=1,nflow
         nelem=ieg(i)
         if(lakon(i)(2:5).ne.'REBR') cycle
         index=ielprop(nelem)
!     
         nelem1=prop(index+2)
         index1=ipkon(nelem1)
         node11=kon(index1+1)
         node21=kon(index1+3)
!     
         nelem2=prop(index+3)
         index2=ipkon(nelem2)
         node12=kon(index2+1)
         node22=kon(index2+3)
!     
         if(node11.eq.node12) then
            node1=node21
            node2=node22
         elseif(node11.eq.node22) then
            node1=node21
            node2=node12
         elseif(node21.eq.node12) then
            node1=node11
            node2=node22
         elseif(node21.eq.node22) then
            node1=node11
            node2=node12
         endif
!     
         if(lakon(i)(6:6).eq.'S') then
!
!           maximum
!
            if(v(2,node1).ge.v(2,node2)) then
               v(2,node2)=v(2,node1)
            else
               v(2,node1)=v(2,node2)
            endif
         elseif(lakon(i)(6:6).eq.'J') then
!
!           minimum
!
            if(v(2,node1).ge.v(2,node2)) then
               v(2,node1)=v(2,node2)
            else
               v(2,node2)=v(2,node1)
            endif
         endif
      enddo
!     
!     identifying the chamber nodes for purely thermal
!     gas networks (needed to determine the static
!     temperature which is used for the material properties)
!     
      if(network.eq.0) then
         do i=1,nflow
            nelem=ieg(i)
            if((lakon(nelem)(2:3).eq.'LP').or.
     &           (lakon(nelem)(2:3).eq.'LI')) cycle
            index=ipkon(nelem)
            node1=kon(index+1)
            node2=kon(index+3)
            if(node1.ne.0) then
               call nident(itg,node1,ntg,id1)
               ineighe(id1)=-1
            endif
            if(node2.ne.0) then
               call nident(itg,node2,ntg,id2)
               ineighe(id2)=-1
            endif
         enddo
      endif
!     
!     initialisation of bc
!     
      do i=1,nteq
         bc(i)=0.d0
      enddo
!     
!     determining the initial mass flow in those nodes for which no
!     flux boundary conditions are defined
!     
      if(network.ne.0)then
         do i=1,nflow
            nelem=ieg(i)
!     
            index=ipkon(nelem)
            node1=kon(index+1)
            node2=kon(index+3)
            if((node1.eq.0).or.(node2.eq.0)) cycle
            nodem=kon(index+2)
!     
!     cycle if both the geometry and the mass flow are known
!     
            if((nactdog(1,nodem).eq.0).and.(nactdog(3,nodem).eq.0)) 
     &           cycle
!     
!     for liquids: determine the gravity vector
!     
            if(lakon(nelem)(2:3).eq.'LI') then
               gravity=.false.
               do j=1,3
                  g(j)=0.d0
               enddo
               if(nbody.gt.0) then
                  index=nelem
                  do
                     j=ipobody(1,index)
                     if(j.eq.0) exit
                     if(ibody(1,j).eq.2) then
                        g(1)=g(1)+xbodyact(1,j)*xbodyact(2,j)
                        g(2)=g(2)+xbodyact(1,j)*xbodyact(3,j)
                        g(3)=g(3)+xbodyact(1,j)*xbodyact(4,j)
                        z1=-g(1)*co(1,node1)-g(2)*co(2,node1)
     &                       -g(3)*co(3,node1)
                        z2=-g(1)*co(1,node2)-g(2)*co(2,node2)
     &                       -g(3)*co(3,node2)
                        gravity=.true.
                     endif
                     index=ipobody(2,index)
                     if(index.eq.0) exit
                  enddo
               endif
               if(.not.gravity) then
                  write(*,*) 
     &                 '*ERROR in initialnet: no gravity vector'
                  write(*,*) 
     &                 '       was defined for liquid element',nelem
                  call exit(201)
               endif
            endif
!     
            tg1=v(0,node1)
            tg2=v(0,node2)
!     
!     For liquid pipes elements the upstream temperature 
!     is used to determine the material properties
!     For all other elements the averaged value of the 
!     temperature between inlet and outlet is used
!     
            if((lakon(nelem)(2:3).ne.'LP').and.
     &           (lakon(nelem)(2:3).ne.'LI')) then
               gastemp=(tg1+tg2)/2.d0
            else
               xflow=v(1,nodem)
               if(xflow.gt.0) then
                  gastemp=tg1
               else
                  gastemp=tg2
               endif
            endif
!     
            imat=ielmat(1,nelem)
            call materialdata_tg(imat,ntmat_,gastemp,shcon,nshcon,cp,
     &           r,dvi,rhcon,nrhcon,rho)
!     
!     If inlet and outlet pressure are equal this leads to a massflow rate 
!     equal to 0 and in turn possibly to a singular matrix configuration
!     
!     gas
            if(((lakon(nelem)(2:3).ne.'LI').and.
     &           (v(2,node1).eq.v(2,node2))).or.
!     liquid
     &           ((lakon(nelem)(2:3).eq.'LI').and.
     &           (v(2,node1)+z1.eq.v(2,node2)+z2))) then
            
!     
!     if neither inlet nor outlet pressure are active D.O.F: error-> stop
!     
               if((nactdog(2,node1).eq.0)
     &           .and.(nactdog(2,node2).eq.0)) then
                  WRITE(*,*) '**************************************'
                  write(*,*) '*ERROR:in subroutine initialnet.f'
                  write(*,*) '       in element', nelem
                  write(*,*) '       Inlet and outlet pressures are '
                  write(*,*) '       boundary conditions '
                  write(*,*) '       node1',node1,' pressure',
     &                 v(2,node1)
                  write(*,*) '       node2',node2,' pressure',
     &                 v(2,node2)
                  call exit(201)
!     
!     if inlet pressure is an active degree of freedom
!     
               else if((nactdog(2,node1).ne.0)
     &                 .and.(nactdog(2,node2).eq.0))then
                  WRITE(*,*) '**************************************'
                  write(*,*) '*WARNING:in subroutine initialnet.f'
                  write(*,*) '       in element', nelem
                  write(*,*) 
     &                 '       Inlet pressure initial condition '
                  write(*,*) '       is changed '
                  write(*,*) '       node1',node1,
     &                 ' given initial pressure',v(2,node1)
                  v(2,node1)=1.1*v(2,node1)
                  write(*,*) '       node1',node1,
     &                 ' new initial pressure',v(2,node1)
                  write(*,*) '       node2',node2,' pressure',
     &                 v(2,node2)
!     
!     if outlet pressure is an active D.O.F.
!     
               else if((nactdog(2,node1).eq.0)
     &                 .and.(nactdog(2,node2).ne.0))then
                  WRITE(*,*) '**************************************'
                  write(*,*) '*WARNING:in subroutine initialnet.f'
                  write(*,*) '       in element', nelem
                  write(*,*) 
     &                 '       Outlet pressure initial condition '
                  write(*,*) '       is changed '
                  write(*,*) '       node1',node1,' pressure'
     &                 ,v(2,node1)    
                  write(*,*) '       node2',node2,
     &                 'given initial pressure',
     &                 v(2,node2)
                  v(2,node2)=0.9*v(2,node2)
                  write(*,*) '       node2',node2,
     &                 ' new initial pressure',v(2,node2)
!     
!     if both inlet and outlet pressures are active D.O.F.
!     
               else if((nactdog(2,node1).ne.0)
     &                 .and.(nactdog(2,node2).ne.0))then
                  WRITE(*,*) '**************************************'
                  write(*,*) '*WARNING:in subroutine initialnet.f'
                  write(*,*) '       in element', nelem
                  write(*,*) '       Inlet and outlet pressure '
                  write(*,*) '       initial condition are changed '
                  write(*,*) '       node1',node1,
     &                 ' given initial pressure',v(2,node1)  
                  v(2,node1)=1.05*v(2,node2)
                  write(*,*) '       node1',node1,
     &                 ' new initial pressure',v(2,node1)
                  write(*,*) '       node2',node2,
     &                 ' given initial pressure',v(2,node2)
                  v(2,node2)=0.95*v(2,node2)
                  write(*,*) '       node2',node2,
     &                 ' new initial pressure',v(2,node2)
               endif
            endif
!     
!           calculating flux if the flux is an unknown AND there was
!           no initial flux defined by the user
!
            if((nactdog(1,nodem).ne.0).and.(v(1,nodem).eq.0.d0)) then
               call flux(node1,node2,nodem,nelem,lakon,kon,ipkon,
     &           nactdog,identity,ielprop,prop,kflag,v,xflow,f,
     &           nodef,idirf,df,cp,r,rho,physcon,g,co,dvi,numf,
     &           vold,set,shcon,nshcon,rhcon,nrhcon,ntmat_,mi,ider,
     &           ttime,time,iaxial)
               v(1,nodem)=xflow
            endif
!     
c            if(nactdog(1,nodem).ne.0) v(1,nodem)=xflow
!     
c            if(lakon(nelem)(2:4).ne.'LIP') then
            if((lakon(nelem)(2:4).ne.'LIP').and.
     &         (lakon(nelem)(2:3).ne.'VO')) then
               if(v(1,nodem).eq.0d0) then
                  WRITE(*,*) '**************************************'
                  write(*,*) '*ERROR:in subroutine initialnet.f'
                  write(*,*) '       in element', nelem,
     &                 lakon(nelem)(1:6)
                  write(*,*) '       mass flow rate value = 0 !'
                  write(*,*) '       node1',node1,' pressure',
     &                 v(2,node1)
                  write(*,*) '       node2',node2,' pressure',
     &                 v(2,node2)
                  call exit(201)
               endif
               if (v(1,nodem).lt.0) then
                  WRITE(*,*) '**************************************'
                  write(*,*) '*WARNING: in subroutine initialnet.f'
                  write(*,*) '        in element', nelem
                  write(*,*) '        mass flow rate value .le. 0 !'
                  write(*,*) '        node1',node1,'pressure',
     &                 v(2,node1)
                  write(*,*) '        node2',node2,'pressure',
     &                 v(2,node2)
                  write(*,*) '        check element definition'
               endif
            endif
         enddo
      endif
!
      call postinitialnet(ieg,lakon,v,ipkon,kon,nflow,prop,ielprop,
     &     ielmat,ntmat_,shcon,nshcon,rhcon,nrhcon,mi,iponoel,inoel,
     &     itg,ntg)
!     
!     calculating the static temperature for nodes belonging to gas pipes
!     and restrictors (except RESTRICTOR WALL ORIFICE)
!     
      if (gaspipe.and.(iin_abs.eq.0)) then
!     
!     ineighe(i) is set to -1 (= chamber node) if more than 2 pipes
!     are connected to the node
!     
         do i=1,ntg
            if(ineighe(i).gt.2) then
               ineighe(i)=-1
               write(*,*) '*WARNING :in subroutine initialnet.f'
               write(*,*) '          more than 2 elements GASPIPE'
               write(*,*) '          or RESTRICTOR are connected '
               write(*,*) '          to node',itg(i),'. The common'
               write(*,*) 
     &              '          node is converted into a chamber.'
               write(*,*) '          Total and static parameters are'
               write(*,*) '          equal'
            endif
         enddo
!     
         do i=1,nflow
            nelem=ieg(i)
            index=ipkon(nelem)
            node1=kon(index+1)
            node2=kon(index+3)
            call nident(itg,node1,ntg,id1)
            call nident(itg,node2,ntg,id2)
!     
!           for each end node i: 
!             if ineighe(i)=-1: chamber
!                          = 0: middle node
!                          > 0: number of pipe connections (max. 2 allowed)
!     
!           the number of pipe connections for ineighe(i)>0 is 
!           replaced by the number of an element the node belongs to:
!     
            if(node1.gt.0) then
               if((ineighe(id1).eq.1).or.
     &              (ineighe(id1).eq.2)) then
                  if(node2.ne.0)then
                     ineighe(id1)=nelem
                  endif
               endif
            endif
!     
            if(node2.gt.0) then
               if((ineighe(id2).eq.1).or.
     &              (ineighe(id2).eq.2)) then
                  if (node1.ne.0) then
                     ineighe(id2)=nelem
                  endif
               endif
            endif
         enddo
!     
!     The static temperature is calculated and stored in v(3,node)
!     total temperatures are supposed equal (adiabatic pipe)
!     
         do i=1,ntg
            node=itg(i)
            if(ineighe(i).gt.0) then 
!     
               nelem=ineighe(i)
               index=ielprop(nelem)
               nodem=kon(ipkon(nelem)+2)
!     
               imat=ielmat(1,nelem)
               call materialdata_tg(imat,ntmat_,v(0,node),
     &              shcon,nshcon,cp,r,dvi,rhcon,nrhcon,rho)
               kappa=cp/(cp-R)
               xflow=v(1,nodem)
               Tt=v(0,node)
               Pt=v(2,node)
!     
               if((lakon(nelem)(2:5).eq.'GAPF')
     &              .or.(lakon(nelem)(2:5).eq.'GAPI')) then
                  A=prop(index+1)
                  if((lakon(nelem)(2:6).eq.'GAPFA') 
     &                 .or.(lakon(nelem)(2:6).eq.'GAPIA')) then
                     icase=0
                  elseif((lakon(nelem)(2:6).eq.'GAPFI')
     &                    .or.(lakon(nelem)(2:6).eq.'GAPII')) then
                     icase=1
                  endif     
!     
               elseif(lakon(nelem)(2:3).eq.'RE') then
                  index2=ipkon(nelem)
                  node1=kon(index2+1)
                  node2=kon(index2+3)
                  if(lakon(nelem)(4:5).eq.'EX') then
                     if((lakon(nint(prop(index+4)))(2:6).eq.'GAPFA')
     &                 .or.(lakon(nint(prop(index+4)))(2:6).eq.'GAPIA'))
     &                    then
                        icase=0
                     elseif
     &                   ((lakon(nint(prop(index+4)))(2:6).eq.'GAPFI')
     &                 .or.(lakon(nint(prop(index+4)))(2:6).eq.'GAPII')) 
     &                       then
                        icase=1
                     endif
                  else
                     icase=0
                  endif
!     
                  if(lakon(nelem)(4:5).eq.'BE') then
                     a=prop(index+1)
!     
                  elseif(lakon(nelem)(4:5).eq.'BR') then
                     if(lakon(nelem)(4:6).eq.'BRJ') then
                        if(nelem.eq.nint(prop(index+2)))then
                           A=prop(index+5)
                        elseif(nelem.eq.nint(prop(index+3))) then
                           A=prop(index+6)
                        endif
                     elseif(lakon(nelem)(4:6).eq.'BRS') then
                        if(nelem.eq.nint(prop(index+2)))then
                           A=prop(index+5)
                        elseif(nelem.eq.nint(prop(index+3))) then
                           A=prop(index+6)
                        endif
                     endif
!     
                  else
                     if(node.eq.node1) then
                        a=prop(index+1)
                     elseif(node.eq.node2) then
                        a=prop(index+2)
                     endif
                  endif
               endif
!     
               if(v(3,node).eq.0) then
                  xflow360=xflow*iaxial
                  call ts_calc(xflow360,Tt,Pt,kappa,r,a,Ts,icase)
                  v(3,node)=Ts
               endif
!     
!     if the element is not of gaspipe or branch type,
!     total and static temperatures are equal for all endnodes
!     
            endif
         enddo
      endif
!     
!     for chambers the static temperature equals the total
!     temperature
!     
      do i=1,ntg
         if(ineighe(i).eq.-1) v(3,itg(i))=v(0,itg(i))
c         write(*,*) 'initialnet ',i,v(0,itg(i)),
c     &      v(1,itg(i)),v(2,itg(i)),ineighe(i)
      enddo
!
c      write(*,*) 'initialnet '
c      do i=1,ntg
c         write(*,'(i10,3(1x,e11.4))') itg(i),(v(j,itg(i)),j=0,2)
c      enddo
!     
      return
      end