Skip to content

Commit

Permalink
TL: update with local developments
Browse files Browse the repository at this point in the history
  • Loading branch information
tlunet committed Oct 23, 2023
1 parent c71c186 commit 349e202
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
6 changes: 3 additions & 3 deletions blockops/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from blockops.utils.params import ParamClass, setParams, \
PositiveInteger, ScalarNumber, VectorNumbers, MultipleChoices

from blockops.schemes import SCHEMES, getTransferMatrices
from blockops.schemes import SCHEMES
from blockops.block import BlockOperator
from blockops.iteration import ALGORITHMS, BlockIteration

Expand Down Expand Up @@ -199,8 +199,8 @@ def setCoarseLevel(self, nPoints, **schemeArgs):
self.lam*self.dt, r'\phi_C', r'\chi_C')

# Build transfer operators
TFtoC, TCtoF = getTransferMatrices(
self.points, self.pointsCoarse, vectorized=self.nLam > 1)
TFtoC, TCtoF = self.scheme.getTransferMatrices(
self.pointsCoarse, vectorized=self.nLam > 1)
self.TFtoC = BlockOperator('T_F^C', matrix=TFtoC, cost=0)
self.TCtoF = BlockOperator('T_C^F', matrix=TCtoF, cost=0)

Expand Down
46 changes: 32 additions & 14 deletions blockops/schemes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@
from blockops.utils.poly import LagrangeApproximation
from blockops.block import BlockOperator


def getTransferMatrices(nodesFine, nodesCoarse, vectorized=False):
# Build polynomial approximations
polyApproxFine = LagrangeApproximation(nodesFine)
polyApproxCoarse = LagrangeApproximation(nodesCoarse)
# Compute interpolation matrix
TFtoC = polyApproxFine.getInterpolationMatrix(nodesCoarse)
TCtoF = polyApproxCoarse.getInterpolationMatrix(nodesFine)
if vectorized:
TFtoC.shape = (1, *TFtoC.shape)
TCtoF.shape = (1, *TCtoF.shape)
return TFtoC, TCtoF


@setParams(
nPoints=PositiveInteger(latexName='$M$'),
ptsType=MultipleChoices(*NODE_TYPES, latexName="Point Distribution"),
Expand Down Expand Up @@ -178,6 +164,38 @@ def getBlockCosts(self) -> [float, float]:
"""
raise NotImplementedError('cannot use BlockScheme class (abstract)')

def getTransferMatrices(self, pointsCoarse,
lamDt=None, mgType="TMG", vectorized=False):
if mgType == "TMG":

# Build polynomial approximations
polyApproxFine = LagrangeApproximation(self.points)
polyApproxCoarse = LagrangeApproximation(pointsCoarse)
# Compute interpolation matrix
TFtoC = polyApproxFine.getInterpolationMatrix(pointsCoarse)
TCtoF = polyApproxCoarse.getInterpolationMatrix(self.points)
if vectorized:
TFtoC.shape = (1, *TFtoC.shape)
TCtoF.shape = (1, *TCtoF.shape)
return TFtoC, TCtoF

elif mgType == "MGRIT":
# Conditions to use MGRIT-type transfers operators
assert lamDt is not None
assert self.points[0] == 0 and self.points[-1] == 1
assert np.size(pointsCoarse) == 2
assert 0, 1 == pointsCoarse
assert self.form == "N2N"

# Eventually generate matrices for several lamDt
lamDt = np.ravel(lamDt)[None, :]

# Generate block matrices
phi, chi = self.getBlockMatrices(lamDt)

else:
raise NotImplementedError(f'mgType={mgType}')

# Dictionnary to store all the BlockScheme implementations
SCHEMES: Dict[str, BlockScheme] = {}

Expand Down
4 changes: 2 additions & 2 deletions scripts/01_discretizationError.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"RungeKutta": {
"rkScheme": 'RK4',
"nStepsPerPoint": 1,
"nPoints": 1,
"nPoints": 3,
},
"Collocation": {
"nPoints": 4,
Expand All @@ -55,4 +55,4 @@

# Plot discretization error on complex plane
fig = bp.plotAccuracyContour(reLam, imLam, err, stab)
fig.show()
fig.show()
6 changes: 3 additions & 3 deletions testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
from blockops.problem import BlockProblem


tEnd = np.pi
lam = 1j-1.0
tEnd = 2*np.pi
lam = 1j-0.1
nBlocks = 4
nStepsF = 20
nStepsG = 1
nPoints = 1
nPointsCoarse = 1
algoName = 'PFASST'

prob = BlockProblem(lam, tEnd, nBlocks, 'RungeKutta',
prob = BlockProblem(lam, tEnd, nBlocks, 'RungeKutta',
rkScheme='BE', nPoints=nPoints, nStepsPerPoint=nStepsF)
prob.setApprox('RungeKutta', rkScheme='BE', nStepsPerPoint=nStepsG)
prob.setCoarseLevel(nPointsCoarse)
Expand Down
4 changes: 2 additions & 2 deletions testingPFASST.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
algo.plotGraph(N=2,K=1)
algo.plotSchedule(
N=4,
K=4, #K=[1,2,3,4],
nProc=4)
K=4, #K=[1,2,3,4],
nProc=4)

0 comments on commit 349e202

Please sign in to comment.