Example #1
0
int main(int argc, char **argv) 
{
  // load the input file
  MBErrorCode result, rval;
  MBEntityHandle input_set;

  rval = MBI()->create_meshset( MESHSET_SET, input_set ); // create a meshset for data
  
  // build a fairly arbitary geometry
  MBEntityHandle handles[2];
  build_geometry(input_set,handles);

  MBTag density_tag;
  // create a tag
  std::cout << handles[0] << " " << handles[1] << std::endl;
  rval = MBI()->tag_get_handle( "Density",1, MB_TYPE_DOUBLE,density_tag,
				moab::MB_TAG_SPARSE|moab::MB_TAG_CREAT);
  if(rval != MB_SUCCESS)
    {
      std::cout << "Failed to create tag!" << std::endl;
      return rval;
    }
 
  double density = 9.0;
  double zero = 0.0;
  // tag the data
  rval = MBI()->tag_set_data( density_tag, &(handles[1]), 1, &density );
  rval = MBI()->tag_set_data( density_tag, &(handles[0]), 1, &zero );


  // save the mesh
  rval = MBI()->write_mesh("test.h5m");

  return 0;  
}
Example #2
0
size_t WKT(int polygon)
{
   while (listHasData(&segs))
   {
      struct keyval *p;
      unsigned int id, to, from;
      double x0, y0, x1, y1;
      p = popItem(&segs);
      id = strtoul(p->value, NULL, 10);
      freeItem(p);

      from = segments[id].from;
      to   = segments[id].to; 

      x0 = nodes[from].lon;
      y0 = nodes[from].lat;
      x1 = nodes[to].lon;
      y1 = nodes[to].lat;
      add_segment(x0,y0,x1,y1);
   }
   return  build_geometry(polygon);
}
Example #3
0
int main() {

	Py_Initialize(); // start Python interpreter
	PyObject* sysPath = PySys_GetObject((char*)"path"); 
	// sysPath has a borrowed reference, no need to decref it
	PyObject* curDir = PyString_FromString(".");
	PyList_Append(sysPath, curDir);
	Py_DECREF(curDir);

	FILE * fp;
	time_t current_time;
	char* c_time_string;
	int i, j, k, cnt;
	
	LUC_sim_pars *simp;
	LUC_fields *fields;
	LUC_diel_mat *diel;
	LUC_abc_fields *abc_fields;
	LUC_source **src;

	printf("------------------------------ LUCIFER v0.3 ------------------------------\n\n");	

	simp = par_config("luc");//<----fix name
	if(!simp){
		printf(C_RED "[ERROR]" C_RES " failed to read configuration file %s\n","luc");
		return 0;
	}
	printf(C_GREEN "[MSG]" C_RES " configuration file read successfully\n");

	fields = allocate_fields(simp);
	if(!fields){
		printf(C_RED "[ERROR]" C_RES " failed to allocate fields (out of memory?)\n");
		return 0;
	}
	printf(C_GREEN "[MSG]" C_RES " e.m. fields are allocated\n");

	diel = allocate_diel(simp);
	if(!diel){
		printf(C_RED "[ERROR]" C_RES " failed to allocate materials (out of memory?)\n");
		return 0;
	}
	printf(C_GREEN "[MSG]" C_RES " materials and geometry are allocated\n");

	abc_fields = allocate_abc(simp);
	if(!abc_fields){
		printf(C_RED "[ERROR]" C_RES " failed to allocate abc fields (out of memory?)\n");
		return 0;
	}
	printf(C_GREEN "[MSG]" C_RES " fields for ABC are allocated\n");

	src = malloc((*simp).n_sources*sizeof(LUC_source**));
	if(!src){
		printf(C_RED "[ERROR]" C_RES " failed to allocate sources (out of memory?)\n");
		return 0;
	}

	for(cnt = 0; cnt < (*simp).n_sources; cnt++)
		if(!source_init((*simp).src_files[cnt], &src[cnt], simp))			
			printf(C_RED "[ERROR]" C_RES "source_init: failed to allocated source %d\n",cnt);

	printf(C_GREEN "[MSG]" C_RES " sources are allocated\n");

	printf(C_GREEN "[MSG]" C_RES " building geometry...\n");
	printf(C_GREEN "[MSG]" C_RES " msgs from " C_BLUE "%s.py" C_RES " begin\n",(*simp).geom_file);
	build_geometry((*simp).geom_file, simp, diel);
	printf(C_GREEN "[MSG]" C_RES " msgs from " C_BLUE "%s.py" C_RES " end\n",(*simp).geom_file);
	printf(C_GREEN "[MSG]" C_RES " geometry done\n\n");
	
	
	printf(C_GREEN "[MSG]" C_RES " simulated domain: x = %g m; y = %g m; z = %g m;\n",(*simp).size_x*(*simp).cell_size,(*simp).size_y*(*simp).cell_size,(*simp).size_z*(*simp).cell_size);
	printf(C_GREEN "[MSG]" C_RES " simulated time: %g s\n", (*simp).sim_time);
	printf(C_GREEN "[MSG]" C_RES " total number of time steps: %d\n", (*simp).max_time);
	//'data will be saved in: ',data_file
	
	// ask if OK	
	
	//--------------------------------
	//---------- START SIM -----------
	//--------------------------------
		
	fp = fopen ("test.dat", "w");

	write_header(fp, simp);
	
	current_time = time(NULL);
    c_time_string = ctime(&current_time);
	printf(C_GREEN "[MSG]" C_RES " simulation started on: %s", c_time_string);
	
	for ((*simp).t_step = 0; (*simp).t_step < (*simp).max_time; (*simp).t_step++) {	
	    				
		updateH(fields, diel, simp);
		updateE(fields, diel, simp);
	
		// add source
		for(cnt = 0; cnt < (*simp).n_sources; cnt++)
		   	add_source(src[cnt], fields, simp);
	       	
    	// apply abc
    	abc(fields, abc_fields, simp);
		    	
    	// apply pbc
    	//pbc(pbc_k,pbc_f,pbc_l,pbc_r,pbc_b,pbc_t);
    	
		write_field_views(fp, fields, simp);
		    	
    	printf(C_GREEN "[MSG]" C_RES " completed: %.2f%%\r", ((float)(*simp).t_step/(float)(*simp).max_time)*100);
    	
	}

	current_time = time(NULL);
    c_time_string = ctime(&current_time);
	printf(C_GREEN "[MSG]" C_RES " simulation finished on: %s\n", c_time_string);
	printf("----------------------------------- END ----------------------------------\n");

	fclose(fp);
	Py_Finalize();

	return 1;
}