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

Bug fix issue 'No quality data generated' #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ahuarte47
Copy link

HydraulicSim manages a QualitySim data member when Water quality analysis is needed in order to fill the water quality data in output.

It fixes the issue:
#4

@Baseform
Copy link
Owner

Dear Alvaro,

Thanks a lot for contributing.
The design idea here was to separate Hydraulic and Quality simulations at least at this level. The idea is that you may want to run them together or separately using the sample .inp layout and options by invoking different "simulators".
Hybrid simulations are, of course desirable and can easily be achieved. Please find below a sample piece of code which does just that. Feel free to contact me directly to discuss possible ways of getting a simpler and better API.


public class Sample_HybridSimulation {
public static void main(String[] args) throws ENException, IOException {

    String filename = "files/Net3.inp";

    Logger log = Logger.getLogger(Sample_RunSimulation.class.toString());
    log.setUseParentHandlers(false);

    // Parse INP file.
    Network netINP = new Network();
    InputParser parserINP = InputParser.create(Network.FileType.INP_FILE, log);
    parserINP.parse(netINP, new File(filename));


    File hydFile = File.createTempFile("outFile", "bin");


    HydraulicSim hydSim = new HydraulicSim(netINP, log);
    QualitySim qualSim = new QualitySim(netINP, log);

    long rTime = 0;

    BufferedOutputStream buffer = new BufferedOutputStream(new FileOutputStream(hydFile), 512 * 1024);
    DataOutput out = new DataOutputStream(buffer);
    PropertiesMap pMap = netINP.getPropertiesMap();
    AwareStep.writeHeader(out, hydSim,pMap.getRstart(),pMap.getRstep(),pMap.getDuration());

    while (true) {
        long time = hydSim.getHtime();
        long step = hydSim.simulateSingleStep();


        if ( time >= rTime) {
            rTime += netINP.getPropertiesMap().getRstep();
            AwareStep.writeHydAndQual(out, hydSim, qualSim, step, time);
        }

        qualSim.simulateSingleStep(hydSim.getnNodes(), hydSim.getnLinks(), step);

        if (step == 0)
            break;
    }

    buffer.close();

    FieldsMap fMap = netINP.getFieldsMap();
    BufferedInputStream inBuffer = new BufferedInputStream(new FileInputStream(hydFile));
    DataInput input = new DataInputStream(inBuffer);
    AwareStep.HeaderInfo header = AwareStep.readHeader(input);


    for (long current = 0; current <= netINP.getPropertiesMap().getDuration(); current += netINP.getPropertiesMap().getRstep()) {
        AwareStep step = new AwareStep(input,header);
        System.out.println("Report Time : " + step.getTime());

        for(int id = 0;id<header.nodes;id++)
            System.out.print(String.format("%.2f\t",fMap.revertUnit(FieldsMap.Type.QUALITY,step.getNodeQuality(id))));

         System.out.print("\n");
    }


}

}

New HydraulicAndQualitySim class to simulate hydraulic and Water quality
analysis in order to fill the water quality data in output.

It fixes the issue:
Baseform#4
@ahuarte47 ahuarte47 force-pushed the HydraulicSim_with_QualitySim branch from d2c2c04 to 4724b9f Compare June 24, 2015 21:40
@ahuarte47
Copy link
Author

Hi, thank you very much for your reply and clarifications.

I have rewritten the code creating a new "HydraulicAndQualitySim" class that explicitly mixes the hydraulic and water quality simulations. The developer then decides which uses as needed.

This change can be a better implementation which does not modify the current behavior. I hope this is most welcome.

Best Regards
Alvaro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants