print "*** LAM ***", lam sys.stdout.flush() (cvode,fun_timings)=ocaml.raw_make_linalg_machine_cvode(\ lam, field_phi0, "jacobian","execute_jplan", "rhs", # True, # same_nonzero_pattern for jacobian False, # same_nonzero_pattern for jacobian # Why doesn't "true" work here?!?? 2, # max_order 10, # krylov_max ) 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) print "*** CVODE ***", cvode sys.stdout.flush() print_field(field_phi0, t=0.0) for tt in range(1, 100): target_time = tt * 1.5 ocaml.raw_cvode_advance(cvode, field_phi, target_time, -1) print " --- " print_field(field_phi, t=target_time)
# Set the electrical contact potential to +/- Phi_ext at left and # right contact: print "Setting external potential" #ocaml.linalg_machine_set_iparam(lam,"Phi_ext",5.0*100*1e12) voltage = SI(0.2186, "V") #Need factor three for new geometry voltage = SI(0.218353, "V") #Need factor three for new geometry print "Setting voltage to", voltage 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',
(cvode, fun_timings) = ocaml.raw_make_linalg_machine_cvode( lam, field_phi0, "jacobian", "execute_jplan", "rhs", # True, # same_nonzero_pattern for jacobian False, # same_nonzero_pattern for jacobian # Why doesn't "true" work here?!?? 2, # max_order 10, # krylov_max ) 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) print "*** CVODE ***", cvode sys.stdout.flush() print_field(field_phi0, t=0.0) for tt in range(1, 100): target_time = tt * 1.5 ocaml.raw_cvode_advance(cvode, field_phi, target_time, -1) print " --- " print_field(field_phi, t=target_time)
lam, sundialsbuffer_starting, "jacobian","execute_jplan", "rhs", jacobi_same_nonzero_pattern, max_order, krylov_max, ) heating_time = 0.5 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")
# Set the electrical contact potential to +/- Phi_ext at left and # right contact: print "Setting external potential" #ocaml.linalg_machine_set_iparam(lam,"Phi_ext",5.0*100*1e12) voltage = SI(0.2186,"V") #Need factor three for new geometry voltage = SI(0.218353,"V") #Need factor three for new geometry print "Setting voltage to",voltage 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"))
def cvode_advance(cvode, result_vector, target_time, max_steps=-1): return ocaml.raw_cvode_advance(cvode, result_vector, target_time, max_steps)
lam, sundialsbuffer_starting, "jacobian","execute_jplan", "rhs", jacobi_same_nonzero_pattern, max_order, krylov_max, ) heating_time=0.5 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")
def cvode_advance(cvode,result_vector,target_time,max_steps=-1): return ocaml.raw_cvode_advance(cvode,result_vector,target_time,max_steps)