diff options
Diffstat (limited to 'intern/mantaflow')
-rw-r--r-- | intern/mantaflow/intern/MANTA_main.cpp | 673 | ||||
-rw-r--r-- | intern/mantaflow/intern/MANTA_main.h | 46 |
2 files changed, 284 insertions, 435 deletions
diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp index c1ac3d3a22d..1e32548bee2 100644 --- a/intern/mantaflow/intern/MANTA_main.cpp +++ b/intern/mantaflow/intern/MANTA_main.cpp @@ -184,17 +184,20 @@ MANTA::MANTA(int *res, FluidModifierData *mmd) : mCurrentID(++solverID) // Setup Mantaflow in Python initializeMantaflow(); + // Initializa RNA map with values that Python will need + initializeRNAMap(mmd); + // Initialize Mantaflow variables in Python // Liquid if (mUsingLiquid) { - initDomain(mmd); - initLiquid(mmd); + initDomain(); + initLiquid(); if (mUsingObstacle) - initObstacle(mmd); + initObstacle(); if (mUsingInvel) - initInVelocity(mmd); + initInVelocity(); if (mUsingOutflow) - initOutflow(mmd); + initOutflow(); if (mUsingDrops || mUsingBubbles || mUsingFloats || mUsingTracers) { mUpresParticle = mmd->domain->particle_scale; @@ -203,8 +206,8 @@ MANTA::MANTA(int *res, FluidModifierData *mmd) : mCurrentID(++solverID) mResZParticle = mUpresParticle * mResZ; mTotalCellsParticles = mResXParticle * mResYParticle * mResZParticle; - initSndParts(mmd); - initLiquidSndParts(mmd); + initSndParts(); + initLiquidSndParts(); } if (mUsingMesh) { @@ -215,39 +218,39 @@ MANTA::MANTA(int *res, FluidModifierData *mmd) : mCurrentID(++solverID) mTotalCellsMesh = mResXMesh * mResYMesh * mResZMesh; // Initialize Mantaflow variables in Python - initMesh(mmd); - initLiquidMesh(mmd); + initMesh(); + initLiquidMesh(); } if (mUsingGuiding) { mResGuiding = (mmd->domain->guide_parent) ? mmd->domain->guide_res : mmd->domain->res; - initGuiding(mmd); + initGuiding(); } if (mUsingFractions) { - initFractions(mmd); + initFractions(); } } // Smoke if (mUsingSmoke) { - initDomain(mmd); - initSmoke(mmd); + initDomain(); + initSmoke(); if (mUsingHeat) - initHeat(mmd); + initHeat(); if (mUsingFire) - initFire(mmd); + initFire(); if (mUsingColors) - initColors(mmd); + initColors(); if (mUsingObstacle) - initObstacle(mmd); + initObstacle(); if (mUsingInvel) - initInVelocity(mmd); + initInVelocity(); if (mUsingOutflow) - initOutflow(mmd); + initOutflow(); if (mUsingGuiding) { mResGuiding = (mmd->domain->guide_parent) ? mmd->domain->guide_res : mmd->domain->res; - initGuiding(mmd); + initGuiding(); } if (mUsingNoise) { @@ -258,12 +261,12 @@ MANTA::MANTA(int *res, FluidModifierData *mmd) : mCurrentID(++solverID) mTotalCellsHigh = mResXNoise * mResYNoise * mResZNoise; // Initialize Mantaflow variables in Python - initNoise(mmd); - initSmokeNoise(mmd); + initNoise(); + initSmokeNoise(); if (mUsingFire) - initFireHigh(mmd); + initFireHigh(); if (mUsingColors) - initColorsHigh(mmd); + initColorsHigh(); } } updatePointers(); @@ -529,6 +532,9 @@ MANTA::~MANTA() tmpString += manta_import; tmpString += fluid_delete_all; + // Initializa RNA map with values that Python will need + initializeRNAMap(); + // Leave out mmd argument in parseScript since only looking up IDs std::string finalString = parseScript(tmpString); pythonCommands.push_back(finalString); @@ -613,401 +619,232 @@ static std::string getCacheFileEnding(char cache_format) } } -std::string MANTA::getRealValue(const std::string &varName, FluidModifierData *mmd) +void MANTA::initializeRNAMap(FluidModifierData *mmd) { - std::ostringstream ss; - bool is2D = false; - int tmpVar; - float tmpFloat; + if (with_debug) + std::cout << "MANTA::initializeRNAMap()" << std::endl; - if (varName == "ID") { - ss << mCurrentID; - return ss.str(); - } + mRNAMap["ID"] = std::to_string(mCurrentID); if (!mmd) { - std::cerr << "Fluid Error -- Invalid modifier data." << std::endl; - ss << "ERROR - INVALID MODIFIER DATA"; - return ss.str(); - } - - is2D = (mmd->domain->solver_res == 2); - - if (varName == "USING_SMOKE") - ss << ((mmd->domain->type == FLUID_DOMAIN_TYPE_GAS) ? "True" : "False"); - if (varName == "USING_LIQUID") - ss << ((mmd->domain->type == FLUID_DOMAIN_TYPE_LIQUID) ? "True" : "False"); - if (varName == "USING_COLORS") - ss << (mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_COLORS ? "True" : "False"); - if (varName == "USING_HEAT") - ss << (mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_HEAT ? "True" : "False"); - if (varName == "USING_FIRE") - ss << (mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_FIRE ? "True" : "False"); - if (varName == "USING_NOISE") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_NOISE ? "True" : "False"); - if (varName == "USING_OBSTACLE") - ss << (mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE ? "True" : "False"); - if (varName == "USING_GUIDING") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_GUIDE ? "True" : "False"); - if (varName == "USING_INVEL") - ss << (mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_INVEL ? "True" : "False"); - if (varName == "USING_OUTFLOW") - ss << (mmd->domain->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW ? "True" : "False"); - if (varName == "USING_LOG_DISSOLVE") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_DISSOLVE_LOG ? "True" : "False"); - if (varName == "USING_DISSOLVE") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_DISSOLVE ? "True" : "False"); - if (varName == "SOLVER_DIM") - ss << mmd->domain->solver_res; - if (varName == "DO_OPEN") { - tmpVar = (FLUID_DOMAIN_BORDER_BACK | FLUID_DOMAIN_BORDER_FRONT | FLUID_DOMAIN_BORDER_LEFT | - FLUID_DOMAIN_BORDER_RIGHT | FLUID_DOMAIN_BORDER_BOTTOM | FLUID_DOMAIN_BORDER_TOP); - ss << (((mmd->domain->border_collisions & tmpVar) == tmpVar) ? "False" : "True"); - } - if (varName == "BOUND_CONDITIONS") { - if (mmd->domain->solver_res == 2) { - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_LEFT) == 0) - ss << "x"; - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_RIGHT) == 0) - ss << "X"; - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_FRONT) == 0) - ss << "y"; - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_BACK) == 0) - ss << "Y"; - } - if (mmd->domain->solver_res == 3) { - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_LEFT) == 0) - ss << "x"; - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_RIGHT) == 0) - ss << "X"; - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_FRONT) == 0) - ss << "y"; - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_BACK) == 0) - ss << "Y"; - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_BOTTOM) == 0) - ss << "z"; - if ((mmd->domain->border_collisions & FLUID_DOMAIN_BORDER_TOP) == 0) - ss << "Z"; - } - } - if (varName == "BOUNDARY_WIDTH") - ss << mmd->domain->boundary_width; - if (varName == "RES") - ss << mMaxRes; - if (varName == "RESX") - ss << mResX; - if (varName == "RESY") - if (is2D) { - ss << mResZ; - } - else { - ss << mResY; - } - else if (varName == "RESZ") { - if (is2D) { - ss << 1; - } - else { - ss << mResZ; - } - } - if (varName == "TIME_SCALE") - ss << mmd->domain->time_scale; - if (varName == "FRAME_LENGTH") - ss << mmd->domain->frame_length; - if (varName == "CFL") - ss << mmd->domain->cfl_condition; - if (varName == "DT") - ss << mmd->domain->dt; - if (varName == "TIMESTEPS_MIN") - ss << mmd->domain->timesteps_minimum; - if (varName == "TIMESTEPS_MAX") - ss << mmd->domain->timesteps_maximum; - if (varName == "TIME_TOTAL") - ss << mmd->domain->time_total; - if (varName == "TIME_PER_FRAME") - ss << mmd->domain->time_per_frame; - if (varName == "VORTICITY") - ss << mmd->domain->vorticity / mConstantScaling; - if (varName == "FLAME_VORTICITY") - ss << mmd->domain->flame_vorticity / mConstantScaling; - if (varName == "NOISE_SCALE") - ss << mmd->domain->noise_scale; - if (varName == "MESH_SCALE") - ss << mmd->domain->mesh_scale; - if (varName == "PARTICLE_SCALE") - ss << mmd->domain->particle_scale; - if (varName == "NOISE_RESX") - ss << mResXNoise; - if (varName == "NOISE_RESY") { - if (is2D) { - ss << mResZNoise; - } - else { - ss << mResYNoise; - } - } - if (varName == "NOISE_RESZ") { - if (is2D) { - ss << 1; - } - else { - ss << mResZNoise; - } - } - if (varName == "MESH_RESX") - ss << mResXMesh; - if (varName == "MESH_RESY") { - if (is2D) { - ss << mResZMesh; - } - else { - ss << mResYMesh; - } - } - if (varName == "MESH_RESZ") { - if (is2D) { - ss << 1; - } - else { - ss << mResZMesh; - } - } - if (varName == "PARTICLE_RESX") - ss << mResXParticle; - if (varName == "PARTICLE_RESY") { - if (is2D) { - ss << mResZParticle; - } - else { - ss << mResYParticle; - } - } - if (varName == "PARTICLE_RESZ") { - if (is2D) { - ss << 1; - } - else { - ss << mResZParticle; - } - } - if (varName == "GUIDING_RESX") - ss << mResGuiding[0]; - if (varName == "GUIDING_RESY") { - if (is2D) { - ss << mResGuiding[2]; - } - else { - ss << mResGuiding[1]; - } + if (with_debug) + std::cout << "No modifier data given in RNA map setup - returning early" << std::endl; + return; } - if (varName == "GUIDING_RESZ") { - if (is2D) { - ss << 1; - } - else { - ss << mResGuiding[2]; - } + + FluidDomainSettings *mds = mmd->domain; + bool is2D = (mds->solver_res == 2); + + int openDomain = (FLUID_DOMAIN_BORDER_BACK | FLUID_DOMAIN_BORDER_FRONT | + FLUID_DOMAIN_BORDER_LEFT | FLUID_DOMAIN_BORDER_RIGHT | + FLUID_DOMAIN_BORDER_BOTTOM | FLUID_DOMAIN_BORDER_TOP); + + std::string borderCollisions = ""; + if ((mds->border_collisions & FLUID_DOMAIN_BORDER_LEFT) == 0) + borderCollisions += "x"; + if ((mds->border_collisions & FLUID_DOMAIN_BORDER_RIGHT) == 0) + borderCollisions += "X"; + if ((mds->border_collisions & FLUID_DOMAIN_BORDER_FRONT) == 0) + borderCollisions += "y"; + if ((mds->border_collisions & FLUID_DOMAIN_BORDER_BACK) == 0) + borderCollisions += "Y"; + if ((mds->border_collisions & FLUID_DOMAIN_BORDER_BOTTOM) == 0) + borderCollisions += "z"; + if ((mds->border_collisions & FLUID_DOMAIN_BORDER_TOP) == 0) + borderCollisions += "Z"; + + std::string simulationMethod = ""; + if (mds->simulation_method & FLUID_DOMAIN_METHOD_FLIP) + simulationMethod += "'FLIP'"; + else if (mds->simulation_method & FLUID_DOMAIN_METHOD_APIC) + simulationMethod += "'APIC'"; + + std::string particleTypesStr = ""; + if (mds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY) + particleTypesStr += "PtypeSpray"; + if (mds->particle_type & FLUID_DOMAIN_PARTICLE_BUBBLE) { + if (!particleTypesStr.empty()) + particleTypesStr += "|"; + particleTypesStr += "PtypeBubble"; + } + if (mds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM) { + if (!particleTypesStr.empty()) + particleTypesStr += "|"; + particleTypesStr += "PtypeFoam"; + } + if (mds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER) { + if (!particleTypesStr.empty()) + particleTypesStr += "|"; + particleTypesStr += "PtypeTracer"; + } + if (particleTypesStr.empty()) + particleTypesStr = "0"; + + int particleTypes = (FLUID_DOMAIN_PARTICLE_SPRAY | FLUID_DOMAIN_PARTICLE_BUBBLE | + FLUID_DOMAIN_PARTICLE_FOAM | FLUID_DOMAIN_PARTICLE_TRACER); + + std::string cacheDirectory(mds->cache_directory); + + mRNAMap["USING_SMOKE"] = std::to_string((mds->type == FLUID_DOMAIN_TYPE_GAS) != 0); + mRNAMap["USING_LIQUID"] = std::to_string((mds->type == FLUID_DOMAIN_TYPE_LIQUID) != 0); + mRNAMap["USING_COLORS"] = std::to_string((mds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS) != 0); + mRNAMap["USING_HEAT"] = std::to_string((mds->active_fields & FLUID_DOMAIN_ACTIVE_HEAT) != 0); + mRNAMap["USING_FIRE"] = std::to_string((mds->active_fields & FLUID_DOMAIN_ACTIVE_FIRE) != 0); + mRNAMap["USING_NOISE"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_NOISE) != 0); + mRNAMap["USING_OBSTACLE"] = std::to_string((mds->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE) != + 0); + mRNAMap["USING_GUIDING"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_GUIDE) != 0); + mRNAMap["USING_INVEL"] = std::to_string((mds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL) != 0); + mRNAMap["USING_OUTFLOW"] = std::to_string((mds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW) != + 0); + mRNAMap["USING_LOG_DISSOLVE"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_DISSOLVE_LOG) != + 0); + mRNAMap["USING_DISSOLVE"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_DISSOLVE) != 0); + mRNAMap["SOLVER_DIM"] = std::to_string(mds->solver_res); + mRNAMap["DO_OPEN"] = std::to_string(((mds->border_collisions & openDomain) == openDomain) == 0); + mRNAMap["BOUND_CONDITIONS"] = borderCollisions; + mRNAMap["BOUNDARY_WIDTH"] = std::to_string(mds->boundary_width); + mRNAMap["RES"] = std::to_string(mMaxRes); + mRNAMap["RESX"] = std::to_string(mResX); + mRNAMap["RESY"] = (is2D) ? std::to_string(mResZ) : std::to_string(mResY); + mRNAMap["RESZ"] = (is2D) ? std::to_string(1) : std::to_string(mResZ); + mRNAMap["TIME_SCALE"] = std::to_string(mds->time_scale); + mRNAMap["FRAME_LENGTH"] = std::to_string(mds->frame_length); + mRNAMap["CFL"] = std::to_string(mds->cfl_condition); + mRNAMap["DT"] = std::to_string(mds->dt); + mRNAMap["TIMESTEPS_MIN"] = std::to_string(mds->timesteps_minimum); + mRNAMap["TIMESTEPS_MAX"] = std::to_string(mds->timesteps_maximum); + mRNAMap["TIME_TOTAL"] = std::to_string(mds->time_total); + mRNAMap["TIME_PER_FRAME"] = std::to_string(mds->time_per_frame); + mRNAMap["VORTICITY"] = std::to_string(mds->vorticity); + mRNAMap["FLAME_VORTICITY"] = std::to_string(mds->flame_vorticity); + mRNAMap["NOISE_SCALE"] = std::to_string(mds->noise_scale); + mRNAMap["MESH_SCALE"] = std::to_string(mds->mesh_scale); + mRNAMap["PARTICLE_SCALE"] = std::to_string(mds->particle_scale); + mRNAMap["NOISE_RESX"] = std::to_string(mResXNoise); + mRNAMap["NOISE_RESY"] = (is2D) ? std::to_string(mResZNoise) : std::to_string(mResYNoise); + mRNAMap["NOISE_RESZ"] = (is2D) ? std::to_string(1) : std::to_string(mResZNoise); + mRNAMap["MESH_RESX"] = std::to_string(mResXMesh); + mRNAMap["MESH_RESY"] = (is2D) ? std::to_string(mResZMesh) : std::to_string(mResYMesh); + mRNAMap["MESH_RESZ"] = (is2D) ? std::to_string(1) : std::to_string(mResZMesh); + mRNAMap["PARTICLE_RESX"] = std::to_string(mResXParticle); + mRNAMap["PARTICLE_RESY"] = (is2D) ? std::to_string(mResZParticle) : + std::to_string(mResYParticle); + mRNAMap["PARTICLE_RESZ"] = (is2D) ? std::to_string(1) : std::to_string(mResZParticle); + mRNAMap["GUIDING_RESX"] = std::to_string(mResGuiding[0]); + mRNAMap["GUIDING_RESY"] = (is2D) ? std::to_string(mResGuiding[2]) : + std::to_string(mResGuiding[1]); + mRNAMap["GUIDING_RESZ"] = (is2D) ? std::to_string(1) : std::to_string(mResGuiding[2]); + mRNAMap["MIN_RESX"] = std::to_string(mds->res_min[0]); + mRNAMap["MIN_RESY"] = std::to_string(mds->res_min[1]); + mRNAMap["MIN_RESZ"] = std::to_string(mds->res_min[2]); + mRNAMap["BASE_RESX"] = std::to_string(mds->base_res[0]); + mRNAMap["BASE_RESY"] = std::to_string(mds->base_res[1]); + mRNAMap["BASE_RESZ"] = std::to_string(mds->base_res[2]); + mRNAMap["WLT_STR"] = std::to_string(mds->noise_strength); + mRNAMap["NOISE_POSSCALE"] = std::to_string(mds->noise_pos_scale); + mRNAMap["NOISE_TIMEANIM"] = std::to_string(mds->noise_time_anim); + mRNAMap["COLOR_R"] = std::to_string(mds->active_color[0]); + mRNAMap["COLOR_G"] = std::to_string(mds->active_color[1]); + mRNAMap["COLOR_B"] = std::to_string(mds->active_color[2]); + mRNAMap["BUOYANCY_ALPHA"] = std::to_string(mds->alpha); + mRNAMap["BUOYANCY_BETA"] = std::to_string(mds->beta); + mRNAMap["DISSOLVE_SPEED"] = std::to_string(mds->diss_speed); + mRNAMap["BURNING_RATE"] = std::to_string(mds->burning_rate); + mRNAMap["FLAME_SMOKE"] = std::to_string(mds->flame_smoke); + mRNAMap["IGNITION_TEMP"] = std::to_string(mds->flame_ignition); + mRNAMap["MAX_TEMP"] = std::to_string(mds->flame_max_temp); + mRNAMap["FLAME_SMOKE_COLOR_X"] = std::to_string(mds->flame_smoke_color[0]); + mRNAMap["FLAME_SMOKE_COLOR_Y"] = std::to_string(mds->flame_smoke_color[1]); + mRNAMap["FLAME_SMOKE_COLOR_Z"] = std::to_string(mds->flame_smoke_color[2]); + mRNAMap["CURRENT_FRAME"] = std::to_string(mmd->time); + mRNAMap["START_FRAME"] = std::to_string(mds->cache_frame_start); + mRNAMap["END_FRAME"] = std::to_string(mds->cache_frame_end); + mRNAMap["CACHE_DATA_FORMAT"] = std::to_string(mds->cache_data_format); + mRNAMap["CACHE_MESH_FORMAT"] = std::to_string(mds->cache_mesh_format); + mRNAMap["CACHE_NOISE_FORMAT"] = std::to_string(mds->cache_noise_format); + mRNAMap["CACHE_PARTICLE_FORMAT"] = std::to_string(mds->cache_particle_format); + mRNAMap["SIMULATION_METHOD"] = simulationMethod; + mRNAMap["FLIP_RATIO"] = std::to_string(mds->flip_ratio); + mRNAMap["PARTICLE_RANDOMNESS"] = std::to_string(mds->particle_randomness); + mRNAMap["PARTICLE_NUMBER"] = std::to_string(mds->particle_number); + mRNAMap["PARTICLE_MINIMUM"] = std::to_string(mds->particle_minimum); + mRNAMap["PARTICLE_MAXIMUM"] = std::to_string(mds->particle_maximum); + mRNAMap["PARTICLE_RADIUS"] = std::to_string(mds->particle_radius); + mRNAMap["FRACTIONS_THRESHOLD"] = std::to_string(mds->fractions_threshold); + mRNAMap["MESH_CONCAVE_UPPER"] = std::to_string(mds->mesh_concave_upper); + mRNAMap["MESH_CONCAVE_LOWER"] = std::to_string(mds->mesh_concave_lower); + mRNAMap["MESH_PARTICLE_RADIUS"] = std::to_string(mds->mesh_particle_radius); + mRNAMap["MESH_SMOOTHEN_POS"] = std::to_string(mds->mesh_smoothen_pos); + mRNAMap["MESH_SMOOTHEN_NEG"] = std::to_string(mds->mesh_smoothen_neg); + mRNAMap["USING_MESH"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_MESH) != 0); + mRNAMap["USING_IMPROVED_MESH"] = std::to_string( + (mds->mesh_generator == FLUID_DOMAIN_MESH_IMPROVED) != 0); + mRNAMap["PARTICLE_BAND_WIDTH"] = std::to_string(mds->particle_band_width); + mRNAMap["SNDPARTICLE_TAU_MIN_WC"] = std::to_string(mds->sndparticle_tau_min_wc); + mRNAMap["SNDPARTICLE_TAU_MAX_WC"] = std::to_string(mds->sndparticle_tau_max_wc); + mRNAMap["SNDPARTICLE_TAU_MIN_TA"] = std::to_string(mds->sndparticle_tau_min_ta); + mRNAMap["SNDPARTICLE_TAU_MAX_TA"] = std::to_string(mds->sndparticle_tau_max_ta); + mRNAMap["SNDPARTICLE_TAU_MIN_K"] = std::to_string(mds->sndparticle_tau_min_k); + mRNAMap["SNDPARTICLE_TAU_MAX_K"] = std::to_string(mds->sndparticle_tau_max_k); + mRNAMap["SNDPARTICLE_K_WC"] = std::to_string(mds->sndparticle_k_wc); + mRNAMap["SNDPARTICLE_K_TA"] = std::to_string(mds->sndparticle_k_ta); + mRNAMap["SNDPARTICLE_K_B"] = std::to_string(mds->sndparticle_k_b); + mRNAMap["SNDPARTICLE_K_D"] = std::to_string(mds->sndparticle_k_d); + mRNAMap["SNDPARTICLE_L_MIN"] = std::to_string(mds->sndparticle_l_min); + mRNAMap["SNDPARTICLE_L_MAX"] = std::to_string(mds->sndparticle_l_max); + mRNAMap["SNDPARTICLE_BOUNDARY_DELETE"] = std::to_string( + (mds->sndparticle_boundary == SNDPARTICLE_BOUNDARY_DELETE) != 0); + mRNAMap["SNDPARTICLE_BOUNDARY_PUSHOUT"] = std::to_string( + (mds->sndparticle_boundary == SNDPARTICLE_BOUNDARY_PUSHOUT) != 0); + mRNAMap["SNDPARTICLE_POTENTIAL_RADIUS"] = std::to_string(mds->sndparticle_potential_radius); + mRNAMap["SNDPARTICLE_UPDATE_RADIUS"] = std::to_string(mds->sndparticle_update_radius); + mRNAMap["LIQUID_SURFACE_TENSION"] = std::to_string(mds->surface_tension); + mRNAMap["FLUID_VISCOSITY"] = std::to_string(mds->viscosity_base * + pow(10.0f, -mds->viscosity_exponent)); + mRNAMap["FLUID_DOMAIN_SIZE"] = std::to_string( + MAX3(mds->global_size[0], mds->global_size[1], mds->global_size[2])); + mRNAMap["SNDPARTICLE_TYPES"] = particleTypesStr; + mRNAMap["USING_SNDPARTS"] = std::to_string((mds->particle_type & particleTypes) != 0); + mRNAMap["GUIDING_ALPHA"] = std::to_string(mds->guide_alpha); + mRNAMap["GUIDING_BETA"] = std::to_string(mds->guide_beta); + mRNAMap["GUIDING_FACTOR"] = std::to_string(mds->guide_vel_factor); + mRNAMap["GRAVITY_X"] = std::to_string(mds->gravity[0]); + mRNAMap["GRAVITY_Y"] = std::to_string(mds->gravity[1]); + mRNAMap["GRAVITY_Z"] = std::to_string(mds->gravity[2]); + mRNAMap["CACHE_DIR"] = cacheDirectory; + mRNAMap["CACHE_RESUMABLE"] = std::to_string((mds->cache_type == FLUID_DOMAIN_CACHE_FINAL) == 0); + mRNAMap["USING_ADAPTIVETIME"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_ADAPTIVE_TIME) != + 0); + mRNAMap["USING_SPEEDVECTORS"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_SPEED_VECTORS) != + 0); + mRNAMap["USING_FRACTIONS"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_FRACTIONS) != 0); + mRNAMap["DELETE_IN_OBSTACLE"] = std::to_string((mds->flags & FLUID_DOMAIN_DELETE_IN_OBSTACLE) != + 0); + mRNAMap["USING_DIFFUSION"] = std::to_string((mds->flags & FLUID_DOMAIN_USE_DIFFUSION) != 0); +} + +std::string MANTA::getRealValue(const std::string &varName) +{ + if (with_debug) + std::cout << "MANTA::getRealValue()" << std::endl; + + std::unordered_map<std::string, std::string>::iterator it; + it = mRNAMap.find(varName); + + if (it == mRNAMap.end()) { + std::cerr << "Fluid Error -- variable " << varName << " not found in RNA map " << it->second + << std::endl; + return ""; } - if (varName == "MIN_RESX") - ss << mmd->domain->res_min[0]; - if (varName == "MIN_RESY") - ss << mmd->domain->res_min[1]; - if (varName == "MIN_RESZ") - ss << mmd->domain->res_min[2]; - if (varName == "BASE_RESX") - ss << mmd->domain->base_res[0]; - if (varName == "BASE_RESY") - ss << mmd->domain->base_res[1]; - if (varName == "BASE_RESZ") - ss << mmd->domain->base_res[2]; - if (varName == "WLT_STR") - ss << mmd->domain->noise_strength; - if (varName == "NOISE_POSSCALE") - ss << mmd->domain->noise_pos_scale; - if (varName == "NOISE_TIMEANIM") - ss << mmd->domain->noise_time_anim; - if (varName == "COLOR_R") - ss << mmd->domain->active_color[0]; - if (varName == "COLOR_G") - ss << mmd->domain->active_color[1]; - if (varName == "COLOR_B") - ss << mmd->domain->active_color[2]; - if (varName == "BUOYANCY_ALPHA") - ss << mmd->domain->alpha; - if (varName == "BUOYANCY_BETA") - ss << mmd->domain->beta; - if (varName == "DISSOLVE_SPEED") - ss << mmd->domain->diss_speed; - if (varName == "BURNING_RATE") - ss << mmd->domain->burning_rate; - if (varName == "FLAME_SMOKE") - ss << mmd->domain->flame_smoke; - if (varName == "IGNITION_TEMP") - ss << mmd->domain->flame_ignition; - if (varName == "MAX_TEMP") - ss << mmd->domain->flame_max_temp; - if (varName == "FLAME_SMOKE_COLOR_X") - ss << mmd->domain->flame_smoke_color[0]; - if (varName == "FLAME_SMOKE_COLOR_Y") - ss << mmd->domain->flame_smoke_color[1]; - if (varName == "FLAME_SMOKE_COLOR_Z") - ss << mmd->domain->flame_smoke_color[2]; - if (varName == "CURRENT_FRAME") - ss << mmd->time; - if (varName == "START_FRAME") - ss << mmd->domain->cache_frame_start; - if (varName == "END_FRAME") - ss << mmd->domain->cache_frame_end; - if (varName == "CACHE_DATA_FORMAT") - ss << getCacheFileEnding(mmd->domain->cache_data_format); - if (varName == "CACHE_MESH_FORMAT") - ss << getCacheFileEnding(mmd->domain->cache_mesh_format); - if (varName == "CACHE_NOISE_FORMAT") - ss << getCacheFileEnding(mmd->domain->cache_noise_format); - if (varName == "CACHE_PARTICLE_FORMAT") - ss << getCacheFileEnding(mmd->domain->cache_particle_format); - if (varName == "SIMULATION_METHOD") { - if (mmd->domain->simulation_method & FLUID_DOMAIN_METHOD_FLIP) { - ss << "'FLIP'"; - } - else if (mmd->domain->simulation_method & FLUID_DOMAIN_METHOD_APIC) { - ss << "'APIC'"; - } - else { - ss << "'NONE'"; - } + if (with_debug) { + std::cout << "Found variable " << varName << " with value " << it->second << std::endl; } - if (varName == "FLIP_RATIO") - ss << mmd->domain->flip_ratio; - if (varName == "PARTICLE_RANDOMNESS") - ss << mmd->domain->particle_randomness; - if (varName == "PARTICLE_NUMBER") - ss << mmd->domain->particle_number; - if (varName == "PARTICLE_MINIMUM") - ss << mmd->domain->particle_minimum; - if (varName == "PARTICLE_MAXIMUM") - ss << mmd->domain->particle_maximum; - if (varName == "PARTICLE_RADIUS") - ss << mmd->domain->particle_radius; - if (varName == "FRACTIONS_THRESHOLD") - ss << mmd->domain->fractions_threshold; - if (varName == "MESH_CONCAVE_UPPER") - ss << mmd->domain->mesh_concave_upper; - if (varName == "MESH_CONCAVE_LOWER") - ss << mmd->domain->mesh_concave_lower; - if (varName == "MESH_PARTICLE_RADIUS") - ss << mmd->domain->mesh_particle_radius; - if (varName == "MESH_SMOOTHEN_POS") - ss << mmd->domain->mesh_smoothen_pos; - if (varName == "MESH_SMOOTHEN_NEG") - ss << mmd->domain->mesh_smoothen_neg; - if (varName == "USING_MESH") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_MESH ? "True" : "False"); - if (varName == "USING_IMPROVED_MESH") - ss << (mmd->domain->mesh_generator == FLUID_DOMAIN_MESH_IMPROVED ? "True" : "False"); - if (varName == "PARTICLE_BAND_WIDTH") - ss << mmd->domain->particle_band_width; - if (varName == "SNDPARTICLE_TAU_MIN_WC") - ss << mmd->domain->sndparticle_tau_min_wc; - if (varName == "SNDPARTICLE_TAU_MAX_WC") - ss << mmd->domain->sndparticle_tau_max_wc; - if (varName == "SNDPARTICLE_TAU_MIN_TA") - ss << mmd->domain->sndparticle_tau_min_ta; - if (varName == "SNDPARTICLE_TAU_MAX_TA") - ss << mmd->domain->sndparticle_tau_max_ta; - if (varName == "SNDPARTICLE_TAU_MIN_K") - ss << mmd->domain->sndparticle_tau_min_k; - if (varName == "SNDPARTICLE_TAU_MAX_K") - ss << mmd->domain->sndparticle_tau_max_k; - if (varName == "SNDPARTICLE_K_WC") - ss << mmd->domain->sndparticle_k_wc; - if (varName == "SNDPARTICLE_K_TA") - ss << mmd->domain->sndparticle_k_ta; - if (varName == "SNDPARTICLE_K_B") - ss << mmd->domain->sndparticle_k_b; - if (varName == "SNDPARTICLE_K_D") - ss << mmd->domain->sndparticle_k_d; - if (varName == "SNDPARTICLE_L_MIN") - ss << mmd->domain->sndparticle_l_min; - if (varName == "SNDPARTICLE_L_MAX") - ss << mmd->domain->sndparticle_l_max; - if (varName == "SNDPARTICLE_BOUNDARY_DELETE") - ss << (mmd->domain->sndparticle_boundary == SNDPARTICLE_BOUNDARY_DELETE); - if (varName == "SNDPARTICLE_BOUNDARY_PUSHOUT") - ss << (mmd->domain->sndparticle_boundary == SNDPARTICLE_BOUNDARY_PUSHOUT); - if (varName == "SNDPARTICLE_POTENTIAL_RADIUS") - ss << mmd->domain->sndparticle_potential_radius; - if (varName == "SNDPARTICLE_UPDATE_RADIUS") - ss << mmd->domain->sndparticle_update_radius; - if (varName == "LIQUID_SURFACE_TENSION") - ss << mmd->domain->surface_tension; - if (varName == "FLUID_VISCOSITY") - ss << mmd->domain->viscosity_base * pow(10.0f, -mmd->domain->viscosity_exponent); - if (varName == "FLUID_DOMAIN_SIZE") { - tmpFloat = MAX3( - mmd->domain->global_size[0], mmd->domain->global_size[1], mmd->domain->global_size[2]); - ss << tmpFloat; - } - if (varName == "SNDPARTICLE_TYPES") { - if (mmd->domain->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY) { - ss << "PtypeSpray"; - } - if (mmd->domain->particle_type & FLUID_DOMAIN_PARTICLE_BUBBLE) { - if (!ss.str().empty()) - ss << "|"; - ss << "PtypeBubble"; - } - if (mmd->domain->particle_type & FLUID_DOMAIN_PARTICLE_FOAM) { - if (!ss.str().empty()) - ss << "|"; - ss << "PtypeFoam"; - } - if (mmd->domain->particle_type & FLUID_DOMAIN_PARTICLE_TRACER) { - if (!ss.str().empty()) - ss << "|"; - ss << "PtypeTracer"; - } - if (ss.str().empty()) - ss << "0"; - } - if (varName == "USING_SNDPARTS") { - tmpVar = (FLUID_DOMAIN_PARTICLE_SPRAY | FLUID_DOMAIN_PARTICLE_BUBBLE | - FLUID_DOMAIN_PARTICLE_FOAM | FLUID_DOMAIN_PARTICLE_TRACER); - ss << (((mmd->domain->particle_type & tmpVar)) ? "True" : "False"); - } - if (varName == "GUIDING_ALPHA") - ss << mmd->domain->guide_alpha; - if (varName == "GUIDING_BETA") - ss << mmd->domain->guide_beta; - if (varName == "GUIDING_FACTOR") - ss << mmd->domain->guide_vel_factor; - if (varName == "GRAVITY_X") - ss << mmd->domain->gravity[0]; - if (varName == "GRAVITY_Y") - ss << mmd->domain->gravity[1]; - if (varName == "GRAVITY_Z") - ss << mmd->domain->gravity[2]; - if (varName == "CACHE_DIR") - ss << mmd->domain->cache_directory; - if (varName == "CACHE_RESUMABLE") - ss << (mmd->domain->cache_type == FLUID_DOMAIN_CACHE_FINAL ? "False" : "True"); - if (varName == "USING_ADAPTIVETIME") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_ADAPTIVE_TIME ? "True" : "False"); - if (varName == "USING_SPEEDVECTORS") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_SPEED_VECTORS ? "True" : "False"); - if (varName == "USING_FRACTIONS") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_FRACTIONS ? "True" : "False"); - if (varName == "DELETE_IN_OBSTACLE") - ss << (mmd->domain->flags & FLUID_DOMAIN_DELETE_IN_OBSTACLE ? "True" : "False"); - if (varName == "USING_DIFFUSION") - ss << (mmd->domain->flags & FLUID_DOMAIN_USE_DIFFUSION ? "True" : "False"); - if (MANTA::with_debug && ss.str().empty()) - std::cerr << "Fluid Error -- Unknown option: " << varName << std::endl; - return ss.str(); -} - -std::string MANTA::parseLine(const std::string &line, FluidModifierData *mmd) + + return it->second; +} + +std::string MANTA::parseLine(const std::string &line) { if (line.size() == 0) return ""; @@ -1024,7 +861,7 @@ std::string MANTA::parseLine(const std::string &line, FluidModifierData *mmd) else if (line[currPos] == delimiter && readingVar) { readingVar = false; end_del = currPos; - res += getRealValue(line.substr(start_del, currPos - start_del), mmd); + res += getRealValue(line.substr(start_del, currPos - start_del)); } currPos++; } @@ -1034,11 +871,19 @@ std::string MANTA::parseLine(const std::string &line, FluidModifierData *mmd) std::string MANTA::parseScript(const std::string &setup_string, FluidModifierData *mmd) { + if (MANTA::with_debug) + std::cout << "MANTA::parseScript()" << std::endl; + std::istringstream f(setup_string); std::ostringstream res; std::string line = ""; + + // Update RNA map if modifier data is handed over + if (mmd) { + initializeRNAMap(mmd); + } while (getline(f, line)) { - res << parseLine(line, mmd) << "\n"; + res << parseLine(line) << "\n"; } return res.str(); } diff --git a/intern/mantaflow/intern/MANTA_main.h b/intern/mantaflow/intern/MANTA_main.h index 21946431f28..5760e31d28d 100644 --- a/intern/mantaflow/intern/MANTA_main.h +++ b/intern/mantaflow/intern/MANTA_main.h @@ -27,6 +27,7 @@ #include <atomic> #include <cassert> #include <string> +#include <unordered_map> #include <vector> struct MANTA { @@ -58,20 +59,20 @@ struct MANTA { void step(struct FluidModifierData *mmd, int startFrame); // Grid initialization functions - void initHeat(struct FluidModifierData *mmd); - void initFire(struct FluidModifierData *mmd); - void initColors(struct FluidModifierData *mmd); - void initFireHigh(struct FluidModifierData *mmd); - void initColorsHigh(struct FluidModifierData *mmd); - void initLiquid(FluidModifierData *mmd); - void initLiquidMesh(FluidModifierData *mmd); - void initObstacle(FluidModifierData *mmd); - void initGuiding(FluidModifierData *mmd); - void initFractions(FluidModifierData *mmd); - void initInVelocity(FluidModifierData *mmd); - void initOutflow(FluidModifierData *mmd); - void initSndParts(FluidModifierData *mmd); - void initLiquidSndParts(FluidModifierData *mmd); + void initHeat(struct FluidModifierData *mmd = NULL); + void initFire(struct FluidModifierData *mmd = NULL); + void initColors(struct FluidModifierData *mmd = NULL); + void initFireHigh(struct FluidModifierData *mmd = NULL); + void initColorsHigh(struct FluidModifierData *mmd = NULL); + void initLiquid(FluidModifierData *mmd = NULL); + void initLiquidMesh(FluidModifierData *mmd = NULL); + void initObstacle(FluidModifierData *mmd = NULL); + void initGuiding(FluidModifierData *mmd = NULL); + void initFractions(FluidModifierData *mmd = NULL); + void initInVelocity(FluidModifierData *mmd = NULL); + void initOutflow(FluidModifierData *mmd = NULL); + void initSndParts(FluidModifierData *mmd = NULL); + void initLiquidSndParts(FluidModifierData *mmd = NULL); // Pointer transfer: Mantaflow -> Blender void updatePointers(); @@ -741,6 +742,8 @@ struct MANTA { size_t mTotalCellsMesh; size_t mTotalCellsParticles; + std::unordered_map<std::string, std::string> mRNAMap; + int mCurrentID; bool mUsingHeat; @@ -864,16 +867,17 @@ struct MANTA { std::vector<pVel> *mSndParticleVelocity; std::vector<float> *mSndParticleLife; - void initDomain(struct FluidModifierData *mmd); - void initNoise(struct FluidModifierData *mmd); - void initMesh(struct FluidModifierData *mmd); - void initSmoke(struct FluidModifierData *mmd); - void initSmokeNoise(struct FluidModifierData *mmd); + void initializeRNAMap(struct FluidModifierData *mmd = NULL); + void initDomain(struct FluidModifierData *mmd = NULL); + void initNoise(struct FluidModifierData *mmd = NULL); + void initMesh(struct FluidModifierData *mmd = NULL); + void initSmoke(struct FluidModifierData *mmd = NULL); + void initSmokeNoise(struct FluidModifierData *mmd = NULL); void initializeMantaflow(); void terminateMantaflow(); bool runPythonString(std::vector<std::string> commands); - std::string getRealValue(const std::string &varName, FluidModifierData *mmd); - std::string parseLine(const std::string &line, FluidModifierData *mmd); + std::string getRealValue(const std::string &varName); + std::string parseLine(const std::string &line); std::string parseScript(const std::string &setup_string, FluidModifierData *mmd = NULL); bool updateMeshFromBobj(std::string filename); bool updateMeshFromObj(std::string filename); |