def print_field(field,name="M",pos=[-4.0,1.0],t=None):
    probed=ocaml.probe_field(field,name,pos)
    v=probed[0][1]
    if t!=None:
        print "%8.6f  %8.6f %8.6f %8.6f" % (t,v[0],v[1],v[2])
    else:
        print "%8.6f %8.6f %8.6f" % (v[0],v[1],v[2])
Exemple #2
0
 def do(idx, position):
     probed = ocaml.probe_field(field, subfield, position)
     if probed != None:
         if len(probed) == 1:
             dofname, value = probed[0]
             out(position, value)
         else:
             assert len(probed) == 0, \
               "Unexpected output from probing function: %s" % str(probed)
Exemple #3
0
 def do(idx, position):
     probed = ocaml.probe_field(field, subfield, position)
     if probed != None:
         if len(probed) == 1:
             dofname, value = probed[0]
             out(position, value)
         else:
             assert len(probed) == 0, \
               "Unexpected output from probing function: %s" % str(probed)
Exemple #4
0
def sample(buffer, fieldname):
    data = []
    xs = []
    left = -500
    right = 500
    n = 100.
    y = 0.
    z = 0.
    for i in range(n):
        x = float(left + (i + 0.5) * (right - left) / float(n))
        T = ocaml.probe_field(buffer, fieldname, [x, y, z])[0][1]
        data.append(T)
        xs.append(x)
    return xs, data
Exemple #5
0
def probe_field(field, position, subfieldname=""):
    """Returns the interpolated value of a collection of degrees
    of freedom with given name in given field at a specific position.

    Trivial interface to probe_field (all it does it to convert the position
    entries to float in case they are ints).

    This is not used by nmag.
    """

    # convert position list into list of floats (in case they are ints, etc)
    position = map(lambda a: float(a), position)

    return ocaml.probe_field(field, subfieldname, position)
Exemple #6
0
def sample(buffer,fieldname):
    data = []
    xs = []
    left = -500
    right = 500
    n = 100.
    y = 0.
    z = 0.
    for i in range(n):
        x = float(left + (i+0.5)*(right-left)/float(n))
        T = ocaml.probe_field(buffer,fieldname,[x,y,z])[0][1]
        data.append(T)
        xs.append(x)
    return xs,data
Exemple #7
0
def probe_field(field, position, subfieldname=""):
    """Returns the interpolated value of a collection of degrees
    of freedom with given name in given field at a specific position.

    Trivial interface to probe_field (all it does it to convert the position
    entries to float in case they are ints).

    This is not used by nmag.
    """

    #convert position list into list of floats (in case they are ints, etc)
    position = map(lambda a: float(a), position)

    return ocaml.probe_field(field, subfieldname, position)
