Skip to content

Commit

Permalink
Last touches. The beginning of a new idea?
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlhicks committed Jul 11, 2024
1 parent d385329 commit 6052f4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
24 changes: 13 additions & 11 deletions q3d/firedrakeplus/fy.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from firedrake import SpatialCoordinate, VectorFunctionSpace, Function
from q3d.uflplus import *

def firedrakefy(func, mesh): # REMOVE?
H1_vec = VectorFunctionSpace(mesh, 'CG', 1, 5)
x0, x1, x2 = SpatialCoordinate(mesh)
def EqnGlobalFunction(func_str, func_space_data):
from q3d.firedrakeplus.eqnglobals import EqnGlobals

H1_vec = VectorFunctionSpace(*func_space_data, 5)
x0, x1, x2 = SpatialCoordinate(func_space_data[0])

func = getattr(EqnGlobals, func_str)

f = Function(H1_vec)
f.interpolate(eval(func))

return f

def RandomFunction(function_space): # CHANGE to mesh instead of func space?
f = Function(function_space)
f.interpolate(as_vector([0,0,0,0,0]))
def RandomFunction(dim, func_space_data): # CHANGE to mesh instead of func space?
H1_vec = VectorFunctionSpace(*func_space_data, dim)

f = Function(H1_vec)
f.assign(Zero((dim,)))

for ii in range(len(f.dat.data)):
f.dat.data[ii] = f.rand(5)*1e+1

return f

def ManuQ(mesh): # REMOVE?
from q3d.firedrakeplus.eqnglobals import EqnGlobals
return firedrakefy(EqnGlobals.manu_q, mesh)
return f
8 changes: 5 additions & 3 deletions scripts/qtensor3d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sys
from time import sleep

from firedrake import COMM_WORLD as comm
from firedrake import Function, VectorFunctionSpace
from firedrake.tsfc_interface import TSFCKernel
from pyop2.global_kernel import GlobalKernel

Expand All @@ -14,7 +15,7 @@ import q3d.config as config
import q3d.printoff as pr
import q3d.saves as saves
import q3d.uflcache as uflcache
from q3d.firedrakeplus import (ManuQ, choose_mesh, compute_energy, errorH1,
from q3d.firedrakeplus import (EqnGlobalFunction, choose_mesh, compute_energy, errorH1,
errorL2, set_eqn_globals, solve_PDE)
from q3d.loaddump import load_json, load_yml
from q3d.misc import Timer, check, get_range
Expand Down Expand Up @@ -134,9 +135,10 @@ def run(path, *, overwrite=False, supersessions={}):
for refinement_level in get_range(settings.mesh.refs):
# choose mesh, depending on the mesh source and mesh name, as well as the refinement level
mesh = choose_mesh(settings.mesh.source, settings.mesh.name, refinement_level=refinement_level)
func_space_data = [mesh,'CG',1] # is this the beginning of good things to come?

# set equation globals to initialize
set_eqn_globals(comp,uflcache_dict)
set_eqn_globals(comp, uflcache_dict)

# solve PDE and get info about it
q_soln, time_elapsed, times, energies, completed = solve_PDE(mesh,ref_lvl=refinement_level)
Expand All @@ -148,7 +150,7 @@ def run(path, *, overwrite=False, supersessions={}):
# go ahead and compute its energy, and compare it to the
# solution we got from solve_PDE()
if 'manu_q' in uflcache.load_userexpr_yml(path).keys():
q_manu = ManuQ(mesh)
q_manu = EqnGlobalFunction('manu_q', func_space_data)
manu_energy = compute_energy(q_manu)
h1_error = errorH1(q_soln,q_manu,mesh)
l2_error = errorL2(q_soln,q_manu,mesh)
Expand Down

0 comments on commit 6052f4e

Please sign in to comment.