-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
112 lines (90 loc) · 2.86 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.IO;
using static DPD.Misc;
namespace DPD
{
class Program
{
private static void save_checkpoint_and_trajectory( DPDSim sim )
{
try
{
using( StreamWriter f = File.CreateText("output.checkpoint") )
{
DPDIO.SaveSim( f, sim );
}
}
catch( Exception ) { Console.WriteLine( "Unable to write checkpoint." ); }
try
{
using( StreamWriter f = File.AppendText("output.lammpstrj") )
{
DPDIO.SaveTrajectoryFrame( f, sim );
}
}
catch( Exception ) { Console.WriteLine( "Unable to write trajectory frame." ); }
}
static void Main( string[] args )
{
if( args.Length < 1 )
{
Console.WriteLine( "Pass in simulation definition file as first parameter!" );
System.Environment.Exit( -1 );
}
DPDSim sim = new DPDSim();
//
// Load DPD sim data
//
try
{
using( StreamReader f = File.OpenText(args[0]) )
{
DPDIO.LoadSim( f, sim );
}
}
catch( Exception e )
{
Console.WriteLine( e );
DPDError( "Unable to open input file '{0}'", args[0] );
}
//
// Print initial system info
//
Console.WriteLine( "Friction coefficient is {0} ( as sigma = {1} )", sim.fric, sim.sigma );
Console.WriteLine( "Bead density is {0} per cubic Rc", ((double)sim.site_ids.Length) / (sim.cell[0]*sim.cell[1]*sim.cell[2]) );
{
sim.ClearEnergyAndPressure();
if( sim.i_am_dumb == 1 ) Forces.DoNonbondedSlow( sim );
else Forces.DoNonbondedFast( sim );
Forces.DoBonds( sim );
Forces.DoAngles( sim );
DPDIO.PrintSimInfo( sim, 0.0 );
}
//
// Main integration loop
//
var time_start = DateTime.Now;
for( ; sim.step_no <= sim.max_steps; sim.step_no++ )
{
sim.ClearEnergyAndPressure();
Integrator.VelocityVerlet( sim );
if( sim.step_no % sim.save_every == 0 )
{
save_checkpoint_and_trajectory( sim );
}
if( sim.step_no % sim.print_every == 0 )
{
DPDIO.PrintSimInfo( sim, (DateTime.Now-time_start).TotalSeconds );
}
}
//
// Final information
//
Console.WriteLine( "" );
Console.WriteLine( "Final information:" );
Console.WriteLine( "" );
DPDIO.PrintSimInfo( sim, (DateTime.Now-time_start).TotalSeconds );
save_checkpoint_and_trajectory( sim );
}
}
}