Skip to content

Commit

Permalink
added support for multiple pressure output
Browse files Browse the repository at this point in the history
  • Loading branch information
daron1337 committed Apr 28, 2015
1 parent d82d3f4 commit 2a8d95c
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 173 deletions.
88 changes: 45 additions & 43 deletions Assembler.py
Expand Up @@ -9,8 +9,8 @@
## Copyright (c) Simone Manini, Luca Antiga. All rights reserved.
## See LICENCE file for details.

## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notices for more information.

## Developed with support from the EC FP7/2007-2013: ARCH, Project n. 224390
Expand All @@ -29,7 +29,7 @@ class Assembler(object):
Assemble: a method for building boundary conditions vectors and assembling
each local Zero, First and Second Order matrix into global Zero, First and Second Order matrix.
'''

def __init__(self):
'''
Constructor
Expand All @@ -48,13 +48,13 @@ def __init__(self):
self.SecondOrderGlobalMatrix = None
self.Evaluator = None
self.Initialized = False

def SetNetworkMesh(self, networkMesh):
'''
Setting NetworkMesh
'''
self.NetworkMesh = networkMesh

def SetBoundaryConditions(self, boundaryConditions):
'''
Setting BoundaryConditions
Expand All @@ -66,41 +66,43 @@ def GetNumberOfGlobalDofs(self):
This method returns number of global degrees of freedom
'''
return self.DofMap.NumberOfGlobalDofs

def AssembleBoundaryConditions(self, simulationContext):
'''
This method assembles arrays of prescribed pressures
'''
self.DofMap = DofMap()
self.DofMap.SetNetworkMesh(self.NetworkMesh)
self.DofMap.Build()

# Searching for prescribed pressure output/input
numberOfElements = 0
for element in self.NetworkMesh.Elements:
for element in self.NetworkMesh.Elements:
for dof in element.GetExternalPressureLocalDofs():
numberOfElements+=1
if self.BoundaryConditions.OutP is not None:
numberOfElements+=1
numberOfElements+=len(self.BoundaryConditions.PressureOut)
if self.BoundaryConditions.InP is not None:
numberOfElements+=1



# Setting Transmural Pressures for windkessel elements and wave propagation elements
PrescribedPressures = zeros((numberOfElements,2))
done = 0
i = 0
for element in self.NetworkMesh.Elements:
for dof in element.GetExternalPressureLocalDofs():
if self.BoundaryConditions.OutP is not None:
if element.Id == self.BoundaryConditions.elementOut.Id:
if done == 0:
value1 = self.DofMap.DofMap[(self.BoundaryConditions.elementOut.Id,self.BoundaryConditions.elementOut.GetLocalDof(int(self.BoundaryConditions.NodeOut)))]
value2 = self.BoundaryConditions.OutP
PrescribedPressures[i,0] = value1
PrescribedPressures[i,1] = value2
done = 1
i+=1
for dof in element.GetExternalPressureLocalDofs():

for el, elProps in self.BoundaryConditions.PressureOut.iteritems():
if element.Id == el.Id:
if done < len(self.BoundaryConditions.PressureOut):
value1 = self.DofMap.DofMap[(el.Id,el.GetLocalDof(int(elProps['node'])))]
value2 = elProps['value']
if value1 not in PrescribedPressures:
PrescribedPressures[i,0] = value1
PrescribedPressures[i,1] = value2
done+=1
i+=1

if self.BoundaryConditions.InP is not None:
if element.Id == self.BoundaryConditions.elementIn.Id:
if done == 0:
Expand All @@ -110,13 +112,13 @@ def AssembleBoundaryConditions(self, simulationContext):
PrescribedPressures[i,1] = value2
done = 1
i+=1

value1 = self.DofMap.DofMap[(element.Id,dof)]
value2 = self.BoundaryConditions.PressureValues[element.Id]
PrescribedPressures[i,0] = value1
PrescribedPressures[i,1] = value2
PrescribedPressures[i,1] = value2
i+=1

