bool ChOpenGLMesh::Initialize(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& normals, std::vector<glm::vec2>& texcoords, std::vector<GLuint>& indices, ChOpenGLMaterial mat) { if (GLReturnedError("Mesh::Initialize - on entry")) { return false; } if (!super::Initialize()) { return false; } this->vertex_indices = indices; ambient = mat.ambient_color; diffuse = mat.diffuse_color; specular = mat.specular_color; for (unsigned int i = 0; i < vertices.size(); i++) { this->data.push_back(ChOpenGLVertexAttributesPN(vertices[i], normals[i])); } PostInitialize(); if (GLReturnedError("ChOpenGLMesh::Initialize - on exit")) { return false; } return true; }
CIORegView::CIORegView() : CToolWindow("DeSmuME_IORegView", IORegView_Proc, "I/O registers", 400, 400) , CPU(ARMCPU_ARM9) , Reg(0) , yoff(0) { liveIORegViews.push_back(this); anyLiveIORegViews = true; PostInitialize(); }
bool ChOpenGLBars::Initialize(ChOpenGLShader* _shader) { if (this->GLReturnedError("ChOpenGLBars::Initialize - on entry")) return false; if (!super::Initialize()) { return false; } PostInitialize(); this->AttachShader(_shader); if (this->GLReturnedError("ChOpenGLBars::Initialize - on exit")) return false; return true; }
void BG_DarkWarriorEntity::InitFunction() { BG_WarriorEntity::InitFunction(); m_havokBehavior = new vHavokBehaviorComponent(); m_havokBehavior->m_projectName = "HavokAnimation/BG_Warriors.hkt"; m_havokBehavior->m_characterName = "Dark_Warrior.hkt"; m_havokBehavior->m_behaviorName = "Dark_Warrior.hkt"; AddComponent(m_havokBehavior); VTextureObject *textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_cloth_d.png"); GetMesh()->GetSurface(3)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_Diffuse, textureHandler); textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_cloth_n.png"); GetMesh()->GetSurface(3)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_NormalMap, textureHandler); textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_bones_d.png"); GetMesh()->GetSurface(1)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_Diffuse, textureHandler); textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_bones_n.png"); GetMesh()->GetSurface(1)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_NormalMap, textureHandler); textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_wepons_d.tga"); GetMesh()->GetSurface(2)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_Diffuse, textureHandler); GetMesh()->GetSurface(0)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_Diffuse, textureHandler); textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_wepons_n.tga"); GetMesh()->GetSurface(2)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_NormalMap, textureHandler); GetMesh()->GetSurface(0)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_NormalMap, textureHandler); m_collisionRadius = 30; m_collisionHeight = 160; m_sensorSize = 64; m_desiredSpeed = 80; PostInitialize(); SetDirection(hkvVec3(-1,0,0)); }
void CAMCode<B,T,D>::Initialize () { ConfigFile &cfg = Code::GetCfgFile (); satversion_t ver = Code::GetCfgVersion (); /******************/ /* Section: SIMUL */ /******************/ _time.Initialize (cfg.GetEntry ("simul"), ver); cfg.GetValue ("simul.momsmooth", _momsmooth, 1); cfg.GetValue ("simul.esmooth", _esmooth, 1); DBG_INFO ("moment/electric Field smoothing: "<< _momsmooth<<", "<<_esmooth); /*****************/ /* Section: MISC */ /*****************/ Mesh<D> mesh; Vector<int,D> ratio; Vector<bool,D> openbc; cfg.GetValue ("parallel.mpi.proc", ratio); cfg.GetValue ("grid.openbc", openbc); cfg.GetValue ("grid.bclen", _bcleni); for (int i=0; i<D; ++i) _bcleni[i] = T(1)/_bcleni[i]; mesh.Initialize (cfg.GetEntry ("grid")); _decomp.Initialize (ratio, Mpi::COMM_WORLD); DBG_INFO ("MPI decomposition ratio : "<<_decomp.Size ()); DBG_INFO ("open Boundary conditions : "<<openbc); for (int i=0; i<D; ++i) while (mesh.Cells()[i] % _decomp.Size()[i] != 0) mesh.Cells()[i]++; _domsize = mesh.Size (); DBG_INFO ("total number of cells : "<<mesh.Cells ()); DBG_INFO (" X spatial resolution : "<<mesh.Resol ()); DBG_INFO (" = physical size : "<<mesh.Size ()); _decomp.Decompose (mesh.Cells ()); DBG_INFO ("Per single CPU:"); DBG_INFO ("total number of cells : "<<mesh.Cells ()); DBG_INFO (" X spatial resolution : "<<mesh.Resol ()); DBG_INFO (" = physical size : "<<mesh.Size ()); // Minimal/Maximal position of the particle: _pmin = PosVector ((T)0.0); _pmax = mesh.Cells (); DBG_INFO2 ("pmin; pmax : " << _pmin<< "; "<<_pmax); // Minimal/Maximal of mesh excluding ghost cells: _pminabs = mesh.Cells(); _pmaxabs = mesh.Cells(); for (int i=0; i<D; ++i) { _pminabs[i] *= _decomp.GetPosition(i); _pmaxabs[i] += _pminabs[i]; } // Variable: # grid points # ghosts # share # total Centring // ================================================================= // E #cells 1 0 #cells + 2 Cell // B #cells + 1 0 0 #cells + 1 Node // U #cells + 1 1 1 #cells + 3 Node // dn #cells + 1 1 1 #cells + 3 Node // Particles #cells 0 0 #cells + 1 Node // // Note that dn and U needs extra 1 grid points on both sides (even though // they are defined on the same grid like B) just to have a space for // boundary conditions. The idea is to use Sync mechanism in Field class to // copy 1 layer of ghost zone and in boundary conditions treatment just add // the ghost values to the outer values. _meshe = mesh; _meshb = mesh; _meshu = mesh; _meshp = mesh; _meshe.Cells () += 2; _meshe.Center () = Cell; _meshb.Cells () += 1; _meshb.Center () = Node; _meshu.Cells () += 3; _meshu.Center () = Node; _meshp.Cells () += 1; _meshp.Center () = Node; // GHOSTS: SHARE: BC: DECOMPOSITION: _layoe.Initialize (Loc<D> (1), Loc<D> (0), openbc, _decomp); _layob.Initialize (Loc<D> (0), Loc<D> (0), openbc, _decomp); _layou.Initialize (Loc<D> (1), Loc<D> (1), openbc, _decomp); _layop.Initialize (Loc<D> (0), Loc<D> (0), openbc, _decomp); /********************/ /* Section: SPECIES */ /********************/ DBG_INFO ("============== Species: ============="); T rmdstot = 0.0; Vector<T,3> currtot = 0.0; cfg.GetValue ("plasma.betae", _betae); cfg.GetValue ("plasma.vmax", _vmax, -1.); DBG_INFO ("max velocity of pcles : "<<_vmax); Timer tspec; tspec.Start (); ConfigEntry &species = cfg.GetEntry ("plasma.specie"); for (int i=0; i<species.GetLength (); ++i) { DBG_INFO ("processing specie: '"<<species[i].GetName ()<<"'"); TSpecie *sp = new CamSpecie<T,D> (); sp->Initialize (species[i], _meshp, _layop); _specie.PushNew (sp); // Just the health check rmdstot += sp->RelMassDens (); currtot += sp->RelMassDens () * sp->InitalVel (); } tspec.Stop (); DBG_INFO ("pcles loaded in : "<<tspec); // SAT_ASSERT_MSG( Math::Abs( rmdstot-1.0 ) < M_MEPS, // "Sum of relative mass densities has to be zero!"); // if (Math::Abs( currtot.Abs() ) > M_MEPS) // DBG_WARN ("Total current is non-zero: "<<currtot); /******************/ /* Section: FIELD */ /******************/ DBG_INFO ("=============== Fields: ============="); cfg.GetValue ("field.nsub", _nsub, 10); cfg.GetValue ("field.imf.phi", _phi, 90.); cfg.GetValue ("field.imf.psi", _psi, 0.); cfg.GetValue ("field.imf.amp", _bamp, 1.); cfg.GetValue ("field.dnmin", _dnmin, 0.05); cfg.GetValue ("field.resist", _resist, 0.001); cfg.GetValue ("field.viscos", _viscos, 0.0); DBG_INFO ("B field sub-steps : "<<_nsub); DBG_INFO ("IMF phi(x,y); psi(x,z) : "<<_phi<<"; "<<_psi); DBG_INFO ("minimal density : "<<_dnmin); DBG_INFO ("resistivity : "<<_resist); DBG_INFO ("viscosity : "<<_viscos); /************************************/ /* Setup initial magnetic field _B0 */ /************************************/ Vector<T,3> b0; _phi = Math::Deg2Rad (_phi); _psi = Math::Deg2Rad (_psi); b0[0] = Math::Cos(_phi) * Math::Cos(_psi); b0[1] = Math::Sin(_phi) * Math::Cos(_psi); b0[2] = Math::Sin(_psi); _B0 = b0 *_bamp; DBG_INFO ("background B field (B_0) : "<<_B0); /*****************************************************************/ /* Setup plasma bulk velocity _v0 and initial electric field _E0 */ /*****************************************************************/ _v0 = 0.; T dnt = 0., dns = 0.; for (int i=0; i<_specie.GetSize (); ++i) { TSpecie *sp = _specie.Get (i); dns = sp->RelMassDens () * sp->ChargeMassRatio (); _v0 += sp->InitalVel () * (T)dns; dnt += dns; } _v0 /= dnt; _E0 = - (_v0 % _B0); DBG_INFO ("background E field (E_0) : "<<_E0); DBG_INFO ("total bulk velocity (u_i) : "<<_v0); /***********************************/ /* Setup the rest of the variables */ /***********************************/ _gamma = 5. / 3.; _betai = 0.; T cd = 0.; for (int i=0; i<_specie.GetSize (); ++i) { TSpecie *sp = _specie.Get (i); _betai += sp->Beta (); cd += sp->ChargeMassRatio () * sp->RelMassDens (); } _te = _betae / (2. * cd); _cs = Math::Sqrt (0.5 * (_betai + _betae)); DBG_INFO ("total ion beta (beta_i) : "<<_betai); DBG_INFO ("ion temperature (T_i) : "<<_betai / (2. * cd)); DBG_INFO ("electron beta (beta_e) : "<<_betae); DBG_INFO ("electron temperature (T_e) : "<<_te); DBG_INFO ("sound speed (c_s) : "<<_cs); /****************************/ /* Setup mesh related stuff */ /****************************/ _E.Initialize (_meshe, _layoe); _Psi.Initialize (_meshe, _layoe); _Psih.Initialize (_meshe, _layoe); _B.Initialize (_meshb, _layob); _Bh.Initialize (_meshb, _layob); _pe.Initialize (_meshu, _layou); _dn.Initialize (_meshu, _layou); _dna.Initialize (_meshu, _layou); _dnf.Initialize (_meshu, _layou); _U.Initialize (_meshu, _layou); _Ua.Initialize (_meshu, _layou); _Uf.Initialize (_meshu, _layou); /*********************/ /* Setup all sensors */ /*********************/ DBG_INFO ("=========== Sensors: ================"); _sensmng.Initialize (cfg); ScaFieldSensor<T,D> *nsens = new ScaFieldSensor<T,D>; ScaFieldSensor<T,D> *psisens = new ScaFieldSensor<T,D>; VecFieldSensor<T,3,D> *bsens = new VecFieldSensor<T,3,D>; VecFieldSensor<T,3,D> *esens = new VecFieldSensor<T,3,D>; VecFieldSensor<T,3,D> *usens = new VecFieldSensor<T,3,D>; TemperatureSensor<T,3,D> *tsens = new TemperatureSensor<T,3,D>; // DistFncSensor<T,D> *dfsens = new DistFncSensor<T,D>; DbDtVecFieldSensor<T,3,D> *dbdtsens = new DbDtVecFieldSensor<T,3,D>; JxBSensor<T,3,D> *jxbsens = new JxBSensor<T,3,D>; CurlBxBSensor<T,3,D> *cbxbsens = new CurlBxBSensor<T,3,D>; KineticEnergySensor<T,3,D> *ken = new KineticEnergySensor<T,3,D>; LaplaceSensor<T,3,D> *lap = new LaplaceSensor<T,3,D>; nsens->Initialize (cfg, "density", &_dn); esens->Initialize (cfg, "elfield", &_E); bsens->Initialize (cfg, "magfield", &_B); usens->Initialize (cfg, "velocity", &_U); tsens->Initialize (cfg, "temp", &_specie, &_B, &_U, &_dn); ken->Initialize (cfg, "kenergy", &_specie, &_B); // dfsens->Initialize (cfg, "distfnc", &_specie, &_B); psisens->Initialize (cfg, "psifnc", &_Psi); lap->Initialize (cfg, "laplace", &_E); dbdtsens->Initialize (cfg, "dbdt", &_E, &_B); jxbsens->Initialize (cfg, "jxb", &_U, &_B, &_dn); cbxbsens->Initialize (cfg, "cbxb", &_B, &_dn); _sensmng.AddSensor (nsens); _sensmng.AddSensor (esens); _sensmng.AddSensor (bsens); _sensmng.AddSensor (usens); _sensmng.AddSensor (tsens); _sensmng.AddSensor (ken); // _sensmng.AddSensor (dfsens); _sensmng.AddSensor (psisens); _sensmng.AddSensor (lap); _sensmng.AddSensor (dbdtsens); _sensmng.AddSensor (jxbsens); _sensmng.AddSensor (cbxbsens); DBG_INFO ("=========== PostInitialize: ========="); PostInitialize (cfg); _E = _E0; // _Psi = T(0); // initial value for psi function // _Psih = T(0); _B = b0; // _Bh is initialized in function First() static_cast<B*>(this)->BInitAdd (_B); /*******************/ /* Species Loading */ /*******************/ int totcleaned = 0; for (int i=0; i<_specie.GetSize (); ++i) { TSpecie *sp = _specie.Get (i); _dn = 1.; _U = sp->InitalVel (); // reuse _dnf, _dna since they are not needed now. _dnf = sp->Vthper (); _dna = sp->Vthpar (); static_cast<B*>(this)->DnInitAdd (sp, _dn); static_cast<B*>(this)->BulkInitAdd (sp, _U); if (static_cast<B*>(this)->VthInitAdd (sp, _dnf, _dna)) sp->LoadPcles (_dn, _U, _B, _dnf, _dna, b0); else sp->LoadPcles (_dn, _U, b0); /// Remove particles based on the problem (for example: inside of the /// planet for the dipole problem) size_t npcle = sp->GetSize (); for (int pid=0; pid<npcle; ++pid) { TParticle &pcle = sp->Get (pid); static_cast<B*>(this)->PcleBCAdd (sp, pid, pcle); } int cleaned; sp->Clean (&cleaned); Mpi::SumReduceOne (&cleaned); totcleaned += cleaned; } // Initialize B field one more time but with actual B0 (can be zero) _B = _B0; // _Bh is initialized in function First() static_cast<B*>(this)->BInitAdd (_B); DBG_INFO ("Particles cleaned during init: " << totcleaned); }
bool ChOpenGLMesh::Initialize(chrono::ChTriangleMeshShape* tri_mesh, ChOpenGLMaterial mat) { if (GLReturnedError("Mesh::Initialize - on entry")) { return false; } if (!super::Initialize()) { return false; } int num_triangles = tri_mesh->GetMesh().getNumTriangles(); for (unsigned int i = 0; i < (unsigned)num_triangles; i++) { chrono::geometry::ChTriangle tri = tri_mesh->GetMesh().getTriangle(i); ChVector<> norm = tri.GetNormal(); ChVector<> v1 = tri.p1; ChVector<> v2 = tri.p2; ChVector<> v3 = tri.p3; this->vertex_indices.push_back(i * 3 + 0); this->vertex_indices.push_back(i * 3 + 1); this->vertex_indices.push_back(i * 3 + 2); glm::vec3 v, n; v = glm::vec3(v1.x(), v1.y(), v1.z()); n = glm::vec3(norm.x(), norm.y(), norm.z()); this->data.push_back(ChOpenGLVertexAttributesPN(v, n)); v = glm::vec3(v2.x(), v2.y(), v2.z()); this->data.push_back(ChOpenGLVertexAttributesPN(v, n)); v = glm::vec3(v3.x(), v3.y(), v3.z()); this->data.push_back(ChOpenGLVertexAttributesPN(v, n)); } ambient = mat.ambient_color; diffuse = mat.diffuse_color; specular = mat.specular_color; // // std::vector<ChVector<int> >& indices = // tri_mesh->GetMesh().getIndicesVertexes(); // std::vector<ChVector<double> >& vertices = // tri_mesh->GetMesh().getCoordsVertices(); // std::vector<ChVector<double> >& normals = // tri_mesh->GetMesh().getCoordsNormals(); // // this->vertex_indices.resize(indices.size() * 3); // for (unsigned int i = 0; i < indices.size(); i++) { // // this->vertex_indices[i * 3 + 0] = indices[i].x; // this->vertex_indices[i * 3 + 1] = indices[i].y; // this->vertex_indices[i * 3 + 2] = indices[i].z; // } // for (unsigned int i = 0; i < vertices.size(); i++) { // glm::vec3 n; // glm::vec3 v(vertices[i].x, vertices[i].y, vertices[i].z); // if (normals.size() > 0) { // n = glm::vec3(normals[i].x, normals[i].y, normals[i].z); // } else { // n = glm::vec3(1, 0, 0); // } // // this->data.push_back(ChOpenGLVertexAttributesPN(v, n)); // } PostInitialize(); if (GLReturnedError("ChOpenGLMesh::Initialize - on exit")) { return false; } return true; }