Exemple #8
0
for i in range(int(heating_time // time_step) + 1):
    ocaml.raw_cvode_advance(cvode, sundialsbuffer_final, float(i * time_step),
                            max_it)

    for name in master_mwes_and_fields_by_name.keys():
        (mwe, field) = master_mwes_and_fields_by_name[name]
        ocaml.linalg_machine_get_field(lam, field, "v_%s" % name)

    fields = map(lambda a: a[1], master_mwes_and_fields_by_name.values())
    #nfem.visual.fields2vtkfile(fields,'H-%02d.vtk' % i,my_mesh,format='binary')

    last_i = i

    j0 = numpy.array(
        ocaml.probe_field(master_mwes_and_fields_by_name['j'][1], 'j',
                          [0., 0., 0.])[0][1])
    j1 = numpy.array(
        ocaml.probe_field(master_mwes_and_fields_by_name['j'][1], 'j',
                          [-499., 0., 0.])[0][1])

    print "j0 in A/m^2:", j0 * su.conversion_factor_of(SI("A/m^2"))
    print "j1 in A/m^2:", j1 * su.conversion_factor_of(SI("A/m^2"))

    T0 = ocaml.probe_field(sundialsbuffer_final, "T", [0.0, 0.0, 0.0])[0][1]
    T1 = ocaml.probe_field(sundialsbuffer_final, "T", [-499.0, 0.0, 0.0])[0][1]
    T2 = ocaml.probe_field(sundialsbuffer_final, "T",
                           [-25.0, 10.0, 10.0])[0][1]
    T3 = ocaml.probe_field(sundialsbuffer_final, "T",
                           [+499.0, 10.0, 10.0])[0][1]

    xs, data = sample(sundialsbuffer_final, "T")
Exemple #9
0
time_step = 100

# Set the electrical contact potential to +/- Phi_ext at left and
# right contact:

ocaml.linalg_machine_set_iparam(lam, "Phi_ext", 5.0)
ocaml.raw_cvode_advance(cvode, sundialsbuffer_final, heating_time, max_it)

# Turn off electric heating:
ocaml.linalg_machine_set_iparam(lam, "Phi_ext", 0.0)
print "Known fieldnames are", master_mwes_and_fields_by_name.keys()
fields = map(lambda a: a[0], master_mwes_and_fields_by_name.values())
for field in fields:
    print "known fields are", ocaml.sys_ocamlpill_type(field)
    #Thomas, we only have one filed in master_mwes and fields -- is that right?x

for i in range(500):
    ocaml.raw_cvode_advance(cvode, sundialsbuffer_final,
                            heating_time + i * time_step, max_it)

    (mwe, field) = master_mwes_and_fields_by_name['T']
    ocaml.linalg_machine_get_field(lam, field, "v_T")

    #Thomas, do we need to copy the data back into master_mwes_and_fields_by_name?
    nfem.visual.fields2vtkfile(master_mwes_and_fields_by_name['T'][1],
                               'T-%04d.vtk' % i,
                               my_mesh,
                               format='binary')
    T0 = ocaml.probe_field(sundialsbuffer_final, "T", [0.0, 0.0, 0.0])
    print "i: %3d T: %s" % (i, repr(T0))
Exemple #10
0
#sim.set_magnetization([1.0,0.0,0.0])
#sim.set_magnetization([0.0,1.0,0.0])
#sim.set_magnetization([0.0,0.0,1.0])
#sim.set_magnetization([0.0,1.0,1.0])
# ^All these yield a magnetic charge imbalance of 0.0


sim.set_magnetization(initial_magnetization)

time_start=time.time()

sim.advance_time(intensive_param_by_name,2.0)
#sim.advance_time(intensive_param_by_name,10.0)

print "H_demag at origin: ",ocaml.probe_field(sim.fields["H_demag"],"H_demag",[0.0,0.0,0.0])


time_end=time.time()

print "SIM INIT TIME: ",time_start-time_init," sec."
print "SIM RUN TIME: ",time_end-time_start," sec."
print "PETSC: ",ocaml.petsc_cpu_cycles("report")
print "PETSC: ",ocaml.petsc_cpu_cycles("reset")
sys.exit()

print
"""

nmag, basic run, mesh pre-generated, cached:
Exemple #11
0
    max_steps=450,
    cache_name="sphere")

#sim.set_magnetization([1.0,0.0,0.0])
#sim.set_magnetization([0.0,1.0,0.0])
#sim.set_magnetization([0.0,0.0,1.0])
#sim.set_magnetization([0.0,1.0,1.0])
# ^All these yield a magnetic charge imbalance of 0.0

sim.set_magnetization(initial_magnetization)

time_start = time.time()

sim.advance_time(intensive_param_by_name, 1e-6)

print "### XXX H_demag: ", ocaml.probe_field(sim.fields["H_demag"], "H_demag",
                                             [0.0, 0.0, 0.0])

for i in range(1, 100):
    target_time = sim.advance_time(intensive_param_by_name, 0.1 * i)

    #write SI data into default file (results.ndt)
    sim.save_data_table()

    #write SU data into special file
    sim.save_data_table_su(filename='results_su.ndt')

    nfem.visual.fields2vtkfile(sim.fields.values(),
                               'sphere-%d.vtk' % i,
                               mesh=sim.mesh)
    print "Field at origin (T=%f):" % target_time, sim.get_m([0.0, 0.0, 0.0])
time_end = time.time()
Exemple #12
0

def fun_sigma0(dof_name_indices, position):
    return sigma0


# Later on, we will modify this field:

field_sigma = ocaml.raw_make_field(
    mwe_sigma,
    [fun_sigma0],
    ""  # petsc name - auto-generated if "".
)

print "field_sigma: ", field_sigma
print "Sigma at origin: ", ocaml.probe_field(field_sigma, "sigma", [0.0, 0.0])
sys.stdout.flush()

# Dirichlet Boundary Conditions on our sample:


def laplace_dbc(coords):
    if (abs(coords[1]) > (2.5 - 0.05)):
        return 1
    else:
        return 0


def laplace_dbc_value(dof_name_indices, coords):
    if (coords[1] > 0.0):
        return 0.5
Exemple #13
0
diffop_laplace = ocaml.make_diffop("-<d/dxj drho_by_dt|sigma|d/dxj phi>, j:2")
diffop_grad_phi = ocaml.make_diffop("<J(k)|sigma|d/dxk phi>, k:2")

# Initial conductivity is spatially constant:


def fun_sigma0(dof_name_indices, position):
    return sigma0


# Later on, we will modify this field:

field_sigma = ocaml.raw_make_field(mwe_sigma, [fun_sigma0], "")  # petsc name - auto-generated if "".

print "field_sigma: ", field_sigma
print "Sigma at origin: ", ocaml.probe_field(field_sigma, "sigma", [0.0, 0.0])
sys.stdout.flush()

# Dirichlet Boundary Conditions on our sample:


def laplace_dbc(coords):
    if abs(coords[1]) > (2.5 - 0.05):
        return 1
    else:
        return 0


def laplace_dbc_value(dof_name_indices, coords):
    if coords[1] > 0.0:
        return 0.5
Exemple #14
0
    # normalize M in set_magnetization!
    print "Setting magnetization for coords=",coords," mag_type=",mag_type
    return [0.0,
            0.8*math.cos(coords[0]/6.0),
            0.6*math.sin(coords[0]/6.0),
            ]

sim.set_magnetization(initial_magnetization)
#sim.set_magnetization([0.0,0.0,1.0])

# XXX Note: this actually should not be necessary! get_M should make
# sure that a timestepper is being created!

sim._ensure_have_timestepper()

print "Field at x=4.5:",ocaml.probe_field(sim.fields["m"],"",[4.5])
print "M0: ",sim.get_m([0.5]) # XXX Note: returns None - this clearly is wrong!

time_start=time.time()

# nfem.visual.fields2vtkfile(sim.fields.values(),'jacobi-0.vtk',mesh=sim.mesh)


for i in range(1,10): # range(1,1000):
    target_time=sim.advance_time(intensive_param_by_name,10*0.05*i)
    print "t=%f Field at x=4.5:" % target_time,ocaml.probe_field(sim.fields["m"],"",[4.5])

    #write SI data into default file (results.ndt)
    sim.save_data_table()

    #write SU data into special file 
Exemple #15
0
                  )

#sim.set_magnetization([1.0,0.0,0.0])
#sim.set_magnetization([0.0,1.0,0.0])
#sim.set_magnetization([0.0,0.0,1.0])
#sim.set_magnetization([0.0,1.0,1.0])
# ^All these yield a magnetic charge imbalance of 0.0


sim.set_magnetization(initial_magnetization)

time_start=time.time()

sim.advance_time(intensive_param_by_name,1e-6)

print "### XXX H_demag: ",ocaml.probe_field(sim.fields["H_demag"],"H_demag",[0.0,0.0,0.0])

for i in range(1,100):
    target_time=sim.advance_time(intensive_param_by_name,0.1*i)

    #write SI data into default file (results.ndt)
    sim.save_data_table()

    #write SU data into special file 
    sim.save_data_table_su(filename='results_su.ndt')

    nfem.visual.fields2vtkfile(sim.fields.values(),'sphere-%d.vtk' % i,mesh=sim.mesh)
    print "Field at origin (T=%f):"%target_time,sim.get_m([0.0,0.0,0.0])
time_end=time.time()

print "SIM RUN TIME: ",time_end-time_start," sec."
Exemple #16
0
ocaml.linalg_machine_set_iparam(lam, "Phi_ext", su.of(voltage))

for i in range(int(heating_time // time_step)):
    ocaml.raw_cvode_advance(cvode, sundialsbuffer_final, float(i * time_step), max_it)

    for name in master_mwes_and_fields_by_name.keys():
        (mwe, field) = master_mwes_and_fields_by_name[name]
        ocaml.linalg_machine_get_field(lam, field, "v_%s" % name)

    fields = map(lambda a: a[1], master_mwes_and_fields_by_name.values())
    nfem.visual.fields2vtkfile(fields, "block-%02d.vtk" % i, my_mesh, format="binary")

    last_i = i

    j = numpy.array(ocaml.probe_field(master_mwes_and_fields_by_name["j"][1], "j", [0.0, 0.0, 0.0])[0][1])

    print "j in A/m^2:", j * su.conversion_factor_of(SI("A/m^2"))

    T0 = ocaml.probe_field(sundialsbuffer_final, "T", [0.0, 0.0, 0.0])[0][1]
    print "i: %3d T: %s (su), T: %s " % (i, repr(T0), su.conversion_factor_of(SI(1, "K")) * T0)
    f.write(
        "%g\t%g\n"
        % (i * time_step * su.conversion_factor_of(SI(1, "s")).value, su.conversion_factor_of(SI(1, "K")).value * T0)
    )


sys.exit(0)

# Turn off electric heating:
ocaml.linalg_machine_set_iparam(lam, "Phi_ext", 0.0)
def print_field(field, name="phi", t=None):
    for pos in range(0, 11):
        probed = ocaml.probe_field(field, name, [float(pos)])
        print "T=%10s POS: %5.2f VAL: %s" % (str(t), pos, probed)
Exemple #18
0
    cache_name="sphere")

#sim.set_magnetization([1.0,0.0,0.0])
#sim.set_magnetization([0.0,1.0,0.0])
#sim.set_magnetization([0.0,0.0,1.0])
#sim.set_magnetization([0.0,1.0,1.0])
# ^All these yield a magnetic charge imbalance of 0.0

sim.set_magnetization(initial_magnetization)

time_start = time.time()

sim.advance_time(intensive_param_by_name, 2.0)
#sim.advance_time(intensive_param_by_name,10.0)

print "H_demag at origin: ", ocaml.probe_field(sim.fields["H_demag"],
                                               "H_demag", [0.0, 0.0, 0.0])

time_end = time.time()

print "SIM INIT TIME: ", time_start - time_init, " sec."
print "SIM RUN TIME: ", time_end - time_start, " sec."
print "PETSC: ", ocaml.petsc_cpu_cycles("report")
print "PETSC: ", ocaml.petsc_cpu_cycles("reset")
sys.exit()

print
"""

nmag, basic run, mesh pre-generated, cached:

DDD CPU cvode_advance total: 213505850182.000000 CPU cycles
def print_field(field, name="phi", t=None):
    for pos in range(0, 11):
        probed = ocaml.probe_field(field, name, [float(pos)])
        print "T=%10s POS: %5.2f VAL: %s" % (str(t), pos, probed)
Exemple #20
0
ocaml.linalg_machine_set_iparam(lam,"Phi_ext",su.of(voltage))

for i in range(int(heating_time//time_step)+1):
    ocaml.raw_cvode_advance(cvode,sundialsbuffer_final,float(i*time_step),max_it)

    for name in master_mwes_and_fields_by_name.keys():
        (mwe,field)=master_mwes_and_fields_by_name[name]
        ocaml.linalg_machine_get_field(lam,field,"v_%s" % name)
    
    fields = map( lambda a: a[1],master_mwes_and_fields_by_name.values())
    nfem.visual.fields2vtkfile(fields,'H-%02d.vtk' % i,my_mesh,format='binary')
    
    last_i = i
    
    j0 = numpy.array(ocaml.probe_field(master_mwes_and_fields_by_name['j'][1],'j',[0.,0.,0.])[0][1])
    j1 = numpy.array(ocaml.probe_field(master_mwes_and_fields_by_name['j'][1],'j',[-499.,0.,0.])[0][1])

    print "j0 in A/m^2:",j0*su.conversion_factor_of(SI("A/m^2"))
    print "j1 in A/m^2:",j1*su.conversion_factor_of(SI("A/m^2"))

    T0 = ocaml.probe_field(sundialsbuffer_final,"T",[0.0, 0.0, 0.0])[0][1]
    T1 = ocaml.probe_field(sundialsbuffer_final,"T",[-499.0, 0.0, 0.0])[0][1]
    T2 = ocaml.probe_field(sundialsbuffer_final,"T",[-25.0, 10.0, 10.0])[0][1]
    print "i: %3d t=%g T: %s (su), T: %s " % (i,i*time_step,repr(T0),su.conversion_factor_of(SI(1,"K"))*T0)
    f.write("%g\t%g\t%g\t%g\n" % (i*time_step*su.conversion_factor_of(SI(1,'s')).value,su.conversion_factor_of(SI(1,"K")).value*T0,su.conversion_factor_of(SI(1,"K")).value*T1,su.conversion_factor_of(SI(1,"K")).value*T2))

# Turn off electric heating:
ocaml.linalg_machine_set_iparam(lam,"Phi_ext",0.0)

print "Done With Heating!"
Exemple #21
0
print "Known fieldnames are", master_mwes_and_fields_by_name.keys()
fields = map(lambda a: a[0], master_mwes_and_fields_by_name.values())
for field in fields:
    print "known fields are", ocaml.sys_ocamlpill_type(field)


for i in range(last_i + 1, int(cooling_time / time_step) + last_i + 2):
    ocaml.raw_cvode_advance(cvode, sundialsbuffer_final, heating_time + i * time_step, max_it)

    # Copying back data master_mwes_and_fields_by_name:

    for name in master_mwes_and_fields_by_name.keys():
        (mwe, field) = master_mwes_and_fields_by_name[name]
        ocaml.linalg_machine_get_field(lam, field, "v_%s" % name)

    fields = map(lambda a: a[1], master_mwes_and_fields_by_name.values())
    nfem.visual.fields2vtkfile(fields, "j-T-%02d.vtk" % i, my_mesh, format="binary")

    T0 = ocaml.probe_field(sundialsbuffer_final, "T", [0.0, 0.0, 0.0])
    print "i: %3d T: %s" % (i, repr(T0))


print su

print "Simulation units of 1 Ampere/m^2 =", su.of(SI(1, "A/m^2"))
print "Simulation units of 1e12 Ampere/m^2 =", su.of(SI(1e12, "A/m^2"))

print "Simulation units of 1V  =", su.of(SI(1, "V"))

print "Simulation units of 100K =", su.of(SI(100, "K"))
Exemple #22
0
ocaml.linalg_machine_set_iparam(lam,"Phi_ext",su.of(voltage))

for i in range(int(heating_time//time_step)):
    ocaml.raw_cvode_advance(cvode,sundialsbuffer_final,float(i*time_step),max_it)

    for name in master_mwes_and_fields_by_name.keys():
        (mwe,field)=master_mwes_and_fields_by_name[name]
        ocaml.linalg_machine_get_field(lam,field,"v_%s" % name)
    
    fields = map( lambda a: a[1],master_mwes_and_fields_by_name.values())
    nfem.visual.fields2vtkfile(fields,'block-%02d.vtk' % i,my_mesh,format='binary')
    
    last_i = i
    
    j = numpy.array(ocaml.probe_field(master_mwes_and_fields_by_name['j'][1],'j',[0.,0.,0.])[0][1])

    print "j in A/m^2:",j*su.conversion_factor_of(SI("A/m^2"))

    T0 = ocaml.probe_field(sundialsbuffer_final,"T",[0.0, 0.0, 0.0])[0][1]
    print "i: %3d T: %s (su), T: %s " % (i,repr(T0),su.conversion_factor_of(SI(1,"K"))*T0)
    f.write("%g\t%g\n" % (i*time_step*su.conversion_factor_of(SI(1,'s')).value,su.conversion_factor_of(SI(1,"K")).value*T0))


sys.exit(0)

# Turn off electric heating:
ocaml.linalg_machine_set_iparam(lam,"Phi_ext",0.0)

print "Done With Heating!"