As part of one of my projects, there is a /chemistry/ simulator. It's not intended to be exact to real-life chemistry, but is still a fair bit more complex than just "A + B = C" This is being done in an Object-Oriented programming language similar to java and c#.
Some background: Before I started working on the project:
The container was an instantiated object. It contained a variable, with an array of instantiated chemicals that *existed in the container*. The chemicals themselves were instantiated objects, with a reference to their container, and a volume.
Whenever the container was interacted with, (such as a new chemical added), the function would instantiate a new chemical, add linking references, and update the volume of the chemical. Then it would iterate through *EVERY* chemical in the container to check for possible reactions using a lookup table, and if a match was found, it would run the reaction, and restart. This included a potential for infinitely 'reacting' chemicals, but the workaround was just careful implementation of recipes to prevent infinite loops.
----------------------------------
Now i saw this, and was absolutely disgusted. And changed it to something more akin to:
In this model, the container has a 2D array of the chemical, and it's volume inside of the container. The chemical is only ever instantiated ONCE, and if a chemical is accessed, the properties of the master chemical are read.
(Each unique chemical has static properties in both models, and the only dynamic variable was *volume*)
Then when the contents of the container are modified, it is *flagged* to receive an update, iterates through the contents, performs all currently possible reactions unless that reaction was already performed during this update. If any reactions occured, it would flag the container to be updated *next* process. This removed the potential for problems caused be recursive reactions, but prevented instantaneous consecutive reactions.
-----------------
The problem!
NOW, i want to add some more realism and complexity to the system, as well as make it more efficient if possible. I want to iterate as infrequently as possible.
containers now store the following variables and properties regarding its chemical contents:
Quantity - The quantity of a chemical within. Equivalent to moles. Thermal Energy - The total thermal energy of chemicals within. Equivalent to joules. Volume - The volume of the container. This is the *SAME* as the total volume of the container's contents. But the volume of each chemical should also be tracked separately. ie. 50 unit container contains 30 units of AIR and 1 unit of OIL and 19 units of WATER. This should be calculated based on the quantity of each substance in the container, the temperature, and the total volume of the container. As well as some data based on the individual chemical's properties. Temperature - This is calculated based on the thermal energy, and the chemical properties of the chemicals within. (IE. Temperature = Total thermal energy / Total specific heat capacity of chemicals.) Pressure - This is calculated based on volume, temperature, quantity, and some chemical properties.
----------
What is the most efficient way for me to *add* or *remove* a chemical from the container?
For example "I add 30 units of water. This displaces the gas in the container, and modifies the specific heat and thermal energy of the container. As a result, modifying the temperature, volume, and pressure of the container contents."
How can i adjust all relevant container values using *just* the values before the water is added, and the properties of the water? What additional information might i need to store?
The volume of the contents of the container is *ALWAYS* equal to the volume of the container. This means that if the container is sealed, and contains 30 units of water @ standard temperature, but the volume of the container is *larger* than the volume of liquid water. How do i find the equilibrium point for the volume of *liquid* water and water *vapour*using only temperature, quantity, total volume, and a single extra variable/coefficient for vapour pressure?
How do i quickly and efficiently calculate that, when there are say, n other chemicals inside the container with different properties, that also need to be in equilibrium?
---
Are there any faster and more efficient methods i can use to look-up all possible reaction matches, and perform the reactions, so that the reactions are in equilibrium?
IE if i have : "1 water + 1 agent A = volatile acid" and "1 water + 1 agent B = volatile explosive" in the recipe list, and i have: "1 water, 1 agent A, and 1 agent B" in the container,
How can i make sure that i end up with 25% acid, 25% explosive, 25% A, 25% B, instead of 50% acid, 50% agent B, with as few iterations as possible?
In the case that "acid" and "explosive" react together to form 3 parts agent C and 1 part water, How can i make the reaction find equilibrium *IN THIS UPDATE*, in as few iterations as possible?
Edited by nullie, Today, 09:39 PM.
See the original post:
HALP! Simultaneous Equations with Chemistry and Physics Simulation - GameDev.net
- ONS t-shirts from Zazzle [Last Updated On: August 17th, 2024] [Originally Added On: April 6th, 2010]
- Scientists Embrace Openness Article in Science Careers [Last Updated On: August 17th, 2024] [Originally Added On: April 12th, 2010]
- ONS Books Wiki [Last Updated On: August 17th, 2024] [Originally Added On: April 20th, 2010]
- Reaction Attempts Book Edition 1 and UsefulChem Archive [Last Updated On: August 17th, 2024] [Originally Added On: April 28th, 2010]
- NMR integration web service expanded [Last Updated On: August 17th, 2024] [Originally Added On: May 1st, 2010]
- The Synaptic Leap Experiments on Reaction Attempts [Last Updated On: August 17th, 2024] [Originally Added On: May 3rd, 2010]
- ChemSpider SyntheticPages [Last Updated On: August 17th, 2024] [Originally Added On: May 4th, 2010]
- The Scientist Article on Electronic Lab Notebooks [Last Updated On: August 17th, 2024] [Originally Added On: May 7th, 2010]
- OpenSciNY Open Notebook Science Talk [Last Updated On: August 17th, 2024] [Originally Added On: May 17th, 2010]
- Setac Europe 2010: ‘It’ll all come out in the wash’ [Last Updated On: August 17th, 2024] [Originally Added On: June 3rd, 2010]
- ASMS: Forget Vioxx, eat chocolate? [Last Updated On: August 17th, 2024] [Originally Added On: June 3rd, 2010]
- Smoking could be good for you – if you get the message [Last Updated On: August 17th, 2024] [Originally Added On: June 3rd, 2010]
- Chemistry World's round-up of money and molecules [Last Updated On: August 17th, 2024] [Originally Added On: June 3rd, 2010]
- ASMS: Anthrax attacks [Last Updated On: August 17th, 2024] [Originally Added On: June 3rd, 2010]
- This week on Chemistry World… [Last Updated On: August 17th, 2024] [Originally Added On: June 3rd, 2010]
- Use of ONS to protect Open Research: the case of the Ugi approach to Praziquantel [Last Updated On: August 17th, 2024] [Originally Added On: June 3rd, 2010]
- IGERT NSF panel on Digital Science [Last Updated On: August 17th, 2024] [Originally Added On: June 8th, 2010]
- Reaction Attempts Explorer [Last Updated On: August 17th, 2024] [Originally Added On: June 25th, 2010]
- Methanol Solubility Prediction Model 4 for Ugi reactions in the literature [Last Updated On: August 17th, 2024] [Originally Added On: July 8th, 2010]
- Secrecy in Astronomy and the Open Science Ratchet [Last Updated On: August 17th, 2024] [Originally Added On: July 12th, 2010]
- Resveratrol Thesis on Reaction Attempts [Last Updated On: August 17th, 2024] [Originally Added On: July 22nd, 2010]
- General Transparent Solubility Prediction using Abraham Descriptors [Last Updated On: August 17th, 2024] [Originally Added On: July 25th, 2010]
- Berkeley Open Science Summit 2010 Notes [Last Updated On: August 17th, 2024] [Originally Added On: August 2nd, 2010]
- The Reaction Attempts Solvent Selector [Last Updated On: August 17th, 2024] [Originally Added On: August 8th, 2010]
- Green Solvent Metric on Solvent Predictor [Last Updated On: August 17th, 2024] [Originally Added On: August 17th, 2010]
- ChemTaverna Workflows of ONS Web Services now on MyExperiment [Last Updated On: August 17th, 2024] [Originally Added On: October 11th, 2010]
- Open Notebook Science in Drug Discovery at Opal Event [Last Updated On: August 17th, 2024] [Originally Added On: October 11th, 2010]
- Cheminfo Retrieval Classes 1 and 2 in 2010 [Last Updated On: August 17th, 2024] [Originally Added On: October 11th, 2010]
- The Meaning of Data panel at a class on the Rhetoric of Science [Last Updated On: August 17th, 2024] [Originally Added On: October 11th, 2010]
- Dynamic links to private tagged Mendeley collections [Last Updated On: August 17th, 2024] [Originally Added On: October 16th, 2010]
- Elizabeth Brown's guest lecture for ChemInfo Retrieval [Last Updated On: August 17th, 2024] [Originally Added On: November 7th, 2010]
- Nanoinformatics 2010 Conference Report [Last Updated On: August 17th, 2024] [Originally Added On: November 7th, 2010]
- Dana Vanderwall on Cheminformatics at Drexel [Last Updated On: August 17th, 2024] [Originally Added On: December 11th, 2010]
- Mirza PhD defense on the Ugi reaction for anti-malarial screening [Last Updated On: August 17th, 2024] [Originally Added On: December 13th, 2010]
- Visualizing Social Networks in Open Notebooks [Last Updated On: August 17th, 2024] [Originally Added On: December 20th, 2010]
- Chemical Information Validation Results from Fall 2010 [Last Updated On: August 17th, 2024] [Originally Added On: January 12th, 2011]
- Science Online 2011 Thoughts [Last Updated On: August 17th, 2024] [Originally Added On: January 22nd, 2011]
- The Spectral Game with ChemDoodle [Last Updated On: August 17th, 2024] [Originally Added On: February 14th, 2011]
- Predicting temperature-dependent solubility for solvent selection [Last Updated On: August 17th, 2024] [Originally Added On: February 14th, 2011]
- Alfa Aesar melting point data now openly available [Last Updated On: August 17th, 2024] [Originally Added On: February 22nd, 2011]
- ONS Solubility Challenge Book cited in a Langmuir nanotechnology paper [Last Updated On: August 17th, 2024] [Originally Added On: February 27th, 2011]
- Validating Melting Point Data from Alfa Aesar, EPI and MDPI [Last Updated On: August 17th, 2024] [Originally Added On: March 6th, 2011]
- Open modeling of melting point data [Last Updated On: August 17th, 2024] [Originally Added On: March 23rd, 2011]
- Towards the automated discovery of useful solubility applications [Last Updated On: August 17th, 2024] [Originally Added On: March 29th, 2011]
- ACS and ACRL presentations on web services and trust in science [Last Updated On: August 17th, 2024] [Originally Added On: April 10th, 2011]
- Collaboration using Open Notebook Science in Academia book chapter [Last Updated On: August 17th, 2024] [Originally Added On: May 8th, 2011]
- Evan Curtin is the May 2011 RSC ONS Challenge Winner [Last Updated On: August 17th, 2024] [Originally Added On: May 8th, 2011]
- Breast Cancer Coalition talk on ONS and Taxol solubility [Last Updated On: August 17th, 2024] [Originally Added On: May 15th, 2011]
- La Science par Cahier de Laboratoire Ouvert à l'Acfas [Last Updated On: August 17th, 2024] [Originally Added On: May 15th, 2011]
- More Open Melting Points from EPI and other sources: on the path to ultimate curation [Last Updated On: August 17th, 2024] [Originally Added On: May 29th, 2011]
- More on 4-benzyltoluene and the impact of melting point data curation and transparency [Last Updated On: August 17th, 2024] [Originally Added On: June 12th, 2011]
- The quest to determine the melting point of 4-benzyltoluene [Last Updated On: August 17th, 2024] [Originally Added On: June 12th, 2011]
- Open Melting Points on iPhone via MMDS [Last Updated On: August 17th, 2024] [Originally Added On: June 12th, 2011]
- My talk at SLA on Trust in Science and Open Melting Point Collections [Last Updated On: August 17th, 2024] [Originally Added On: June 19th, 2011]
- Live Tweeting Haumea: the Open Science Ratchet at work? [Last Updated On: August 17th, 2024] [Originally Added On: June 19th, 2011]
- Google Apps Scripts for an intuitive interface to organic chemistry Open Notebooks [Last Updated On: August 17th, 2024] [Originally Added On: June 19th, 2011]
- The 4-benzyltoluene melting point twist [Last Updated On: August 17th, 2024] [Originally Added On: June 26th, 2011]
- Open Notebook Science Talk at HUBbub 2011 [Last Updated On: August 17th, 2024] [Originally Added On: July 3rd, 2011]
- Practical Tips on using Google Apps Scripts for Chemistry Applications [Last Updated On: August 17th, 2024] [Originally Added On: July 17th, 2011]
- Burberry Acoustic - 'Chemistry' by One Night Only for Vogue Fashion Night Out [Last Updated On: August 17th, 2024] [Originally Added On: July 23rd, 2011]
- Rapid analysis of melting point trends and models using Google Apps Scripts [Last Updated On: August 17th, 2024] [Originally Added On: July 24th, 2011]
- Open Melting Point Collection Book Edition 1 [Last Updated On: August 17th, 2024] [Originally Added On: August 14th, 2011]
- Google Apps Scripts Workshop at Drexel University [Last Updated On: August 17th, 2024] [Originally Added On: August 21st, 2011]
- Patrick Ndungu talk at Drexel on Nanotechnology [Last Updated On: August 17th, 2024] [Originally Added On: August 21st, 2011]
- MiniSymposium Bradley Lab 2011 [Last Updated On: August 17th, 2024] [Originally Added On: October 9th, 2011]
- Chemistry [Last Updated On: August 17th, 2024] [Originally Added On: October 10th, 2011]
- Interpol - Rest My Chemistry [Last Updated On: August 17th, 2024] [Originally Added On: October 10th, 2011]
- Queens Of The Stone Age - Better Living Through Chemistry [Last Updated On: August 17th, 2024] [Originally Added On: October 12th, 2011]
- Greatest Chemistry Discoveries - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 13th, 2011]
- Butterfingers - The Chemistry - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 13th, 2011]
- Lec 1 Introduction to Chemistry [Last Updated On: August 17th, 2024] [Originally Added On: October 14th, 2011]
- KATNISS AND PEETA: Chemistry Screen Test using the cave scene from The Hunger Games - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 15th, 2011]
- The Smiths - Live on Data Run c. 1984, a British TV Program - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 15th, 2011]
- Organic Chemistry reactions - 7 clues from Obi Wan - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 15th, 2011]
- CHEMISTRY Period Live Fullmetal Alchemist Brotherhood 4 OP - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 16th, 2011]
- Rush - Chemistry - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 16th, 2011]
- The Office: Jim and Pam - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 17th, 2011]
- Chemistry 1A - Lecture 3 - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 19th, 2011]
- Chemical Party - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 19th, 2011]
- Shiny Toy Guns-Chemistry of a Car Crash (with lyrics) - Video [Last Updated On: August 17th, 2024] [Originally Added On: October 21st, 2011]