Ejemplo n.º 1
0
def build():

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### INITIALS ###

    def apply(system):

        curvedBox = CoordSystems.Radial(
            system.mesh.radialLengths,
            system.mesh.angularExtent,
            boxDims=((0., 1.), (0., 1.))).curved_box(system.mesh.data)

        initialConditions = InitialConditions.Group([
            InitialConditions.Sinusoidal(system.temperatureField.data,
                                         curvedBox),
            InitialConditions.Indices(system.temperatureField.data,
                                      [(system.outer.data, 0.),
                                       (system.inner.data, 1.)]),
            InitialConditions.SetVal([
                system.velocityField.data, system.pressureField.data,
                system.temperatureDotField.data
            ], 0.),
        ])

        initialConditions.apply()
        system.solve()

    ### HOUSEKEEPING: IMPORTANT! ###
    return Grouper(locals())
Ejemplo n.º 2
0
def build(
        gradient = 3.,
        exponent = 0.5,
        smoothness = 10.,
        randomSeed = 1066,
        ):

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### INITIALS ###

    def apply(system):

        if type(system.mesh) == uw.mesh._spherical_mesh.FeMesh_Annulus:
            phase = 1.
            curvedBox = CoordSystems.Radial(
                system.mesh.radialLengths,
                system.mesh.angularExtent,
                boxDims = ((0., 1.), (0., 1.))
                ).curved_box
        else:
            def curvedBox(argument):
                return argument

        initialConditions = InitialConditions.Group([
            InitialConditions.NoisyGradient(
                system.temperatureField.data,
                curvedBox(system.mesh.data),
                gradient = gradient,
                exponent = exponent,
                smoothness = smoothness,
                randomSeed = randomSeed,
                tempRange = (system.surfT, system.baseT),
                ),
            InitialConditions.Indices(
                system.temperatureField.data,
                [(system.outer.data, system.surfT),
                (system.inner.data, system.baseT)]
                ),
            InitialConditions.SetVal(
                [system.velocityField.data,
                 system.pressureField.data,
                 system.temperatureDotField.data],
                0.
                ),
            ])

        initialConditions.apply()
        system.step.value = 0
        system.modeltime.value = 0.
        system.solve()

    ### HOUSEKEEPING: IMPORTANT! ###

    return Grouper(locals())
Ejemplo n.º 3
0
def build(obsVars, step, modeltime):

    ### HOUSEKEEPING: IMPORTANT! ###

#     inputs = locals().copy()
    inputs = {'obsVars': sorted(obsVars.keys())}
    script = __file__

    ### MAKE STATS ###

    statsDict = {}
    formatDict = {}

    for varName, var in sorted(obsVars.items()):

        pevar = planetengine.standardise(var)
        var = pevar.var

        standardIntegralSuite = {
            'surface': ['volume', 'inner', 'outer'],
            'comp': ['mag', 'ang', 'rad'],
            'gradient': [None, 'ang', 'rad']
            }

        for inputDict in planetengine.utilities.suite_list(standardIntegralSuite):

            anVar = analysis.Analyse.StandardIntegral(
                var,
                **inputDict
                )
            statsDict[varName + '_' + anVar.opTag] = anVar

            formatDict[varName + '_' + anVar.opTag] = "{:.2f}"

    zerodAnalyser = analysis.Analyser(
        'zerodData',
        statsDict,
        formatDict,
        step,
        modeltime
        )
    analysers = [zerodAnalyser,] # MAGIC NAME: MUST BE DEFINED

    maincollector = analysis.DataCollector(analysers)
    collectors = [maincollector,] # MAGIC NAME: MUST BE DEFINED

    ### FIGS ###

    mainfig = visualisation.QuickFig(
        *sorted(obsVars.items()),
        figname = 'standard'
        )
    figs = [mainfig,] # MAGIC NAME: MUST BE DEFINED

    ### HOUSEKEEPING: IMPORTANT! ###

    return Grouper(locals())
Ejemplo n.º 4
0
    def make_data(system, step, modeltime):
        zerodDataDict = {
            'Nu':
            analysis.Analyse.DimensionlessGradient(system.temperatureField,
                                                   system.mesh,
                                                   surfIndexSet=system.outer,
                                                   baseIndexSet=system.inner),
            'avTemp':
            analysis.Analyse.ScalarFieldAverage(system.temperatureField,
                                                system.mesh),
            'VRMS':
            analysis.Analyse.VectorFieldVolRMS(system.velocityField,
                                               system.mesh),
            'surfVRMS':
            analysis.Analyse.VectorFieldSurfRMS(system.velocityField,
                                                system.mesh, system.outer),
            'avVisc':
            analysis.Analyse.ScalarFieldAverage(system.viscosityFn,
                                                system.mesh),
            'yielding':
            analysis.Analyse.ScalarFieldAverage(
                fn.branching.conditional([
                    (system.creepViscFn < system.plasticViscFn, 0.), (True, 1.)
                ]), system.mesh),
            'step':
            analysis.Analyse.ArrayStripper(step, (0, 0)),
            'modeltime':
            analysis.Analyse.ArrayStripper(modeltime, (0, 0)),
        }

        zerodFormatDict = {
            'Nu': "{:.1f}",
            'avTemp': "{:.2f}",
            'VRMS': "{:.2f}",
            'surfVRMS': "{:.2f}",
            'avVisc': "{:.1E}",
            'yielding': "{0:.0%}",
            'step': "{:.0f}",
            'modeltime': "{:.1E}",
        }

        zerodAnalyser = analysis.Analyser('zerodData', zerodDataDict,
                                          zerodFormatDict)
        dataCollector = analysis.DataCollector([
            zerodAnalyser,
        ])
        data = {
            'analysers': [
                zerodAnalyser,
            ],
            'collectors': [
                dataCollector,
            ],
        }
        return Grouper(data)
Ejemplo n.º 5
0
    def make_tools(system):

        viscosityProj = uw.mesh.MeshVariable(system.mesh, 1)
        viscosityProjector = uw.utils.MeshVariable_Projection(
            viscosityProj,
            system.viscosityFn,
        )

        projectors = {'viscosityProjector': viscosityProjector}
        projections = {'viscosityProj': viscosityProj}
        tools = {'projectors': projectors, 'projections': projections}
        return Grouper(tools)
def build(
    pert=0.2,
    freq=1.,
    phase=0.,
):

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### INITIALS ###

    def apply(system):

        if type(system.mesh) == uw.mesh._spherical_mesh.FeMesh_Annulus:
            phase = 1.
            curvedBox = CoordSystems.Radial(system.mesh.radialLengths,
                                            system.mesh.angularExtent,
                                            boxDims=((0., 1.),
                                                     (0., 1.))).curved_box
        else:

            def curvedBox(argument):
                return argument

        initialConditions = InitialConditions.Group([
            InitialConditions.Sinusoidal(system.temperatureField.data,
                                         curvedBox(system.mesh.data),
                                         phase=phase,
                                         freq=freq,
                                         pert=pert,
                                         tempRange=(system.surfT,
                                                    system.baseT)),
            InitialConditions.Indices(system.temperatureField.data,
                                      [(system.outer.data, system.surfT),
                                       (system.inner.data, system.baseT)]),
            InitialConditions.SetVal([
                system.velocityField.data, system.pressureField.data,
                system.temperatureDotField.data, system.step.value,
                system.modeltime.value
            ], 0.),
        ])

        initialConditions.apply()
        system.step.value = 0
        system.modeltime.value = 0.
        system.solve()

    ### HOUSEKEEPING: IMPORTANT! ###

    return Grouper(locals())
Ejemplo n.º 7
0
    def make_tools(system):

        tools = {}

        return Grouper(tools)
Ejemplo n.º 8
0
def build():

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### PROJECTORS ###

    def make_tools(system):

        tools = {}

        return Grouper(tools)

    ### FIGURES ###

    def make_figs(system, tools):

        fig = glucifer.Figure(edgecolour="white", quality=2)

        figTempComponent = fig.Surface(system.mesh,
                                       system.temperatureField,
                                       colourBar=True)

        figVelComponent = fig.VectorArrows(system.mesh, system.velocityField)

        figs = {
            'fig': fig,
        }

        return figs

    ### DATA ###

    def make_data(system, tools):

        zerodDataDict = {
            'Nu':
            analysis.Analyse.DimensionlessGradient(
                system.temperatureField,
                system.mesh,
                system.outer,
                system.inner,
            ),
            'avTemp':
            analysis.Analyse.ScalarFieldAverage(
                system.temperatureField,
                system.mesh,
            ),
            'VRMS':
            analysis.Analyse.VectorFieldVolRMS(
                system.velocityField,
                system.mesh,
            ),
            'surfVRMS':
            analysis.Analyse.VectorFieldSurfRMS(
                system.velocityField,
                system.mesh,
                system.outer,
            ),
            'step':
            analysis.Analyse.ArrayStripper(
                system.step,
                (0, 0),
            ),
            'modeltime':
            analysis.Analyse.ArrayStripper(
                system.modeltime,
                (0, 0),
            ),
        }

        zerodFormatDict = {
            'Nu': "{:.1f}",
            'avTemp': "{:.2f}",
            'VRMS': "{:.2f}",
            'surfVRMS': "{:.2f}",
            'step': "{:.0f}",
            'modeltime': "{:.1E}",
        }

        zerodAnalyser = analysis.Analyser('zerodData', zerodDataDict,
                                          zerodFormatDict)
        dataCollector = analysis.DataCollector([
            zerodAnalyser,
        ])
        data = {
            'analysers': [
                zerodAnalyser,
            ],
            'collectors': [
                dataCollector,
            ],
        }

        return data

    ### HOUSEKEEPING: IMPORTANT! ###

    return Grouper(locals())
Ejemplo n.º 9
0
def build(
    gradient=3.,
    exponent=0.5,
    smoothness=10.,
    randomSeed=1066,
    cont_centre=0.5,
    cont_width=1. / 3.,
    cont_thickness=0.035,
):

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### INITIALS ###

    def apply(system):

        if type(system.mesh) == uw.mesh._spherical_mesh.FeMesh_Annulus:
            phase = 1.
            curvedBox = CoordSystems.Radial(system.mesh.radialLengths,
                                            system.mesh.angularExtent,
                                            boxDims=((0., 1.),
                                                     (0., 1.))).curved_box
        else:

            def curvedBox(argument):
                return argument

        initialConditions = InitialConditions.Group([
            InitialConditions.NoisyGradient(
                system.temperatureField.data,
                curvedBox(system.mesh.data),
                gradient=gradient,
                exponent=exponent,
                smoothness=smoothness,
                randomSeed=randomSeed,
                tempRange=(system.surfT, system.baseT),
            ),
            InitialConditions.Indices(system.temperatureField.data,
                                      [(system.outer.data, system.surfT),
                                       (system.inner.data, system.baseT)]),
            InitialConditions.Extents(
                system.materialVar.data,
                curvedBox(system.swarm.particleCoordinates.data),
                initialExtents=[
                    (0, fn.misc.constant(True)),
                    (1,
                     fn.shape.Polygon(
                         np.array([[
                             cont_centre - cont_width / 2., 1. - cont_thickness
                         ], [cont_centre - cont_width / 2., 1.],
                                   [cont_centre + cont_width / 2., 1.],
                                   [
                                       cont_centre + cont_width / 2.,
                                       1. - cont_thickness
                                   ]]))),
                    #(2, fn.shape.Polygon(np.array([[0., 0.], [0., 0.02], [2., 0.02], [2., 0.]]))),
                ]),
            InitialConditions.SetVal([
                system.velocityField.data, system.pressureField.data,
                system.temperatureDotField.data
            ], 0.),
        ])

        initialConditions.apply()
        system.step.value = 0
        system.modeltime.value = 0.
        system.solve()

    ### HOUSEKEEPING: IMPORTANT! ###

    return Grouper(locals())
Ejemplo n.º 10
0
def build(
    res=64,
    f=0.54,
    aspect=1.,
    Ra=1e7,
    eta0=3e4,
):

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### MESH & MESH VARIABLES ###

    maxf = 0.99999
    if f == 'max' or f == 1.:
        f = maxf
    else:
        assert f < maxf

    length = 1.
    outerRad = 1. / (1. - f)
    radii = (outerRad - length, outerRad)

    maxAspect = math.pi * sum(radii) / length
    if aspect == 'max':
        aspect = maxAspect
        periodic = True
    else:
        assert aspect < maxAspect
        periodic = False

    width = length**2 * aspect * 2. / (radii[1]**2 - radii[0]**2)
    midpoint = math.pi / 2.
    angExtentRaw = (midpoint - 0.5 * width, midpoint + 0.5 * width)
    angExtentDeg = [item * 180. / math.pi for item in angExtentRaw]
    angularExtent = [
        max(0., angExtentDeg[0]),
        min(360., angExtentDeg[1] + abs(min(0., angExtentDeg[0])))
    ]
    angLen = angExtentRaw[1] - angExtentRaw[0]

    assert res % 4 == 0
    radRes = res
    angRes = 4 * int(angLen * (int(radRes * radii[1] / length)) / 4)
    elementRes = (radRes, angRes)

    mesh = uw.mesh.FeMesh_Annulus(elementRes=elementRes,
                                  radialLengths=radii,
                                  angularExtent=angularExtent,
                                  periodic=[False, periodic])

    temperatureField = uw.mesh.MeshVariable(mesh, 1)
    temperatureDotField = uw.mesh.MeshVariable(mesh, 1)
    pressureField = uw.mesh.MeshVariable(mesh.subMesh, 1)
    velocityField = uw.mesh.MeshVariable(mesh, 2)

    ### BOUNDARIES ###

    inner = mesh.specialSets["inner"]
    outer = mesh.specialSets["outer"]
    sides = mesh.specialSets["MaxJ_VertexSet"] + mesh.specialSets[
        "MinJ_VertexSet"]

    if periodic:
        velBC = uw.conditions.RotatedDirichletCondition(
            variable=velocityField,
            indexSetsPerDof=(inner + outer, None),
            basis_vectors=(mesh.bnd_vec_normal, mesh.bnd_vec_tangent))
    else:
        velBC = uw.conditions.RotatedDirichletCondition(
            variable=velocityField,
            indexSetsPerDof=(inner + outer, sides),
            basis_vectors=(mesh.bnd_vec_normal, mesh.bnd_vec_tangent))

    tempBC = uw.conditions.DirichletCondition(variable=temperatureField,
                                              indexSetsPerDof=(inner +
                                                               outer, ))

    ### FUNCTIONS ###

    vc = uw.mesh.MeshVariable(mesh=mesh, nodeDofCount=2)
    vc_eqNum = uw.systems.sle.EqNumber(vc, False)
    vcVec = uw.systems.sle.SolutionVector(vc, vc_eqNum)

    buoyancyFn = Ra * temperatureField

    diffusivityFn = 1.

    heatingFn = 1.

    ### RHEOLOGY ###

    viscosityFn = fn.math.pow(eta0, 1. - temperatureField)

    ### SYSTEMS ###

    stokes = uw.systems.Stokes(
        velocityField=velocityField,
        pressureField=pressureField,
        conditions=[
            velBC,
        ],
        fn_viscosity=viscosityFn,
        fn_bodyforce=buoyancyFn * mesh.unitvec_r_Fn,
        _removeBCs=False,
    )

    solver = uw.systems.Solver(stokes)

    advDiff = uw.systems.AdvectionDiffusion(phiField=temperatureField,
                                            phiDotField=temperatureDotField,
                                            velocityField=vc,
                                            fn_diffusivity=diffusivityFn,
                                            fn_sourceTerm=heatingFn,
                                            conditions=[
                                                tempBC,
                                            ])

    step = fn.misc.constant(0)
    modeltime = fn.misc.constant(0.)

    ### SOLVING ###

    def postSolve():
        # realign solution using the rotation matrix on stokes
        uw.libUnderworld.Underworld.AXequalsY(stokes._rot._cself,
                                              stokes._velocitySol._cself,
                                              vcVec._cself, False)
        # remove null space - the solid body rotation velocity contribution
        uw.libUnderworld.StgFEM.SolutionVector_RemoveVectorSpace(
            stokes._velocitySol._cself, stokes._vnsVec._cself)

    def solve():
        velocityField.data[:] = 0.
        solver.solve(
            nonLinearIterate=False,
            callback_post_solve=postSolve,
        )
        uw.libUnderworld.Underworld.AXequalsX(stokes._rot._cself,
                                              stokes._velocitySol._cself,
                                              False)

    def integrate():
        dt = advDiff.get_max_dt()
        advDiff.integrate(dt)
        modeltime.value += dt
        step.value += 1

    def clipVals():
        for varName, var in sorted(varsOfState.items()):
            varScale = varScales[varName]
            inArr = var.data
            var.data[:] = np.array([
                np.clip(subarr, *clipval)
                for subarr, clipval in zip(var.data.T, varScale)
            ]).T

    def iterate():
        integrate()
        clipVals()
        solve()

    ### HOUSEKEEPING: IMPORTANT! ###

    varsOfState = {'temperatureField': temperatureField}
    obsVars = {'velocityField': velocityField}
    varScales = {'temperatureField': [[0., 1.]]}
    varBounds = {'temperatureField': [[0., 1., '.', '.']]}

    return Grouper(locals())
Ejemplo n.º 11
0
def build(
    res=32,
    ratio=0.5,
    aspect=1.,
    length=1.,
    isoviscous=False,
    Ra=1e7,
    maxVisc=3e4,
    tau0=4e5,
    tau1=1e7,
):

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### MESH & MESH VARIABLES ###

    outerRad = length / (1. - min(0.99999, max(0.00001, ratio)))
    radii = (outerRad - length, outerRad)
    width = length**2 * aspect * 2. / (radii[1]**2 - radii[0]**2)
    midpoint = math.pi / 2.
    angExtentRaw = (midpoint - 0.5 * width, midpoint + 0.5 * width)
    angularExtent = [item * 180. / math.pi for item in angExtentRaw]
    angLen = angExtentRaw[1] - angExtentRaw[0]
    radRes = res
    angRes = 4 * int(angLen * (int(radRes * radii[1] / length)) / 4.)
    elementRes = (radRes, angRes)

    mesh = uw.mesh.FeMesh_Annulus(elementRes=elementRes,
                                  radialLengths=radii,
                                  angularExtent=angularExtent,
                                  periodic=[False, False])

    temperatureField = uw.mesh.MeshVariable(mesh, 1)
    temperatureDotField = uw.mesh.MeshVariable(mesh, 1)
    pressureField = uw.mesh.MeshVariable(mesh.subMesh, 1)
    velocityField = uw.mesh.MeshVariable(mesh, 2)

    varsOfState = [((("temperatureField", temperatureField), ), ("mesh", mesh))
                   ]

    ### BOUNDARIES ###

    inner = mesh.specialSets["inner"]
    outer = mesh.specialSets["outer"]
    sides = mesh.specialSets["MaxJ_VertexSet"] + mesh.specialSets[
        "MinJ_VertexSet"]

    velBC = uw.conditions.RotatedDirichletCondition(
        variable=velocityField,
        indexSetsPerDof=(inner + outer, sides),
        basis_vectors=(mesh.bnd_vec_normal, mesh.bnd_vec_tangent))

    tempBC = uw.conditions.DirichletCondition(variable=temperatureField,
                                              indexSetsPerDof=(inner +
                                                               outer, ))

    ### RHEOLOGY ###

    vc = uw.mesh.MeshVariable(mesh=mesh, nodeDofCount=2)
    vc_eqNum = uw.systems.sle.EqNumber(vc, False)
    vcVec = uw.systems.sle.SolutionVector(vc, vc_eqNum)

    invDensityFn = temperatureField * Ra
    buoyancyFn = invDensityFn * mesh.unitvec_r_Fn

    if isoviscous:
        viscosityFn = creepViscFn = plasticViscFn = 1.
    else:
        magnitude = fn.math.sqrt(fn.coord()[0]**2 + fn.coord()[1]**2)
        depthFn = mesh.radialLengths[1] - magnitude
        yieldStressFn = tau0 + (tau1 * depthFn)
        secInvFn = fn.tensor.second_invariant(
            fn.tensor.symmetric(vc.fn_gradient))
        plasticViscFn = yieldStressFn / (2. * secInvFn + 1e-18)
        creepViscFn = fn.math.pow(fn.misc.constant(maxVisc),
                                  -1. * (temperatureField - 1.))
        viscosityFn = fn.misc.min(
            maxVisc, fn.misc.max(1., fn.misc.min(creepViscFn, plasticViscFn)))

    ### SYSTEMS ###

    stokes = uw.systems.Stokes(
        velocityField=velocityField,
        pressureField=pressureField,
        conditions=[
            velBC,
        ],
        fn_viscosity=viscosityFn,
        fn_bodyforce=buoyancyFn,
        _removeBCs=False,
    )

    solver = uw.systems.Solver(stokes)

    advDiff = uw.systems.AdvectionDiffusion(phiField=temperatureField,
                                            phiDotField=temperatureDotField,
                                            velocityField=vc,
                                            fn_diffusivity=1.,
                                            conditions=[
                                                tempBC,
                                            ])

    ### SOLVING ###

    def postSolve():
        # realign solution using the rotation matrix on stokes
        uw.libUnderworld.Underworld.AXequalsY(stokes._rot._cself,
                                              stokes._velocitySol._cself,
                                              vcVec._cself, False)
        # remove null space - the solid body rotation velocity contribution
        uw.libUnderworld.StgFEM.SolutionVector_RemoveVectorSpace(
            stokes._velocitySol._cself, stokes._vnsVec._cself)

    def solve():
        velocityField.data[:] = 0.
        solver.solve(
            nonLinearIterate=not isoviscous,
            callback_post_solve=postSolve,
        )
        uw.libUnderworld.Underworld.AXequalsX(stokes._rot._cself,
                                              stokes._velocitySol._cself,
                                              False)

    def integrate():
        dt = advDiff.get_max_dt()
        advDiff.integrate(dt)
        return dt

    def iterate():
        solve()
        return integrate()

    ### HOUSEKEEPING: IMPORTANT! ###
    return Grouper(locals())
