void MarchingCubes::updateGL(Octnode* node) { // traverse tree here and call polygonize_node if (node->valid()) return; if ( node->is_undecided() && node->isLeaf() ) { mc_node(node); node->setValid(); } // current node done, now recurse into tree. if ( node->childcount == 8 ) { for (unsigned int m=0;m<8;m++) { if (!node->child[m]->valid()) updateGL( node->child[m] ); } } }
// Create a photoexcited carrier at the given Node for a the given photon energies. // The transistion will be between the given cb and vb. Returns the created particle. Particle create_photoexcited_carrier(Node *node, double photon_energy, double total_scattering_rate[NOAMTIA+1], int conduction_band, int valence_band) { double mc = node->mat->cb.mstar[conduction_band], mv = node->mat->vb.mstar[valence_band]; double mr = mc * mv / (mc + mv); double e2 = (mr / mc) * (photon_energy - node->mat->Eg - node->mat->vb.emin[valence_band]); Vec2 loc = mc_random_location_in_node(node); double kf = node->mat->cb.smh[conduction_band] * sqrt(e2 * (1. + node->mat->cb.alpha[conduction_band] * e2)); double cs = 1. - 2. * rnd(); // random number -1 -> 1 double sn = sqrt(1. - cs * cs); double fai = 2. * PI * rnd(); // random angle (radians) 0 -> 2pi double kx = kf * cs, ky = kf * sn * cos(fai), kz = kf * sn * sin(fai); int id = g_config->next_particle_id++; double time = -log(rnd()) / total_scattering_rate[node->material]; return (Particle) { .id=id, .t=time, .valley=conduction_band, .x=loc.x, .y=loc.y, .kx=kx, .ky=ky, .kz=kz, .photoemission_flag=1 }; } // Photoexcite carriers at the given energy. Returns the number of photogenerated // carriers int photoexcite_carriers(Mesh *mesh, double photon_energy, double transistion_rate[NOAMTIA][DIME][3], double total_scattering_rate[NOAMTIA+1], Particle particles[NPMAX+1]) { int p = g_config->num_particles; for(int j = 1; j <= mesh->ny + 1; ++j) { for(int i = 1; i <= mesh->nx + 1; ++i) { Node *node = mc_node(i, j); int e = (int)((photon_energy - node->mat->Eg) / DE); int num_carriers = electrons_in_cell(mesh, node, photon_energy); for(int n = 0; n < num_carriers; ++n) { double r = rnd(); for(int v = 0; v < 3; ++v) { if(r <= transistion_rate[node->material][e][v]) { particles[p] = create_photoexcited_carrier(node, photon_energy, total_scattering_rate, 1, v); ++p; break; } } } // carriers per cell } // i } // j int num_photoexcited = p - g_config->num_particles; g_config->num_particles = p; return num_photoexcited; }