Example #1
0
def diffop_applicator(diffop_or_string,
                      mwe_left,
                      mwe_right,
                      field_mid=None,
                      interface_coeffs=[],
                      petsc_name="",
                      result="cofield"):
    """In many situations (when we do not use a changing middle field),
    we can map a diffop directly to an applicator by combining prematrix
    and prematrix_applicator"""
    log.debug("In diffop_applicator for '%s'" % diffop_or_string)
    mwe_mid = None
    ignore_jumps = True
    if field_mid:
        mwe_mid = ocaml.get_mwe(field_mid)
    if len(interface_coeffs) > 0:
        log.debug("Setting ignore_jumps=False")
        ignore_jumps = False
    else:
        log.debug("Setting ignore_jumps=True")

    pmx = prematrix(diffop_or_string,
                    mwe_left,
                    mwe_right,
                    mwe_mid=mwe_mid,
                    ignore_jumps=ignore_jumps)
    app = prematrix_applicator(pmx,
                               field_mid=field_mid,
                               interface_coeffs=interface_coeffs,
                               petsc_name=petsc_name,
                               result=result)
    return app
Example #2
0
def surface_interaction(m_h_list, couplings):
    """This function is used to calculate the exchange interactions between
  magnetisations defined at the same sites in the mesh."""

    mwes = []
    fields = []
    i = 1
    for m_h_couple in m_h_list:
        m, h = m_h_couple

        m_new_name = "m%d" % i
        h_new_name = "h%d" % i
        i += 1

        mwe_m = ocaml.get_mwe(m)
        mwe_mn = nfem.mwe_sibling(mwe_m, m_new_name, "renamed_m",
                                  [("m", m_new_name)])
        mn = nfem.field_alias(m, mwe_mn)

        mwe_h = ocaml.get_mwe(h)
        mwe_hn = nfem.mwe_sibling(mwe_h, h_new_name, "renamed_h",
                                  [("h_total", h_new_name)])
        hn = nfem.field_alias(h, mwe_hn)

        fields.append(mn)
        fields.append(hn)

        mwes.append(mwe_mn)
        mwes.append(mwe_hn)

    ccode = ccode_surface_interaction
    for ac in couplings:
        i1, i2, m_sat1, m_sat2, ec = ac  # ec is the exchange coupling constant
        ccode += "SURF_INTERACTION(m%d, %f, h%d, m%d, %f, h%d, %f)\n" % \
          (i1, m_sat1, i1, i2, m_sat2, i2, ec)

    original_fn = nfem.site_wise_applicator([], ccode, field_mwes=mwes)

    def fn():
        original_fn([], fields=fields)

    return fn
Example #3
0
def surface_interaction(m_h_list, couplings):
  """This function is used to calculate the exchange interactions between
  magnetisations defined at the same sites in the mesh."""

  mwes = []
  fields = []
  i = 1
  for m_h_couple in m_h_list:
    m, h = m_h_couple

    m_new_name = "m%d" % i
    h_new_name = "h%d" % i
    i += 1

    mwe_m = ocaml.get_mwe(m)
    mwe_mn = nfem.mwe_sibling(mwe_m, m_new_name, "renamed_m", [("m", m_new_name)])
    mn = nfem.field_alias(m, mwe_mn)

    mwe_h = ocaml.get_mwe(h)
    mwe_hn = nfem.mwe_sibling(mwe_h, h_new_name, "renamed_h", [("h_total", h_new_name)])
    hn = nfem.field_alias(h, mwe_hn)

    fields.append( mn )
    fields.append( hn )

    mwes.append( mwe_mn )
    mwes.append( mwe_hn )

  ccode = ccode_surface_interaction
  for ac in couplings:
    i1, i2, m_sat1, m_sat2, ec = ac # ec is the exchange coupling constant
    ccode += "SURF_INTERACTION(m%d, %f, h%d, m%d, %f, h%d, %f)\n" % \
      (i1, m_sat1, i1, i2, m_sat2, i2, ec)

  original_fn = nfem.site_wise_applicator([], ccode, field_mwes=mwes)
  def fn():
    original_fn([], fields=fields)

  return fn
Example #4
0
def save_field(field, fieldname, filename):
    ccode = (
        '''
#line 19 "save_field.py"
  static FILE *f = (FILE *) NULL;

  if ( close_file > 0.0 ) {
    if ( f != (FILE *) NULL) {
      (void) fclose(f);
      f = (FILE *) NULL;
    }

  } else {
    if ( f == (FILE *) NULL )
      f = fopen("'''
        + filename
        + """", "w");

    if ( f != (FILE *) NULL ) {
      if ( have_"""
        + fieldname
        + """ ) {
        double c[3] = {0.0, 0.0, 0.0};
        int i;
        for(i=0; i<((int) dim); i++) c[i] = COORDS(i);
        fprintf(f, "%g %f %f %f %g %g %g\\n",
          time, c[0], c[1], c[2], """
        + fieldname
        + """(0), """
        + fieldname
        + """(1), """
        + fieldname
        + """(2));
      }
    }
  }
  """
    )

    dim = float(field_dim(field))
    mwe = ocaml.get_mwe(field)
    fn = nfem.site_wise_applicator(["close_file", "time", "dim"], ccode, field_mwes=[mwe])

    def saver(close=False, time=0.0):
        if close:
            fn([1.0, float(time), dim], fields=[field])
        else:
            fn([-1.0, float(time), dim], fields=[field])

    return saver
Example #5
0
def diffop_applicator(
    diffop_or_string, mwe_left, mwe_right, field_mid=None, interface_coeffs=[], petsc_name="", result="cofield"
):
    """In many situations (when we do not use a changing middle field),
    we can map a diffop directly to an applicator by combining prematrix
    and prematrix_applicator"""
    log.debug("In diffop_applicator for '%s'" % diffop_or_string)
    mwe_mid = None
    ignore_jumps = True
    if field_mid:
        mwe_mid = ocaml.get_mwe(field_mid)
    if len(interface_coeffs) > 0:
        log.debug("Setting ignore_jumps=False")
        ignore_jumps = False
    else:
        log.debug("Setting ignore_jumps=True")

    pmx = prematrix(diffop_or_string, mwe_left, mwe_right, mwe_mid=mwe_mid, ignore_jumps=ignore_jumps)
    app = prematrix_applicator(
        pmx, field_mid=field_mid, interface_coeffs=interface_coeffs, petsc_name=petsc_name, result=result
    )
    return app
Example #6
0
def renamed_field(field, old_name, new_name):
  mwe = ocaml.get_mwe(field)
  new_mwe = nfem.mwe_sibling(mwe, new_name, "renamed_"+old_name, [(old_name, new_name)])
  return nfem.field_alias(field, new_mwe)
Example #7
0
def renamed_field(field, old_name, new_name):
    mwe = ocaml.get_mwe(field)
    new_mwe = nfem.mwe_sibling(mwe, new_name, "renamed_" + old_name,
                               [(old_name, new_name)])
    return nfem.field_alias(field, new_mwe)