def build(
    res=64,
    ratio=0.54,
    aspect=1.,
    length=1.,
    Ra=1e7,
    heating=0.,
    surfT=0.,
    deltaT=1.,
    diffusivity=1.,
    buoyancy=1.,
    creep=1.,
    periodic=False,
):

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### MESH & MESH VARIABLES ###

    outerRad = length / (1. - min(0.99999, max(0.00001, ratio)))
    inputs['ratio'] = ratio
    radii = (outerRad - length, outerRad)

    maxAspect = math.pi * sum(radii) / length
    aspect = min(aspect, maxAspect)
    inputs['aspect'] = aspect
    if aspect == maxAspect:
        periodic = True
        inputs['periodic'] = periodic

    width = length**2 * aspect * 2. / (radii[1]**2 - radii[0]**2)
    midpoint = math.pi / 2.
    angExtentRaw = (midpoint - 0.5 * width, midpoint + 0.5 * width)
    angExtentDeg = [item * 180. / math.pi for item in angExtentRaw]
    angularExtent = [
        max(0., angExtentDeg[0]),
        min(360., angExtentDeg[1] + abs(min(0., angExtentDeg[0])))
    ]
    angLen = angExtentRaw[1] - angExtentRaw[0]

    radRes = max(16, int(res / 16) * 16)
    inputs['res'] = radRes
    angRes = 16 * int(angLen * (int(radRes * radii[1] / length)) / 16)
    elementRes = (radRes, angRes)

    mesh = uw.mesh.FeMesh_Annulus(elementRes=elementRes,
                                  radialLengths=radii,
                                  angularExtent=angularExtent,
                                  periodic=[False, periodic])

    temperatureField = uw.mesh.MeshVariable(mesh, 1)
    temperatureDotField = uw.mesh.MeshVariable(mesh, 1)
    pressureField = uw.mesh.MeshVariable(mesh.subMesh, 1)
    velocityField = uw.mesh.MeshVariable(mesh, 2)

    ### BOUNDARIES ###

    inner = mesh.specialSets["inner"]
    outer = mesh.specialSets["outer"]
    sides = mesh.specialSets["MaxJ_VertexSet"] + mesh.specialSets[
        "MinJ_VertexSet"]

    if periodic:
        velBC = uw.conditions.RotatedDirichletCondition(
            variable=velocityField,
            indexSetsPerDof=(inner + outer, None),
            basis_vectors=(mesh.bnd_vec_normal, mesh.bnd_vec_tangent))
    else:
        velBC = uw.conditions.RotatedDirichletCondition(
            variable=velocityField,
            indexSetsPerDof=(inner + outer, sides),
            basis_vectors=(mesh.bnd_vec_normal, mesh.bnd_vec_tangent))

    tempBC = uw.conditions.DirichletCondition(variable=temperatureField,
                                              indexSetsPerDof=(inner +
                                                               outer, ))

    ### FUNCTIONS ###

    baseT = surfT + deltaT

    buoyancyFn = temperatureField * Ra * mesh.unitvec_r_Fn * buoyancy

    diffusivityFn = diffusivity

    heatingFn = heating

    ### RHEOLOGY ###

    vc = uw.mesh.MeshVariable(mesh=mesh, nodeDofCount=2)
    vc_eqNum = uw.systems.sle.EqNumber(vc, False)
    vcVec = uw.systems.sle.SolutionVector(vc, vc_eqNum)

    viscosityFn = 1.

    ### SYSTEMS ###

    stokes = uw.systems.Stokes(
        velocityField=velocityField,
        pressureField=pressureField,
        conditions=[
            velBC,
        ],
        fn_viscosity=viscosityFn,
        fn_bodyforce=buoyancyFn,
        _removeBCs=False,
    )

    solver = uw.systems.Solver(stokes)

    advDiff = uw.systems.AdvectionDiffusion(phiField=temperatureField,
                                            phiDotField=temperatureDotField,
                                            velocityField=vc,
                                            fn_diffusivity=diffusivityFn,
                                            fn_sourceTerm=heatingFn,
                                            conditions=[
                                                tempBC,
                                            ])

    step = fn.misc.constant(0)
    modeltime = fn.misc.constant(0.)

    ### SOLVING ###

    def postSolve():
        # realign solution using the rotation matrix on stokes
        uw.libUnderworld.Underworld.AXequalsY(stokes._rot._cself,
                                              stokes._velocitySol._cself,
                                              vcVec._cself, False)
        # remove null space - the solid body rotation velocity contribution
        uw.libUnderworld.StgFEM.SolutionVector_RemoveVectorSpace(
            stokes._velocitySol._cself, stokes._vnsVec._cself)

    def solve():
        velocityField.data[:] = 0.
        solver.solve(callback_post_solve=postSolve, )
        uw.libUnderworld.Underworld.AXequalsX(stokes._rot._cself,
                                              stokes._velocitySol._cself,
                                              False)

    def integrate():
        dt = advDiff.get_max_dt()
        advDiff.integrate(dt)
        return dt

    def iterate():
        solve()
        dt = integrate()
        modeltime.value += dt
        step.value += 1

    ### HOUSEKEEPING: IMPORTANT! ###

    varsOfState = [
        (temperatureField, 'temperatureField'),
    ]
    blackhole = [0., 0.]

    return Grouper(locals())
Ejemplo n.º 13
0
def build(
    res=32,
    isoviscous=False,
    aspect=1.,
    length=1.,
    Ra=1e7,
    maxVisc=3e4,
    tau0=4e5,
    tau1=1e7,
):

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### MESH & MESH VARIABLES ###

    elementRes = (res, int(int(4. * res * aspect) / 4))
    maxCoord = (aspect, length)

    mesh = uw.mesh.FeMesh_Cartesian(elementRes=elementRes, maxCoord=maxCoord)

    temperatureField = uw.mesh.MeshVariable(mesh, 1)
    temperatureDotField = uw.mesh.MeshVariable(mesh, 1)
    pressureField = uw.mesh.MeshVariable(mesh.subMesh, 1)
    velocityField = uw.mesh.MeshVariable(mesh, 2)

    varsOfState = [((("temperatureField", temperatureField), ), ("mesh", mesh))
                   ]

    ### BOUNDARIES ###

    inner = mesh.specialSets["MinJ_VertexSet"]
    outer = mesh.specialSets["MaxJ_VertexSet"]
    sides = mesh.specialSets["MaxI_VertexSet"] + mesh.specialSets[
        "MinI_VertexSet"]

    velBC = uw.conditions.DirichletCondition(
        variable=velocityField,
        indexSetsPerDof=(sides, inner + outer),
    )

    tempBC = uw.conditions.DirichletCondition(variable=temperatureField,
                                              indexSetsPerDof=(inner +
                                                               outer, ))

    ### RHEOLOGY ###

    invDensityFn = temperatureField * Ra
    buoyancyFn = invDensityFn * (0., 1.)

    if isoviscous:
        viscosityFn = creepViscFn = plasticViscFn = 1.
    else:
        magnitude = fn.math.sqrt(fn.coord()[0]**2 + fn.coord()[1]**2)
        depthFn = mesh.maxCoord[1] - magnitude
        yieldStressFn = tau0 + (tau1 * depthFn)
        secInvFn = fn.tensor.second_invariant(
            fn.tensor.symmetric(velocityField.fn_gradient))
        plasticViscFn = yieldStressFn / (2. * secInvFn + 1e-18)
        creepViscFn = fn.math.pow(fn.misc.constant(maxVisc),
                                  -1. * (temperatureField - 1.))
        viscosityFn = fn.misc.min(
            maxVisc, fn.misc.max(1., fn.misc.min(creepViscFn, plasticViscFn)))

    ### SYSTEMS ###

    stokes = uw.systems.Stokes(
        velocityField=velocityField,
        pressureField=pressureField,
        conditions=[
            velBC,
        ],
        fn_viscosity=viscosityFn,
        fn_bodyforce=buoyancyFn,
        _removeBCs=False,
    )

    solver = uw.systems.Solver(stokes)

    advDiff = uw.systems.AdvectionDiffusion(phiField=temperatureField,
                                            phiDotField=temperatureDotField,
                                            velocityField=velocityField,
                                            fn_diffusivity=1.,
                                            conditions=[
                                                tempBC,
                                            ])

    ### SOLVING ###

    def solve():
        velocityField.data[:] = 0.
        solver.solve(nonLinearIterate=not isoviscous, )

    def integrate():
        dt = advDiff.get_max_dt()
        advDiff.integrate(dt)
        return dt

    def iterate():
        solve()
        return integrate()

    ### HOUSEKEEPING: IMPORTANT! ###
    return Grouper(locals())
