CalcTree Help Pages
  • What is CalcTree?
  • Getting started
    • CalcTree Pages
    • Create a CalcTree Page
    • Add a calculation
    • Collaborate with a colleague
  • Calculations
    • Parameters
      • Math formulas
        • Parameter Data Types
        • Native Functions
          • Arithmetic Functions
          • Trigonometric Functions
          • Logical & Comparison Functions
          • Matrix & Vector Functions
          • Probability & Combinatorics Functions
          • Statistical Functions
          • String Functions
          • Utility Functions
          • Other Native Functions
        • Valid Expression Syntax
      • Supported Units
      • Dropdown List Parameters
        • Linking CSV Data to Dependent Dropdowns in CalcTree
      • Parameter Settings
    • Integrations
      • Python in CalcTree
        • Adding a Python Source
        • Defining Parameters in Python
        • Referencing Other Parameters in Python
        • Working with Units in Python
        • Creating Tables and Visuals in Python
        • Consuming Files in Python
        • Using Pre-installed Python Libraries
      • Spreadsheets [Coming Soon!]
      • File Upload
        • CSV files
      • 3rd Party Software Plugins
        • Excel
        • Grasshopper
        • ETABS [v20 & v21]
        • ETABS [v22]
        • SAP 2000
        • CSI Bridge [v26]
    • Templates [Coming Soon!]
    • Optimising your calculations
  • Pages & Reports
    • CalcTree Documents
    • Static content
    • Parametric content
      • Parametric equation
      • Inputs
      • Outputs
  • Export to PDF
  • API
    • GraphQL API
      • Generating an API key
      • Queries
        • GetCalculation
        • Calculate
      • Examples
        • Bulk calculations with Python
  • Collaborate
    • Add members
    • Review and approval
    • Add stakeholders
  • Administrate
    • CalcTree Workspace
    • Versioning and Audit trail
  • CalcTree for System Administrators
Powered by GitBook
On this page
  • Keep Page Size Manageable
  • Use Native Math Where Possible
  • Keep Python Code Sources Lightweight
  1. Calculations

Optimising your calculations

Tips and tricks on how to optimise your calculation pages.

To ensure your pages are fast, responsive, and easy to maintain, we recommend the following best practices when building calculations and reports:

Keep Page Size Manageable

Avoid building a single, oversized page that includes all aspects of your project. Instead:

  • Break your work into multiple pages (e.g. input summary, structural checks, charts/reporting).

  • Link pages together using subpages or workspace structure for modularity and clarity. [Cross page linking of parameter feature is coming soon].

Use Native Math Where Possible

Where you can, stick to native math notation and parameter definitions (i.e. mathjs formulas) in the page. These run faster and allow you to build dynamic, pretty, math notation.

Keep Python Code Sources Lightweight

If you're using Python for more complex functions, data manipulation or charting:

Avoid loading large libraries

For example, if you’re just reading and using table data, you likely don’t need pandas. It adds load time and memory use—especially for small files or simple logic. Instead, use Python’s built-in csv module:

import csv

def read_csv_native(filename):
    with open(ct.page_files[filename], mode='r', encoding='utf-8-sig') as f:
        reader = csv.DictReader(f)
        return [row for row in reader]

Example: Pulling Dimensions from a Section Table

def get_section_dims(section_name):
    rows = read_csv_native("sections.csv")
    for row in rows:
        if row["section"] == section_name:
            return float(row["b"]), float(row["d"])
    return None, None

Then assign it to variables ready to be referenced in the pafe.

[b, d] = get_section_dims("360UB56.7")

Keep code short

Keep and focused on a specific task (e.g. chart generation, table parsing). Create a new code source for different tasks.

Use Functions in Python

Where appropriate, move logic into Python functions to reduce clutter. Instead of defining several math variables which aren't all needed in your page, like this:

b = 300 mm
d = 500 mm
f_c = 32 MPa
phi = 0.9
alpha_2 = 0.85
M_u = phi * alpha_2 * f_c * b * d^2

You can wrap the logic into a Python function:

def design_moment_capacity(b, d, f_c, phi=0.9, alpha_2=0.85):
    """
    Calculates the ultimate moment capacity of a rectangular concrete section.
    Units should be consistent (e.g. mm and MPa).
    """
    M_u = phi * alpha_2 * f_c * b * d**2
    return M_u

Then define a single variable, which you can reference from page parameters:

M_u = design_moment_capacity(300 mm, 500 mm, 32 MPa)

Why This Helps

  • You hide complexity in the Python code, keeping your page cleaner.

  • You reduce the number of intermediate parameters (e.g. phi, alpha_2) cluttering your UI.

  • You can re-use the same function across multiple pages or checks (e.g. for T-beams, doubly reinforced sections, etc.).

  • You maintain flexibility to edit formulas in one place.

PreviousTemplates [Coming Soon!]NextCalcTree Documents

Last updated 27 days ago