Exemplo n.º 1
0
def update_sigma(the_field_sigma,i):
    compute_J=nfem.prematrix_applicator(prematrix_J,
                                         field_mid=the_field_sigma)
    laplace_solver=nfem.laplace_solver(prematrix_laplace,
                                        dirichlet_bcs=[(-1,1,laplace_dbc)],
                                        mwe_mid=the_field_sigma)
    #
    field_phi = laplace_solver(cofield_drho_by_dt,
                               dbc_values=laplace_dbc_values)
    field_J = nfem.cofield_to_field(compute_J(field_phi))

   

    #print "field_J contents:", nfem.data_doftypes(field_J)
    
    # XXX NOTE: we should be able to make an applicator that does the
    # cofield_to_field conversion automatically!
    #
    #
    # Next, let us compute the new condictivity by site-wise operation on
    # field_J. We just overwrite field_sigma:
    #
    recompute_conductivity([h_x,h_y,sigma0,alpha],fields=[the_field_sigma,field_J])
    print "Refcount field_sigma:",ocaml.sys_refcount(the_field_sigma)
    return the_field_sigma
Exemplo n.º 2
0
def update_sigma(the_field_sigma):
    compute_J=nfem.prematrix_applicator(prematrix_J,
                                         mwe_mid=the_field_sigma)
    laplace_solver=nfem.laplace_solver(prematrix_laplace,
                                        dirichlet_bcs=[(-1,1,laplace_dbc)],
                                        mwe_mid=the_field_sigma)
    #
    field_phi = laplace_solver(cofield_drho_by_dt,
                               dbc_values=laplace_dbc_values)
    field_J = nfem.cofield_to_field(compute_J(field_phi))
    # XXX NOTE: we should be able to make an applicator that does the
    # cofield_to_field conversion automatically!
    #
    #
    # Next, let us compute the new condictivity by site-wise operation on
    # field_J. We just overwrite field_sigma:
    #
    recompute_conductivity=nfem.site_wise_applicator(parameter_names=["H_x","H_y","sigma0","alpha"],
                                                      # all the names of extra parameters
                                                      code=code_recompute_conductivity,
                                                      fields=[the_field_sigma,field_J]
                                                      )
    #
    #
    recompute_conductivity([h_x,h_y,sigma0,alpha])
    return the_field_sigma
Exemplo n.º 3
0
def update_sigma(the_field_sigma, i):
    compute_J = nfem.prematrix_applicator(prematrix_J,
                                          field_mid=the_field_sigma)
    laplace_solver = nfem.laplace_solver(prematrix_laplace,
                                         dirichlet_bcs=[(-1, 1, laplace_dbc)],
                                         mwe_mid=the_field_sigma)
    #
    field_phi = laplace_solver(cofield_drho_by_dt,
                               dbc_values=laplace_dbc_values)
    field_J = nfem.cofield_to_field(compute_J(field_phi))

    #print "field_J contents:", nfem.data_doftypes(field_J)

    # XXX NOTE: we should be able to make an applicator that does the
    # cofield_to_field conversion automatically!
    #
    #
    # Next, let us compute the new condictivity by site-wise operation on
    # field_J. We just overwrite field_sigma:
    #
    recompute_conductivity([h_x, h_y, sigma0, alpha],
                           fields=[the_field_sigma, field_J])

    nfem.visual.fields2vtkfile([field_phi, field_J, the_field_sigma],
                               'fem-rings2_all%d.vtk' % i, the_mesh)

    return the_field_sigma
Exemplo n.º 4
0
solve_bem=nfem.laplace_solver_bem(prematrix_laplace,inside_regions=[1])

log.info("OK 4!")

compute_div_M=nfem.prematrix_applicator(prematrix_div_M,interface_coeffs=[(1,-1,1.0)])
compute_grad_phi=nfem.prematrix_applicator(prematrix_grad_phi)

log.info("OK 5!")

field_M0=nfem.make_field(mwe_M,fun_M0)

cofield_div_M=compute_div_M(field_M0)

# DDD
ddd_field_div_M=nfem.cofield_to_field(cofield_div_M)
print "DDD div M: ",nfem.probe_field(ddd_field_div_M,[2.7,0.2,0.0]) # we may add: ,name_stem="rho_M")
# END DDD

field_phi_M=solve_bem(cofield_div_M)

log.info("OK 6!")
field_H=nfem.cofield_to_field(compute_grad_phi(field_phi_M))

log.info("OK 7!")
# Also, we do direct summation, just for comparison:

direct_summer = ocaml.dipole_field_direct_summer(1, # nr cpus (processes to fork to)
                                                 0.0, # minimal distance
                                                 mwe_H,
                                                 mwe_M,
Exemplo n.º 5
0
# Note that this magnetization is "mostly zero":
def fun_M0(dof_name_indices, position):
    if dof_name_indices[1][0] == 1:  # y-direction
        x = position[0]
        return 1.0 / (1.0 + (x * x / 4.0))
    else:
        return 0.0


field_M = nfem.make_field(mwe_M, fun_M0)

prematrix_v_laplace = nfem.prematrix(diffop_v_laplace, mwe_H, mwe_M)

v_laplace = nfem.prematrix_applicator(prematrix_v_laplace)

field_H = nfem.cofield_to_field(v_laplace(field_M))

range_i = 100

# nfem.field_print_contents(field_H)

for i in range(0, range_i):
    pos = [-4.5 + 9.0 * i / (0.0 + range_i), 0.0, 0.0]
    field_val = nfem.probe_field(field_H, "H", pos)
    print pos[0], " ", field_val[1]

#for i in range(0,range_i):
#    pos=[-4.5+9.0*i/(0.0+range_i),0.0,0.0]
#    print pos, "=> ", nfem.probe_field(field_H,"H",pos)
Exemplo n.º 6
0
# Note that this magnetization is "mostly zero":
def fun_M0(dof_name_indices,position):
    if dof_name_indices[1][0]==1: # y-direction
        x=position[0]
        return 1.0/(1.0+(x*x/4.0))
    else:
        return 0.0


field_M=nfem.make_field(mwe_M,fun_M0)

prematrix_v_laplace=nfem.prematrix(diffop_v_laplace,mwe_H,mwe_M)

v_laplace=nfem.prematrix_applicator(prematrix_v_laplace)

field_H=nfem.cofield_to_field(v_laplace(field_M))

range_i=100

# nfem.field_print_contents(field_H)

for i in range(0,range_i):
    pos=[-4.5+9.0*i/(0.0+range_i),0.0,0.0]
    field_val=nfem.probe_field(field_H,"H",pos)
    print pos[0], " ", field_val[1]


#for i in range(0,range_i):
#    pos=[-4.5+9.0*i/(0.0+range_i),0.0,0.0]
#    print pos, "=> ", nfem.probe_field(field_H,"H",pos)
Exemplo n.º 7
0
pmx2d_laplace=nfem.prematrix(diffop_laplace,mwe2d_rho_M,mwe2d_phi_M)
pmx2d_div_M=nfem.prematrix(diffop_div_M,mwe2d_rho_M,mwe2d_M,ignore_jumps=False)
pmx2d_grad_phi=nfem.prematrix(diffop_grad_phi,mwe2d_H,mwe2d_phi_M)

solve_bem_2d=nfem.laplace_solver_bem(pmx2d_laplace,inside_regions=[1], thickness=thickness2d)

compute_div_M_2d=nfem.prematrix_applicator(pmx2d_div_M,interface_coeffs=[(1,-1,1.0)])
compute_grad_phi_2d=nfem.prematrix_applicator(pmx2d_grad_phi)

field2d_M0=nfem.make_field(mwe2d_M,fun_M0)

cofield2d_div_M=compute_div_M_2d(field2d_M0)

field2d_phi_M=solve_bem_2d(cofield2d_div_M)

field2d_H=nfem.cofield_to_field(compute_grad_phi_2d(field2d_phi_M))

# DDDDDD

print "phi_M left: ",nfem.probe_field(field2d_phi_M,[-3.8,0.0])
print "phi_M right: ",nfem.probe_field(field2d_phi_M,[3.8,0.0])

nfem.plot_scalar_field(field2d_phi_M,
                        "phi_M","/tmp/plot-phi-M.ps",
                        plot_edges=False,
                        color_scheme=[(-0.3,[0.1,0.1,1.0]),
                                      (0.0,[0.1,1.0,0.1]),
                                      (0.3,[1.0,0.1,0.1])])

nfem.plot_scalar_field(nfem.cofield_to_field(cofield2d_div_M),
                        "rho_M","/tmp/plot-rho-M.ps",
Exemplo n.º 8
0
prematrix_laplace=nfem.prematrix(diffop_laplace,
                                  mwe_drho_by_dt,mwe_phi,
                                  mwe_mid=mwe_sigma)

print "2"
prematrix_J=nfem.prematrix(diffop_J,
                                   mwe_J,mwe_phi,
                                   mwe_mid=mwe_sigma)

print "3"
compute_J=nfem.prematrix_applicator(prematrix_J,
                                     field_mid=field_sigma)
print "4"
laplace_solver=nfem.laplace_solver(prematrix_laplace,
                                    dirichlet_bcs=[(-1,1,laplace_dbc)],
                                    mwe_mid=field_sigma)

print "5"
field_phi = laplace_solver(cofield_drho_by_dt,
                           dbc_values=laplace_dbc_values)
print "6"
field_J = nfem.cofield_to_field(compute_J(field_phi))

nfem.visual.fields2vtkfile([field_phi,field_J],'result.vtk',the_mesh)

print "Try to visualise with "
print "mayavi -d run_bug-fem2-halfring/result.vtk -m SurfaceMap -m VelocityVector"


Exemplo n.º 9
0
solve_bem = nfem.laplace_solver_bem(prematrix_laplace, inside_regions=[1])

log.info("OK 4!")

compute_div_M = nfem.prematrix_applicator(prematrix_div_M,
                                          interface_coeffs=[(1, -1, 1.0)])
compute_grad_phi = nfem.prematrix_applicator(prematrix_grad_phi)

log.info("OK 5!")

field_M0 = nfem.make_field(mwe_M, fun_M0)

cofield_div_M = compute_div_M(field_M0)

# DDD
ddd_field_div_M = nfem.cofield_to_field(cofield_div_M)
print "DDD div M: ", nfem.probe_field(
    ddd_field_div_M, [2.7, 0.2, 0.0])  # we may add: ,name_stem="rho_M")
# END DDD

field_phi_M = solve_bem(cofield_div_M)

log.info("OK 6!")
field_H = nfem.cofield_to_field(compute_grad_phi(field_phi_M))

log.info("OK 7!")
# Also, we do direct summation, just for comparison:

direct_summer = ocaml.dipole_field_direct_summer(
    1,  # nr cpus (processes to fork to)
    0.0,  # minimal distance
Exemplo n.º 10
0
    print "Computed div J!"
    sys.stdout.flush()
    # ^ Works up to here!
    return _accumulate_J_total([0.0,0.0,0.0,0.0])

compute_J=nfem.prematrix_applicator(prematrix_J,
                                     mwe_mid=field_sigma)

laplace_solver=nfem.laplace_solver(prematrix_laplace,
                                    dirichlet_bcs=[(-1,1,laplace_dbc)],
                                    mwe_mid=field_sigma)

field_phi = laplace_solver(cofield_drho_by_dt,
                           dbc_values=laplace_dbc_values)

field_J = nfem.cofield_to_field(compute_J(field_phi))

print "Total current: ",compute_total_current(field_J)

nfem.plot_scalar_field(nfem.cofield_to_field(_cofield_div_J),
                        "drho_by_dt","/tmp/plot-div-j.ps",
                        color_scheme=[(-2.0,[0.2,0.2,1.0]),
                                      (-0.2,[0.2,1.0,1.0]),
                                      (0.0,[0.4,0.4,0.4]),
                                      (0.2,[1.0,1.0,0.0]),
                                      (2.0,[1.0,0.2,0.2])]);


# 
# Results from a timed test run with cached mesh
# 
Exemplo n.º 11
0
field_M2=nfem.make_field(mwe_M2,fun_M0)

print "Made M2"
sys.stdout.flush()


diffop_m_m2 = nfem.diffop("<M(j) || M2(j)>, j:3")
prematrix_m_m2=nfem.prematrix(diffop_m_m2,mwe_M,mwe_M2)

print "Made M2->M prematrix"
sys.stdout.flush()


m_m2=nfem.prematrix_applicator(prematrix_m_m2)

field_M=nfem.cofield_to_field(m_m2(field_M2))

print "Have field_M"
sys.stdout.flush()

# MMM


prematrix_v_laplace=nfem.prematrix(diffop_v_laplace,mwe_H,mwe_M)

v_laplace=nfem.prematrix_applicator(prematrix_v_laplace)

field_H=nfem.cofield_to_field(v_laplace(field_M))

range_i=100
Exemplo n.º 12
0
 def calculate_h_exch():
   compute_h_exch(field_m, target=h_exch_cofield)
   nfem.cofield_to_field(h_exch_cofield, target=field_h_exch)
Exemplo n.º 13
0
  def setup(self):
    '''This function should be called after the method 'set' to setup
       the simulation (create the fields, the operators and so on)'''

    # Should not do initializizations more than once
    if self.is_ready: return

    mwe_m, field_m = self.new_mwe_and_field("m", [3], initial_values=self.initial_mag)
    mwe_h_total, field_h_total = self.new_mwe_and_field("h_total", [3])

    if self.features["include_demag"]:
      self.new_field("h_demag", indices=[3])
    if self.features["include_exchange"]:
      self.new_field("h_exch", indices=[3])
    if self.features["external_field"]:
      h0 = self.features["external_field"]
      self.new_field("h_ext", indices=[3], initial_values=h0)

    # The demag field
    if self.features["include_demag"]:
      if self.mesh.dim != 3:
        raise "Sorry, the demag-calculation is implemented only for 3-D space."

      mwe_h_demag = self.mwes["h_demag"]
      field_h_demag = self.fields["h_demag"]

      mwe_scalar = self.new_mwe("scalar")
      mwe_rho_m = nfem.mwe_sibling(mwe_scalar, "mwe_rho_m", "renamed_scalar", [("scalar", "rho_m")])
      mwe_phi_m = nfem.mwe_sibling(mwe_scalar, "mwe_phi_m", "renamed_scalar", [("scalar", "phi_m")])

      field_div_m = nfem.make_field(mwe_rho_m)
      field_phi_m = nfem.make_field(mwe_phi_m)

      diffop_div_m_str = "%f <rho_m||d/dxj m(j)>, j:3" % self.m_sat
      print diffop_div_m_str
      compute_div_m = \
       nfem.diffop_applicator(diffop_div_m_str,
                              mwe_rho_m, mwe_m,
                              interface_coeffs=[(-2,-2,1.0)],
                              petsc_name="mumag_div_m")

      prematrix_laplace = \
       nfem.prematrix("-<d/dxj rho_m||d/dxj phi_m>, j:3", mwe_rho_m, mwe_phi_m)

      solve_bem = \
       nfem.laplace_solver_bem(prematrix_laplace, inside_regions=self.where)

      compute_grad_phi = \
       nfem.diffop_applicator("<h_demag(j)||d/dxj phi_m>, j:3",
                              mwe_h_demag, mwe_phi_m, result="field")

      cofield_div_m = compute_div_m(self.fields["m"])
      solve_bem(cofield_div_m, target=field_phi_m)
      compute_grad_phi(field_phi_m, target=field_h_demag)

      def calculate_h_demag():
        compute_div_m(self.fields["m"], target=cofield_div_m)
        solve_bem(cofield_div_m, target=field_phi_m)
        compute_grad_phi(field_phi_m, target=field_h_demag)

      self.calculate_h_demag = calculate_h_demag

    # Now we add the exchange and demag fields if needed
    if self.features["include_exchange"]:
      if not self.features["exchange_coupling"]:
        raise "You want to include exchange interaction, " + \
         "but you did not specify the exchange coupling constant!"
      ec = self.features["exchange_coupling"]
      if ec < 0.0:
        raise "Error: you specified a negative exchange coupling constant."
      mwe_h_exch = self.mwes["h_exch"]
      field_h_exch = self.fields["h_exch"]
      exch_factor  = -2.0*ec/self.m_sat_mu0
      op_str = "%f <d/dxi h_exch(j) || d/dxi m(j)>, i:%d, j:3" % (exch_factor, self.mesh.dim)
      op_h_exch = nfem.diffop(op_str)
      p = nfem.prematrix(op_h_exch, mwe_h_exch, mwe_m, ignore_jumps=True)
      compute_h_exch = nfem.prematrix_applicator(p)
      h_exch_cofield = compute_h_exch(field_m)
      nfem.cofield_to_field(h_exch_cofield, target=field_h_exch)
      def calculate_h_exch():
        compute_h_exch(field_m, target=h_exch_cofield)
        nfem.cofield_to_field(h_exch_cofield, target=field_h_exch)

      self.calculate_h_exch = calculate_h_exch

    # Create the C-functions which performs the different parts
    # of the computation

    some_names = ["m", "h_total"]
    some_mwes = self.mwe_list(some_names)
    some_fields = self.field_list(some_names)

    if self.uniaxial_anis:
      args = ["m_sat_mu0", "axis_x", "axis_y", "axis_z", "k1", "k2"]
      c_uniaxial = nfem.site_wise_applicator(args, ccode_uniaxial, field_mwes=some_mwes)
      def calculate_uniaxial_anis():
        for ua in self.uniaxial_anis:
          axis, k1, k2 = ua
          axis_x, axis_y, axis_z = axis
          args_values = [self.m_sat_mu0, axis_x, axis_y, axis_z, k1, k2]
          c_uniaxial(args_values, fields=some_fields)

      self.calculate_uniaxial_anis = calculate_uniaxial_anis

    if self.cubic_anis:
      args = ["m_sat_mu0", "axis1_x", "axis1_y", "axis1_z",
       "axis2_x", "axis2_y", "axis2_z", "k1", "k2", "k3"]
      c_cubic = nfem.site_wise_applicator(args, ccode_cubic, field_mwes=some_mwes)
      def calculate_cubic_anis():
        for ca in self.cubic_anis:
          axis1, axis2, k1, k2, k3 = ca
          axis1_x, axis1_y, axis1_z = axis1
          axis2_x, axis2_y, axis2_z = axis2
          args_values = [self.m_sat_mu0, axis1_x, axis1_y, axis1_z,
          axis2_x, axis2_y, axis2_z, k1, k2, k3]
          c_cubic(args_values, fields=some_fields)
      self.calculate_cubic_anis = calculate_cubic_anis

    more_names = ["h_total", "h_ext", "h_demag", "h_exch"]
    more_mwes = self.mwe_list(more_names)
    more_fields = self.field_list(more_names)
    add_fields = nfem.site_wise_applicator([], ccode_add_fields, field_mwes=more_mwes)
    def add_ext_demag_exch():
      add_fields([], fields=more_fields)
    self.add_ext_demag_exch = add_ext_demag_exch

    if self.features["calculate_energy"]:
      swa_calculate_energy = \
       nfem.site_wise_applicator(["energy"], ccode_calculate_energy,
                                 field_mwes=[mwe_m],cofield_mwes=[mwe_h_total])
      cofield_h_total = nfem.field_to_cofield(field_h_total)
      def calculate_energy():
        nfem.field_to_cofield(field_h_total, target=cofield_h_total)
        energy = swa_calculate_energy([0.0], fields=[field_m], cofields=[cofield_h_total])
        return -self.m_sat_mu0*energy[0]
      self.__calculate_energy = calculate_energy

    self.is_ready = True
Exemplo n.º 14
0
 def calculate_h_exch():
     compute_h_exch(field_m, target=h_exch_cofield)
     nfem.cofield_to_field(h_exch_cofield, target=field_h_exch)
Exemplo n.º 15
0
    def setup(self):
        '''This function should be called after the method 'set' to setup
       the simulation (create the fields, the operators and so on)'''

        # Should not do initializizations more than once
        if self.is_ready: return

        mwe_m, field_m = self.new_mwe_and_field(
            "m", [3], initial_values=self.initial_mag)
        mwe_h_total, field_h_total = self.new_mwe_and_field("h_total", [3])

        if self.features["include_demag"]:
            self.new_field("h_demag", indices=[3])
        if self.features["include_exchange"]:
            self.new_field("h_exch", indices=[3])
        if self.features["external_field"]:
            h0 = self.features["external_field"]
            self.new_field("h_ext", indices=[3], initial_values=h0)

        # The demag field
        if self.features["include_demag"]:
            if self.mesh.dim != 3:
                raise "Sorry, the demag-calculation is implemented only for 3-D space."

            mwe_h_demag = self.mwes["h_demag"]
            field_h_demag = self.fields["h_demag"]

            mwe_scalar = self.new_mwe("scalar")
            mwe_rho_m = nfem.mwe_sibling(mwe_scalar, "mwe_rho_m",
                                         "renamed_scalar",
                                         [("scalar", "rho_m")])
            mwe_phi_m = nfem.mwe_sibling(mwe_scalar, "mwe_phi_m",
                                         "renamed_scalar",
                                         [("scalar", "phi_m")])

            field_div_m = nfem.make_field(mwe_rho_m)
            field_phi_m = nfem.make_field(mwe_phi_m)

            diffop_div_m_str = "%f <rho_m||d/dxj m(j)>, j:3" % self.m_sat
            print diffop_div_m_str
            compute_div_m = \
             nfem.diffop_applicator(diffop_div_m_str,
                                    mwe_rho_m, mwe_m,
                                    interface_coeffs=[(-2,-2,1.0)],
                                    petsc_name="mumag_div_m")

            prematrix_laplace = \
             nfem.prematrix("-<d/dxj rho_m||d/dxj phi_m>, j:3", mwe_rho_m, mwe_phi_m)

            solve_bem = \
             nfem.laplace_solver_bem(prematrix_laplace, inside_regions=self.where)

            compute_grad_phi = \
             nfem.diffop_applicator("<h_demag(j)||d/dxj phi_m>, j:3",
                                    mwe_h_demag, mwe_phi_m, result="field")

            cofield_div_m = compute_div_m(self.fields["m"])
            solve_bem(cofield_div_m, target=field_phi_m)
            compute_grad_phi(field_phi_m, target=field_h_demag)

            def calculate_h_demag():
                compute_div_m(self.fields["m"], target=cofield_div_m)
                solve_bem(cofield_div_m, target=field_phi_m)
                compute_grad_phi(field_phi_m, target=field_h_demag)

            self.calculate_h_demag = calculate_h_demag

        # Now we add the exchange and demag fields if needed
        if self.features["include_exchange"]:
            if not self.features["exchange_coupling"]:
                raise "You want to include exchange interaction, " + \
                 "but you did not specify the exchange coupling constant!"
            ec = self.features["exchange_coupling"]
            if ec < 0.0:
                raise "Error: you specified a negative exchange coupling constant."
            mwe_h_exch = self.mwes["h_exch"]
            field_h_exch = self.fields["h_exch"]
            exch_factor = -2.0 * ec / self.m_sat_mu0
            op_str = "%f <d/dxi h_exch(j) || d/dxi m(j)>, i:%d, j:3" % (
                exch_factor, self.mesh.dim)
            op_h_exch = nfem.diffop(op_str)
            p = nfem.prematrix(op_h_exch, mwe_h_exch, mwe_m, ignore_jumps=True)
            compute_h_exch = nfem.prematrix_applicator(p)
            h_exch_cofield = compute_h_exch(field_m)
            nfem.cofield_to_field(h_exch_cofield, target=field_h_exch)

            def calculate_h_exch():
                compute_h_exch(field_m, target=h_exch_cofield)
                nfem.cofield_to_field(h_exch_cofield, target=field_h_exch)

            self.calculate_h_exch = calculate_h_exch

        # Create the C-functions which performs the different parts
        # of the computation

        some_names = ["m", "h_total"]
        some_mwes = self.mwe_list(some_names)
        some_fields = self.field_list(some_names)

        if self.uniaxial_anis:
            args = ["m_sat_mu0", "axis_x", "axis_y", "axis_z", "k1", "k2"]
            c_uniaxial = nfem.site_wise_applicator(args,
                                                   ccode_uniaxial,
                                                   field_mwes=some_mwes)

            def calculate_uniaxial_anis():
                for ua in self.uniaxial_anis:
                    axis, k1, k2 = ua
                    axis_x, axis_y, axis_z = axis
                    args_values = [
                        self.m_sat_mu0, axis_x, axis_y, axis_z, k1, k2
                    ]
                    c_uniaxial(args_values, fields=some_fields)

            self.calculate_uniaxial_anis = calculate_uniaxial_anis

        if self.cubic_anis:
            args = [
                "m_sat_mu0", "axis1_x", "axis1_y", "axis1_z", "axis2_x",
                "axis2_y", "axis2_z", "k1", "k2", "k3"
            ]
            c_cubic = nfem.site_wise_applicator(args,
                                                ccode_cubic,
                                                field_mwes=some_mwes)

            def calculate_cubic_anis():
                for ca in self.cubic_anis:
                    axis1, axis2, k1, k2, k3 = ca
                    axis1_x, axis1_y, axis1_z = axis1
                    axis2_x, axis2_y, axis2_z = axis2
                    args_values = [
                        self.m_sat_mu0, axis1_x, axis1_y, axis1_z, axis2_x,
                        axis2_y, axis2_z, k1, k2, k3
                    ]
                    c_cubic(args_values, fields=some_fields)

            self.calculate_cubic_anis = calculate_cubic_anis

        more_names = ["h_total", "h_ext", "h_demag", "h_exch"]
        more_mwes = self.mwe_list(more_names)
        more_fields = self.field_list(more_names)
        add_fields = nfem.site_wise_applicator([],
                                               ccode_add_fields,
                                               field_mwes=more_mwes)

        def add_ext_demag_exch():
            add_fields([], fields=more_fields)

        self.add_ext_demag_exch = add_ext_demag_exch

        if self.features["calculate_energy"]:
            swa_calculate_energy = \
             nfem.site_wise_applicator(["energy"], ccode_calculate_energy,
                                       field_mwes=[mwe_m],cofield_mwes=[mwe_h_total])
            cofield_h_total = nfem.field_to_cofield(field_h_total)

            def calculate_energy():
                nfem.field_to_cofield(field_h_total, target=cofield_h_total)
                energy = swa_calculate_energy([0.0],
                                              fields=[field_m],
                                              cofields=[cofield_h_total])
                return -self.m_sat_mu0 * energy[0]

            self.__calculate_energy = calculate_energy

        self.is_ready = True
Exemplo n.º 16
0
# MMM

field_M2 = nfem.make_field(mwe_M2, fun_M0)

print "Made M2"
sys.stdout.flush()

diffop_m_m2 = nfem.diffop("<M(j) || M2(j)>, j:3")
prematrix_m_m2 = nfem.prematrix(diffop_m_m2, mwe_M, mwe_M2)

print "Made M2->M prematrix"
sys.stdout.flush()

m_m2 = nfem.prematrix_applicator(prematrix_m_m2)

field_M = nfem.cofield_to_field(m_m2(field_M2))

print "Have field_M"
sys.stdout.flush()

# MMM

prematrix_v_laplace = nfem.prematrix(diffop_v_laplace, mwe_H, mwe_M)

v_laplace = nfem.prematrix_applicator(prematrix_v_laplace)

field_H = nfem.cofield_to_field(v_laplace(field_M))

range_i = 100

# nfem.field_print_contents(field_H)
Exemplo n.º 17
0
        raise StandardError, "this place can't be reached"


cofield_drho_by_dt = nfem.make_cofield(mwe_drho_by_dt)

print "1"

prematrix_laplace = nfem.prematrix(
    diffop_laplace, mwe_drho_by_dt, mwe_phi, mwe_mid=mwe_sigma)

print "2"
prematrix_J = nfem.prematrix(diffop_J, mwe_J, mwe_phi, mwe_mid=mwe_sigma)

print "3"
compute_J = nfem.prematrix_applicator(prematrix_J, field_mid=field_sigma)
print "4"
laplace_solver = nfem.laplace_solver(
    prematrix_laplace,
    dirichlet_bcs=[(-1, 1, laplace_dbc)],
    mwe_mid=field_sigma)

print "5"
field_phi = laplace_solver(cofield_drho_by_dt, dbc_values=laplace_dbc_values)
print "6"
field_J = nfem.cofield_to_field(compute_J(field_phi))

nfem.visual.fields2vtkfile([field_phi, field_J], 'result.vtk', the_mesh)

print "Try to visualise with "
print "mayavi -d run_bug-fem2-halfring/result.vtk -m SurfaceMap -m VelocityVector"
Exemplo n.º 18
0
sys.exit()

# This example shows that we indeed are on the right track and the
# artefacts I encuntered yesterday were just a product of working too
# long... The important thing to remember is:
# DO NOT COMPUTE div(sigma*grad(phi)), compute Laplace(phi)
# (with modified laplace operator) to get div j. The div-grad-thingy will
# do strange things when taking the gradient of phi at the boundary.


###### END ######



field_J = nfem.cofield_to_field(compute_J(field_phi))

recompute_conductivity=nfem.site_wise_applicator(parameter_names=["H_x","H_y","sigma0","alpha"],
                                                  # all the names of extra parameters
                                                  code=code_recompute_conductivity,
                                                  fields=[field_sigma,field_J]
                                                  )
#
#
recompute_conductivity([h_x,h_y,sigma0,alpha])

#for i in range(1,2): # was: range(1,5)
#    update_sigma(field_sigma)
#    print "Iteration ",i," sigma at origin: ",nfem.probe_field(field_sigma,"sigma",[0.0,0.0])

# === XXX The part below has to be re-done. For now, we just test whether it works! ===