self.BoundaryConditions.SetSimulationContext(simulationContext)
for el in self.BoundaryConditions.elementFlow:
self.FlowDof[el.Id] = self.DofMap.DofMap[(el.Id,el.GetLocalDof(int(self.BoundaryConditions.NodeFlow[el.Id])))]
Expand All @@ -129,21 +131,21 @@ def AssembleInit(self, simulationContext, evaluator):
Pressures GlobalDofs and Input Flow Vector from BoundaryConditions (Prescribed Pressures matrix, each row ---> Dof, Value).
Zero, First and Second Order Global Matrix from Local Matrix of each element.
'''

#Assembling global matrices from local matrices.
self.LinearZeroOrderGlobalMatrix = zeros((self.DofMap.NumberOfGlobalDofs, self.DofMap.NumberOfGlobalDofs))
self.LinearFirstOrderGlobalMatrix = zeros((self.DofMap.NumberOfGlobalDofs, self.DofMap.NumberOfGlobalDofs))
self.LinearSecondOrderGlobalMatrix = zeros((self.DofMap.NumberOfGlobalDofs, self.DofMap.NumberOfGlobalDofs))
self.ZeroOrderGlobalMatrix = zeros((self.DofMap.NumberOfGlobalDofs, self.DofMap.NumberOfGlobalDofs))
self.FirstOrderGlobalMatrix = zeros((self.DofMap.NumberOfGlobalDofs, self.DofMap.NumberOfGlobalDofs))
self.SecondOrderGlobalMatrix = zeros((self.DofMap.NumberOfGlobalDofs, self.DofMap.NumberOfGlobalDofs))

nonLinear = False
#Building Global Linear Matrices
#Building Global Linear Matrices
for element in self.DofMap.NetworkMesh.Elements:
if element.Initialized == False:
if element.Initialized == False:
element.Initialize(simulationContext)
if element.nonLinear == False:
if element.nonLinear == False:
element.InputParameters(evaluator)
zeroOrderMatrix = element.GetZeroOrderMatrix()
firstOrderMatrix = element.GetFirstOrderMatrix()
Expand All @@ -152,34 +154,34 @@ def AssembleInit(self, simulationContext, evaluator):
rowGlobalDof = self.DofMap.GetDof(element.Id,rowLocalDof)
for columnLocalDof in element.dof:
columnGlobalDof = self.DofMap.GetDof(element.Id,columnLocalDof)
self.LinearZeroOrderGlobalMatrix[rowGlobalDof,columnGlobalDof] += zeroOrderMatrix[rowLocalDof,columnLocalDof]
self.LinearZeroOrderGlobalMatrix[rowGlobalDof,columnGlobalDof] += zeroOrderMatrix[rowLocalDof,columnLocalDof]
self.LinearFirstOrderGlobalMatrix[rowGlobalDof,columnGlobalDof] += firstOrderMatrix[rowLocalDof,columnLocalDof]
self.LinearSecondOrderGlobalMatrix[rowGlobalDof,columnGlobalDof] += secondOrderMatrix[rowLocalDof,columnLocalDof]
else:
nonLinear = True
if nonLinear == True:

if nonLinear == True:
self.ZeroOrderGlobalMatrix,self.FirstOrderGlobalMatrix,self.SecondOrderGlobalMatrix = \
self.Assemble(simulationContext, evaluator, self.LinearZeroOrderGlobalMatrix, self.LinearFirstOrderGlobalMatrix, self.LinearSecondOrderGlobalMatrix)

else:
self.ZeroOrderGlobalMatrix[:,:] = self.LinearZeroOrderGlobalMatrix[:,:]
self.FirstOrderGlobalMatrix[:,:] = self.LinearFirstOrderGlobalMatrix[:,:]
self.SecondOrderGlobalMatrix[:,:] = self.LinearSecondOrderGlobalMatrix[:,:]

return self.LinearZeroOrderGlobalMatrix, self.LinearFirstOrderGlobalMatrix, self.LinearSecondOrderGlobalMatrix
def Assemble(self, simulationContext, evaluator, linearZeroOrder, linearFirstOrder, linearSecondOrder):


def Assemble(self, simulationContext, evaluator, linearZeroOrder, linearFirstOrder, linearSecondOrder):
'''
This method builds non-linear elements of the global matrices from linear matrices.
'''

#Building non linear matrices
self.ZeroOrderGlobalMatrix[:,:] = linearZeroOrder[:,:]
self.ZeroOrderGlobalMatrix[:,:] = linearZeroOrder[:,:]
self.FirstOrderGlobalMatrix[:,:] = linearFirstOrder[:,:]
self.SecondOrderGlobalMatrix[:,:] = linearSecondOrder[:,:]
self.SecondOrderGlobalMatrix[:,:] = linearSecondOrder[:,:]

for element in self.DofMap.NetworkMesh.Elements:
if element.nonLinear == True:
element.Initialize(simulationContext)
Expand All @@ -191,7 +193,7 @@ def Assemble(self, simulationContext, evaluator, linearZeroOrder, linearFirstOrd
rowGlobalDof = self.DofMap.GetDof(element.Id,rowLocalDof)
for columnLocalDof in element.dof:
columnGlobalDof = self.DofMap.GetDof(element.Id,columnLocalDof)
self.ZeroOrderGlobalMatrix[rowGlobalDof,columnGlobalDof] += zeroOrderMatrix[rowLocalDof,columnLocalDof]
self.ZeroOrderGlobalMatrix[rowGlobalDof,columnGlobalDof] += zeroOrderMatrix[rowLocalDof,columnLocalDof]
self.FirstOrderGlobalMatrix[rowGlobalDof,columnGlobalDof] += firstOrderMatrix[rowLocalDof,columnLocalDof]
self.SecondOrderGlobalMatrix[rowGlobalDof,columnGlobalDof] += secondOrderMatrix[rowLocalDof,columnLocalDof]
return self.ZeroOrderGlobalMatrix, self.FirstOrderGlobalMatrix, self.SecondOrderGlobalMatrix
return self.ZeroOrderGlobalMatrix, self.FirstOrderGlobalMatrix, self.SecondOrderGlobalMatrix

0 comments on commit 2a8d95c

Please sign in to comment.