VTT-ProperTune / OpenPFC

Open-source solver for phase field crystal type (PFC) type problems.
GNU Affero General Public License v3.0
10 stars 6 forks source link

Input file format #6

Open ahojukka5 opened 1 year ago

ahojukka5 commented 1 year ago

We should include descriptions of parameters to input file. The problem is that json does not support comments. In principle, they could be added but then all json validators will fail and comments must be stripped out before parsing the file. One possible option would be to add more structure, i.e. instead of having e.g.

{
    "name": "tungsten",
    "params": {
        "n0": -0.10,
        "alpha": 0.50,
        "n_sol": -0.047,
    }
}

we could have

{
    "name": "tungsten",
    "params": [
        {
            "name": "n0",
            "description": "Density of metastable fluid",
            "type": "number",
            "value": -0.10
        },
        {
            "name": "alpha",
            "description": "Thermal expansion coefficient",
            "type": "number",
            "value": 0.50
        },
        {
            "name": "n_sol",
            "description": "Density of solid",
            "type": "number",
            "value": -0.047
        }
    ]
}

Even better, we could introduce schema, and in that case, we could also validate (https://github.com/pboettch/json-schema-validator) the input against the schema and give clear error message if there is something wrong with the json file. Example:

{
    "schema": {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "title": "Schema for Tungsten model",
        "properties": {
            "n0": {
                "description": "Density of metastable fluid",
                "type": "number"
            },
            "alpha": {
                "description": "Thermal expansion coefficient",
                "type": "number"
            },
            "n_sol": {
                "description": "Density of solid",
                "type": "number"
            }
        },
        "required": [
            "n0",
            "alpha",
            "n_sol"
        ],
        "type": "object"
    },

    "data": {
        "n0": -0.10,
        "alpha": 0.50,
        "n_sol": -0.047
    }
}

Of course, simulation data and schema can be on different files if that's better. I bet there's json editors that takes schema and builds nice user interface based on that so that json files can be easily done.

ahojukka5 commented 1 year ago

https://github.com/json-editor/json-editor