Skip to content

Commit

Permalink
Merge pull request #1173 from StochSS/boundary-conditions
Browse files Browse the repository at this point in the history
Fixed boundary conditions for species and velocity
  • Loading branch information
BryanRumsey authored Jun 30, 2021
2 parents 58c52d9 + 8693d74 commit 300474d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 15 deletions.
10 changes: 8 additions & 2 deletions client/templates/includes/boundaryConditionsEditor.pug
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,21 @@ div#boundary-conditions.card
td(data-hook="new-bc-target")
tr
th(scope="row") Value
td(data-hook="new-bc-value" data-target="value")
td
div(data-hook="new-bc-velocity-value")
div(data-hook="new-bc-value-x" data-target="value")
div(data-hook="new-bc-value-y" data-target="value")
div(data-hook="new-bc-value-z" data-target="value")
div(data-hook="new-bc-other-value" style="display: none")
div(data-hook="new-bc-value" data-target="value")
tr
th(scope="row") Concentration
td
input(type="checkbox" checked=this.newBC.deterministic data-hook="new-bc-deterministic" disabled)

div.col-sm-6

div
div(style="display: flex;")

span.inline.mr-3(for="new-bc-type") <b>Type</b>:
div.inline(id="new-bc-type" data-hook="new-bc-type" data-target="type_id")
Expand Down
82 changes: 74 additions & 8 deletions client/views/boundary-conditions-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module.exports = View.extend({
'change [data-hook=new-bc-deterministic]' : 'handleSetDeterministic',
'change [data-hook=new-bc-type]' : 'handleSetValue',
'change [data-hook=new-bc-value]' : 'handleSetValue',
'change [data-hook=new-bc-value-x]' : 'handleSetValue',
'change [data-hook=new-bc-value-y]' : 'handleSetValue',
'change [data-hook=new-bc-value-z]' : 'handleSetValue',
'change [data-hook=new-bc-x-min]' : 'handleSetValue',
'change [data-hook=new-bc-x-max]' : 'handleSetValue',
'change [data-hook=new-bc-y-min]' : 'handleSetValue',
Expand Down Expand Up @@ -77,7 +80,12 @@ module.exports = View.extend({
handleAddBCClick: function (e) {
let endpoint = path.join(app.getApiPath(), "model/new-bc")
let self = this;
app.postXHR(endpoint, this.newBC, {
if(this.newBC.property === "v") {
this.newBC.value = this.newBCVector
}
let data = {model_path: this.collection.parent.directory,
kwargs: this.newBC}
app.postXHR(endpoint, data, {
success: function (err, response, body) {
self.collection.addNewBoundaryCondition(self.newBCName, body.expression);
self.setDefaultBC();
Expand All @@ -92,12 +100,22 @@ module.exports = View.extend({
let properties = ["v", "nu", "rho"];
let target = e.target.value;
if(properties.includes(target)) {
if(target === "v") {
$(this.queryByHook("new-bc-other-value")).css("display", "none");
$(this.queryByHook("new-bc-velocity-value")).css("display", "block");
}else {
$(this.queryByHook("new-bc-velocity-value")).css("display", "none");
$(this.queryByHook("new-bc-other-value")).css("display", "block");
}
this.newBC.property = target;
this.newBC.species = null;
$(this.queryByHook("new-bc-deterministic")).prop("disabled", true);
}else{
let species = this.collection.parent.species.filter(function (specie) {
return specie.compID === Number(target)
})[0].name;
this.newBC.property = null;
this.newBC.species = target;
this.newBC.species = species;
$(this.queryByHook("new-bc-deterministic")).prop("disabled", false);
}
},
Expand All @@ -108,11 +126,18 @@ module.exports = View.extend({
this.newBCName = value;
}else{
if(key.endsWith("min") || key.endsWith("max") || key === "type_id"){
value = this.validateNewBCCondition(key, value);
}else if(key === "value" && value === "") {
value = null;
this.newBC[key] = this.validateNewBCCondition(key, value);
}else if(key === "value") {
if(e.delegateTarget.dataset.hook.endsWith("x")) {
this.newBCVector[0] = value === "" ? 0 : value
}else if(e.delegateTarget.dataset.hook.endsWith("y")) {
this.newBCVector[1] = value === "" ? 0 : value
}else if(e.delegateTarget.dataset.hook.endsWith("z")) {
this.newBCVector[2] = value === "" ? 0 : value
}else{
this.newBC[key] = value === "" ? null : value
}
}
this.newBC[key] = value;
}
this.toggleAddNewBCButton();
},
Expand Down Expand Up @@ -169,10 +194,13 @@ module.exports = View.extend({
this.newBCName = "";
this.newBC = {"species": null, "property": "v", "value": null, "deterministic": true, "type_id": null,
"xmin": null, "ymin": null, "zmin": null, "xmax": null, "ymax": null, "zmax": null};
this.newBCVector = [0, 0, 0]
this.setConditions = [];
},
toggleAddNewBCButton: function () {
let disabled = this.newBCName === "" || this.newBC.value === null || !this.setConditions.length;
let invalidName = this.newBCName === ""
let invalidValue = this.newBC.property === "v" ? this.newBCVector === [0, 0, 0] : this.newBC.value === null
let disabled = invalidName || invalidValue || !this.setConditions.length;
$(this.queryByHook("add-new-bc")).prop("disabled", disabled);
},
update: function (e) {},
Expand Down Expand Up @@ -229,7 +257,45 @@ module.exports = View.extend({
name: 'value',
tests: tests.valueTests,
valueType: 'number',
value: this.newBC.value
});
}
},
newBCValueX: {
hook: "new-bc-value-x",
prepareView: function (el) {
return new InputView({
parent: this,
required: false,
name: 'value-x',
tests: tests.valueTests,
valueType: 'number',
label: "X: "
});
}
},
newBCValueY: {
hook: "new-bc-value-y",
prepareView: function (el) {
return new InputView({
parent: this,
required: false,
name: 'value-y',
tests: tests.valueTests,
valueType: 'number',
label: "Y: "
});
}
},
newBCValueZ: {
hook: "new-bc-value-z",
prepareView: function (el) {
return new InputView({
parent: this,
required: false,
name: 'value-z',
tests: tests.valueTests,
valueType: 'number',
label: "Z: "
});
}
},
Expand Down
7 changes: 5 additions & 2 deletions stochss/handlers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,14 @@ async def post(self):
----------
'''
self.set_header('Content-Type', 'application/json')
kwargs = json.loads(self.request.body.decode())
data = json.loads(self.request.body.decode())
path = data['model_path']
kwargs = data['kwargs']
log.debug("Args passed to the boundary condition constructor: %s", kwargs)
try:
log.info("Creating the new boundary condition")
resp = StochSSSpatialModel.create_boundary_condition(kwargs)
model = StochSSSpatialModel(path=path)
resp = model.create_boundary_condition(kwargs)
log.info("Successfully created the new boundary condition")
log.debug("Response Message: %s", resp)
self.write(resp)
Expand Down
6 changes: 3 additions & 3 deletions stochss/handlers/util/stochss_spatial_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ def convert_to_spatialpy(self):
return s_model


@classmethod
def create_boundary_condition(cls, kwargs):
def create_boundary_condition(self, kwargs):
'''
Create a new boundary condition using spatialpy.BoundaryCondition
Expand All @@ -399,7 +398,8 @@ def create_boundary_condition(cls, kwargs):
kwargs : dict
Arguments passed to the spatialpy.BoundaryCondition constructor
'''
new_bc = BoundaryCondition(**kwargs)
model = self.convert_to_spatialpy()
new_bc = BoundaryCondition(model=model, **kwargs)
expression = new_bc.expression()
return {"expression": expression}

Expand Down

0 comments on commit 300474d

Please sign in to comment.