Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working on Adding Subcatchments #52

Merged
merged 14 commits into from
Oct 20, 2019
Merged

Working on Adding Subcatchments #52

merged 14 commits into from
Oct 20, 2019

Conversation

rena0157
Copy link
Owner

Adding The Subcatchments Entity

This Pull Request which is a WIP is for the adding of subcatchments into the develop branch. This is the first entity so it will required a little more work up front to set up the required infrastructure to parse all entities.

So far I have added a few new things such as the EntityTests base class that will be used to serve as a base for all entity test in an attempt to add more code reuse in the project.

I have also added the INode interface that adds an X, Y, and Z to any inheritors that want to add the INode functionality.

For the database I have added a method class GetEntities<T> that will return an IEnumerable<T> that can be used to traverse the IInpEntities in the database without having to return a whole list of them.

This pull request is to address #34 and will work towards the V0.3.0 milestone.

@rena0157 rena0157 added New Feature New feature or request WIP A Work In Progress InpFiles Work Related to the Droplet.Core.Inp namespace labels Oct 19, 2019
@rena0157 rena0157 added this to the V0.3.0 milestone Oct 19, 2019
@rena0157 rena0157 self-assigned this Oct 19, 2019
@rena0157
Copy link
Owner Author

Inp Entity Data

In the above commit I have added the InpEntityData class that will serve as a base class for all entities that are not stand alone entities. This includes for example the (Yet to be created) SubArea entity. This is presented in its own table within an inp file which can be seen below.

[SUBAREAS]
;;Subcatchment   N-Imperv   N-Perv     S-Imperv   S-Perv     PctZero    RouteTo    PctRouted 
;;-------------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
1                0.01       0.1        0.05       0.05       100        IMPERVIOUS 50        
3                0.01       0.1        0.05       0.05       25         OUTLET    
5                0.01       0.1        0.05       0.05       25         OUTLET    
6                0.01       0.1        0.05       0.05       25         OUTLET    
7                0.01       0.1        0.05       0.05       25         OUTLET    
8                0.01       0.1        0.05       0.05       25         OUTLET    

The SubArea Entity makes reference to another entity; in this case a Subcatchment Entity. These entities will have to be parsed a little differently than regular entities. I have left them as an IInpEntity as they will still be Initialized in a similar way to other entities in the following method in the InpTableRow class:

private IInpEntity? InitializeEntity(IInpDatabase database) => InpTable.Name switch
{
        InpOption.HeaderName => InpOption.CreateFromOptionName(Key, this, database),
        
        Subcatchment.InpName => new Subcatchment(this, database),
        
        _                    => new InpEntity()
};

This method will then return to the UpdateDatabase() method where they will be linked to their reference entity and not added as a new entity to the _objectDictionary. This will be done by comparing if they are an InpEntity or an InpEntityData class.

@rena0157
Copy link
Owner Author

Sub-Area Entity

Introduction

In the above commits I added the SubArea entity and the basic framework for dealing with InpEntityData classes and the parsing of them.

Method

First the entity is read from the inp file into a InpTableRow like any other entity and then in the UpdateDatabase where the is initialized the constructor is called. I will be talking about the SubArea entity here but the basic methodology will span across all InpEntityData classes.

In the constructor of the SubArea entity the following code is run

(Database?.GetEntity<Subcatchment>(Name) as IEntityDataHost<SubArea>)?.AddEntityData(this);

This gets the relevant referenced entity from the database and then calls the AddEntityData method. The AddEntityData method is a method that is implemented from the IEntityDataHost<T> interface. This interface defines only one function, the void AddEntityData(T entityData); function. This was done so that when inheriting from the interface a new method for dealing with the entity data would need to be implemented in the host class. The host class in this case is the Subcatchment. In the Subcatchment class this data is then processed and it's relevant properties are then updated.

After the UpdateDatabase method returns the Purge method is called where all InpEntityData classes that were previously added to the database are removed.

In conclusion this above process can be simplified into the following steps

  1. Create a new class (Say class X) that inherits from the InpEntityData class.
  2. 'Register' this class by inheriting the IEntityDataHost<X> in the host class (Say class Y).
  3. Implement the internal constructor for class X and place the above mentioned AddEntityData code in this constructor
  4. Implement the AddEntityData method in Class Y

@rena0157 rena0157 merged commit ab18371 into develop Oct 20, 2019
@rena0157 rena0157 deleted the Add-Subcatchments branch October 20, 2019 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
InpFiles Work Related to the Droplet.Core.Inp namespace New Feature New feature or request WIP A Work In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant