10#include <r1/field/Domain.h>
11#include <r1/solvers/Mixture.h>
12#include <r1/solvers/Polymer.h>
13#include <r1/solvers/Solvent.h>
14#include <r1/solvers/Block.h>
16#include <pscf/chem/Vertex.h>
18#include <util/misc/FileMaster.h>
19#include <util/format/Str.h>
20#include <util/format/Int.h>
21#include <util/format/Dbl.h>
48 fileMasterPtr_ = &fileMaster;
52 std::string
const & filename)
55 fileMaster().openInputFile(filename, in);
78 for (
int i = 0; i < nm; ++i) {
84 for (i = 0; i < nx; ++i) {
87 for (j = 0; j < nm; ++j) {
94 UTIL_THROW(
"Missing or invalid value in field file");
99 std::string
const & filename,
bool writeHeader)
const
102 fileMaster().openOutputFile(filename, out);
113 out <<
"nx " << nx << std::endl;
117 for (i = 0; i < nx; ++i) {
118 out <<
" " <<
Dbl(field[i], 18, 11);
124 std::string
const & filename,
bool writeHeader)
128 fileMaster().openOutputFile(filename, out);
134 std::ostream& out,
bool writeHeader)
142 for (
int i = 0; i < nm; ++i) {
147 out <<
"nx " << nx << std::endl;
148 out <<
"nm " << nm << std::endl;
152 for (i = 0; i < nx; ++i) {
154 for (j = 0; j < nm; ++j) {
155 out <<
" " <<
Dbl(fields[j][i], 18, 11);
162 std::string
const & filename)
const
165 fileMaster().openOutputFile(filename, out);
176 int nx = domain().nx();
178 int nb_tot = mixture.
nBlock();
181 out <<
"nx " << nx << std::endl;
182 out <<
"n_block " << nb_tot << std::endl;
183 out <<
"n_solvent " << ns << std::endl;
188 for (i = 0; i < nx; ++i) {
190 for (j = 0; j < np; ++j) {
191 nb = mixture.
polymer(j).nBlock();
192 for (k = 0; k < nb; ++k) {
193 c = mixture.
polymer(j).block(k).cField()[i];
194 out <<
" " <<
Dbl(c, 15, 8);
197 for (l = 0; l < ns; ++l) {
198 c = mixture.
solvent(l).cField()[i];
199 out <<
" " <<
Dbl(c, 15, 8);
209 int polymerId,
int vertexId,
210 std::string
const & filename)
const
213 fileMaster().openOutputFile(filename, out);
222 int polymerId,
int vertexId,
223 std::ostream& out)
const
231 int nb = vertex.
size();
232 int nx = domain().nx();
239 for (i = 0; i < nx; ++i) {
242 for (j = 0; j < nb; ++j) {
250 out <<
" " <<
Dbl(c, 15, 8);
253 out <<
" " <<
Dbl(
product, 15, 8) << std::endl;
262 std::string
const & filename)
266 UTIL_THROW(
"Number of grid points nx < 2 in remesh");
269 fileMaster().openOutputFile(filename, out);
281 UTIL_THROW(
"Number of grid points nx < 2 in remesh");
287 for (
int i = 0; i < nm; ++i) {
288 UTIL_CHECK(fields[i].capacity() == domain().nx());
292 out <<
"nx " << nx << std::endl;
293 out <<
"nm " << nm << std::endl;
299 for (j = 0; j < nm; ++j) {
300 out <<
" " <<
Dbl(fields[j][i]);
305 double dx = (domain().xMax() - domain().xMin())/
double(nx-1);
315 for (i = 1; i < nx -1; ++i) {
316 y = dx*double(i)/domain().dx();
324 for (j = 0; j < nm; ++j) {
325 w = fl*fields[j][yi] + fu*fields[j][yi+1];
326 out <<
" " <<
Dbl(w);
332 out <<
Int(nx - 1, 5);
333 i = domain().nx() - 1;
334 for (j = 0; j < nm; ++j) {
335 out <<
" " <<
Dbl(fields[j][i]);
343 std::string
const & filename)
347 UTIL_THROW(
"Number of added grid points m < 0 in extend");
350 fileMaster().openOutputFile(filename, out);
362 UTIL_THROW(
"Number of added grid points m < 0 in extend");
371 for (
int i = 0; i < nm; ++i) {
377 out <<
"nx " << nx + m << std::endl;
378 out <<
"nm " << nm << std::endl;
382 for (i = 0; i < nx; ++i) {
384 for (j = 0; j < nm; ++j) {
385 out <<
" " <<
Dbl(fields[j][i]);
391 for (i = nx; i < nx + m; ++i) {
393 for (j = 0; j < nm; ++j) {
394 out <<
" " <<
Dbl(fields[j][nx-1]);
int nPolymer() const
Get number of polymer species.
int nSolvent() const
Get number of solvent (point particle) species.
int nBlock() const
Get total number blocks among all polymer species.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
SolventT & solvent(int id)
Get a solvent solver object.
const Vertex & vertex(int id) const
Get a specified Vertex by const reference.
int nBlock() const
Number of blocks.
PT & propagator(int blockId, int directionId)
Get the propagator for a specific block and direction (non-const).
One-dimensional spatial domain and discretization grid.
void writeVertexQ(Mixture const &mixture, int polymerId, int vertexId, std::ostream &out) const
Write product of incoming q fields for one vertex to stream.
void writeFields(DArray< Field > const &fields, std::ostream &out, bool writeHeader=true) const
Write a set of fields, one per monomer type, to an output stream.
void writeBlockCFields(Mixture const &mixture, std::ostream &out) const
Write block concentration fields for all blocks to an output stream.
void extend(DArray< Field > const &fields, int m, std::ostream &out)
Add points to the end of a field mesh and write to stream.
void remesh(DArray< Field > const &fields, int nx, std::ostream &out)
Interpolate an array of fields onto a new mesh and write to stream.
void writeField(Field const &field, std::ostream &out, bool writeHeader=true) const
Write a single field to an output stream.
void readFields(DArray< Field > &fields, std::istream &in)
Read a set of fields, one per monomer type.
void associate(Domain const &domain, FileMaster const &fileMaster)
Get and store addresses of associated objects.
Solver and descriptor for a mixture of polymers and solvents.
Descriptor and solver for a block polymer species.
A junction or chain end in a block polymer.
int size() const
Get the number of attached blocks.
Pair< int > const & inPropagatorId(int i) const
Get the block and direction of an incoming propagator.
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
Dbl()
Default constructor.
A FileMaster manages input and output files for a simulation.
Int()
Default constructor.
An array of exactly 2 objects.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
SCFT with real 1D fields.
PSCF package top-level namespace.
float product(float a, float b)
Product for float Data.