Skip to content

Commit

Permalink
Merge pull request #423 from inowas/feature/2086-fix-concentration-re…
Browse files Browse the repository at this point in the history
…sults

Feature/2086 - Fix concentration results
  • Loading branch information
Roschl authored Oct 22, 2021
2 parents cd46c2f + 64e2611 commit 755c74b
Show file tree
Hide file tree
Showing 23 changed files with 2,121 additions and 2,214 deletions.
38 changes: 18 additions & 20 deletions src/core/model/flopy/packages/FlopyPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import md5 from 'md5';
import { JSON_SCHEMA_URL } from '../../../../services/api';

export default class FlopyPackages {

get version() {
return this._version;
}
Expand Down Expand Up @@ -113,7 +112,6 @@ export default class FlopyPackages {
}

public static create(modelId: string, mf: FlopyModflow, mp: FlopyModpath, mt: FlopyMt3d, swt: FlopySeawat) {

const self = new this();
self.modelId = modelId;
self.mf = mf;
Expand All @@ -136,14 +134,14 @@ export default class FlopyPackages {
public static fromObject(obj: IFlopyPackages) {
const mf = FlopyModflow.fromObject(obj.mf);
const mp = obj.mp ? FlopyModpath.fromObject(obj.mp) : new FlopyModpath();
const mt = FlopyMt3d.fromObject(obj.mt);
const swt = FlopySeawat.fromObject(obj.swt);
const mt = obj.mt ? FlopyMt3d.fromObject(obj.mt) : null;
const swt = obj.swt ? FlopySeawat.fromObject(obj.swt) : null;
const modelId = obj.model_id;

const self = new this();
self._modelId = modelId;
self._mf = mf;
self._mf.setTransportEnabled(mt.enabled || false);
self._mf.setTransportEnabled(mt ? mt.enabled : false);
self._mp = mp;
self._mt = mt;
self._swt = swt;
Expand Down Expand Up @@ -171,9 +169,16 @@ export default class FlopyPackages {
transport: Transport,
variableDensity: VariableDensity
) => {
this.mf = this.mf.recalculate(model, soilmodel, boundaries.filter((b) => !b.isExcludedFromCalculation));
this.mf = this.mf.recalculate(
model,
soilmodel,
boundaries.filter((b) => !b.isExcludedFromCalculation)
);
this.mf.setTransportEnabled(transport.enabled);
this.mt = this.mt.recalculate(transport, boundaries.filter((b) => !b.isExcludedFromCalculation));
this.mt = this.mt.recalculate(
transport,
boundaries.filter((b) => !b.isExcludedFromCalculation)
);
this.swt = this.swt.recalculate(variableDensity);
return this;
};
Expand Down Expand Up @@ -216,9 +221,9 @@ export default class FlopyPackages {
version: this.version,
model_id: this.modelId || '',
mf: this.mf.toObject(),
mp: this.mp ? this.mp.toObject() : null,
mt: this.mt ? this.mt.toObject() : null,
swt: this.swt ? this.swt.toObject() : null
mp: this.mp ? this.mp.toObject() : undefined,
mt: this.mt ? this.mt.toObject() : undefined,
swt: this.swt ? this.swt.toObject() : undefined,
};
}

Expand All @@ -229,7 +234,7 @@ export default class FlopyPackages {
version: this.version,
calculation_id: this.calculation_id,
model_id: this.modelId || '',
data: this.getData()
data: this.getData(),
};
}

Expand Down Expand Up @@ -270,17 +275,10 @@ export default class FlopyPackages {
};

public validate(forCalculationServer = true) {

if (forCalculationServer) {
return jsonSchemaValidate(
this.toFlopyCalculation(),
JSON_SCHEMA_URL + '/modflow/packages/flopyCalculation.json'
);
return jsonSchemaValidate(this.toFlopyCalculation(), JSON_SCHEMA_URL + '/modflow/packages/flopyCalculation.json');
}

return jsonSchemaValidate(
this.toObject(),
JSON_SCHEMA_URL + '/modflow/packages/flopyCalculationPackages.json'
);
return jsonSchemaValidate(this.toObject(), JSON_SCHEMA_URL + '/modflow/packages/flopyCalculationPackages.json');
}
}
42 changes: 22 additions & 20 deletions src/core/model/flopy/packages/FlopyPackages.type.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import {IFlopyModflow} from './mf/FlopyModflow.type';
import { IFlopyModflow } from './mf/FlopyModflow.type';
import { IFlopyMt3d } from './mt/FlopyMt3d';
import { IFlopySeawat } from './swt/FlopySeawat';

export interface IFlopyPackages {
model_id: string;
version: string;
author: string;
project: string;
mf: IFlopyModflow;
mp?: any;
mt?: any;
swt?: any;
model_id: string;
version: string;
author: string;
project: string;
mf: IFlopyModflow;
mp?: any;
mt?: IFlopyMt3d;
swt?: IFlopySeawat;
}

export interface IFlopyCalculation {
author: string;
project: string;
version: string;
calculation_id: string;
model_id: string;
data: {
mf: IFlopyModflow;
mp?: any;
mt?: any;
swt?: any;
};
author: string;
project: string;
version: string;
calculation_id: string;
model_id: string;
data: {
mf: IFlopyModflow;
mp?: any;
mt?: IFlopyMt3d;
swt?: IFlopySeawat;
};
}
213 changes: 104 additions & 109 deletions src/core/model/flopy/packages/mt/FlopyMt3d.ts
Original file line number Diff line number Diff line change
@@ -1,136 +1,131 @@
import {GenericObject} from '../../../genericObject/GenericObject';
import {IPropertyValueObject} from '../../../types';
import FlopyMt3dMt, {IFlopyMt3dMt} from './FlopyMt3dMt';

import FlopyMt3dMtadv, {IFlopyMt3dMtAdv} from './FlopyMt3dMtadv';
import FlopyMt3dMtbtn, {IFlopyMt3dMtBtn} from './FlopyMt3dMtbtn';
import FlopyMt3dMtdsp, {IFlopyMt3dMtdsp} from './FlopyMt3dMtdsp';
import FlopyMt3dMtgcg, {IFlopyMt3dMtgcg} from './FlopyMt3dMtgcg';
import FlopyMt3dMtrct, {IFlopyMt3dMtrct} from './FlopyMt3dMtrct';
import FlopyMt3dMtssm, {IFlopyMt3dMtssm} from './FlopyMt3dMtssm';

import {BoundaryCollection} from '../../../modflow/boundaries';
import {Transport} from '../../../modflow';
import { BoundaryCollection } from '../../../modflow/boundaries';
import { GenericObject } from '../../../genericObject/GenericObject';
import { IPropertyValueObject } from '../../../types';
import { Transport } from '../../../modflow';
import FlopyMt3dMt, { IFlopyMt3dMt } from './FlopyMt3dMt';
import FlopyMt3dMtadv, { IFlopyMt3dMtAdv } from './FlopyMt3dMtadv';
import FlopyMt3dMtbtn, { IFlopyMt3dMtBtn } from './FlopyMt3dMtbtn';
import FlopyMt3dMtdsp, { IFlopyMt3dMtdsp } from './FlopyMt3dMtdsp';
import FlopyMt3dMtgcg, { IFlopyMt3dMtgcg } from './FlopyMt3dMtgcg';
import FlopyMt3dMtrct, { IFlopyMt3dMtrct } from './FlopyMt3dMtrct';
import FlopyMt3dMtssm, { IFlopyMt3dMtssm } from './FlopyMt3dMtssm';
import FlopyMt3dPackage from './FlopyMt3dPackage';

export interface IFlopyMt3d extends IPropertyValueObject {
enabled: boolean;
mt: IFlopyMt3dMt;
adv: IFlopyMt3dMtAdv;
btn: IFlopyMt3dMtBtn;
dsp: IFlopyMt3dMtdsp;
gcg: IFlopyMt3dMtgcg;
rct: IFlopyMt3dMtrct;
ssm: IFlopyMt3dMtssm;
enabled: boolean;
mt: IFlopyMt3dMt;
adv: IFlopyMt3dMtAdv;
btn: IFlopyMt3dMtBtn;
dsp: IFlopyMt3dMtdsp;
gcg: IFlopyMt3dMtgcg;
rct: IFlopyMt3dMtrct;
ssm: IFlopyMt3dMtssm;
}

export const packagesMap: IPropertyValueObject = {
mt: FlopyMt3dMt,
adv: FlopyMt3dMtadv,
btn: FlopyMt3dMtbtn,
dsp: FlopyMt3dMtdsp,
gcg: FlopyMt3dMtgcg,
rct: FlopyMt3dMtrct,
ssm: FlopyMt3dMtssm
mt: FlopyMt3dMt,
adv: FlopyMt3dMtadv,
btn: FlopyMt3dMtbtn,
dsp: FlopyMt3dMtdsp,
gcg: FlopyMt3dMtgcg,
rct: FlopyMt3dMtrct,
ssm: FlopyMt3dMtssm,
};

class FlopyMt3d extends GenericObject<IFlopyMt3d> {
get enabled() {
return this._props.enabled;
}

set enabled(value) {
this._props.enabled = value;
}

public static create(transport: Transport, boundaries: BoundaryCollection) {
const obj: IFlopyMt3d = {
enabled: transport.enabled,
mt: FlopyMt3dMt.create().toObject(),
btn: FlopyMt3dMtbtn.create().update(transport).toObject(),
adv: FlopyMt3dMtadv.create().toObject(),
dsp: FlopyMt3dMtdsp.create().toObject(),
gcg: FlopyMt3dMtgcg.create().toObject(),
rct: FlopyMt3dMtrct.create().toObject(),
ssm: FlopyMt3dMtssm.create(transport, boundaries).toObject(),
};

get enabled() {
return this._props.enabled;
return new this(obj);
}

public static fromObject(obj: IFlopyMt3d) {
return new this(obj);
}

public recalculate = (transport: Transport, boundaries: BoundaryCollection) => {
this.enabled = transport.enabled;
this._props.adv = FlopyMt3dMtadv.fromObject(this._props.adv).update().toObject();
this._props.btn = FlopyMt3dMtbtn.fromObject(this._props.btn).update(transport).toObject();
this._props.dsp = FlopyMt3dMtdsp.fromObject(this._props.dsp).update().toObject();
this._props.gcg = FlopyMt3dMtgcg.fromObject(this._props.gcg).update().toObject();
this._props.rct = FlopyMt3dMtrct.fromObject(this._props.rct).update().toObject();
this._props.ssm = FlopyMt3dMtssm.fromObject(this._props.ssm).update(transport, boundaries).toObject();
return this;
};

public toggleEnabled() {
this._props.enabled = !this._props.enabled;
}

public setPackage = (pck: FlopyMt3dPackage<any>) => {
const type = this.getTypeFromPackage(pck);
this._props[type] = pck.toObject();
return this;
};

public getTypeFromPackage = (pck: FlopyMt3dPackage<any>) => {
let type: string | null = null;
for (const t in packagesMap) {
if (packagesMap.hasOwnProperty(t)) {
if (pck instanceof packagesMap[t]) {
type = t;
}
}
}

set enabled(value) {
this._props.enabled = value;
if (type === null) {
throw Error('Type not registered in PackagesMap');
}

public static create(transport: Transport, boundaries: BoundaryCollection) {

const obj: IFlopyMt3d = {
enabled: transport.enabled,
mt: FlopyMt3dMt.create().toObject(),
btn: FlopyMt3dMtbtn.create().update(transport).toObject(),
adv: FlopyMt3dMtadv.create().toObject(),
dsp: FlopyMt3dMtdsp.create().toObject(),
gcg: FlopyMt3dMtgcg.create().toObject(),
rct: FlopyMt3dMtrct.create().toObject(),
ssm: FlopyMt3dMtssm.create(transport, boundaries).toObject()
};
return type;
};

return new this(obj);
public getPackage = (type: string): FlopyMt3dPackage<any> | undefined => {
if (!packagesMap.hasOwnProperty(type)) {
return undefined;
}

public static fromObject(obj: IFlopyMt3d) {
return new this(obj);
if (this._props[type] === undefined) {
return undefined;
}

public recalculate = (transport: Transport, boundaries: BoundaryCollection) => {

this.enabled = transport.enabled;
this._props.adv = FlopyMt3dMtadv.fromObject(this._props.adv).update().toObject();
this._props.btn = FlopyMt3dMtbtn.fromObject(this._props.btn).update(transport).toObject();
this._props.dsp = FlopyMt3dMtdsp.fromObject(this._props.dsp).update().toObject();
this._props.gcg = FlopyMt3dMtgcg.fromObject(this._props.gcg).update().toObject();
this._props.rct = FlopyMt3dMtrct.fromObject(this._props.rct).update().toObject();
this._props.ssm = FlopyMt3dMtssm.fromObject(this._props.ssm).update(transport, boundaries).toObject();

return this;
};
const className = packagesMap[type];
return className.fromObject(this._props[type]);
};

public toggleEnabled() {
this._props.enabled = !this._props.enabled;
public toFlopyCalculation = () => {
if (!this.enabled) {
return null;
}

public setPackage = (pck: FlopyMt3dPackage<any>) => {
const type = this.getTypeFromPackage(pck);
this._props[type] = pck.toObject();
return this;
};

public getTypeFromPackage = (pck: FlopyMt3dPackage<any>) => {
let type: string | null = null;
for (const t in packagesMap) {
if (packagesMap.hasOwnProperty(t)) {
if (pck instanceof packagesMap[t]) {
type = t;
}
}
}

if (type === null) {
throw Error('Type not registered in PackagesMap');
}

return type;
};

public getPackage = (type: string): FlopyMt3dPackage<any> | undefined => {
if (!packagesMap.hasOwnProperty(type)) {
return undefined;
}

if (this._props[type] === undefined) {
return undefined;
}

const className = packagesMap[type];
return className.fromObject(this._props[type]);
};

public toFlopyCalculation = () => {
if (!this.enabled) {
return null;
}

const obj = {...this._props};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete obj.enabled;
const obj = { ...this._props };
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete obj.enabled;

return {
...obj, packages: Object.keys(obj)
};
return {
...obj,
packages: Object.keys(obj),
};
};
}

export default FlopyMt3d;
Loading

0 comments on commit 755c74b

Please sign in to comment.