Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/femprime/src/compiler/high-to-mid/expand-fem.sml
ViewVC logotype

View of /branches/femprime/src/compiler/high-to-mid/expand-fem.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5048 - (download) (annotate)
Thu Jul 13 01:09:59 2017 UTC (2 years, 1 month ago) by cchiw
File size: 3747 byte(s)
put evalfem in ein ir
(* expand-fem.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2016 The University of Chicago
 * All rights reserved.
 *)

structure ExpandFem : sig

    val transform : MidIR.assign -> MidIR.assign list

  end = struct

    structure IR = MidIR
    structure Op = MidOps
    structure V = IR.Var
    structure Ty = MidTypes
    structure E = Ein
    structure DE = DerivativeEin
    fun transform (y, IR.EINAPP(ein as E.EIN{body,index,...}, args)) = (case (body)
        of E.Probe(E.OField(E.Fem, e1, e2, dx), pos) =>
            let
                val _ = print(String.concat ["\n fem  ttansform:", EinPP.toString(ein)])
                val [f,p] = args
                (* creating new mid-ir variables*)
                val b = V.new ( "basis", Ty.tensorTy [])
                val l = V.new ( "numcell", Ty.tensorTy [])
                val nm = V.new ( "celltonode", Ty.tensorTy [])
                val pm = V.new ( "nodetopoint", Ty.tensorTy [])
                val x = V.new ( "coordinates", Ty.tensorTy [])
                val fc = V.new ( "cp", Ty.tensorTy [])
                val cell = V.new ( "cell", Ty.tensorTy [])
                val newpos = V.new ( "newpos", Ty.tensorTy [])
                val node = V.new ( "node", Ty.tensorTy [])
                val coordsrelevant = V.new ( "coordsrel", Ty.tensorTy [])
                val basisrelevant = V.new ( "basisrel", Ty.tensorTy [])

                (* creating mid-ir assignmment *)
                val p0  = (b, IR.OP(Op.BasisData, [f]))
                val p1  = (l, IR.OP(Op.NumCells, [f]))
                val p2  = (nm, IR.OP(Op.CellToNode, [f]))
                val p3  = (pm, IR.OP(Op.NodeToPoint, [f]))
                val p4  = (x, IR.OP(Op.Coordinates, [f]))
                val p5  = (fc,IR.OP(Op.FindCell, [p,l,nm,pm, b]))
                val p6  = (cell,IR.OP(Op.GetCell, [fc]))
                val p7  = (newpos,IR.OP(Op.GetPos, [fc]))
                val p8  = (node, IR.OP(Op.GetNode, [cell, nm]))
                val p9  = (coordsrelevant, IR.OP(Op.ProbeNode, [node,x]))
                val p10  = (basisrelevant, IR.OP(Op.ProbeNode, [node,b]))
                (*val p11  = (y, IR.OP(Op.EvalFem, [newpos, coordsrelevant, basisrelevant]))*)


                (*parameter list, id list and args lists must match*)
                val args = [basisrelevant, coordsrelevant, newpos]
                val idn = 2 (*newpos*)
                val idc = 1 (*coordsrelevant*)
                val idb = 0 (*basisrelevant*)

val pos = E.Tensor(idn, [])
val fld = E.BigF(idc, [])               (*F(pos)*)
val inv = E.Inverse(fld)                            (*(F(pos))^-1*)
val phi = E.Basis(idb,[])               (*Phi((F(pos))^-1)*)


                val body = E.EvalFem [phi, inv, pos]

                val params = [E.TEN(true,[]), E.TEN(true,[]), E.TEN(true,[])]
      val _ =  print("\n\n*** before deriving:\n\t"^EinPP.expToString(body))
                val body = DE.differentiate ([E.V 0], body)
  val _ =  print("\n\n*** frist derivative:\n\t"^EinPP.expToString(body))
                val body = DE.differentiate ([E.V 1], body)
val _ =  print("\n\n*** second derivative:\n\t"^EinPP.expToString(body))
val body = DE.differentiate ([E.V 2], body)
val _ =  print("\n\n*** third derivative:\n\t"^EinPP.expToString(body))
                val ein = E.EIN{body=body, index=index, params=params}
                val p11  = (y, IR.EINAPP(ein,args))
            in
                [p0,p1,p2,p3,p4,p5,p6,p7,p8, p9,p10,p11]
            end

        | _ => (print(String.concat ["\n ttansform--else:", EinPP.toString(ein)]); [(y, IR.EINAPP(ein, args))])
        (* end case*))
    | transform (y, e) =   [(y, e)]

end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0