### JSON: Example Bathtub Model Structure Source: https://github.com/scottfr/modeljson/blob/main/docs/index.html An example ModelJSON file representing a bathtub model. It defines simulation parameters, states (Is Filling, Is Bathing, Is Draining), and transitions between states based on time triggers. ```json { "engine": "SIMULATION_PACKAGE", "name": "Bathtub", "simulation": { "algorithm": "RK1", "time_start": 0, "time_length": 20, "time_step": 1, "time_units": "MINUTES" }, "elements": [ { "type": "STATE", "name": "Is Filling", "display": { "coordinates": [ 630, 110 ], "size": [ 100, 40 ] }, "behavior": { "initial_value": true } }, { "type": "STATE", "name": "Is Bathing", "display": { "coordinates": [ 630, 230 ], "size": [ 100, 40 ] }, "behavior": { "initial_value": false } }, { "type": "STATE", "name": "Is Draining", "display": { "coordinates": [ 630, 350 ], "size": [ 100, 40 ] }, "behavior": { "initial_value": false } }, { "type": "TRANSITION", "name": "Done Filling", "from": "Is Filling", "to": "Is Bathing", "behavior": { "trigger": "TIMEOUT", "value": 5 } } ``` -------------------------------- ### Implement SIR Disease Model Source: https://context7.com/scottfr/modeljson/llms.txt A comprehensive example of an SIR model using stocks, flows, variables, and links. It demonstrates the integration of simulation parameters, interactive display properties, and time-series visualization. ```json { "engine": "SIMULATION_PACKAGE", "simulation": { "algorithm": "RK1", "time_start": 0, "time_length": 20, "time_step": 0.2, "time_units": "WEEKS" }, "elements": [ { "type": "STOCK", "name": "S", "description": "Initial number of susceptible individuals.", "behavior": { "initial_value": 100 }, "display": { "interactive": true, "interactive_min": 0, "interactive_max": 100, "coordinates": [140, 60], "size": [100, 40] } }, { "type": "STOCK", "name": "I", "description": "Initial number of infected individuals.", "behavior": { "initial_value": 3 }, "display": { "coordinates": [140, 190], "size": [100, 40], "interactive": true, "interactive_min": 0, "interactive_max": 100 } }, { "type": "STOCK", "name": "R", "description": "Initial number of recovered individuals.", "behavior": { "initial_value": 0 }, "display": { "coordinates": [140, 310], "size": [100, 40], "interactive": true, "interactive_min": 0, "interactive_max": 100 } }, { "type": "VARIABLE", "name": "β", "behavior": { "value": 0.01 }, "display": { "coordinates": [50, 40], "size": [50, 50], "interactive": true, "interactive_min": 0, "interactive_max": 0.05 } }, { "type": "VARIABLE", "name": "γ", "behavior": { "value": 0.3 }, "display": { "coordinates": [50, 185], "size": [50, 50], "interactive": true, "interactive_min": 0, "interactive_max": 1 } }, { "type": "FLOW", "name": "Infection", "from": "S", "to": "I", "behavior": { "value": "[β] * [S] * [I]" } }, { "type": "FLOW", "name": "Recovery", "from": "I", "to": "R", "behavior": { "value": "[γ] * [I]" } }, { "type": "LINK", "from": "β", "to": "Infection" }, { "type": "LINK", "from": "γ", "to": "Recovery" } ], "visualizations": [ { "type": "TIME_SERIES", "name": "Disease Spread", "elements": ["I", "R", "S"] } ] } ``` -------------------------------- ### JavaScript to Generate Model Download Links Source: https://github.com/scottfr/modeljson/blob/main/docs/index.html This JavaScript code iterates through a list of examples, creating downloadable JSON files for each model. It dynamically generates anchor tags with 'data:' URIs for the JSON content and appends them to a list in the HTML. ```javascript EXAMPLES.forEach(example => { const li = document.createElement('li'); const a = document.createElement('a'); a.download = example.file; a.href = `data:application/json;charset=utf-8,${encodeURIComponent(example.modeljson)}`; a.innerHTML = ` ${example.name}`; li.appendChild(a); document.querySelector('.examples-list').appendChild(li); }); ``` -------------------------------- ### Define Custom Extension Properties in ModelJSON Source: https://context7.com/scottfr/modeljson/llms.txt This example demonstrates how to add custom properties to elements and the root object by prefixing them with an underscore. These properties are ignored by standard parsers but preserved for application-specific logic. ```json { "name": "Extended Model", "elements": [ { "type": "STOCK", "name": "Inventory", "behavior": { "initial_value": 100 }, "_custom_color": "#FF5733", "_custom_category": "warehouse", "_MY_APP_SETTING": "custom_value" } ], "_application_metadata": { "version": "2.0", "author": "System Designer" } } ``` -------------------------------- ### Define Custom Unit with Factor (JSON) Source: https://github.com/scottfr/modeljson/blob/main/README.md Example of defining a custom unit 'Century' that automatically converts to and from the built-in unit 'Year' using a specified factor. This demonstrates extending unit conversions within the ModelJSON format. ```json { "name": "Century", "base": "Year", "factor": 100 } ``` -------------------------------- ### Configure Simulation Engine and Units Source: https://github.com/scottfr/modeljson/blob/main/docs/index.html This snippet shows how to configure the simulation engine settings, including the algorithm (e.g., RK4), time parameters, and custom unit definitions for physical modeling. ```json { "engine": "SIMULATION_PACKAGE", "simulation": { "algorithm": "RK4", "time_start": 0, "time_length": 10, "time_step": 0.1 }, "engine_settings": { "globals": "g <- {9.81 m/s^2}", "units": [ { "name": "kg", "base": "grams", "factor": 1000 }, { "name": "s", "base": "seconds", "factor": 1 } ] } } ``` -------------------------------- ### Configure Engine Settings and Custom Units Source: https://context7.com/scottfr/modeljson/llms.txt Defines global initialization code and custom unit conversion factors for the SIMULATION_PACKAGE engine. This allows for extending base units with specific scaling factors. ```json { "engine": "SIMULATION_PACKAGE", "engine_settings": { "globals": "# Acceleration due to gravity\ng <- {9.81 m/s^2}", "units": [ { "name": "kg", "base": "grams", "factor": 1000 }, { "name": "Century", "base": "Year", "factor": 100 }, { "name": "m", "base": "meters", "factor": 1 } ] }, "elements": [] } ``` -------------------------------- ### Configure Simulation Parameters Source: https://context7.com/scottfr/modeljson/llms.txt The simulation object defines the numerical execution environment, including the algorithm (e.g., RK4), time boundaries, and units. ```json { "engine": "SIMULATION_PACKAGE", "name": "Example Simulation", "simulation": { "algorithm": "RK4", "time_start": 0, "time_length": 100, "time_step": 0.5, "time_units": "YEARS" }, "elements": [] } ``` -------------------------------- ### Predator/Prey Simulation Configuration (ModelJSON) Source: https://github.com/scottfr/modeljson/blob/main/README.md This JSON configuration defines a Lotka-Volterra predator-prey simulation. It includes simulation engine details, time parameters, and the definition of stocks (Prey, Predators), variables (rates), and flows (births, deaths). It also specifies desired visualizations like time-series graphs and data tables. ```json { "engine": "SIMULATION_PACKAGE", "name": "Predator Prey Model", "description": "Version of the classic Lotka-Volterra model.", "simulation": { "algorithm": "RK4", "time_start": 2000, "time_length": 50, "time_step": 0.5, "time_units": "YEARS" }, "elements": [ { "type": "STOCK", "name": "Prey", "behavior": { "initial_value": 400, "non_negative": true, "units": "Prey" }, "display": { "symbol": "🐰", "interactive": true, "interactive_min": 0, "interactive_max": 1000, "coordinates": [135, 214], "size": [100, 40] } }, { "type": "VARIABLE", "name": "Prey Birth Rate", "display": { "coordinates": [30, 30], "size": [120, 50] }, "behavior": { "value": 0.25, "units": "1 / Years" } }, { "type": "VARIABLE", "name": "Prey Death Rate", "display": { "coordinates": [285, 371], "size": [150, 50] }, "behavior": { "value": "{0.005 1/(Predators * Years)} * [Predators]", "units": "1 / Years" } }, { "type": "VARIABLE", "name": "Predator Birth Rate", "display": { "coordinates": [300, 50], "size": [120, 50] }, "behavior": { "value": "{0.0002 1 / (Prey * Years)} * [Prey]", "units": "1 / Years" } }, { "type": "VARIABLE", "name": "Predator Death Rate", "display": { "coordinates": [637, 340], "size": [120, 50] }, "behavior": { "value": 0.25, "units": "1 / Years" } }, { "type": "STOCK", "name": "Predators", "behavior": { "initial_value": 20, "non_negative": true, "units": "Predators" }, "display": { "symbol": "🦊", "interactive": true, "interactive_min": 0, "interactive_max": 100, "coordinates": [506, 212], "size": [100, 40] } }, { "type": "FLOW", "name": "Prey Births", "from": null, "to": "Prey", "display": { "from_coordinates": [185, 62] }, "behavior": { "value": "[Prey]*[Prey Birth Rate]", "non_negative": true, "units": "Prey / Years" } }, { "type": "FLOW", "name": "Prey Deaths", "from": "Prey", "to": null, "display": { "to_coordinates": [185, 422] }, "behavior": { "value": "[Prey]*[Prey Death Rate]", "non_negative": true, "units": "Prey / Years" } }, { "type": "FLOW", "name": "Predator Births", "from": null, "to": "Predators", "display": { "from_coordinates": [556, 60] }, "behavior": { "value": "[Predators]*[Predator Birth Rate]", "non_negative": true, "units": "Predators / Years" } }, { "type": "FLOW", "name": "Predator Deaths", "from": "Predators", "to": null, "display": { "to_coordinates": [556, 420] }, "behavior": { "value": "[Predator Death Rate]*[Predators]", "non_negative": true, "units": "Predators / Years" } }, { "type": "LINK", "from": "Prey Birth Rate", "to": "Prey Births" }, { "type": "LINK", "from": "Prey Death Rate", "to": "Prey Deaths" }, { "type": "LINK", "from": "Predators", "to": "Prey Death Rate" }, { "type": "LINK", "from": "Predator Death Rate", "to": "Predator Deaths" }, { "type": "LINK", "from": "Predator Birth Rate", "to": "Predator Births" }, { "type": "LINK", "from": "Prey", "to": "Predator Birth Rate" } ], "visualizations": [ { "type": "TIME_SERIES", "name": "Prey and Predators", "elements": [ "Prey", "Predators" ] }, { "type": "TABLE", "name": "Details Table", "elements": [ "Predators", "Prey", "Predator Deaths", "Predator Births", "Prey Births", "Prey Deaths" ] } ] } ``` -------------------------------- ### Bathtub Simulation Model Definition (JSON) Source: https://github.com/scottfr/modeljson/blob/main/README.md This JSON defines a simulation model for a bathtub. It includes the simulation engine, time parameters, and a detailed list of elements such as states (Is Filling, Is Bathing, Is Draining), transitions between states, a stock representing the bathtub's volume, and flows for filling and draining. It also configures time-series visualizations for the bathtub's volume and its states. ```json { "engine": "SIMULATION_PACKAGE", "name": "Bathtub", "simulation": { "algorithm": "RK1", "time_start": 0, "time_length": 20, "time_step": 1, "time_units": "MINUTES" }, "elements": [ { "type": "STATE", "name": "Is Filling", "display": { "coordinates": [630, 110], "size": [100, 40] }, "behavior": { "initial_value": true } }, { "type": "STATE", "name": "Is Bathing", "display": { "coordinates": [630, 230], "size": [100, 40] }, "behavior": { "initial_value": false } }, { "type": "STATE", "name": "Is Draining", "display": { "coordinates": [630, 350], "size": [100, 40] }, "behavior": { "initial_value": false } }, { "type": "TRANSITION", "name": "Done Filling", "from": "Is Filling", "to": "Is Bathing", "behavior": { "trigger": "TIMEOUT", "value": 5 } }, { "type": "TRANSITION", "name": "Bath Over", "from": "Is Bathing", "to": "Is Draining", "behavior": { "trigger": "TIMEOUT", "value": 5 } }, { "type": "STOCK", "name": "Bathtub", "description": "The bathtub starts empty.", "display": { "coordinates": [390, 220], "size": [100, 40] }, "behavior": { "initial_value": 0, "non_negative": true, "units": "Liters" } }, { "type": "FLOW", "name": "Filling", "description": "Water fills at a rate of 10 liters per minute.", "from": null, "to": "Bathtub", "display": { "from_coordinates": [440, 90] }, "behavior": { "value": "if [Is Filling] then\n 10\nend if", "non_negative": true, "units": "Liters/Minute" } }, { "type": "FLOW", "name": "Draining", "description": "Water drains at a rate of 20% per minute.", "from": "Bathtub", "to": null, "display": { "to_coordinates": [440, 400] }, "behavior": { "value": "if [Is Draining] then\n {0.2 1/Minute} * [Bathtub]\nend if", "non_negative": true, "units": "Liters/Minute" } }, { "type": "LINK", "from": "Is Filling", "to": "Filling" }, { "type": "LINK", "from": "Is Draining", "to": "Draining" } ], "visualizations": [ { "type": "TIME_SERIES", "name": "Bathtub Volume", "elements": [ "Bathtub" ] }, { "type": "TIME_SERIES", "name": "States", "elements": [ "Is Filling", "Is Bathing", "Is Draining" ] } ] } ``` -------------------------------- ### ModelJSON Simulation Object Source: https://context7.com/scottfr/modeljson/llms.txt Configures the numerical simulation parameters, including algorithm, time boundaries, and time units. ```APIDOC ## Simulation Object ### Description The simulation object configures the numerical simulation parameters including algorithm choice, time boundaries, and time units. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```json { "engine": "SIMULATION_PACKAGE", "name": "Example Simulation", "simulation": { "algorithm": "RK4", "time_start": 0, "time_length": 100, "time_step": 0.5, "time_units": "YEARS" }, "elements": [] } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Define ModelJSON Root Object Source: https://context7.com/scottfr/modeljson/llms.txt The root object serves as the entry point for a model, containing metadata, simulation settings, and collections of elements and visualizations. ```json { "name": "My System Model", "description": "A description of the model's purpose and behavior.", "file_notes": "Optional notes about export/import issues.", "engine": "SIMULATION_PACKAGE", "engine_settings": {}, "simulation": {}, "elements": [], "visualizations": [] } ``` -------------------------------- ### Define Visualization Objects Source: https://context7.com/scottfr/modeljson/llms.txt Configures how simulation results are rendered. Supports TIME_SERIES and TABLE types to display specific model elements. ```json { "visualizations": [ { "type": "TIME_SERIES", "name": "Population Over Time", "elements": ["Population", "Birth Rate", "Death Rate"] }, { "type": "TABLE", "name": "Detailed Results", "elements": ["Population", "Growth Rate"] } ] } ``` -------------------------------- ### Define System Dynamics Model in JSON Source: https://github.com/scottfr/modeljson/blob/main/docs/index.html This snippet demonstrates how to define a system dynamics model using the ModelJSON format. It includes stocks, flows, variables, and links to represent dynamic relationships. ```json { "type": "STOCK", "name": "Predators", "behavior": { "initial_value": 20, "non_negative": true, "units": "Predators" }, "display": { "symbol": "🦊", "interactive": true, "coordinates": [506, 212] } } ``` -------------------------------- ### Define System Elements Source: https://context7.com/scottfr/modeljson/llms.txt ModelJSON supports various element types including Stocks for accumulation, Flows for movement, Variables for constants/calculations, Links for dependencies, Converters for lookup tables, and States/Transitions for state machines. ```json { "type": "STOCK", "name": "Population", "behavior": { "initial_value": 1000, "non_negative": true, "units": "People" } } { "type": "FLOW", "name": "Birth Rate", "from": null, "to": "Population", "behavior": { "value": "[Population] * 0.02", "units": "People / Years" } } { "type": "VARIABLE", "name": "Growth Rate", "behavior": { "value": 0.025, "units": "1 / Years" } } { "type": "LINK", "from": "Growth Rate", "to": "Birth Rate", "behavior": { "polarity": "POSITIVE" } } { "type": "CONVERTER", "name": "Growth Rate Lookup", "behavior": { "input": "ELEMENT", "input_element": "Population", "data": [[0, 2.0], [10000, 0]] } } { "type": "STATE", "name": "Is Active", "behavior": { "initial_value": true } } { "type": "TRANSITION", "name": "Activation Timeout", "from": "Is Active", "to": "Is Inactive", "behavior": { "trigger": "TIMEOUT", "value": 5 } } ``` -------------------------------- ### Define State Machine Bathtub Simulation Source: https://context7.com/scottfr/modeljson/llms.txt This JSON structure defines a bathtub simulation using states, transitions, stocks, and conditional flows. It utilizes an RK1 simulation algorithm to track volume over time based on active states. ```json { "engine": "SIMULATION_PACKAGE", "name": "Bathtub", "simulation": { "algorithm": "RK1", "time_start": 0, "time_length": 20, "time_step": 1, "time_units": "MINUTES" }, "elements": [ { "type": "STATE", "name": "Is Filling", "behavior": { "initial_value": true } }, { "type": "STATE", "name": "Is Bathing", "behavior": { "initial_value": false } }, { "type": "STATE", "name": "Is Draining", "behavior": { "initial_value": false } }, { "type": "TRANSITION", "name": "Done Filling", "from": "Is Filling", "to": "Is Bathing", "behavior": { "trigger": "TIMEOUT", "value": 5 } }, { "type": "STOCK", "name": "Bathtub", "behavior": { "initial_value": 0, "non_negative": true, "units": "Liters" } }, { "type": "FLOW", "name": "Filling", "behavior": { "value": "if [Is Filling] then\n 10\nend if" } } ] } ``` -------------------------------- ### JavaScript: Handle ModelJSON File Upload and Preview Source: https://github.com/scottfr/modeljson/blob/main/docs/index.html This JavaScript code handles file uploads via drag-and-drop or file input. It validates JSON files, checks for size limits, and redirects to a preview URL for valid ModelJSON files. It includes event listeners for drag-and-drop interactions and file selection. ```javascript const dropZone = document.getElementById('drop-zone'); const fileInput = document.getElementById('fileInput'); dropZone.addEventListener('click', () => fileInput.click()); ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { dropZone.addEventListener(eventName, preventDefaults, false); }); function preventDefaults (e) { e.preventDefault(); e.stopPropagation(); } ['dragenter', 'dragover'].forEach(eventName => { dropZone.addEventListener(eventName, highlight, false); }); ['dragleave', 'drop'].forEach(eventName => { dropZone.addEventListener(eventName, unhighlight, false); }); function highlight(e) { dropZone.classList.add('dragover'); } function unhighlight(e) { dropZone.classList.remove('dragover'); } dropZone.addEventListener('drop', handleDrop, false); fileInput.addEventListener('change', handleFileSelect, false); function handleDrop(e) { const dt = e.dataTransfer; const files = dt.files; handleFiles(files); } function handleFileSelect(e) { const files = e.target.files; handleFiles(files); } function handleFiles(files) { const file = files[0]; if (file && file.type === 'application/json') { const reader = new FileReader(); reader.onload = (e) => { const content = e.target.result; // check if the content is valid JSON let json = null; try { json = JSON.parse(content); } catch (error) { alert('Invalid JSON file'); return; } let modelString = encodeURIComponent(JSON.stringify(json)); if (modelString.length > 8000) { alert('This model is too large (>8 Kb) to preview via this playground. Please use the Insight Maker website (https://insightmaker.com/insight > "Share menu" > "Import") to import it.'); return; } window.location.href = `https://insightmaker.com/modeljson/view?modeljson=${modelString}`; }; reader.readAsText(file); } else { alert('Please upload a JSON file'); } } ``` -------------------------------- ### ModelJSON Root Object Schema Source: https://context7.com/scottfr/modeljson/llms.txt Defines the overall structure of a ModelJSON file, including metadata, simulation settings, elements, and visualizations. ```APIDOC ## Root Object Schema ### Description The root object defines the overall model structure with metadata, simulation settings, elements array, and optional visualizations. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```json { "name": "My System Model", "description": "A description of the model's purpose and behavior.", "file_notes": "Optional notes about export/import issues.", "engine": "SIMULATION_PACKAGE", "engine_settings": {}, "simulation": {}, "elements": [], "visualizations": [] } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Population Growth Model JSON Structure Source: https://github.com/scottfr/modeljson/blob/main/docs/index.html This JSON defines a population growth simulation model. It features 'Population' as a stock, 'Growth Rate' as a converter, and a 'Flow' element to manage population changes. The simulation uses the 'RK4' algorithm over 20 years with a time step of 0.2 years. ```json { "engine": "SIMULATION_PACKAGE", "name": "Population Growth", "simulation": { "algorithm": "RK4", "time_start": 0, "time_length": 20, "time_step": 0.2, "time_units": "YEARS" }, "elements": [ { "type": "STOCK", "name": "Population", "display": { "coordinates": [ 130, 210 ], "size": [ 100, 40 ] }, "behavior": { "initial_value": 1, "non_negative": true } }, { "type": "CONVERTER", "name": "Growth Rate", "display": { "coordinates": [ 260, 90 ], "size": [ 120, 50 ] }, "behavior": { "input": "ELEMENT", "interpolation": "LINEAR", "data": [ [0, 2], [1500, 1.07], [3990, 0.429], [6780, 0.125], [10000, 0] ], "input_element": "Population" } }, { "type": "FLOW", "name": "Flow", "from": null, "to": "Population", "display": { "from_coordinates": [ 180, 60 ] }, "behavior": { "value": "[Population] * [Growth Rate]", "non_negative": true } }, { "type": "LINK", "from": "Growth Rate", "to": "Flow" }, { "type": "LINK", "from": "Population", "to": "Growth Rate" } ], "visualizations": [ { "type": "TIME_SERIES", "name": "Default Display", "elements": [ "Population" ] } ] } ``` -------------------------------- ### Define Population Growth Simulation Source: https://github.com/scottfr/modeljson/blob/main/README.md A JSON configuration for a population growth model with carrying capacity. It utilizes a converter with linear interpolation to determine growth rates based on population size. ```json { "engine": "SIMULATION_PACKAGE", "name": "Population Growth", "simulation": { "algorithm": "RK4", "time_start": 0, "time_length": 20, "time_step": 0.2, "time_units": "YEARS" }, "elements": [ { "type": "STOCK", "name": "Population", "behavior": { "initial_value": 1, "non_negative": true } }, { "type": "CONVERTER", "name": "Growth Rate", "behavior": { "input": "ELEMENT", "data": [[0, 2], [1500, 1.07], [10000, 0]], "input_element": "Population" } }, { "type": "FLOW", "name": "Flow", "behavior": { "value": "[Population] * [Growth Rate]" } } ] } ``` -------------------------------- ### ModelJSON Stock Element Source: https://context7.com/scottfr/modeljson/llms.txt Represents state variables that accumulate quantities over time, supporting initial values, constraints, and display options. ```APIDOC ## Stock Element ### Description Stocks are state variables that accumulate quantities over time. They support initial values, non-negative constraints, units, and interactive display options with position coordinates. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```json { "type": "STOCK", "name": "Population", "description": "Total population count", "behavior": { "initial_value": 1000, "non_negative": true, "units": "People" }, "display": { "interactive": true, "interactive_min": 0, "interactive_max": 10000, "symbol": "👥", "coordinates": [130, 210], "size": [100, 40] } } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### ModelJSON Transition Element Source: https://context7.com/scottfr/modeljson/llms.txt Represents transitions that move state elements between true/false values, triggered by timeout, condition, or probability. ```APIDOC ## Transition Element ### Description Transitions move state elements between true/false values. They can be triggered by timeout, condition evaluation, or probability. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```json { "type": "TRANSITION", "name": "Activation Timeout", "from": "Is Active", "to": "Is Inactive", "behavior": { "trigger": "TIMEOUT", "value": 5 } } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### ModelJSON Converter Element Source: https://context7.com/scottfr/modeljson/llms.txt Provides lookup table functionality, mapping input values to output values with optional linear interpolation. ```APIDOC ## Converter Element ### Description Converters provide lookup table functionality, mapping input values (either time or another element's value) to output values with optional linear interpolation. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```json { "type": "CONVERTER", "name": "Growth Rate Lookup", "display": { "coordinates": [260, 90], "size": [120, 50] }, "behavior": { "input": "ELEMENT", "input_element": "Population", "interpolation": "LINEAR", "data": [ [0, 2.0], [1500, 1.07], [3990, 0.429], [6780, 0.125], [10000, 0] ], "units": "1 / Years" } } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Define Damped Pendulum Simulation Source: https://github.com/scottfr/modeljson/blob/main/README.md A JSON configuration for a damped pendulum model. It defines physical constants, simulation parameters using the RK4 algorithm, and the mathematical relationships between angle, velocity, and damping. ```json { "engine": "SIMULATION_PACKAGE", "name": "Damped pendulum", "description": "A simple damped pendulum model. Uses common SI units mapping to SIMULATION_PACKAGE built-in units.", "simulation": { "algorithm": "RK4", "time_start": 0, "time_length": 10, "time_step": 0.1, "time_units": "SECONDS" }, "elements": [ { "type": "STOCK", "name": "Angle", "behavior": { "initial_value": 0.2, "units": "rad" } }, { "type": "STOCK", "name": "Angular Velocity", "behavior": { "initial_value": 0, "units": "rad/s" } }, { "type": "FLOW", "name": "Angular Acceleration", "behavior": { "value": "-([Damping Coefficient]/([Mass]*[Length]^2))*[Angular Velocity] - (g /[Length])*sin([Angle]) * {1 radian}" } } ] } ``` -------------------------------- ### ModelJSON Flow Element Source: https://context7.com/scottfr/modeljson/llms.txt Represents flows that move quantities between stocks, requiring `from` and `to` properties and supporting formulas or numeric values. ```APIDOC ## Flow Element ### Description Flows move quantities between stocks. They require `from` and `to` properties specifying connected stocks (use `null` for external sources/sinks) and support formulas or numeric values. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```json { "type": "FLOW", "name": "Birth Rate", "from": null, "to": "Population", "display": { "from_coordinates": [180, 60] }, "behavior": { "value": "[Population] * 0.02", "non_negative": true, "units": "People / Years" } } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Converter Element Source: https://github.com/scottfr/modeljson/blob/main/README.md Defines a Converter element which uses a lookup table to determine output values. ```APIDOC ## Converter ### Description A Converter is a table of input/output values used to determine output based on an input source. ### Properties - **behavior.input** (string) - Optional - Input source ("TIME" or "ELEMENT"). - **behavior.data** (array) - Optional - An array of [input, output] pairs. - **behavior.interpolation** (string) - Optional - Interpolation method ("NONE" or "LINEAR"). ### Example { "type": "Converter", "behavior": { "input": "TIME", "data": [[0, 10], [1, 20]], "interpolation": "LINEAR" } } ``` -------------------------------- ### ModelJSON Link Element Source: https://context7.com/scottfr/modeljson/llms.txt Connects elements to indicate dependencies and influence relationships, specifying polarity for causal relationships. ```APIDOC ## Link Element ### Description Links connect elements to indicate dependencies and influence relationships. They specify polarity (positive, negative, or neutral) for causal relationships. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```json { "type": "LINK", "from": "Growth Rate", "to": "Birth Rate", "behavior": { "polarity": "POSITIVE" } } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Define Balancing Population Growth Causal Loop Diagram Source: https://github.com/scottfr/modeljson/blob/main/README.md This JSON structure defines a causal loop diagram representing population growth. It uses variables and links with defined polarities (positive or negative) to map the relationships between births, deaths, and carrying capacity. ```json { "elements": [ { "type": "VARIABLE", "name": "Population" }, { "type": "VARIABLE", "name": "Births" }, { "type": "VARIABLE", "name": "Carrying Capacity" }, { "type": "VARIABLE", "name": "Deaths" }, { "type": "LINK", "from": "Population", "to": "Deaths", "behavior": { "polarity": "POSITIVE" } }, { "type": "LINK", "from": "Carrying Capacity", "to": "Deaths", "behavior": { "polarity": "NEGATIVE" } }, { "type": "LINK", "from": "Net Growth", "to": "Population", "behavior": { "polarity": "POSITIVE" } } ] } ``` -------------------------------- ### ModelJSON State Element Source: https://context7.com/scottfr/modeljson/llms.txt Represents boolean variables that can be either true or false, used in state machine and transition diagram models. ```APIDOC ## State Element ### Description States represent boolean variables that can be either true or false, used in state machine and transition diagram models. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```json { "type": "STATE", "name": "Is Active", "display": { "coordinates": [630, 110], "size": [100, 40] }, "behavior": { "initial_value": true } } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Define Causal Loop Diagram Source: https://context7.com/scottfr/modeljson/llms.txt This JSON structure models a causal loop diagram for population dynamics. It defines variables and links with specific polarities to represent positive and negative feedback loops. ```json { "elements": [ { "type": "VARIABLE", "name": "Population" }, { "type": "VARIABLE", "name": "Births" }, { "type": "LINK", "from": "Population", "to": "Births", "behavior": { "polarity": "POSITIVE" } }, { "type": "LINK", "from": "Births", "to": "Net Growth", "behavior": { "polarity": "POSITIVE" } } ] } ```