1!
2!     CalculiX - A 3-dimensional finite element program
3!     Copyright (C) 1998-2021 Guido Dhondt
4!
5!     This program is free software; you can redistribute it and/or
6!     modify it under the terms of the GNU General Public License as
7!     published by the Free Software Foundation(version 2);
8!
9!
10!     This program is distributed in the hope that it will be useful,
11!     but WITHOUT ANY WARRANTY; without even the implied warranty of
12!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13!     GNU General Public License for more details.
14!
15!     You should have received a copy of the GNU General Public License
16!     along with this program; if not, write to the Free Software
17!     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18!
19      subroutine normmpc(nmpc,ipompc,nodempc,coefmpc,inomat,coefmodmpc,
20     &     ikboun,nboun)
21!
22!     normalizing the coefficients of MPC's for fluid applications
23!     (CFD)
24!
25      implicit none
26!
27      integer i,node,index,nmpc,inomat(*),nodempc(3,*),ipompc(*),
28     &     ikboun(*),nboun,nodei,ndiri,idof,id
29!
30      real*8 coefmpc(*),size,coefmodmpc(*)
31!
32!     normalizing the MPC-coefficients
33!
34      do i=1,nmpc
35        index=ipompc(i)
36!
37!     check whether fluid node
38!
39        node=nodempc(1,index)
40        if(inomat(node).eq.0) cycle
41!
42!     calculating sum of the square of the MPC coefficients
43!
44        size=coefmpc(index)**2
45        coefmodmpc(index)=coefmpc(index)
46        do
47          index=nodempc(3,index)
48          if(index.eq.0) exit
49!
50!     check whether term is subject to SPC
51!
52          nodei=nodempc(1,index)
53          ndiri=nodempc(2,index)
54          idof=8*(nodei-1)+ndiri
55          call nident(ikboun,idof,nboun,id)
56          if(id.gt.0) then
57            if(ikboun(id).eq.idof) then
58              coefmodmpc(index)=0.d0
59              cycle
60            endif
61          endif
62          coefmodmpc(index)=coefmpc(index)
63!
64          size=size+coefmpc(index)**2
65        enddo
66!
67        size=dsqrt(size)
68!
69!     normalizing all terms of the MPC
70!
71        index=ipompc(i)
72        do
73          coefmodmpc(index)=coefmodmpc(index)/size
74          coefmpc(index)=coefmpc(index)/size
75          index=nodempc(3,index)
76          if(index.eq.0) exit
77        enddo
78      enddo
79!
80      return
81      end
82
83