Ejemplo n.º 14
0
def build():

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### PROJECTORS ###

    def make_tools(system):

        viscosityProj = uw.mesh.MeshVariable(system.mesh, 1)
        viscosityProjector = uw.utils.MeshVariable_Projection(
            viscosityProj,
            system.viscosityFn,
        )

        projectors = {'viscosityProjector': viscosityProjector}
        projections = {'viscosityProj': viscosityProj}
        tools = {'projectors': projectors, 'projections': projections}
        return Grouper(tools)

    ### FIGURES ###

    def make_figs(system, tools):

        fig = glucifer.Figure(edgecolour="white", quality=2)

        figTempComponent = fig.Surface(system.mesh,
                                       system.temperatureField,
                                       colourBar=True)

        figVelComponent = fig.VectorArrows(system.mesh, system.velocityField)

        figViscComponent = fig.Contours(
            system.mesh,
            fn.math.log10(tools.projections['viscosityProj']),
            colours="red black",
            interval=0.5,
            colourBar=False,
        )

        figMaterialComponent = fig.Points(
            system.swarm,
            fn_colour=system.materialVar,
            fn_mask=system.materialVar,
            fn_size=4.,
            colours="purple",
            colourBar=False,
        )

        figs = {
            'fig': fig,
        }

        return figs

    ### DATA ###

    def make_data(system, tools):
        zerodDataDict = {
            'Nu':
            analysis.Analyse.DimensionlessGradient(
                system.temperatureField,
                system.mesh,
                system.outer,
                system.inner,
            ),
            'avTemp':
            analysis.Analyse.ScalarFieldAverage(
                system.temperatureField,
                system.mesh,
            ),
            'VRMS':
            analysis.Analyse.VectorFieldVolRMS(
                system.velocityField,
                system.mesh,
            ),
            'surfVRMS':
            analysis.Analyse.VectorFieldSurfRMS(
                system.velocityField,
                system.mesh,
                system.outer,
            ),
            'avVisc':
            analysis.Analyse.ScalarFieldAverage(
                system.viscosityFn,
                system.mesh,
            ),
            'yielding':
            analysis.Analyse.ScalarFieldAverage(
                fn.branching.conditional([
                    (system.creepViscFn < system.plasticViscFn, 0.),
                    (True, 1.),
                ]), system.mesh),
            'step':
            analysis.Analyse.ArrayStripper(
                system.step,
                (0, 0),
            ),
            'modeltime':
            analysis.Analyse.ArrayStripper(
                system.modeltime,
                (0, 0),
            ),
        }

        zerodFormatDict = {
            'Nu': "{:.1f}",
            'avTemp': "{:.2f}",
            'VRMS': "{:.2f}",
            'surfVRMS': "{:.2f}",
            'avVisc': "{:.1E}",
            'yielding': "{0:.0%}",
            'step': "{:.0f}",
            'modeltime': "{:.1E}",
        }

        zerodAnalyser = analysis.Analyser('zerodData', zerodDataDict,
                                          zerodFormatDict)
        dataCollector = analysis.DataCollector([
            zerodAnalyser,
        ])
        data = {
            'analysers': [
                zerodAnalyser,
            ],
            'collectors': [
                dataCollector,
            ],
        }

        return data

    ### HOUSEKEEPING: IMPORTANT! ###

    return Grouper(locals())
Ejemplo n.º 15
0
def build():

    ### HOUSEKEEPING: IMPORTANT! ###

    inputs = locals().copy()
    script = __file__

    ### FIGURES ###

    def make_figs(system, step, modeltime):
        fig = glucifer.Figure(edgecolour="white", quality=2)
        figTempComponent = fig.Surface(system.mesh,
                                       system.temperatureField,
                                       colourBar=True)
        figVelComponent = fig.VectorArrows(system.mesh, system.velocityField)
        figViscComponent = fig.Contours(system.mesh,
                                        fn.math.log10(system.viscosityFn),
                                        colours="red black",
                                        interval=0.5,
                                        colourBar=False)

        figs = {
            'fig': fig,
        }
        return figs

    ### DATA ###

    def make_data(system, step, modeltime):
        zerodDataDict = {
            'Nu':
            analysis.Analyse.DimensionlessGradient(system.temperatureField,
                                                   system.mesh,
                                                   surfIndexSet=system.outer,
                                                   baseIndexSet=system.inner),
            'avTemp':
            analysis.Analyse.ScalarFieldAverage(system.temperatureField,
                                                system.mesh),
            'VRMS':
            analysis.Analyse.VectorFieldVolRMS(system.velocityField,
                                               system.mesh),
            'surfVRMS':
            analysis.Analyse.VectorFieldSurfRMS(system.velocityField,
                                                system.mesh, system.outer),
            'avVisc':
            analysis.Analyse.ScalarFieldAverage(system.viscosityFn,
                                                system.mesh),
            'yielding':
            analysis.Analyse.ScalarFieldAverage(
                fn.branching.conditional([
                    (system.creepViscFn < system.plasticViscFn, 0.), (True, 1.)
                ]), system.mesh),
            'step':
            analysis.Analyse.ArrayStripper(step, (0, 0)),
            'modeltime':
            analysis.Analyse.ArrayStripper(modeltime, (0, 0)),
        }

        zerodFormatDict = {
            'Nu': "{:.1f}",
            'avTemp': "{:.2f}",
            'VRMS': "{:.2f}",
            'surfVRMS': "{:.2f}",
            'avVisc': "{:.1E}",
            'yielding': "{0:.0%}",
            'step': "{:.0f}",
            'modeltime': "{:.1E}",
        }

        zerodAnalyser = analysis.Analyser('zerodData', zerodDataDict,
                                          zerodFormatDict)
        dataCollector = analysis.DataCollector([
            zerodAnalyser,
        ])
        data = {
            'analysers': [
                zerodAnalyser,
            ],
            'collectors': [
                dataCollector,
            ],
        }
        return Grouper(data)

    ### HOUSEKEEPING: IMPORTANT! ###
    return Grouper(locals())